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.

drh 2021-01-31 21:00 trunk
Commit 4eca7eb902b5576da1bb060712cde9d41fa6197030bbc78457ddcb4f98645088
1 file changed +20 -16
+20 -16
--- src/checkin.c
+++ src/checkin.c
@@ -1209,17 +1209,24 @@
12091209
#if defined(_WIN32)
12101210
blob_add_cr(pPrompt);
12111211
#endif
12121212
if( blob_size(pPrompt)>0 ) blob_write_to_file(pPrompt, zFile);
12131213
if( zEditor ){
1214
+ char *z, *zEnd;
12141215
zCmd = mprintf("%s %$", zEditor, zFile);
12151216
fossil_print("%s\n", zCmd);
12161217
if( fossil_system(zCmd) ){
12171218
fossil_fatal("editor aborted: \"%s\"", zCmd);
12181219
}
1219
-
12201220
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
+ }
12211228
}else{
12221229
char zIn[300];
12231230
blob_zero(&reply);
12241231
while( fgets(zIn, sizeof(zIn), stdin)!=0 ){
12251232
if( zIn[0]=='.' && (zIn[1]==0 || zIn[1]=='\r' || zIn[1]=='\n') ){
@@ -1237,15 +1244,10 @@
12371244
int i, n;
12381245
char *z;
12391246
n = blob_size(&line);
12401247
z = blob_buffer(&line);
12411248
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
- }
12471249
if( i<n && z[i]=='#' ) continue;
12481250
if( i<n || blob_size(pComment)>0 ){
12491251
blob_appendf(pComment, "%b", &line);
12501252
}
12511253
}
@@ -1275,11 +1277,12 @@
12751277
*/
12761278
static void prepare_commit_comment(
12771279
Blob *pComment,
12781280
char *zInit,
12791281
CheckinInfo *p,
1280
- int parent_rid
1282
+ int parent_rid,
1283
+ int dryRunFlag
12811284
){
12821285
Blob prompt;
12831286
#if defined(_WIN32) || defined(__CYGWIN__)
12841287
int bomSize;
12851288
const unsigned char *bom = get_utf8_bom(&bomSize);
@@ -1294,10 +1297,14 @@
12941297
"\n"
12951298
"# Enter a commit message for this check-in."
12961299
" Lines beginning with # are ignored.\n"
12971300
"#\n", -1
12981301
);
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
+ }
12991306
blob_appendf(&prompt, "# user: %s\n",
13001307
p->zUserOvrd ? p->zUserOvrd : login_name());
13011308
if( p->zBranch && p->zBranch[0] ){
13021309
blob_appendf(&prompt, "# tags: %s\n#\n", p->zBranch);
13031310
}else{
@@ -1331,14 +1338,14 @@
13311338
"# All merged-in branches will be closed due to the --integrate flag\n"
13321339
"#\n", -1
13331340
);
13341341
}
13351342
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
+ '#'
13401347
);
13411348
if( g.aCommitFile ){
13421349
FileDirList *diffFiles;
13431350
int i;
13441351
diffFiles = fossil_malloc_zero((g.argc-1) * sizeof(*diffFiles));
@@ -2130,12 +2137,11 @@
21302137
** --integrate close all merged-in branches
21312138
** -m|--comment COMMENT-TEXT use COMMENT-TEXT as commit comment
21322139
** -M|--message-file FILE read the commit comment from given file
21332140
** --mimetype MIMETYPE mimetype of check-in comment
21342141
** -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
21372143
** --no-prompt This option disables prompting the user for
21382144
** input and assumes an answer of 'No' for every
21392145
** question.
21402146
** --no-warnings omit all warnings about file contents
21412147
** --no-verify do not run before-commit hooks
@@ -2484,15 +2490,13 @@
24842490
blob_append(&comment, zComment, -1);
24852491
}else if( zComFile ){
24862492
blob_zero(&comment);
24872493
blob_read_from_file(&comment, zComFile, ExtFILE);
24882494
blob_to_utf8_no_bom(&comment, 1);
2489
- }else if( dryRunFlag ){
2490
- blob_zero(&comment);
24912495
}else if( !noPrompt ){
24922496
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);
24942498
if( zInit && zInit[0] && fossil_strcmp(zInit, blob_str(&comment))==0 ){
24952499
prompt_user("unchanged check-in comment. continue (y/N)? ", &ans);
24962500
cReply = blob_str(&ans)[0];
24972501
blob_reset(&ans);
24982502
if( cReply!='y' && cReply!='Y' ){
24992503
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button