Fossil SCM

Update the "fossil stash" command so that it always prompts for a comment if the -m option is omitted.

drh 2012-10-05 13:10 trunk
Commit 16371dcb1b5b48701289fab8c6fb54192fe8cd5f
2 files changed +94 -79 +14
+94 -79
--- src/checkin.c
+++ src/checkin.c
@@ -417,10 +417,94 @@
417417
}
418418
}
419419
}
420420
db_finalize(&q);
421421
}
422
+
423
+/*
424
+** Prompt the user for a check-in or stash comment (given in pPrompt),
425
+** gather the response, then return the response in pComment.
426
+**
427
+** Lines of the prompt that begin with # are discarded. Excess whitespace
428
+** is removed from the reply.
429
+**
430
+** Appropriate encoding translations are made on windows.
431
+*/
432
+void prompt_for_user_comment(Blob *pComment, Blob *pPrompt){
433
+ const char *zEditor;
434
+ char *zCmd;
435
+ char *zFile;
436
+ Blob reply, line;
437
+ char *zComment;
438
+ int i;
439
+
440
+ zEditor = db_get("editor", 0);
441
+ if( zEditor==0 ){
442
+ zEditor = fossil_getenv("VISUAL");
443
+ }
444
+ if( zEditor==0 ){
445
+ zEditor = fossil_getenv("EDITOR");
446
+ }
447
+ if( zEditor==0 ){
448
+ blob_append(pPrompt,
449
+ "#\n"
450
+ "# Since no default text editor is set using EDITOR or VISUAL\n"
451
+ "# environment variables or the \"fossil set editor\" command,\n"
452
+ "# and because no comment was specified using the \"-m\" or \"-M\"\n"
453
+ "# command-line options, you will need to enter the comment below.\n"
454
+ "# Type \".\" on a line by itself when you are done:\n", -1);
455
+ zFile = mprintf("-");
456
+ }else{
457
+ zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'",
458
+ g.zLocalRoot);
459
+ }
460
+#if defined(_WIN32)
461
+ blob_add_cr(pPrompt);
462
+#endif
463
+ blob_write_to_file(pPrompt, zFile);
464
+ if( zEditor ){
465
+ zCmd = mprintf("%s \"%s\"", zEditor, zFile);
466
+ fossil_print("%s\n", zCmd);
467
+ if( fossil_system(zCmd) ){
468
+ fossil_fatal("editor aborted: \"%s\"", zCmd);
469
+ }
470
+
471
+ blob_read_from_file(&reply, zFile);
472
+ }else{
473
+ char zIn[300];
474
+ blob_zero(&reply);
475
+ while( fgets(zIn, sizeof(zIn), stdin)!=0 ){
476
+ char *zUtf8 = fossil_mbcs_to_utf8(zIn);
477
+ if( zUtf8[0]=='.' && (zUtf8[1]==0 || zUtf8[1]=='\r' || zUtf8[1]=='\n') ){
478
+ fossil_mbcs_free(zUtf8);
479
+ break;
480
+ }
481
+ blob_append(&reply, zUtf8, -1);
482
+ fossil_mbcs_free(zUtf8);
483
+ }
484
+ }
485
+ blob_remove_cr(&reply);
486
+ file_delete(zFile);
487
+ free(zFile);
488
+ blob_zero(pComment);
489
+ while( blob_line(&reply, &line) ){
490
+ int i, n;
491
+ char *z;
492
+ n = blob_size(&line);
493
+ z = blob_buffer(&line);
494
+ for(i=0; i<n && fossil_isspace(z[i]); i++){}
495
+ if( i<n && z[i]=='#' ) continue;
496
+ if( i<n || blob_size(pComment)>0 ){
497
+ blob_appendf(pComment, "%b", &line);
498
+ }
499
+ }
500
+ blob_reset(&reply);
501
+ zComment = blob_str(pComment);
502
+ i = strlen(zComment);
503
+ while( i>0 && fossil_isspace(zComment[i-1]) ){ i--; }
504
+ blob_resize(pComment, i);
505
+}
422506
423507
/*
424508
** Prepare a commit comment. Let the user modify it using the
425509
** editor specified in the global_config table or either
426510
** the VISUAL or EDITOR environment variable.
@@ -442,104 +526,35 @@
442526
char *zInit,
443527
const char *zBranch,
444528
int parent_rid,
445529
const char *zUserOvrd
446530
){
447
- const char *zEditor;
448
- char *zCmd;
449
- char *zFile;
450
- Blob text, line;
451
- char *zComment;
452
- int i;
453
- blob_init(&text, zInit, -1);
454
- blob_append(&text,
531
+ Blob prompt;
532
+ blob_init(&prompt, zInit, -1);
533
+ blob_append(&prompt,
455534
"\n"
456535
"# Enter comments on this check-in. Lines beginning with # are ignored.\n"
457536
"# The check-in comment follows wiki formatting rules.\n"
458537
"#\n", -1
459538
);
460
- blob_appendf(&text, "# user: %s\n", zUserOvrd ? zUserOvrd : g.zLogin);
539
+ blob_appendf(&prompt, "# user: %s\n", zUserOvrd ? zUserOvrd : g.zLogin);
461540
if( zBranch && zBranch[0] ){
462
- blob_appendf(&text, "# tags: %s\n#\n", zBranch);
541
+ blob_appendf(&prompt, "# tags: %s\n#\n", zBranch);
463542
}else{
464543
char *zTags = info_tags_of_checkin(parent_rid, 1);
465
- if( zTags ) blob_appendf(&text, "# tags: %z\n#\n", zTags);
544
+ if( zTags ) blob_appendf(&prompt, "# tags: %z\n#\n", zTags);
466545
}
546
+ status_report(&prompt, "# ", 1, 0);
467547
if( g.markPrivate ){
468
- blob_append(&text,
548
+ blob_append(&prompt,
469549
"# PRIVATE BRANCH: This check-in will be private and will not sync to\n"
470550
"# repositories.\n"
471551
"#\n", -1
472552
);
473553
}
474
- status_report(&text, "# ", 1, 0);
475
- zEditor = db_get("editor", 0);
476
- if( zEditor==0 ){
477
- zEditor = fossil_getenv("VISUAL");
478
- }
479
- if( zEditor==0 ){
480
- zEditor = fossil_getenv("EDITOR");
481
- }
482
- if( zEditor==0 ){
483
- blob_append(&text,
484
- "#\n"
485
- "# Since no default text editor is set using EDITOR or VISUAL\n"
486
- "# environment variables or the \"fossil set editor\" command,\n"
487
- "# and because no check-in comment was specified using the \"-m\"\n"
488
- "# or \"-M\" command-line options, you will need to enter the\n"
489
- "# check-in comment below. Type \".\" on a line by itself when\n"
490
- "# you are done:\n", -1);
491
- zFile = mprintf("-");
492
- }else{
493
- zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'",
494
- g.zLocalRoot);
495
- }
496
-#if defined(_WIN32)
497
- blob_add_cr(&text);
498
-#endif
499
- blob_write_to_file(&text, zFile);
500
- if( zEditor ){
501
- zCmd = mprintf("%s \"%s\"", zEditor, zFile);
502
- fossil_print("%s\n", zCmd);
503
- if( fossil_system(zCmd) ){
504
- fossil_panic("editor aborted");
505
- }
506
- blob_reset(&text);
507
- blob_read_from_file(&text, zFile);
508
- }else{
509
- char zIn[300];
510
- blob_reset(&text);
511
- while( fgets(zIn, sizeof(zIn), stdin)!=0 ){
512
- char *zUtf8 = fossil_mbcs_to_utf8(zIn);
513
- if( zUtf8[0]=='.' && (zUtf8[1]==0 || zUtf8[1]=='\r' || zUtf8[1]=='\n') ){
514
- fossil_mbcs_free(zUtf8);
515
- break;
516
- }
517
- blob_append(&text, zUtf8, -1);
518
- fossil_mbcs_free(zUtf8);
519
- }
520
- }
521
- blob_remove_cr(&text);
522
- file_delete(zFile);
523
- free(zFile);
524
- blob_zero(pComment);
525
- while( blob_line(&text, &line) ){
526
- int i, n;
527
- char *z;
528
- n = blob_size(&line);
529
- z = blob_buffer(&line);
530
- for(i=0; i<n && fossil_isspace(z[i]); i++){}
531
- if( i<n && z[i]=='#' ) continue;
532
- if( i<n || blob_size(pComment)>0 ){
533
- blob_appendf(pComment, "%b", &line);
534
- }
535
- }
536
- blob_reset(&text);
537
- zComment = blob_str(pComment);
538
- i = strlen(zComment);
539
- while( i>0 && fossil_isspace(zComment[i-1]) ){ i--; }
540
- blob_resize(pComment, i);
554
+ prompt_for_user_comment(pComment, &prompt);
555
+ blob_reset(&prompt);
541556
}
542557
543558
/*
544559
** Populate the Global.aCommitFile[] based on the command line arguments
545560
** to a [commit] command. Global.aCommitFile is an array of integers
546561
--- src/checkin.c
+++ src/checkin.c
@@ -417,10 +417,94 @@
417 }
418 }
419 }
420 db_finalize(&q);
421 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422
423 /*
424 ** Prepare a commit comment. Let the user modify it using the
425 ** editor specified in the global_config table or either
426 ** the VISUAL or EDITOR environment variable.
@@ -442,104 +526,35 @@
442 char *zInit,
443 const char *zBranch,
444 int parent_rid,
445 const char *zUserOvrd
446 ){
447 const char *zEditor;
448 char *zCmd;
449 char *zFile;
450 Blob text, line;
451 char *zComment;
452 int i;
453 blob_init(&text, zInit, -1);
454 blob_append(&text,
455 "\n"
456 "# Enter comments on this check-in. Lines beginning with # are ignored.\n"
457 "# The check-in comment follows wiki formatting rules.\n"
458 "#\n", -1
459 );
460 blob_appendf(&text, "# user: %s\n", zUserOvrd ? zUserOvrd : g.zLogin);
461 if( zBranch && zBranch[0] ){
462 blob_appendf(&text, "# tags: %s\n#\n", zBranch);
463 }else{
464 char *zTags = info_tags_of_checkin(parent_rid, 1);
465 if( zTags ) blob_appendf(&text, "# tags: %z\n#\n", zTags);
466 }
 
467 if( g.markPrivate ){
468 blob_append(&text,
469 "# PRIVATE BRANCH: This check-in will be private and will not sync to\n"
470 "# repositories.\n"
471 "#\n", -1
472 );
473 }
474 status_report(&text, "# ", 1, 0);
475 zEditor = db_get("editor", 0);
476 if( zEditor==0 ){
477 zEditor = fossil_getenv("VISUAL");
478 }
479 if( zEditor==0 ){
480 zEditor = fossil_getenv("EDITOR");
481 }
482 if( zEditor==0 ){
483 blob_append(&text,
484 "#\n"
485 "# Since no default text editor is set using EDITOR or VISUAL\n"
486 "# environment variables or the \"fossil set editor\" command,\n"
487 "# and because no check-in comment was specified using the \"-m\"\n"
488 "# or \"-M\" command-line options, you will need to enter the\n"
489 "# check-in comment below. Type \".\" on a line by itself when\n"
490 "# you are done:\n", -1);
491 zFile = mprintf("-");
492 }else{
493 zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'",
494 g.zLocalRoot);
495 }
496 #if defined(_WIN32)
497 blob_add_cr(&text);
498 #endif
499 blob_write_to_file(&text, zFile);
500 if( zEditor ){
501 zCmd = mprintf("%s \"%s\"", zEditor, zFile);
502 fossil_print("%s\n", zCmd);
503 if( fossil_system(zCmd) ){
504 fossil_panic("editor aborted");
505 }
506 blob_reset(&text);
507 blob_read_from_file(&text, zFile);
508 }else{
509 char zIn[300];
510 blob_reset(&text);
511 while( fgets(zIn, sizeof(zIn), stdin)!=0 ){
512 char *zUtf8 = fossil_mbcs_to_utf8(zIn);
513 if( zUtf8[0]=='.' && (zUtf8[1]==0 || zUtf8[1]=='\r' || zUtf8[1]=='\n') ){
514 fossil_mbcs_free(zUtf8);
515 break;
516 }
517 blob_append(&text, zUtf8, -1);
518 fossil_mbcs_free(zUtf8);
519 }
520 }
521 blob_remove_cr(&text);
522 file_delete(zFile);
523 free(zFile);
524 blob_zero(pComment);
525 while( blob_line(&text, &line) ){
526 int i, n;
527 char *z;
528 n = blob_size(&line);
529 z = blob_buffer(&line);
530 for(i=0; i<n && fossil_isspace(z[i]); i++){}
531 if( i<n && z[i]=='#' ) continue;
532 if( i<n || blob_size(pComment)>0 ){
533 blob_appendf(pComment, "%b", &line);
534 }
535 }
536 blob_reset(&text);
537 zComment = blob_str(pComment);
538 i = strlen(zComment);
539 while( i>0 && fossil_isspace(zComment[i-1]) ){ i--; }
540 blob_resize(pComment, i);
541 }
542
543 /*
544 ** Populate the Global.aCommitFile[] based on the command line arguments
545 ** to a [commit] command. Global.aCommitFile is an array of integers
546
--- src/checkin.c
+++ src/checkin.c
@@ -417,10 +417,94 @@
417 }
418 }
419 }
420 db_finalize(&q);
421 }
422
423 /*
424 ** Prompt the user for a check-in or stash comment (given in pPrompt),
425 ** gather the response, then return the response in pComment.
426 **
427 ** Lines of the prompt that begin with # are discarded. Excess whitespace
428 ** is removed from the reply.
429 **
430 ** Appropriate encoding translations are made on windows.
431 */
432 void prompt_for_user_comment(Blob *pComment, Blob *pPrompt){
433 const char *zEditor;
434 char *zCmd;
435 char *zFile;
436 Blob reply, line;
437 char *zComment;
438 int i;
439
440 zEditor = db_get("editor", 0);
441 if( zEditor==0 ){
442 zEditor = fossil_getenv("VISUAL");
443 }
444 if( zEditor==0 ){
445 zEditor = fossil_getenv("EDITOR");
446 }
447 if( zEditor==0 ){
448 blob_append(pPrompt,
449 "#\n"
450 "# Since no default text editor is set using EDITOR or VISUAL\n"
451 "# environment variables or the \"fossil set editor\" command,\n"
452 "# and because no comment was specified using the \"-m\" or \"-M\"\n"
453 "# command-line options, you will need to enter the comment below.\n"
454 "# Type \".\" on a line by itself when you are done:\n", -1);
455 zFile = mprintf("-");
456 }else{
457 zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'",
458 g.zLocalRoot);
459 }
460 #if defined(_WIN32)
461 blob_add_cr(pPrompt);
462 #endif
463 blob_write_to_file(pPrompt, zFile);
464 if( zEditor ){
465 zCmd = mprintf("%s \"%s\"", zEditor, zFile);
466 fossil_print("%s\n", zCmd);
467 if( fossil_system(zCmd) ){
468 fossil_fatal("editor aborted: \"%s\"", zCmd);
469 }
470
471 blob_read_from_file(&reply, zFile);
472 }else{
473 char zIn[300];
474 blob_zero(&reply);
475 while( fgets(zIn, sizeof(zIn), stdin)!=0 ){
476 char *zUtf8 = fossil_mbcs_to_utf8(zIn);
477 if( zUtf8[0]=='.' && (zUtf8[1]==0 || zUtf8[1]=='\r' || zUtf8[1]=='\n') ){
478 fossil_mbcs_free(zUtf8);
479 break;
480 }
481 blob_append(&reply, zUtf8, -1);
482 fossil_mbcs_free(zUtf8);
483 }
484 }
485 blob_remove_cr(&reply);
486 file_delete(zFile);
487 free(zFile);
488 blob_zero(pComment);
489 while( blob_line(&reply, &line) ){
490 int i, n;
491 char *z;
492 n = blob_size(&line);
493 z = blob_buffer(&line);
494 for(i=0; i<n && fossil_isspace(z[i]); i++){}
495 if( i<n && z[i]=='#' ) continue;
496 if( i<n || blob_size(pComment)>0 ){
497 blob_appendf(pComment, "%b", &line);
498 }
499 }
500 blob_reset(&reply);
501 zComment = blob_str(pComment);
502 i = strlen(zComment);
503 while( i>0 && fossil_isspace(zComment[i-1]) ){ i--; }
504 blob_resize(pComment, i);
505 }
506
507 /*
508 ** Prepare a commit comment. Let the user modify it using the
509 ** editor specified in the global_config table or either
510 ** the VISUAL or EDITOR environment variable.
@@ -442,104 +526,35 @@
526 char *zInit,
527 const char *zBranch,
528 int parent_rid,
529 const char *zUserOvrd
530 ){
531 Blob prompt;
532 blob_init(&prompt, zInit, -1);
533 blob_append(&prompt,
 
 
 
 
 
534 "\n"
535 "# Enter comments on this check-in. Lines beginning with # are ignored.\n"
536 "# The check-in comment follows wiki formatting rules.\n"
537 "#\n", -1
538 );
539 blob_appendf(&prompt, "# user: %s\n", zUserOvrd ? zUserOvrd : g.zLogin);
540 if( zBranch && zBranch[0] ){
541 blob_appendf(&prompt, "# tags: %s\n#\n", zBranch);
542 }else{
543 char *zTags = info_tags_of_checkin(parent_rid, 1);
544 if( zTags ) blob_appendf(&prompt, "# tags: %z\n#\n", zTags);
545 }
546 status_report(&prompt, "# ", 1, 0);
547 if( g.markPrivate ){
548 blob_append(&prompt,
549 "# PRIVATE BRANCH: This check-in will be private and will not sync to\n"
550 "# repositories.\n"
551 "#\n", -1
552 );
553 }
554 prompt_for_user_comment(pComment, &prompt);
555 blob_reset(&prompt);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
556 }
557
558 /*
559 ** Populate the Global.aCommitFile[] based on the command line arguments
560 ** to a [commit] command. Global.aCommitFile is an array of integers
561
+14
--- src/stash.c
+++ src/stash.c
@@ -155,10 +155,24 @@
155155
int stashid; /* ID of the new stash */
156156
int vid; /* Current checkout */
157157
158158
zComment = find_option("comment", "m", 1);
159159
verify_all_options();
160
+ if( zComment==0 ){
161
+ Blob prompt; /* Prompt for stash comment */
162
+ Blob comment; /* User comment reply */
163
+ blob_zero(&prompt);
164
+ blob_append(&prompt,
165
+ "\n"
166
+ "# Enter a description of what is being stashed. Lines beginning\n"
167
+ "# with \"#\" are ignored. Stash comments are plain text except.\n"
168
+ "# newlines are not preserved.\n",
169
+ -1);
170
+ prompt_for_user_comment(&comment, &prompt);
171
+ blob_reset(&prompt);
172
+ zComment = blob_str(&comment);
173
+ }
160174
stashid = db_lget_int("stash-next", 1);
161175
db_lset_int("stash-next", stashid+1);
162176
vid = db_lget_int("checkout", 0);
163177
vfile_check_signature(vid, 0, 0);
164178
db_multi_exec(
165179
--- src/stash.c
+++ src/stash.c
@@ -155,10 +155,24 @@
155 int stashid; /* ID of the new stash */
156 int vid; /* Current checkout */
157
158 zComment = find_option("comment", "m", 1);
159 verify_all_options();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160 stashid = db_lget_int("stash-next", 1);
161 db_lset_int("stash-next", stashid+1);
162 vid = db_lget_int("checkout", 0);
163 vfile_check_signature(vid, 0, 0);
164 db_multi_exec(
165
--- src/stash.c
+++ src/stash.c
@@ -155,10 +155,24 @@
155 int stashid; /* ID of the new stash */
156 int vid; /* Current checkout */
157
158 zComment = find_option("comment", "m", 1);
159 verify_all_options();
160 if( zComment==0 ){
161 Blob prompt; /* Prompt for stash comment */
162 Blob comment; /* User comment reply */
163 blob_zero(&prompt);
164 blob_append(&prompt,
165 "\n"
166 "# Enter a description of what is being stashed. Lines beginning\n"
167 "# with \"#\" are ignored. Stash comments are plain text except.\n"
168 "# newlines are not preserved.\n",
169 -1);
170 prompt_for_user_comment(&comment, &prompt);
171 blob_reset(&prompt);
172 zComment = blob_str(&comment);
173 }
174 stashid = db_lget_int("stash-next", 1);
175 db_lset_int("stash-next", stashid+1);
176 vid = db_lget_int("checkout", 0);
177 vfile_check_signature(vid, 0, 0);
178 db_multi_exec(
179

Keyboard Shortcuts

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