Fossil SCM
When running the changes or status command from inside a sub-directory of the check out, only show the changes in or below the current directory unless the --show-all option is used.
Commit
e0d2e1f9b85eab0b0eb788a2820161a27ba9a761
Parent
35ecc92b69f7d0a…
1 file changed
+55
-14
+55
-14
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -32,57 +32,91 @@ | ||
| 32 | 32 | ** are not true files results in a fatal error. |
| 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 | - int missingIsFatal /* MISSING and NOT_A_FILE are fatal errors */ | |
| 37 | + int missingIsFatal, /* MISSING and NOT_A_FILE are fatal errors */ | |
| 38 | + int reportSubdirOnly /* Only report for the current sub-dir */ | |
| 38 | 39 | ){ |
| 39 | 40 | Stmt q; |
| 40 | 41 | int nPrefix = strlen(zPrefix); |
| 41 | 42 | int nErr = 0; |
| 43 | + Blob currentDir, rootDir; | |
| 44 | + const char *zShowSubDir = 0; | |
| 45 | + int showSubDirLen = 0; | |
| 46 | + int otherChanges = 0; | |
| 42 | 47 | db_prepare(&q, |
| 43 | 48 | "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)" |
| 44 | 49 | " FROM vfile " |
| 45 | 50 | " WHERE file_is_selected(id)" |
| 46 | 51 | " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1" |
| 47 | 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 */ | |
| 48 | 71 | while( db_step(&q)==SQLITE_ROW ){ |
| 49 | 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 | + } | |
| 50 | 84 | int isDeleted = db_column_int(&q, 1); |
| 51 | 85 | int isChnged = db_column_int(&q,2); |
| 52 | 86 | int isNew = db_column_int(&q,3)==0; |
| 53 | 87 | int isRenamed = db_column_int(&q,4); |
| 54 | 88 | char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname); |
| 55 | 89 | blob_append(report, zPrefix, nPrefix); |
| 56 | 90 | if( isDeleted ){ |
| 57 | - blob_appendf(report, "DELETED %s\n", zPathname); | |
| 91 | + blob_appendf(report, "DELETED %s\n", zDisplayName); | |
| 58 | 92 | }else if( !file_isfile(zFullName) ){ |
| 59 | 93 | if( file_access(zFullName, 0)==0 ){ |
| 60 | - blob_appendf(report, "NOT_A_FILE %s\n", zPathname); | |
| 94 | + blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName); | |
| 61 | 95 | if( missingIsFatal ){ |
| 62 | - fossil_warning("not a file: %s", zPathname); | |
| 96 | + fossil_warning("not a file: %s", zDisplayName); | |
| 63 | 97 | nErr++; |
| 64 | 98 | } |
| 65 | 99 | }else{ |
| 66 | - blob_appendf(report, "MISSING %s\n", zPathname); | |
| 100 | + blob_appendf(report, "MISSING %s\n", zDisplayName); | |
| 67 | 101 | if( missingIsFatal ){ |
| 68 | - fossil_warning("missing file: %s", zPathname); | |
| 102 | + fossil_warning("missing file: %s", zDisplayName); | |
| 69 | 103 | nErr++; |
| 70 | 104 | } |
| 71 | 105 | } |
| 72 | 106 | }else if( isNew ){ |
| 73 | - blob_appendf(report, "ADDED %s\n", zPathname); | |
| 107 | + blob_appendf(report, "ADDED %s\n", zDisplayName); | |
| 74 | 108 | }else if( isDeleted ){ |
| 75 | - blob_appendf(report, "DELETED %s\n", zPathname); | |
| 109 | + blob_appendf(report, "DELETED %s\n", zDisplayName); | |
| 76 | 110 | }else if( isChnged==2 ){ |
| 77 | - blob_appendf(report, "UPDATED_BY_MERGE %s\n", zPathname); | |
| 111 | + blob_appendf(report, "UPDATED_BY_MERGE %s\n", zDisplayName); | |
| 78 | 112 | }else if( isChnged==3 ){ |
| 79 | - blob_appendf(report, "ADDED_BY_MERGE %s\n", zPathname); | |
| 113 | + blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName); | |
| 80 | 114 | }else if( isChnged==1 ){ |
| 81 | - blob_appendf(report, "EDITED %s\n", zPathname); | |
| 115 | + blob_appendf(report, "EDITED %s\n", zDisplayName); | |
| 82 | 116 | }else if( isRenamed ){ |
| 83 | - blob_appendf(report, "RENAMED %s\n", zPathname); | |
| 117 | + blob_appendf(report, "RENAMED %s\n", zDisplayName); | |
| 84 | 118 | } |
| 85 | 119 | free(zFullName); |
| 86 | 120 | } |
| 87 | 121 | db_finalize(&q); |
| 88 | 122 | db_prepare(&q, "SELECT uuid FROM vmerge JOIN blob ON merge=rid" |
| @@ -90,10 +124,13 @@ | ||
| 90 | 124 | while( db_step(&q)==SQLITE_ROW ){ |
| 91 | 125 | blob_append(report, zPrefix, nPrefix); |
| 92 | 126 | blob_appendf(report, "MERGED_WITH %s\n", db_column_text(&q, 0)); |
| 93 | 127 | } |
| 94 | 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 | + } | |
| 95 | 132 | if( nErr ){ |
| 96 | 133 | fossil_fatal("aborting due to prior errors"); |
| 97 | 134 | } |
| 98 | 135 | } |
| 99 | 136 | |
| @@ -107,20 +144,24 @@ | ||
| 107 | 144 | ** |
| 108 | 145 | ** Options: |
| 109 | 146 | ** |
| 110 | 147 | ** --sha1sum Verify file status using SHA1 hashing rather |
| 111 | 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. | |
| 112 | 152 | */ |
| 113 | 153 | void changes_cmd(void){ |
| 114 | 154 | Blob report; |
| 115 | 155 | int vid; |
| 116 | 156 | int useSha1sum = find_option("sha1sum", 0, 0)!=0; |
| 157 | + int showAllFlag = find_option("show-all","S",0)!=0; | |
| 117 | 158 | db_must_be_within_tree(); |
| 118 | 159 | blob_zero(&report); |
| 119 | 160 | vid = db_lget_int("checkout", 0); |
| 120 | 161 | vfile_check_signature(vid, 0, useSha1sum); |
| 121 | - status_report(&report, "", 0); | |
| 162 | + status_report(&report, "", 0, !showAllFlag); | |
| 122 | 163 | blob_write_to_file(&report, "-"); |
| 123 | 164 | } |
| 124 | 165 | |
| 125 | 166 | /* |
| 126 | 167 | ** COMMAND: status |
| @@ -367,11 +408,11 @@ | ||
| 367 | 408 | "# PRIVATE BRANCH: This check-in will be private and will not sync to\n" |
| 368 | 409 | "# repositories.\n" |
| 369 | 410 | "#\n", -1 |
| 370 | 411 | ); |
| 371 | 412 | } |
| 372 | - status_report(&text, "# ", 1); | |
| 413 | + status_report(&text, "# ", 1, 0); | |
| 373 | 414 | zEditor = db_get("editor", 0); |
| 374 | 415 | if( zEditor==0 ){ |
| 375 | 416 | zEditor = getenv("VISUAL"); |
| 376 | 417 | } |
| 377 | 418 | if( zEditor==0 ){ |
| 378 | 419 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -32,57 +32,91 @@ | |
| 32 | ** are not true files results in a fatal error. |
| 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 | ){ |
| 39 | Stmt q; |
| 40 | int nPrefix = strlen(zPrefix); |
| 41 | int nErr = 0; |
| 42 | db_prepare(&q, |
| 43 | "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)" |
| 44 | " FROM vfile " |
| 45 | " WHERE file_is_selected(id)" |
| 46 | " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1" |
| 47 | ); |
| 48 | while( db_step(&q)==SQLITE_ROW ){ |
| 49 | const char *zPathname = db_column_text(&q,0); |
| 50 | int isDeleted = db_column_int(&q, 1); |
| 51 | int isChnged = db_column_int(&q,2); |
| 52 | int isNew = db_column_int(&q,3)==0; |
| 53 | int isRenamed = db_column_int(&q,4); |
| 54 | char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname); |
| 55 | blob_append(report, zPrefix, nPrefix); |
| 56 | if( isDeleted ){ |
| 57 | blob_appendf(report, "DELETED %s\n", zPathname); |
| 58 | }else if( !file_isfile(zFullName) ){ |
| 59 | if( file_access(zFullName, 0)==0 ){ |
| 60 | blob_appendf(report, "NOT_A_FILE %s\n", zPathname); |
| 61 | if( missingIsFatal ){ |
| 62 | fossil_warning("not a file: %s", zPathname); |
| 63 | nErr++; |
| 64 | } |
| 65 | }else{ |
| 66 | blob_appendf(report, "MISSING %s\n", zPathname); |
| 67 | if( missingIsFatal ){ |
| 68 | fossil_warning("missing file: %s", zPathname); |
| 69 | nErr++; |
| 70 | } |
| 71 | } |
| 72 | }else if( isNew ){ |
| 73 | blob_appendf(report, "ADDED %s\n", zPathname); |
| 74 | }else if( isDeleted ){ |
| 75 | blob_appendf(report, "DELETED %s\n", zPathname); |
| 76 | }else if( isChnged==2 ){ |
| 77 | blob_appendf(report, "UPDATED_BY_MERGE %s\n", zPathname); |
| 78 | }else if( isChnged==3 ){ |
| 79 | blob_appendf(report, "ADDED_BY_MERGE %s\n", zPathname); |
| 80 | }else if( isChnged==1 ){ |
| 81 | blob_appendf(report, "EDITED %s\n", zPathname); |
| 82 | }else if( isRenamed ){ |
| 83 | blob_appendf(report, "RENAMED %s\n", zPathname); |
| 84 | } |
| 85 | free(zFullName); |
| 86 | } |
| 87 | db_finalize(&q); |
| 88 | db_prepare(&q, "SELECT uuid FROM vmerge JOIN blob ON merge=rid" |
| @@ -90,10 +124,13 @@ | |
| 90 | while( db_step(&q)==SQLITE_ROW ){ |
| 91 | blob_append(report, zPrefix, nPrefix); |
| 92 | blob_appendf(report, "MERGED_WITH %s\n", db_column_text(&q, 0)); |
| 93 | } |
| 94 | db_finalize(&q); |
| 95 | if( nErr ){ |
| 96 | fossil_fatal("aborting due to prior errors"); |
| 97 | } |
| 98 | } |
| 99 | |
| @@ -107,20 +144,24 @@ | |
| 107 | ** |
| 108 | ** Options: |
| 109 | ** |
| 110 | ** --sha1sum Verify file status using SHA1 hashing rather |
| 111 | ** than relying on file mtimes. |
| 112 | */ |
| 113 | void changes_cmd(void){ |
| 114 | Blob report; |
| 115 | int vid; |
| 116 | int useSha1sum = find_option("sha1sum", 0, 0)!=0; |
| 117 | db_must_be_within_tree(); |
| 118 | blob_zero(&report); |
| 119 | vid = db_lget_int("checkout", 0); |
| 120 | vfile_check_signature(vid, 0, useSha1sum); |
| 121 | status_report(&report, "", 0); |
| 122 | blob_write_to_file(&report, "-"); |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | ** COMMAND: status |
| @@ -367,11 +408,11 @@ | |
| 367 | "# PRIVATE BRANCH: This check-in will be private and will not sync to\n" |
| 368 | "# repositories.\n" |
| 369 | "#\n", -1 |
| 370 | ); |
| 371 | } |
| 372 | status_report(&text, "# ", 1); |
| 373 | zEditor = db_get("editor", 0); |
| 374 | if( zEditor==0 ){ |
| 375 | zEditor = getenv("VISUAL"); |
| 376 | } |
| 377 | if( zEditor==0 ){ |
| 378 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -32,57 +32,91 @@ | |
| 32 | ** are not true files results in a fatal error. |
| 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 ){ |
| 94 | blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName); |
| 95 | if( missingIsFatal ){ |
| 96 | fossil_warning("not a file: %s", zDisplayName); |
| 97 | nErr++; |
| 98 | } |
| 99 | }else{ |
| 100 | blob_appendf(report, "MISSING %s\n", zDisplayName); |
| 101 | if( missingIsFatal ){ |
| 102 | fossil_warning("missing file: %s", zDisplayName); |
| 103 | nErr++; |
| 104 | } |
| 105 | } |
| 106 | }else if( isNew ){ |
| 107 | blob_appendf(report, "ADDED %s\n", zDisplayName); |
| 108 | }else if( isDeleted ){ |
| 109 | blob_appendf(report, "DELETED %s\n", zDisplayName); |
| 110 | }else if( isChnged==2 ){ |
| 111 | blob_appendf(report, "UPDATED_BY_MERGE %s\n", zDisplayName); |
| 112 | }else if( isChnged==3 ){ |
| 113 | blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName); |
| 114 | }else if( isChnged==1 ){ |
| 115 | blob_appendf(report, "EDITED %s\n", zDisplayName); |
| 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" |
| @@ -90,10 +124,13 @@ | |
| 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 | |
| @@ -107,20 +144,24 @@ | |
| 144 | ** |
| 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 |
| @@ -367,11 +408,11 @@ | |
| 408 | "# PRIVATE BRANCH: This check-in will be private and will not sync to\n" |
| 409 | "# repositories.\n" |
| 410 | "#\n", -1 |
| 411 | ); |
| 412 | } |
| 413 | status_report(&text, "# ", 1, 0); |
| 414 | zEditor = db_get("editor", 0); |
| 415 | if( zEditor==0 ){ |
| 416 | zEditor = getenv("VISUAL"); |
| 417 | } |
| 418 | if( zEditor==0 ){ |
| 419 |