Fossil SCM

Add the verify-comments logic to the "fossil amend" command.

drh 2025-03-19 17:30 trunk
Commit eff2b2b9b07606803bfc89ae21fad055ece61a7fbab21308bf0a8ee8c1f34ec7
3 files changed +1 -1 +84 -26 +1 -1
+1 -1
--- src/checkin.c
+++ src/checkin.c
@@ -2319,11 +2319,11 @@
23192319
** stdout and return non-zero. The return value is some combination
23202320
** of the COMCK_* flags, depending on what went wrong.
23212321
**
23222322
** If no issues are seen, do not output anything and return zero.
23232323
*/
2324
-static int suspicious_comment(Blob *pComment, int mFlags){
2324
+int suspicious_comment(Blob *pComment, int mFlags){
23252325
char *zStart = blob_str(pComment);
23262326
char *z;
23272327
char *zEnd, *zEnd2;
23282328
char *zSep;
23292329
char cSave1;
23302330
--- src/checkin.c
+++ src/checkin.c
@@ -2319,11 +2319,11 @@
2319 ** stdout and return non-zero. The return value is some combination
2320 ** of the COMCK_* flags, depending on what went wrong.
2321 **
2322 ** If no issues are seen, do not output anything and return zero.
2323 */
2324 static int suspicious_comment(Blob *pComment, int mFlags){
2325 char *zStart = blob_str(pComment);
2326 char *z;
2327 char *zEnd, *zEnd2;
2328 char *zSep;
2329 char cSave1;
2330
--- src/checkin.c
+++ src/checkin.c
@@ -2319,11 +2319,11 @@
2319 ** stdout and return non-zero. The return value is some combination
2320 ** of the COMCK_* flags, depending on what went wrong.
2321 **
2322 ** If no issues are seen, do not output anything and return zero.
2323 */
2324 int suspicious_comment(Blob *pComment, int mFlags){
2325 char *zStart = blob_str(pComment);
2326 char *z;
2327 char *zEnd, *zEnd2;
2328 char *zSep;
2329 char cSave1;
2330
+84 -26
--- src/info.c
+++ src/info.c
@@ -3881,25 +3881,26 @@
38813881
** Usage: %fossil amend HASH OPTION ?OPTION ...?
38823882
**
38833883
** Amend the tags on check-in HASH to change how it displays in the timeline.
38843884
**
38853885
** Options:
3886
-** --author USER Make USER the author for check-in
3887
-** -m|--comment COMMENT Make COMMENT the check-in comment
3888
-** -M|--message-file FILE Read the amended comment from FILE
3889
-** -e|--edit-comment Launch editor to revise comment
3890
-** --date DATETIME Make DATETIME the check-in time
3891
-** --bgcolor COLOR Apply COLOR to this check-in
3892
-** --branchcolor COLOR Apply and propagate COLOR to the branch
3893
-** --tag TAG Add new TAG to this check-in
3894
-** --cancel TAG Cancel TAG from this check-in
3895
-** --branch NAME Rename branch of check-in to NAME
3896
-** --hide Hide branch starting from this check-in
3897
-** --close Mark this "leaf" as closed
3898
-** -n|--dry-run Print control artifact, but make no changes
3899
-** --date-override DATETIME Set the change time on the control artifact
3900
-** --user-override USER Set the user name on the control artifact
3886
+** --author USER Make USER the author for check-in
3887
+** --bgcolor COLOR Apply COLOR to this check-in
3888
+** --branch NAME Rename branch of check-in to NAME
3889
+** --branchcolor COLOR Apply and propagate COLOR to the branch
3890
+** --cancel TAG Cancel TAG from this check-in
3891
+** --close Mark this "leaf" as closed
3892
+** --date DATETIME Make DATETIME the check-in time
3893
+** --date-override DATETIME Set the change time on the control artifact
3894
+** -e|--edit-comment Launch editor to revise comment
3895
+** --hide Hide branch starting from this check-in
3896
+** -m|--comment COMMENT Make COMMENT the check-in comment
3897
+** -M|--message-file FILE Read the amended comment from FILE
3898
+** -n|--dry-run Print control artifact, but make no changes
3899
+** --no-verify-comment Do not validate the check-in comment
3900
+** --tag TAG Add new TAG to this check-in
3901
+** --user-override USER Set the user name on the control artifact
39013902
**
39023903
** DATETIME may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
39033904
** year-month-day form, it may be truncated, the "T" may be replaced by
39043905
** a space, and it may also name a timezone offset from UTC as "-HH:MM"
39053906
** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z"
@@ -3926,19 +3927,22 @@
39263927
int fNewPropagateColor = 0; /* True if color propagates after amend */
39273928
int fHasHidden = 0; /* True if hidden tag already set */
39283929
int fHasClosed = 0; /* True if closed tag already set */
39293930
int fEditComment; /* True if editor to be used for comment */
39303931
int fDryRun; /* Print control artifact, make no changes */
3932
+ int noVerifyCom = 0; /* Allow suspicious check-in comments */
39313933
const char *zChngTime; /* The change time on the control artifact */
39323934
const char *zUserOvrd; /* The user name on the control artifact */
39333935
const char *zUuid;
39343936
Blob ctrl;
39353937
Blob comment;
39363938
char *zNow;
39373939
int nTags, nCancels;
39383940
int i;
39393941
Stmt q;
3942
+ int ckComFlgs; /* Flags passed to suspicious_comment() */
3943
+
39403944
39413945
fEditComment = find_option("edit-comment","e",0)!=0;
39423946
zNewComment = find_option("comment","m",1);
39433947
zComFile = find_option("message-file","M",1);
39443948
zNewBranch = find_option("branch",0,1);
@@ -3956,10 +3960,11 @@
39563960
fHide = find_option("hide",0,0)!=0;
39573961
fDryRun = find_option("dry-run","n",0)!=0;
39583962
zChngTime = find_option("date-override",0,1);
39593963
if( zChngTime==0 ) zChngTime = find_option("chngtime",0,1);
39603964
zUserOvrd = find_option("user-override",0,1);
3965
+ noVerifyCom = find_option("no-verify-comment",0,0)!=0;
39613966
db_find_and_open_repository(0,0);
39623967
user_select();
39633968
verify_all_options();
39643969
if( g.argc<3 || g.argc>=4 ) usage(AMEND_USAGE_STMT);
39653970
rid = name_to_typed_rid(g.argv[2], "ci");
@@ -4014,21 +4019,74 @@
40144019
);
40154020
}
40164021
if( (zNewColor!=0 && zNewColor[0]==0) && (zColor && zColor[0] ) ){
40174022
cancel_color();
40184023
}
4019
- if( fEditComment ){
4020
- prepare_amend_comment(&comment, zComment, zUuid);
4021
- zNewComment = blob_str(&comment);
4022
- }else if( zComFile ){
4023
- blob_zero(&comment);
4024
- blob_read_from_file(&comment, zComFile, ExtFILE);
4025
- blob_to_utf8_no_bom(&comment, 1);
4026
- zNewComment = blob_str(&comment);
4027
- }
4028
- if( zNewComment && zNewComment[0]
4029
- && comment_compare(zComment,zNewComment)==0 ) add_comment(zNewComment);
4024
+ if( fEditComment || zNewComment || zComFile ){
4025
+ blob_init(&comment, 0, 0);
4026
+
4027
+ /* Figure out how much comment verification is requested */
4028
+ if( noVerifyCom ){
4029
+ ckComFlgs = 0;
4030
+ }else{
4031
+ const char *zVerComs = db_get("verify-comments","on");
4032
+ if( is_false(zVerComs) ){
4033
+ ckComFlgs = 0;
4034
+ }else if( strcmp(zVerComs,"preview")==0 ){
4035
+ ckComFlgs = COMCK_PREVIEW | COMCK_LINKS | COMCK_MARKUP;
4036
+ }else if( strcmp(zVerComs,"links")==0 ){
4037
+ ckComFlgs = COMCK_LINKS;
4038
+ }else{
4039
+ ckComFlgs = COMCK_LINKS | COMCK_MARKUP;
4040
+ }
4041
+ if( zNewComment || zComFile ){
4042
+ ckComFlgs = (ckComFlgs & COMCK_LINKS) | COMCK_NOPREVIEW;
4043
+ }
4044
+ }
4045
+ if( fEditComment ){
4046
+ prepare_amend_comment(&comment, zComment, zUuid);
4047
+ }else if( zComFile ){
4048
+ blob_read_from_file(&comment, zComFile, ExtFILE);
4049
+ blob_to_utf8_no_bom(&comment, 1);
4050
+ }else if( zNewComment ){
4051
+ blob_init(&comment, zNewComment, -1);
4052
+ }
4053
+ if( blob_size(&comment)>0
4054
+ && comment_compare(zComment, blob_str(&comment))==0
4055
+ ){
4056
+ int rc;
4057
+ while( (rc = suspicious_comment(&comment, ckComFlgs))!=0 ){
4058
+ char cReply;
4059
+ Blob ans;
4060
+ if( !fEditComment ){
4061
+ fossil_fatal("Amend aborted; "
4062
+ "use --no-verify-comment to override");
4063
+ }
4064
+ if( rc==COMCK_PREVIEW ){
4065
+ prompt_user("\nContinue (Y/n/e=edit)? ", &ans);
4066
+ }else{
4067
+ prompt_user("\nContinue (y/n/E=edit)? ", &ans);
4068
+ }
4069
+ cReply = blob_str(&ans)[0];
4070
+ cReply = fossil_tolower(cReply);
4071
+ blob_reset(&ans);
4072
+ if( cReply=='n' ){
4073
+ fossil_fatal("Amend aborted.");
4074
+ }
4075
+ if( cReply=='e' || (cReply!='y' && rc!=COMCK_PREVIEW) ){
4076
+ char *zPrior = blob_materialize(&comment);
4077
+ blob_init(&comment, 0, 0);
4078
+ prepare_amend_comment(&comment, zPrior, zUuid);
4079
+ fossil_free(zPrior);
4080
+ continue;
4081
+ }else{
4082
+ break;
4083
+ }
4084
+ }
4085
+ }
4086
+ add_comment(blob_str(&comment));
4087
+ }
40304088
if( zNewDate && zNewDate[0] && fossil_strcmp(zDate,zNewDate)!=0 ){
40314089
if( is_datetime(zNewDate) ){
40324090
add_date(zNewDate);
40334091
}else{
40344092
fossil_fatal("Unsupported date format, use YYYY-MM-DD HH:MM:SS");
40354093
--- src/info.c
+++ src/info.c
@@ -3881,25 +3881,26 @@
3881 ** Usage: %fossil amend HASH OPTION ?OPTION ...?
3882 **
3883 ** Amend the tags on check-in HASH to change how it displays in the timeline.
3884 **
3885 ** Options:
3886 ** --author USER Make USER the author for check-in
3887 ** -m|--comment COMMENT Make COMMENT the check-in comment
3888 ** -M|--message-file FILE Read the amended comment from FILE
3889 ** -e|--edit-comment Launch editor to revise comment
3890 ** --date DATETIME Make DATETIME the check-in time
3891 ** --bgcolor COLOR Apply COLOR to this check-in
3892 ** --branchcolor COLOR Apply and propagate COLOR to the branch
3893 ** --tag TAG Add new TAG to this check-in
3894 ** --cancel TAG Cancel TAG from this check-in
3895 ** --branch NAME Rename branch of check-in to NAME
3896 ** --hide Hide branch starting from this check-in
3897 ** --close Mark this "leaf" as closed
3898 ** -n|--dry-run Print control artifact, but make no changes
3899 ** --date-override DATETIME Set the change time on the control artifact
3900 ** --user-override USER Set the user name on the control artifact
 
3901 **
3902 ** DATETIME may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
3903 ** year-month-day form, it may be truncated, the "T" may be replaced by
3904 ** a space, and it may also name a timezone offset from UTC as "-HH:MM"
3905 ** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z"
@@ -3926,19 +3927,22 @@
3926 int fNewPropagateColor = 0; /* True if color propagates after amend */
3927 int fHasHidden = 0; /* True if hidden tag already set */
3928 int fHasClosed = 0; /* True if closed tag already set */
3929 int fEditComment; /* True if editor to be used for comment */
3930 int fDryRun; /* Print control artifact, make no changes */
 
3931 const char *zChngTime; /* The change time on the control artifact */
3932 const char *zUserOvrd; /* The user name on the control artifact */
3933 const char *zUuid;
3934 Blob ctrl;
3935 Blob comment;
3936 char *zNow;
3937 int nTags, nCancels;
3938 int i;
3939 Stmt q;
 
 
3940
3941 fEditComment = find_option("edit-comment","e",0)!=0;
3942 zNewComment = find_option("comment","m",1);
3943 zComFile = find_option("message-file","M",1);
3944 zNewBranch = find_option("branch",0,1);
@@ -3956,10 +3960,11 @@
3956 fHide = find_option("hide",0,0)!=0;
3957 fDryRun = find_option("dry-run","n",0)!=0;
3958 zChngTime = find_option("date-override",0,1);
3959 if( zChngTime==0 ) zChngTime = find_option("chngtime",0,1);
3960 zUserOvrd = find_option("user-override",0,1);
 
3961 db_find_and_open_repository(0,0);
3962 user_select();
3963 verify_all_options();
3964 if( g.argc<3 || g.argc>=4 ) usage(AMEND_USAGE_STMT);
3965 rid = name_to_typed_rid(g.argv[2], "ci");
@@ -4014,21 +4019,74 @@
4014 );
4015 }
4016 if( (zNewColor!=0 && zNewColor[0]==0) && (zColor && zColor[0] ) ){
4017 cancel_color();
4018 }
4019 if( fEditComment ){
4020 prepare_amend_comment(&comment, zComment, zUuid);
4021 zNewComment = blob_str(&comment);
4022 }else if( zComFile ){
4023 blob_zero(&comment);
4024 blob_read_from_file(&comment, zComFile, ExtFILE);
4025 blob_to_utf8_no_bom(&comment, 1);
4026 zNewComment = blob_str(&comment);
4027 }
4028 if( zNewComment && zNewComment[0]
4029 && comment_compare(zComment,zNewComment)==0 ) add_comment(zNewComment);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4030 if( zNewDate && zNewDate[0] && fossil_strcmp(zDate,zNewDate)!=0 ){
4031 if( is_datetime(zNewDate) ){
4032 add_date(zNewDate);
4033 }else{
4034 fossil_fatal("Unsupported date format, use YYYY-MM-DD HH:MM:SS");
4035
--- src/info.c
+++ src/info.c
@@ -3881,25 +3881,26 @@
3881 ** Usage: %fossil amend HASH OPTION ?OPTION ...?
3882 **
3883 ** Amend the tags on check-in HASH to change how it displays in the timeline.
3884 **
3885 ** Options:
3886 ** --author USER Make USER the author for check-in
3887 ** --bgcolor COLOR Apply COLOR to this check-in
3888 ** --branch NAME Rename branch of check-in to NAME
3889 ** --branchcolor COLOR Apply and propagate COLOR to the branch
3890 ** --cancel TAG Cancel TAG from this check-in
3891 ** --close Mark this "leaf" as closed
3892 ** --date DATETIME Make DATETIME the check-in time
3893 ** --date-override DATETIME Set the change time on the control artifact
3894 ** -e|--edit-comment Launch editor to revise comment
3895 ** --hide Hide branch starting from this check-in
3896 ** -m|--comment COMMENT Make COMMENT the check-in comment
3897 ** -M|--message-file FILE Read the amended comment from FILE
3898 ** -n|--dry-run Print control artifact, but make no changes
3899 ** --no-verify-comment Do not validate the check-in comment
3900 ** --tag TAG Add new TAG to this check-in
3901 ** --user-override USER Set the user name on the control artifact
3902 **
3903 ** DATETIME may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
3904 ** year-month-day form, it may be truncated, the "T" may be replaced by
3905 ** a space, and it may also name a timezone offset from UTC as "-HH:MM"
3906 ** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z"
@@ -3926,19 +3927,22 @@
3927 int fNewPropagateColor = 0; /* True if color propagates after amend */
3928 int fHasHidden = 0; /* True if hidden tag already set */
3929 int fHasClosed = 0; /* True if closed tag already set */
3930 int fEditComment; /* True if editor to be used for comment */
3931 int fDryRun; /* Print control artifact, make no changes */
3932 int noVerifyCom = 0; /* Allow suspicious check-in comments */
3933 const char *zChngTime; /* The change time on the control artifact */
3934 const char *zUserOvrd; /* The user name on the control artifact */
3935 const char *zUuid;
3936 Blob ctrl;
3937 Blob comment;
3938 char *zNow;
3939 int nTags, nCancels;
3940 int i;
3941 Stmt q;
3942 int ckComFlgs; /* Flags passed to suspicious_comment() */
3943
3944
3945 fEditComment = find_option("edit-comment","e",0)!=0;
3946 zNewComment = find_option("comment","m",1);
3947 zComFile = find_option("message-file","M",1);
3948 zNewBranch = find_option("branch",0,1);
@@ -3956,10 +3960,11 @@
3960 fHide = find_option("hide",0,0)!=0;
3961 fDryRun = find_option("dry-run","n",0)!=0;
3962 zChngTime = find_option("date-override",0,1);
3963 if( zChngTime==0 ) zChngTime = find_option("chngtime",0,1);
3964 zUserOvrd = find_option("user-override",0,1);
3965 noVerifyCom = find_option("no-verify-comment",0,0)!=0;
3966 db_find_and_open_repository(0,0);
3967 user_select();
3968 verify_all_options();
3969 if( g.argc<3 || g.argc>=4 ) usage(AMEND_USAGE_STMT);
3970 rid = name_to_typed_rid(g.argv[2], "ci");
@@ -4014,21 +4019,74 @@
4019 );
4020 }
4021 if( (zNewColor!=0 && zNewColor[0]==0) && (zColor && zColor[0] ) ){
4022 cancel_color();
4023 }
4024 if( fEditComment || zNewComment || zComFile ){
4025 blob_init(&comment, 0, 0);
4026
4027 /* Figure out how much comment verification is requested */
4028 if( noVerifyCom ){
4029 ckComFlgs = 0;
4030 }else{
4031 const char *zVerComs = db_get("verify-comments","on");
4032 if( is_false(zVerComs) ){
4033 ckComFlgs = 0;
4034 }else if( strcmp(zVerComs,"preview")==0 ){
4035 ckComFlgs = COMCK_PREVIEW | COMCK_LINKS | COMCK_MARKUP;
4036 }else if( strcmp(zVerComs,"links")==0 ){
4037 ckComFlgs = COMCK_LINKS;
4038 }else{
4039 ckComFlgs = COMCK_LINKS | COMCK_MARKUP;
4040 }
4041 if( zNewComment || zComFile ){
4042 ckComFlgs = (ckComFlgs & COMCK_LINKS) | COMCK_NOPREVIEW;
4043 }
4044 }
4045 if( fEditComment ){
4046 prepare_amend_comment(&comment, zComment, zUuid);
4047 }else if( zComFile ){
4048 blob_read_from_file(&comment, zComFile, ExtFILE);
4049 blob_to_utf8_no_bom(&comment, 1);
4050 }else if( zNewComment ){
4051 blob_init(&comment, zNewComment, -1);
4052 }
4053 if( blob_size(&comment)>0
4054 && comment_compare(zComment, blob_str(&comment))==0
4055 ){
4056 int rc;
4057 while( (rc = suspicious_comment(&comment, ckComFlgs))!=0 ){
4058 char cReply;
4059 Blob ans;
4060 if( !fEditComment ){
4061 fossil_fatal("Amend aborted; "
4062 "use --no-verify-comment to override");
4063 }
4064 if( rc==COMCK_PREVIEW ){
4065 prompt_user("\nContinue (Y/n/e=edit)? ", &ans);
4066 }else{
4067 prompt_user("\nContinue (y/n/E=edit)? ", &ans);
4068 }
4069 cReply = blob_str(&ans)[0];
4070 cReply = fossil_tolower(cReply);
4071 blob_reset(&ans);
4072 if( cReply=='n' ){
4073 fossil_fatal("Amend aborted.");
4074 }
4075 if( cReply=='e' || (cReply!='y' && rc!=COMCK_PREVIEW) ){
4076 char *zPrior = blob_materialize(&comment);
4077 blob_init(&comment, 0, 0);
4078 prepare_amend_comment(&comment, zPrior, zUuid);
4079 fossil_free(zPrior);
4080 continue;
4081 }else{
4082 break;
4083 }
4084 }
4085 }
4086 add_comment(blob_str(&comment));
4087 }
4088 if( zNewDate && zNewDate[0] && fossil_strcmp(zDate,zNewDate)!=0 ){
4089 if( is_datetime(zNewDate) ){
4090 add_date(zNewDate);
4091 }else{
4092 fossil_fatal("Unsupported date format, use YYYY-MM-DD HH:MM:SS");
4093
+1 -1
--- src/user.c
+++ src/user.c
@@ -298,11 +298,11 @@
298298
** Prompt the user to enter a single line of text.
299299
*/
300300
void prompt_user(const char *zPrompt, Blob *pIn){
301301
char *z;
302302
char zLine[1000];
303
- blob_zero(pIn);
303
+ blob_init(pIn, 0, 0);
304304
fossil_force_newline();
305305
fossil_print("%s", zPrompt);
306306
fflush(stdout);
307307
z = fgets(zLine, sizeof(zLine), stdin);
308308
if( z ){
309309
--- src/user.c
+++ src/user.c
@@ -298,11 +298,11 @@
298 ** Prompt the user to enter a single line of text.
299 */
300 void prompt_user(const char *zPrompt, Blob *pIn){
301 char *z;
302 char zLine[1000];
303 blob_zero(pIn);
304 fossil_force_newline();
305 fossil_print("%s", zPrompt);
306 fflush(stdout);
307 z = fgets(zLine, sizeof(zLine), stdin);
308 if( z ){
309
--- src/user.c
+++ src/user.c
@@ -298,11 +298,11 @@
298 ** Prompt the user to enter a single line of text.
299 */
300 void prompt_user(const char *zPrompt, Blob *pIn){
301 char *z;
302 char zLine[1000];
303 blob_init(pIn, 0, 0);
304 fossil_force_newline();
305 fossil_print("%s", zPrompt);
306 fflush(stdout);
307 z = fgets(zLine, sizeof(zLine), stdin);
308 if( z ){
309

Keyboard Shortcuts

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