Fossil SCM
More robust exclusion of the -v diff when extracting the comment message from the user's editor output. Enhance the -n (--dryrun) flag on "fossil commit" so that it goes through the commit prompt sequence for debugging.
Commit
4eca7eb902b5576da1bb060712cde9d41fa6197030bbc78457ddcb4f98645088
Parent
7ee98fea2d28090…
1 file changed
+20
-16
+20
-16
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -1209,17 +1209,24 @@ | ||
| 1209 | 1209 | #if defined(_WIN32) |
| 1210 | 1210 | blob_add_cr(pPrompt); |
| 1211 | 1211 | #endif |
| 1212 | 1212 | if( blob_size(pPrompt)>0 ) blob_write_to_file(pPrompt, zFile); |
| 1213 | 1213 | if( zEditor ){ |
| 1214 | + char *z, *zEnd; | |
| 1214 | 1215 | zCmd = mprintf("%s %$", zEditor, zFile); |
| 1215 | 1216 | fossil_print("%s\n", zCmd); |
| 1216 | 1217 | if( fossil_system(zCmd) ){ |
| 1217 | 1218 | fossil_fatal("editor aborted: \"%s\"", zCmd); |
| 1218 | 1219 | } |
| 1219 | - | |
| 1220 | 1220 | blob_read_from_file(&reply, zFile, ExtFILE); |
| 1221 | + z = blob_str(&reply); | |
| 1222 | + zEnd = strstr(z, "##########"); | |
| 1223 | + if( zEnd ){ | |
| 1224 | + /* Truncate the reply at any sequence of 10 or more # characters. | |
| 1225 | + ** The diff for the -v option occurs after such a sequence. */ | |
| 1226 | + blob_resize(&reply, (int)(zEnd - z)); | |
| 1227 | + } | |
| 1221 | 1228 | }else{ |
| 1222 | 1229 | char zIn[300]; |
| 1223 | 1230 | blob_zero(&reply); |
| 1224 | 1231 | while( fgets(zIn, sizeof(zIn), stdin)!=0 ){ |
| 1225 | 1232 | if( zIn[0]=='.' && (zIn[1]==0 || zIn[1]=='\r' || zIn[1]=='\n') ){ |
| @@ -1237,15 +1244,10 @@ | ||
| 1237 | 1244 | int i, n; |
| 1238 | 1245 | char *z; |
| 1239 | 1246 | n = blob_size(&line); |
| 1240 | 1247 | z = blob_buffer(&line); |
| 1241 | 1248 | for(i=0; i<n && fossil_isspace(z[i]); i++){} |
| 1242 | - if( fossil_strncmp( | |
| 1243 | - "# NOTE: The below diff is not inserted into the commit message.\n", | |
| 1244 | - z, n)==0 ){ | |
| 1245 | - break; | |
| 1246 | - } | |
| 1247 | 1249 | if( i<n && z[i]=='#' ) continue; |
| 1248 | 1250 | if( i<n || blob_size(pComment)>0 ){ |
| 1249 | 1251 | blob_appendf(pComment, "%b", &line); |
| 1250 | 1252 | } |
| 1251 | 1253 | } |
| @@ -1275,11 +1277,12 @@ | ||
| 1275 | 1277 | */ |
| 1276 | 1278 | static void prepare_commit_comment( |
| 1277 | 1279 | Blob *pComment, |
| 1278 | 1280 | char *zInit, |
| 1279 | 1281 | CheckinInfo *p, |
| 1280 | - int parent_rid | |
| 1282 | + int parent_rid, | |
| 1283 | + int dryRunFlag | |
| 1281 | 1284 | ){ |
| 1282 | 1285 | Blob prompt; |
| 1283 | 1286 | #if defined(_WIN32) || defined(__CYGWIN__) |
| 1284 | 1287 | int bomSize; |
| 1285 | 1288 | const unsigned char *bom = get_utf8_bom(&bomSize); |
| @@ -1294,10 +1297,14 @@ | ||
| 1294 | 1297 | "\n" |
| 1295 | 1298 | "# Enter a commit message for this check-in." |
| 1296 | 1299 | " Lines beginning with # are ignored.\n" |
| 1297 | 1300 | "#\n", -1 |
| 1298 | 1301 | ); |
| 1302 | + if( dryRunFlag ){ | |
| 1303 | + blob_appendf(&prompt, "# DRY-RUN: This is a test commit. No changes " | |
| 1304 | + "will be made to the repository\n#\n"); | |
| 1305 | + } | |
| 1299 | 1306 | blob_appendf(&prompt, "# user: %s\n", |
| 1300 | 1307 | p->zUserOvrd ? p->zUserOvrd : login_name()); |
| 1301 | 1308 | if( p->zBranch && p->zBranch[0] ){ |
| 1302 | 1309 | blob_appendf(&prompt, "# tags: %s\n#\n", p->zBranch); |
| 1303 | 1310 | }else{ |
| @@ -1331,14 +1338,14 @@ | ||
| 1331 | 1338 | "# All merged-in branches will be closed due to the --integrate flag\n" |
| 1332 | 1339 | "#\n", -1 |
| 1333 | 1340 | ); |
| 1334 | 1341 | } |
| 1335 | 1342 | if( p->verboseFlag ){ |
| 1336 | - blob_append(&prompt, | |
| 1337 | - "#\n" | |
| 1338 | - "# NOTE: The below diff is not inserted into the commit message.\n\n", | |
| 1339 | - -1 | |
| 1343 | + blob_appendf(&prompt, | |
| 1344 | + "#\n%.78c\n" | |
| 1345 | + "# The following diff is excluded from the commit message:\n#\n", | |
| 1346 | + '#' | |
| 1340 | 1347 | ); |
| 1341 | 1348 | if( g.aCommitFile ){ |
| 1342 | 1349 | FileDirList *diffFiles; |
| 1343 | 1350 | int i; |
| 1344 | 1351 | diffFiles = fossil_malloc_zero((g.argc-1) * sizeof(*diffFiles)); |
| @@ -2130,12 +2137,11 @@ | ||
| 2130 | 2137 | ** --integrate close all merged-in branches |
| 2131 | 2138 | ** -m|--comment COMMENT-TEXT use COMMENT-TEXT as commit comment |
| 2132 | 2139 | ** -M|--message-file FILE read the commit comment from given file |
| 2133 | 2140 | ** --mimetype MIMETYPE mimetype of check-in comment |
| 2134 | 2141 | ** -n|--dry-run If given, display instead of run actions |
| 2135 | -** -v|--verbose Display in the editor a unified diff of the | |
| 2136 | -** changes to be committed with this check-in | |
| 2142 | +** -v|--verbose Show a diff in the commit message prompt | |
| 2137 | 2143 | ** --no-prompt This option disables prompting the user for |
| 2138 | 2144 | ** input and assumes an answer of 'No' for every |
| 2139 | 2145 | ** question. |
| 2140 | 2146 | ** --no-warnings omit all warnings about file contents |
| 2141 | 2147 | ** --no-verify do not run before-commit hooks |
| @@ -2484,15 +2490,13 @@ | ||
| 2484 | 2490 | blob_append(&comment, zComment, -1); |
| 2485 | 2491 | }else if( zComFile ){ |
| 2486 | 2492 | blob_zero(&comment); |
| 2487 | 2493 | blob_read_from_file(&comment, zComFile, ExtFILE); |
| 2488 | 2494 | blob_to_utf8_no_bom(&comment, 1); |
| 2489 | - }else if( dryRunFlag ){ | |
| 2490 | - blob_zero(&comment); | |
| 2491 | 2495 | }else if( !noPrompt ){ |
| 2492 | 2496 | char *zInit = db_text(0,"SELECT value FROM vvar WHERE name='ci-comment'"); |
| 2493 | - prepare_commit_comment(&comment, zInit, &sCiInfo, vid); | |
| 2497 | + prepare_commit_comment(&comment, zInit, &sCiInfo, vid, dryRunFlag); | |
| 2494 | 2498 | if( zInit && zInit[0] && fossil_strcmp(zInit, blob_str(&comment))==0 ){ |
| 2495 | 2499 | prompt_user("unchanged check-in comment. continue (y/N)? ", &ans); |
| 2496 | 2500 | cReply = blob_str(&ans)[0]; |
| 2497 | 2501 | blob_reset(&ans); |
| 2498 | 2502 | if( cReply!='y' && cReply!='Y' ){ |
| 2499 | 2503 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -1209,17 +1209,24 @@ | |
| 1209 | #if defined(_WIN32) |
| 1210 | blob_add_cr(pPrompt); |
| 1211 | #endif |
| 1212 | if( blob_size(pPrompt)>0 ) blob_write_to_file(pPrompt, zFile); |
| 1213 | if( zEditor ){ |
| 1214 | zCmd = mprintf("%s %$", zEditor, zFile); |
| 1215 | fossil_print("%s\n", zCmd); |
| 1216 | if( fossil_system(zCmd) ){ |
| 1217 | fossil_fatal("editor aborted: \"%s\"", zCmd); |
| 1218 | } |
| 1219 | |
| 1220 | blob_read_from_file(&reply, zFile, ExtFILE); |
| 1221 | }else{ |
| 1222 | char zIn[300]; |
| 1223 | blob_zero(&reply); |
| 1224 | while( fgets(zIn, sizeof(zIn), stdin)!=0 ){ |
| 1225 | if( zIn[0]=='.' && (zIn[1]==0 || zIn[1]=='\r' || zIn[1]=='\n') ){ |
| @@ -1237,15 +1244,10 @@ | |
| 1237 | int i, n; |
| 1238 | char *z; |
| 1239 | n = blob_size(&line); |
| 1240 | z = blob_buffer(&line); |
| 1241 | for(i=0; i<n && fossil_isspace(z[i]); i++){} |
| 1242 | if( fossil_strncmp( |
| 1243 | "# NOTE: The below diff is not inserted into the commit message.\n", |
| 1244 | z, n)==0 ){ |
| 1245 | break; |
| 1246 | } |
| 1247 | if( i<n && z[i]=='#' ) continue; |
| 1248 | if( i<n || blob_size(pComment)>0 ){ |
| 1249 | blob_appendf(pComment, "%b", &line); |
| 1250 | } |
| 1251 | } |
| @@ -1275,11 +1277,12 @@ | |
| 1275 | */ |
| 1276 | static void prepare_commit_comment( |
| 1277 | Blob *pComment, |
| 1278 | char *zInit, |
| 1279 | CheckinInfo *p, |
| 1280 | int parent_rid |
| 1281 | ){ |
| 1282 | Blob prompt; |
| 1283 | #if defined(_WIN32) || defined(__CYGWIN__) |
| 1284 | int bomSize; |
| 1285 | const unsigned char *bom = get_utf8_bom(&bomSize); |
| @@ -1294,10 +1297,14 @@ | |
| 1294 | "\n" |
| 1295 | "# Enter a commit message for this check-in." |
| 1296 | " Lines beginning with # are ignored.\n" |
| 1297 | "#\n", -1 |
| 1298 | ); |
| 1299 | blob_appendf(&prompt, "# user: %s\n", |
| 1300 | p->zUserOvrd ? p->zUserOvrd : login_name()); |
| 1301 | if( p->zBranch && p->zBranch[0] ){ |
| 1302 | blob_appendf(&prompt, "# tags: %s\n#\n", p->zBranch); |
| 1303 | }else{ |
| @@ -1331,14 +1338,14 @@ | |
| 1331 | "# All merged-in branches will be closed due to the --integrate flag\n" |
| 1332 | "#\n", -1 |
| 1333 | ); |
| 1334 | } |
| 1335 | if( p->verboseFlag ){ |
| 1336 | blob_append(&prompt, |
| 1337 | "#\n" |
| 1338 | "# NOTE: The below diff is not inserted into the commit message.\n\n", |
| 1339 | -1 |
| 1340 | ); |
| 1341 | if( g.aCommitFile ){ |
| 1342 | FileDirList *diffFiles; |
| 1343 | int i; |
| 1344 | diffFiles = fossil_malloc_zero((g.argc-1) * sizeof(*diffFiles)); |
| @@ -2130,12 +2137,11 @@ | |
| 2130 | ** --integrate close all merged-in branches |
| 2131 | ** -m|--comment COMMENT-TEXT use COMMENT-TEXT as commit comment |
| 2132 | ** -M|--message-file FILE read the commit comment from given file |
| 2133 | ** --mimetype MIMETYPE mimetype of check-in comment |
| 2134 | ** -n|--dry-run If given, display instead of run actions |
| 2135 | ** -v|--verbose Display in the editor a unified diff of the |
| 2136 | ** changes to be committed with this check-in |
| 2137 | ** --no-prompt This option disables prompting the user for |
| 2138 | ** input and assumes an answer of 'No' for every |
| 2139 | ** question. |
| 2140 | ** --no-warnings omit all warnings about file contents |
| 2141 | ** --no-verify do not run before-commit hooks |
| @@ -2484,15 +2490,13 @@ | |
| 2484 | blob_append(&comment, zComment, -1); |
| 2485 | }else if( zComFile ){ |
| 2486 | blob_zero(&comment); |
| 2487 | blob_read_from_file(&comment, zComFile, ExtFILE); |
| 2488 | blob_to_utf8_no_bom(&comment, 1); |
| 2489 | }else if( dryRunFlag ){ |
| 2490 | blob_zero(&comment); |
| 2491 | }else if( !noPrompt ){ |
| 2492 | char *zInit = db_text(0,"SELECT value FROM vvar WHERE name='ci-comment'"); |
| 2493 | prepare_commit_comment(&comment, zInit, &sCiInfo, vid); |
| 2494 | if( zInit && zInit[0] && fossil_strcmp(zInit, blob_str(&comment))==0 ){ |
| 2495 | prompt_user("unchanged check-in comment. continue (y/N)? ", &ans); |
| 2496 | cReply = blob_str(&ans)[0]; |
| 2497 | blob_reset(&ans); |
| 2498 | if( cReply!='y' && cReply!='Y' ){ |
| 2499 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -1209,17 +1209,24 @@ | |
| 1209 | #if defined(_WIN32) |
| 1210 | blob_add_cr(pPrompt); |
| 1211 | #endif |
| 1212 | if( blob_size(pPrompt)>0 ) blob_write_to_file(pPrompt, zFile); |
| 1213 | if( zEditor ){ |
| 1214 | char *z, *zEnd; |
| 1215 | zCmd = mprintf("%s %$", zEditor, zFile); |
| 1216 | fossil_print("%s\n", zCmd); |
| 1217 | if( fossil_system(zCmd) ){ |
| 1218 | fossil_fatal("editor aborted: \"%s\"", zCmd); |
| 1219 | } |
| 1220 | blob_read_from_file(&reply, zFile, ExtFILE); |
| 1221 | z = blob_str(&reply); |
| 1222 | zEnd = strstr(z, "##########"); |
| 1223 | if( zEnd ){ |
| 1224 | /* Truncate the reply at any sequence of 10 or more # characters. |
| 1225 | ** The diff for the -v option occurs after such a sequence. */ |
| 1226 | blob_resize(&reply, (int)(zEnd - z)); |
| 1227 | } |
| 1228 | }else{ |
| 1229 | char zIn[300]; |
| 1230 | blob_zero(&reply); |
| 1231 | while( fgets(zIn, sizeof(zIn), stdin)!=0 ){ |
| 1232 | if( zIn[0]=='.' && (zIn[1]==0 || zIn[1]=='\r' || zIn[1]=='\n') ){ |
| @@ -1237,15 +1244,10 @@ | |
| 1244 | int i, n; |
| 1245 | char *z; |
| 1246 | n = blob_size(&line); |
| 1247 | z = blob_buffer(&line); |
| 1248 | for(i=0; i<n && fossil_isspace(z[i]); i++){} |
| 1249 | if( i<n && z[i]=='#' ) continue; |
| 1250 | if( i<n || blob_size(pComment)>0 ){ |
| 1251 | blob_appendf(pComment, "%b", &line); |
| 1252 | } |
| 1253 | } |
| @@ -1275,11 +1277,12 @@ | |
| 1277 | */ |
| 1278 | static void prepare_commit_comment( |
| 1279 | Blob *pComment, |
| 1280 | char *zInit, |
| 1281 | CheckinInfo *p, |
| 1282 | int parent_rid, |
| 1283 | int dryRunFlag |
| 1284 | ){ |
| 1285 | Blob prompt; |
| 1286 | #if defined(_WIN32) || defined(__CYGWIN__) |
| 1287 | int bomSize; |
| 1288 | const unsigned char *bom = get_utf8_bom(&bomSize); |
| @@ -1294,10 +1297,14 @@ | |
| 1297 | "\n" |
| 1298 | "# Enter a commit message for this check-in." |
| 1299 | " Lines beginning with # are ignored.\n" |
| 1300 | "#\n", -1 |
| 1301 | ); |
| 1302 | if( dryRunFlag ){ |
| 1303 | blob_appendf(&prompt, "# DRY-RUN: This is a test commit. No changes " |
| 1304 | "will be made to the repository\n#\n"); |
| 1305 | } |
| 1306 | blob_appendf(&prompt, "# user: %s\n", |
| 1307 | p->zUserOvrd ? p->zUserOvrd : login_name()); |
| 1308 | if( p->zBranch && p->zBranch[0] ){ |
| 1309 | blob_appendf(&prompt, "# tags: %s\n#\n", p->zBranch); |
| 1310 | }else{ |
| @@ -1331,14 +1338,14 @@ | |
| 1338 | "# All merged-in branches will be closed due to the --integrate flag\n" |
| 1339 | "#\n", -1 |
| 1340 | ); |
| 1341 | } |
| 1342 | if( p->verboseFlag ){ |
| 1343 | blob_appendf(&prompt, |
| 1344 | "#\n%.78c\n" |
| 1345 | "# The following diff is excluded from the commit message:\n#\n", |
| 1346 | '#' |
| 1347 | ); |
| 1348 | if( g.aCommitFile ){ |
| 1349 | FileDirList *diffFiles; |
| 1350 | int i; |
| 1351 | diffFiles = fossil_malloc_zero((g.argc-1) * sizeof(*diffFiles)); |
| @@ -2130,12 +2137,11 @@ | |
| 2137 | ** --integrate close all merged-in branches |
| 2138 | ** -m|--comment COMMENT-TEXT use COMMENT-TEXT as commit comment |
| 2139 | ** -M|--message-file FILE read the commit comment from given file |
| 2140 | ** --mimetype MIMETYPE mimetype of check-in comment |
| 2141 | ** -n|--dry-run If given, display instead of run actions |
| 2142 | ** -v|--verbose Show a diff in the commit message prompt |
| 2143 | ** --no-prompt This option disables prompting the user for |
| 2144 | ** input and assumes an answer of 'No' for every |
| 2145 | ** question. |
| 2146 | ** --no-warnings omit all warnings about file contents |
| 2147 | ** --no-verify do not run before-commit hooks |
| @@ -2484,15 +2490,13 @@ | |
| 2490 | blob_append(&comment, zComment, -1); |
| 2491 | }else if( zComFile ){ |
| 2492 | blob_zero(&comment); |
| 2493 | blob_read_from_file(&comment, zComFile, ExtFILE); |
| 2494 | blob_to_utf8_no_bom(&comment, 1); |
| 2495 | }else if( !noPrompt ){ |
| 2496 | char *zInit = db_text(0,"SELECT value FROM vvar WHERE name='ci-comment'"); |
| 2497 | prepare_commit_comment(&comment, zInit, &sCiInfo, vid, dryRunFlag); |
| 2498 | if( zInit && zInit[0] && fossil_strcmp(zInit, blob_str(&comment))==0 ){ |
| 2499 | prompt_user("unchanged check-in comment. continue (y/N)? ", &ans); |
| 2500 | cReply = blob_str(&ans)[0]; |
| 2501 | blob_reset(&ans); |
| 2502 | if( cReply!='y' && cReply!='Y' ){ |
| 2503 |