Fossil SCM
By default, the changes and status commands list all changed files relative to the current working directory, unless the --non-relative option is used.
Commit
a05bbff46acb84964af5aaae53b11f6939030a38
Parent
e0d2e1f9b85eab0…
1 file changed
+15
-40
+15
-40
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -33,61 +33,38 @@ | ||
| 33 | 33 | */ |
| 34 | 34 | static void status_report( |
| 35 | 35 | Blob *report, /* Append the status report here */ |
| 36 | 36 | const char *zPrefix, /* Prefix on each line of the report */ |
| 37 | 37 | int missingIsFatal, /* MISSING and NOT_A_FILE are fatal errors */ |
| 38 | - int reportSubdirOnly /* Only report for the current sub-dir */ | |
| 38 | + int cwdRelative /* Report relative to the current working dir */ | |
| 39 | 39 | ){ |
| 40 | 40 | Stmt q; |
| 41 | 41 | int nPrefix = strlen(zPrefix); |
| 42 | 42 | int nErr = 0; |
| 43 | - Blob currentDir, rootDir; | |
| 44 | - const char *zShowSubDir = 0; | |
| 45 | - int showSubDirLen = 0; | |
| 46 | - int otherChanges = 0; | |
| 43 | + Blob rewrittenPathname; | |
| 47 | 44 | db_prepare(&q, |
| 48 | 45 | "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)" |
| 49 | 46 | " FROM vfile " |
| 50 | 47 | " WHERE file_is_selected(id)" |
| 51 | 48 | " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1" |
| 52 | 49 | ); |
| 53 | - /* If sub-directory only reports are acceptable, check to see if we're | |
| 54 | - ** in a sub-directory of the checkout. */ | |
| 55 | - if( reportSubdirOnly ){ | |
| 56 | - blob_zero(¤tDir); | |
| 57 | - file_canonical_name(".", ¤tDir); | |
| 58 | - blob_zero(&rootDir); | |
| 59 | - file_canonical_name(g.zLocalRoot, &rootDir); | |
| 60 | - if( blob_compare(¤tDir, &rootDir)!=0 | |
| 61 | - && blob_size(¤tDir)>blob_size(&rootDir) ){ | |
| 62 | - /* Current directory is not the root of the repository */ | |
| 63 | - blob_appendf(report, "%sIn sub-directory %s:\n", zPrefix, | |
| 64 | - blob_str(¤tDir) + blob_size(&rootDir) + 1); | |
| 65 | - blob_append(¤tDir,"/",1); | |
| 66 | - zShowSubDir = blob_str(¤tDir) + blob_size(&rootDir) + 1; | |
| 67 | - showSubDirLen = blob_size(¤tDir) - blob_size(&rootDir) - 1; | |
| 68 | - } | |
| 69 | - } | |
| 70 | - /* Show the changes */ | |
| 50 | + blob_zero(&rewrittenPathname); | |
| 71 | 51 | while( db_step(&q)==SQLITE_ROW ){ |
| 72 | 52 | const char *zPathname = db_column_text(&q,0); |
| 73 | 53 | const char *zDisplayName = zPathname; |
| 74 | - if( zShowSubDir!=0 ){ | |
| 75 | - if( strncmp(zPathname,zShowSubDir,showSubDirLen)!=0 ){ | |
| 76 | - /* Not in sub-directory, don't display this file */ | |
| 77 | - otherChanges++; | |
| 78 | - continue; | |
| 79 | - }else{ | |
| 80 | - /* In sub directory, so hide the prefix */ | |
| 81 | - zDisplayName += showSubDirLen; | |
| 82 | - } | |
| 83 | - } | |
| 84 | 54 | int isDeleted = db_column_int(&q, 1); |
| 85 | 55 | int isChnged = db_column_int(&q,2); |
| 86 | 56 | int isNew = db_column_int(&q,3)==0; |
| 87 | 57 | int isRenamed = db_column_int(&q,4); |
| 88 | 58 | char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname); |
| 59 | + if( cwdRelative ){ | |
| 60 | + file_relative_name(zFullName, &rewrittenPathname); | |
| 61 | + zDisplayName = blob_str(&rewrittenPathname); | |
| 62 | + if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){ | |
| 63 | + zDisplayName += 2; /* no unnecessary ./ prefix */ | |
| 64 | + } | |
| 65 | + } | |
| 89 | 66 | blob_append(report, zPrefix, nPrefix); |
| 90 | 67 | if( isDeleted ){ |
| 91 | 68 | blob_appendf(report, "DELETED %s\n", zDisplayName); |
| 92 | 69 | }else if( !file_isfile(zFullName) ){ |
| 93 | 70 | if( file_access(zFullName, 0)==0 ){ |
| @@ -116,21 +93,19 @@ | ||
| 116 | 93 | }else if( isRenamed ){ |
| 117 | 94 | blob_appendf(report, "RENAMED %s\n", zDisplayName); |
| 118 | 95 | } |
| 119 | 96 | free(zFullName); |
| 120 | 97 | } |
| 98 | + blob_reset(&rewrittenPathname); | |
| 121 | 99 | db_finalize(&q); |
| 122 | 100 | db_prepare(&q, "SELECT uuid FROM vmerge JOIN blob ON merge=rid" |
| 123 | 101 | " WHERE id=0"); |
| 124 | 102 | while( db_step(&q)==SQLITE_ROW ){ |
| 125 | 103 | blob_append(report, zPrefix, nPrefix); |
| 126 | 104 | blob_appendf(report, "MERGED_WITH %s\n", db_column_text(&q, 0)); |
| 127 | 105 | } |
| 128 | 106 | db_finalize(&q); |
| 129 | - if( otherChanges!=0 ){ | |
| 130 | - blob_appendf(report, "%d other changes. Use --show-all option to list all changes.\n"); | |
| 131 | - } | |
| 132 | 107 | if( nErr ){ |
| 133 | 108 | fossil_fatal("aborting due to prior errors"); |
| 134 | 109 | } |
| 135 | 110 | } |
| 136 | 111 | |
| @@ -145,23 +120,23 @@ | ||
| 145 | 120 | ** Options: |
| 146 | 121 | ** |
| 147 | 122 | ** --sha1sum Verify file status using SHA1 hashing rather |
| 148 | 123 | ** than relying on file mtimes. |
| 149 | 124 | ** |
| 150 | -** --show-all When invoked from a sub-directory, show changes | |
| 151 | -** even if they're outside the current directory. | |
| 125 | +** --non-relative Don't display filenames relative to the current | |
| 126 | +** working directory. | |
| 152 | 127 | */ |
| 153 | 128 | void changes_cmd(void){ |
| 154 | 129 | Blob report; |
| 155 | 130 | int vid; |
| 156 | 131 | int useSha1sum = find_option("sha1sum", 0, 0)!=0; |
| 157 | - int showAllFlag = find_option("show-all","S",0)!=0; | |
| 132 | + int nonRelative = find_option("non-relative", 0, 0)!=0; | |
| 158 | 133 | db_must_be_within_tree(); |
| 159 | 134 | blob_zero(&report); |
| 160 | 135 | vid = db_lget_int("checkout", 0); |
| 161 | 136 | vfile_check_signature(vid, 0, useSha1sum); |
| 162 | - status_report(&report, "", 0, !showAllFlag); | |
| 137 | + status_report(&report, "", 0, !nonRelative); | |
| 163 | 138 | blob_write_to_file(&report, "-"); |
| 164 | 139 | } |
| 165 | 140 | |
| 166 | 141 | /* |
| 167 | 142 | ** COMMAND: status |
| 168 | 143 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -33,61 +33,38 @@ | |
| 33 | */ |
| 34 | static void status_report( |
| 35 | Blob *report, /* Append the status report here */ |
| 36 | const char *zPrefix, /* Prefix on each line of the report */ |
| 37 | int missingIsFatal, /* MISSING and NOT_A_FILE are fatal errors */ |
| 38 | int reportSubdirOnly /* Only report for the current sub-dir */ |
| 39 | ){ |
| 40 | Stmt q; |
| 41 | int nPrefix = strlen(zPrefix); |
| 42 | int nErr = 0; |
| 43 | Blob currentDir, rootDir; |
| 44 | const char *zShowSubDir = 0; |
| 45 | int showSubDirLen = 0; |
| 46 | int otherChanges = 0; |
| 47 | db_prepare(&q, |
| 48 | "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)" |
| 49 | " FROM vfile " |
| 50 | " WHERE file_is_selected(id)" |
| 51 | " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1" |
| 52 | ); |
| 53 | /* If sub-directory only reports are acceptable, check to see if we're |
| 54 | ** in a sub-directory of the checkout. */ |
| 55 | if( reportSubdirOnly ){ |
| 56 | blob_zero(¤tDir); |
| 57 | file_canonical_name(".", ¤tDir); |
| 58 | blob_zero(&rootDir); |
| 59 | file_canonical_name(g.zLocalRoot, &rootDir); |
| 60 | if( blob_compare(¤tDir, &rootDir)!=0 |
| 61 | && blob_size(¤tDir)>blob_size(&rootDir) ){ |
| 62 | /* Current directory is not the root of the repository */ |
| 63 | blob_appendf(report, "%sIn sub-directory %s:\n", zPrefix, |
| 64 | blob_str(¤tDir) + blob_size(&rootDir) + 1); |
| 65 | blob_append(¤tDir,"/",1); |
| 66 | zShowSubDir = blob_str(¤tDir) + blob_size(&rootDir) + 1; |
| 67 | showSubDirLen = blob_size(¤tDir) - blob_size(&rootDir) - 1; |
| 68 | } |
| 69 | } |
| 70 | /* Show the changes */ |
| 71 | while( db_step(&q)==SQLITE_ROW ){ |
| 72 | const char *zPathname = db_column_text(&q,0); |
| 73 | const char *zDisplayName = zPathname; |
| 74 | if( zShowSubDir!=0 ){ |
| 75 | if( strncmp(zPathname,zShowSubDir,showSubDirLen)!=0 ){ |
| 76 | /* Not in sub-directory, don't display this file */ |
| 77 | otherChanges++; |
| 78 | continue; |
| 79 | }else{ |
| 80 | /* In sub directory, so hide the prefix */ |
| 81 | zDisplayName += showSubDirLen; |
| 82 | } |
| 83 | } |
| 84 | int isDeleted = db_column_int(&q, 1); |
| 85 | int isChnged = db_column_int(&q,2); |
| 86 | int isNew = db_column_int(&q,3)==0; |
| 87 | int isRenamed = db_column_int(&q,4); |
| 88 | char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname); |
| 89 | blob_append(report, zPrefix, nPrefix); |
| 90 | if( isDeleted ){ |
| 91 | blob_appendf(report, "DELETED %s\n", zDisplayName); |
| 92 | }else if( !file_isfile(zFullName) ){ |
| 93 | if( file_access(zFullName, 0)==0 ){ |
| @@ -116,21 +93,19 @@ | |
| 116 | }else if( isRenamed ){ |
| 117 | blob_appendf(report, "RENAMED %s\n", zDisplayName); |
| 118 | } |
| 119 | free(zFullName); |
| 120 | } |
| 121 | db_finalize(&q); |
| 122 | db_prepare(&q, "SELECT uuid FROM vmerge JOIN blob ON merge=rid" |
| 123 | " WHERE id=0"); |
| 124 | while( db_step(&q)==SQLITE_ROW ){ |
| 125 | blob_append(report, zPrefix, nPrefix); |
| 126 | blob_appendf(report, "MERGED_WITH %s\n", db_column_text(&q, 0)); |
| 127 | } |
| 128 | db_finalize(&q); |
| 129 | if( otherChanges!=0 ){ |
| 130 | blob_appendf(report, "%d other changes. Use --show-all option to list all changes.\n"); |
| 131 | } |
| 132 | if( nErr ){ |
| 133 | fossil_fatal("aborting due to prior errors"); |
| 134 | } |
| 135 | } |
| 136 | |
| @@ -145,23 +120,23 @@ | |
| 145 | ** Options: |
| 146 | ** |
| 147 | ** --sha1sum Verify file status using SHA1 hashing rather |
| 148 | ** than relying on file mtimes. |
| 149 | ** |
| 150 | ** --show-all When invoked from a sub-directory, show changes |
| 151 | ** even if they're outside the current directory. |
| 152 | */ |
| 153 | void changes_cmd(void){ |
| 154 | Blob report; |
| 155 | int vid; |
| 156 | int useSha1sum = find_option("sha1sum", 0, 0)!=0; |
| 157 | int showAllFlag = find_option("show-all","S",0)!=0; |
| 158 | db_must_be_within_tree(); |
| 159 | blob_zero(&report); |
| 160 | vid = db_lget_int("checkout", 0); |
| 161 | vfile_check_signature(vid, 0, useSha1sum); |
| 162 | status_report(&report, "", 0, !showAllFlag); |
| 163 | blob_write_to_file(&report, "-"); |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | ** COMMAND: status |
| 168 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -33,61 +33,38 @@ | |
| 33 | */ |
| 34 | static void status_report( |
| 35 | Blob *report, /* Append the status report here */ |
| 36 | const char *zPrefix, /* Prefix on each line of the report */ |
| 37 | int missingIsFatal, /* MISSING and NOT_A_FILE are fatal errors */ |
| 38 | int cwdRelative /* Report relative to the current working dir */ |
| 39 | ){ |
| 40 | Stmt q; |
| 41 | int nPrefix = strlen(zPrefix); |
| 42 | int nErr = 0; |
| 43 | Blob rewrittenPathname; |
| 44 | db_prepare(&q, |
| 45 | "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)" |
| 46 | " FROM vfile " |
| 47 | " WHERE file_is_selected(id)" |
| 48 | " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1" |
| 49 | ); |
| 50 | blob_zero(&rewrittenPathname); |
| 51 | while( db_step(&q)==SQLITE_ROW ){ |
| 52 | const char *zPathname = db_column_text(&q,0); |
| 53 | const char *zDisplayName = zPathname; |
| 54 | int isDeleted = db_column_int(&q, 1); |
| 55 | int isChnged = db_column_int(&q,2); |
| 56 | int isNew = db_column_int(&q,3)==0; |
| 57 | int isRenamed = db_column_int(&q,4); |
| 58 | char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname); |
| 59 | if( cwdRelative ){ |
| 60 | file_relative_name(zFullName, &rewrittenPathname); |
| 61 | zDisplayName = blob_str(&rewrittenPathname); |
| 62 | if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){ |
| 63 | zDisplayName += 2; /* no unnecessary ./ prefix */ |
| 64 | } |
| 65 | } |
| 66 | blob_append(report, zPrefix, nPrefix); |
| 67 | if( isDeleted ){ |
| 68 | blob_appendf(report, "DELETED %s\n", zDisplayName); |
| 69 | }else if( !file_isfile(zFullName) ){ |
| 70 | if( file_access(zFullName, 0)==0 ){ |
| @@ -116,21 +93,19 @@ | |
| 93 | }else if( isRenamed ){ |
| 94 | blob_appendf(report, "RENAMED %s\n", zDisplayName); |
| 95 | } |
| 96 | free(zFullName); |
| 97 | } |
| 98 | blob_reset(&rewrittenPathname); |
| 99 | db_finalize(&q); |
| 100 | db_prepare(&q, "SELECT uuid FROM vmerge JOIN blob ON merge=rid" |
| 101 | " WHERE id=0"); |
| 102 | while( db_step(&q)==SQLITE_ROW ){ |
| 103 | blob_append(report, zPrefix, nPrefix); |
| 104 | blob_appendf(report, "MERGED_WITH %s\n", db_column_text(&q, 0)); |
| 105 | } |
| 106 | db_finalize(&q); |
| 107 | if( nErr ){ |
| 108 | fossil_fatal("aborting due to prior errors"); |
| 109 | } |
| 110 | } |
| 111 | |
| @@ -145,23 +120,23 @@ | |
| 120 | ** Options: |
| 121 | ** |
| 122 | ** --sha1sum Verify file status using SHA1 hashing rather |
| 123 | ** than relying on file mtimes. |
| 124 | ** |
| 125 | ** --non-relative Don't display filenames relative to the current |
| 126 | ** working directory. |
| 127 | */ |
| 128 | void changes_cmd(void){ |
| 129 | Blob report; |
| 130 | int vid; |
| 131 | int useSha1sum = find_option("sha1sum", 0, 0)!=0; |
| 132 | int nonRelative = find_option("non-relative", 0, 0)!=0; |
| 133 | db_must_be_within_tree(); |
| 134 | blob_zero(&report); |
| 135 | vid = db_lget_int("checkout", 0); |
| 136 | vfile_check_signature(vid, 0, useSha1sum); |
| 137 | status_report(&report, "", 0, !nonRelative); |
| 138 | blob_write_to_file(&report, "-"); |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | ** COMMAND: status |
| 143 |