Fossil SCM

Enhance the options for the 'amend' command: document --date-override, and add --user-override, --verbose, and --dry-run

florian 2018-12-25 09:49 UTC trunk
Commit 36369faab401d5cf9914addaa244e9424162aa8076207b96ce6510938a6d5df6
1 file changed +47 -11
+47 -11
--- src/info.c
+++ src/info.c
@@ -2489,11 +2489,18 @@
24892489
24902490
/*
24912491
** The apply_newtags method is called after all newtags have been added
24922492
** and the control artifact is completed and then written to the DB.
24932493
*/
2494
-static void apply_newtags(Blob *ctrl, int rid, const char *zUuid){
2494
+static void apply_newtags(
2495
+ Blob *ctrl,
2496
+ int rid,
2497
+ const char *zUuid,
2498
+ const char *zUserOvrd, /* The user name on the control artifact */
2499
+ int fVerbose, /* Print the generated control artifact */
2500
+ int fDryRun /* Make no changes, just print what would happen */
2501
+){
24952502
Stmt q;
24962503
int nChng = 0;
24972504
24982505
db_prepare(&q, "SELECT tag, prefix, value FROM newtags"
24992506
" ORDER BY prefix || tag");
@@ -2510,19 +2517,36 @@
25102517
}
25112518
db_finalize(&q);
25122519
if( nChng>0 ){
25132520
int nrid;
25142521
Blob cksum;
2515
- blob_appendf(ctrl, "U %F\n", login_name());
2522
+ if( zUserOvrd && zUserOvrd[0] ){
2523
+ blob_appendf(ctrl, "U %F\n", zUserOvrd);
2524
+ }else{
2525
+ blob_appendf(ctrl, "U %F\n", login_name());
2526
+ }
25162527
md5sum_blob(ctrl, &cksum);
25172528
blob_appendf(ctrl, "Z %b\n", &cksum);
2518
- db_begin_transaction();
2519
- g.markPrivate = content_is_private(rid);
2520
- nrid = content_put(ctrl);
2521
- manifest_crosslink(nrid, ctrl, MC_PERMIT_HOOKS);
2522
- assert( blob_is_reset(ctrl) );
2523
- db_end_transaction(0);
2529
+ if( fVerbose!=0 ){
2530
+ assert( g.isHTTP==0 ); /* Only print control artifact in console mode. */
2531
+ fossil_print("%s\n", blob_str(ctrl));
2532
+ }
2533
+ if( fDryRun==0 ){
2534
+ db_begin_transaction();
2535
+ g.markPrivate = content_is_private(rid);
2536
+ nrid = content_put(ctrl);
2537
+ manifest_crosslink(nrid, ctrl, MC_PERMIT_HOOKS);
2538
+ assert( blob_is_reset(ctrl) );
2539
+ db_end_transaction(0);
2540
+ }else{
2541
+ blob_reset(ctrl);
2542
+ }
2543
+ }else{
2544
+ if( fVerbose!=0 ){
2545
+ assert( g.isHTTP==0 ); /* Only print control artifact in console mode. */
2546
+ fossil_print("No changes (empty control artifact)\n\n");
2547
+ }
25242548
}
25252549
}
25262550
25272551
/*
25282552
** This method checks that the date can be parsed.
@@ -2658,11 +2682,11 @@
26582682
db_finalize(&q);
26592683
if( zHideFlag[0] ) hide_branch();
26602684
if( zCloseFlag[0] ) close_leaf(rid);
26612685
if( zNewTagFlag[0] && zNewTag[0] ) add_tag(zNewTag);
26622686
if( zNewBrFlag[0] && zNewBranch[0] ) change_branch(rid,zNewBranch);
2663
- apply_newtags(&ctrl, rid, zUuid);
2687
+ apply_newtags(&ctrl, rid, zUuid, 0, 0, 0);
26642688
cgi_redirectf("%R/ci/%S", zUuid);
26652689
}
26662690
blob_zero(&comment);
26672691
blob_append(&comment, zNewComment, -1);
26682692
zUuid[10] = 0;
@@ -2912,10 +2936,14 @@
29122936
** --tag TAG Add new TAG to this check-in
29132937
** --cancel TAG Cancel TAG from this check-in
29142938
** --branch NAME Make this check-in the start of branch NAME
29152939
** --hide Hide branch starting from this check-in
29162940
** --close Mark this "leaf" as closed
2941
+** -v|--verbose Print the generated control artifact
2942
+** -n|--dry-run Make no changes, just print what would happen
2943
+** --date-override DATETIME Set the change time on the control artifact
2944
+** --user-override USER Set the user name on the control artifact
29172945
**
29182946
** DATETIME may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
29192947
** year-month-day form, it may be truncated, the "T" may be replaced by
29202948
** a space, and it may also name a timezone offset from UTC as "-HH:MM"
29212949
** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z"
@@ -2941,11 +2969,14 @@
29412969
int fPropagateColor; /* True if color propagates before amend */
29422970
int fNewPropagateColor = 0; /* True if color propagates after amend */
29432971
int fHasHidden = 0; /* True if hidden tag already set */
29442972
int fHasClosed = 0; /* True if closed tag already set */
29452973
int fEditComment; /* True if editor to be used for comment */
2974
+ int fVerbose; /* Print the generated control artifact */
2975
+ int fDryRun; /* No changes, just print what would happen */
29462976
const char *zChngTime; /* The change time on the control artifact */
2977
+ const char *zUserOvrd; /* The user name on the control artifact */
29472978
const char *zUuid;
29482979
Blob ctrl;
29492980
Blob comment;
29502981
char *zNow;
29512982
int nTags, nCancels;
@@ -2967,11 +2998,16 @@
29672998
zNewUser = find_option("author",0,1);
29682999
pzNewTags = find_repeatable_option("tag",0,&nTags);
29693000
pzCancelTags = find_repeatable_option("cancel",0,&nCancels);
29703001
fClose = find_option("close",0,0)!=0;
29713002
fHide = find_option("hide",0,0)!=0;
2972
- zChngTime = find_option("chngtime",0,1);
3003
+ fVerbose = find_option("verbose","v",0)!=0;
3004
+ fDryRun = find_option("dry-run","n",0)!=0;
3005
+ if( fDryRun==0 ) fDryRun = find_option("dryrun","n",0)!=0;
3006
+ zChngTime = find_option("date-override",0,1);
3007
+ if( zChngTime==0 ) zChngTime = find_option("chngtime",0,1);
3008
+ zUserOvrd = find_option("user-override",0,1);
29733009
db_find_and_open_repository(0,0);
29743010
user_select();
29753011
verify_all_options();
29763012
if( g.argc<3 || g.argc>=4 ) usage(AMEND_USAGE_STMT);
29773013
rid = name_to_typed_rid(g.argv[2], "ci");
@@ -3063,8 +3099,8 @@
30633099
fossil_free((void *)pzCancelTags);
30643100
}
30653101
if( fHide && !fHasHidden ) hide_branch();
30663102
if( fClose && !fHasClosed ) close_leaf(rid);
30673103
if( zNewBranch && zNewBranch[0] ) change_branch(rid,zNewBranch);
3068
- apply_newtags(&ctrl, rid, zUuid);
3104
+ apply_newtags(&ctrl, rid, zUuid, zUserOvrd, fVerbose, fDryRun);
30693105
show_common_info(rid, "uuid:", 1, 0);
30703106
}
30713107
--- src/info.c
+++ src/info.c
@@ -2489,11 +2489,18 @@
2489
2490 /*
2491 ** The apply_newtags method is called after all newtags have been added
2492 ** and the control artifact is completed and then written to the DB.
2493 */
2494 static void apply_newtags(Blob *ctrl, int rid, const char *zUuid){
 
 
 
 
 
 
 
2495 Stmt q;
2496 int nChng = 0;
2497
2498 db_prepare(&q, "SELECT tag, prefix, value FROM newtags"
2499 " ORDER BY prefix || tag");
@@ -2510,19 +2517,36 @@
2510 }
2511 db_finalize(&q);
2512 if( nChng>0 ){
2513 int nrid;
2514 Blob cksum;
2515 blob_appendf(ctrl, "U %F\n", login_name());
 
 
 
 
2516 md5sum_blob(ctrl, &cksum);
2517 blob_appendf(ctrl, "Z %b\n", &cksum);
2518 db_begin_transaction();
2519 g.markPrivate = content_is_private(rid);
2520 nrid = content_put(ctrl);
2521 manifest_crosslink(nrid, ctrl, MC_PERMIT_HOOKS);
2522 assert( blob_is_reset(ctrl) );
2523 db_end_transaction(0);
 
 
 
 
 
 
 
 
 
 
 
 
 
2524 }
2525 }
2526
2527 /*
2528 ** This method checks that the date can be parsed.
@@ -2658,11 +2682,11 @@
2658 db_finalize(&q);
2659 if( zHideFlag[0] ) hide_branch();
2660 if( zCloseFlag[0] ) close_leaf(rid);
2661 if( zNewTagFlag[0] && zNewTag[0] ) add_tag(zNewTag);
2662 if( zNewBrFlag[0] && zNewBranch[0] ) change_branch(rid,zNewBranch);
2663 apply_newtags(&ctrl, rid, zUuid);
2664 cgi_redirectf("%R/ci/%S", zUuid);
2665 }
2666 blob_zero(&comment);
2667 blob_append(&comment, zNewComment, -1);
2668 zUuid[10] = 0;
@@ -2912,10 +2936,14 @@
2912 ** --tag TAG Add new TAG to this check-in
2913 ** --cancel TAG Cancel TAG from this check-in
2914 ** --branch NAME Make this check-in the start of branch NAME
2915 ** --hide Hide branch starting from this check-in
2916 ** --close Mark this "leaf" as closed
 
 
 
 
2917 **
2918 ** DATETIME may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
2919 ** year-month-day form, it may be truncated, the "T" may be replaced by
2920 ** a space, and it may also name a timezone offset from UTC as "-HH:MM"
2921 ** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z"
@@ -2941,11 +2969,14 @@
2941 int fPropagateColor; /* True if color propagates before amend */
2942 int fNewPropagateColor = 0; /* True if color propagates after amend */
2943 int fHasHidden = 0; /* True if hidden tag already set */
2944 int fHasClosed = 0; /* True if closed tag already set */
2945 int fEditComment; /* True if editor to be used for comment */
 
 
2946 const char *zChngTime; /* The change time on the control artifact */
 
2947 const char *zUuid;
2948 Blob ctrl;
2949 Blob comment;
2950 char *zNow;
2951 int nTags, nCancels;
@@ -2967,11 +2998,16 @@
2967 zNewUser = find_option("author",0,1);
2968 pzNewTags = find_repeatable_option("tag",0,&nTags);
2969 pzCancelTags = find_repeatable_option("cancel",0,&nCancels);
2970 fClose = find_option("close",0,0)!=0;
2971 fHide = find_option("hide",0,0)!=0;
2972 zChngTime = find_option("chngtime",0,1);
 
 
 
 
 
2973 db_find_and_open_repository(0,0);
2974 user_select();
2975 verify_all_options();
2976 if( g.argc<3 || g.argc>=4 ) usage(AMEND_USAGE_STMT);
2977 rid = name_to_typed_rid(g.argv[2], "ci");
@@ -3063,8 +3099,8 @@
3063 fossil_free((void *)pzCancelTags);
3064 }
3065 if( fHide && !fHasHidden ) hide_branch();
3066 if( fClose && !fHasClosed ) close_leaf(rid);
3067 if( zNewBranch && zNewBranch[0] ) change_branch(rid,zNewBranch);
3068 apply_newtags(&ctrl, rid, zUuid);
3069 show_common_info(rid, "uuid:", 1, 0);
3070 }
3071
--- src/info.c
+++ src/info.c
@@ -2489,11 +2489,18 @@
2489
2490 /*
2491 ** The apply_newtags method is called after all newtags have been added
2492 ** and the control artifact is completed and then written to the DB.
2493 */
2494 static void apply_newtags(
2495 Blob *ctrl,
2496 int rid,
2497 const char *zUuid,
2498 const char *zUserOvrd, /* The user name on the control artifact */
2499 int fVerbose, /* Print the generated control artifact */
2500 int fDryRun /* Make no changes, just print what would happen */
2501 ){
2502 Stmt q;
2503 int nChng = 0;
2504
2505 db_prepare(&q, "SELECT tag, prefix, value FROM newtags"
2506 " ORDER BY prefix || tag");
@@ -2510,19 +2517,36 @@
2517 }
2518 db_finalize(&q);
2519 if( nChng>0 ){
2520 int nrid;
2521 Blob cksum;
2522 if( zUserOvrd && zUserOvrd[0] ){
2523 blob_appendf(ctrl, "U %F\n", zUserOvrd);
2524 }else{
2525 blob_appendf(ctrl, "U %F\n", login_name());
2526 }
2527 md5sum_blob(ctrl, &cksum);
2528 blob_appendf(ctrl, "Z %b\n", &cksum);
2529 if( fVerbose!=0 ){
2530 assert( g.isHTTP==0 ); /* Only print control artifact in console mode. */
2531 fossil_print("%s\n", blob_str(ctrl));
2532 }
2533 if( fDryRun==0 ){
2534 db_begin_transaction();
2535 g.markPrivate = content_is_private(rid);
2536 nrid = content_put(ctrl);
2537 manifest_crosslink(nrid, ctrl, MC_PERMIT_HOOKS);
2538 assert( blob_is_reset(ctrl) );
2539 db_end_transaction(0);
2540 }else{
2541 blob_reset(ctrl);
2542 }
2543 }else{
2544 if( fVerbose!=0 ){
2545 assert( g.isHTTP==0 ); /* Only print control artifact in console mode. */
2546 fossil_print("No changes (empty control artifact)\n\n");
2547 }
2548 }
2549 }
2550
2551 /*
2552 ** This method checks that the date can be parsed.
@@ -2658,11 +2682,11 @@
2682 db_finalize(&q);
2683 if( zHideFlag[0] ) hide_branch();
2684 if( zCloseFlag[0] ) close_leaf(rid);
2685 if( zNewTagFlag[0] && zNewTag[0] ) add_tag(zNewTag);
2686 if( zNewBrFlag[0] && zNewBranch[0] ) change_branch(rid,zNewBranch);
2687 apply_newtags(&ctrl, rid, zUuid, 0, 0, 0);
2688 cgi_redirectf("%R/ci/%S", zUuid);
2689 }
2690 blob_zero(&comment);
2691 blob_append(&comment, zNewComment, -1);
2692 zUuid[10] = 0;
@@ -2912,10 +2936,14 @@
2936 ** --tag TAG Add new TAG to this check-in
2937 ** --cancel TAG Cancel TAG from this check-in
2938 ** --branch NAME Make this check-in the start of branch NAME
2939 ** --hide Hide branch starting from this check-in
2940 ** --close Mark this "leaf" as closed
2941 ** -v|--verbose Print the generated control artifact
2942 ** -n|--dry-run Make no changes, just print what would happen
2943 ** --date-override DATETIME Set the change time on the control artifact
2944 ** --user-override USER Set the user name on the control artifact
2945 **
2946 ** DATETIME may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
2947 ** year-month-day form, it may be truncated, the "T" may be replaced by
2948 ** a space, and it may also name a timezone offset from UTC as "-HH:MM"
2949 ** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z"
@@ -2941,11 +2969,14 @@
2969 int fPropagateColor; /* True if color propagates before amend */
2970 int fNewPropagateColor = 0; /* True if color propagates after amend */
2971 int fHasHidden = 0; /* True if hidden tag already set */
2972 int fHasClosed = 0; /* True if closed tag already set */
2973 int fEditComment; /* True if editor to be used for comment */
2974 int fVerbose; /* Print the generated control artifact */
2975 int fDryRun; /* No changes, just print what would happen */
2976 const char *zChngTime; /* The change time on the control artifact */
2977 const char *zUserOvrd; /* The user name on the control artifact */
2978 const char *zUuid;
2979 Blob ctrl;
2980 Blob comment;
2981 char *zNow;
2982 int nTags, nCancels;
@@ -2967,11 +2998,16 @@
2998 zNewUser = find_option("author",0,1);
2999 pzNewTags = find_repeatable_option("tag",0,&nTags);
3000 pzCancelTags = find_repeatable_option("cancel",0,&nCancels);
3001 fClose = find_option("close",0,0)!=0;
3002 fHide = find_option("hide",0,0)!=0;
3003 fVerbose = find_option("verbose","v",0)!=0;
3004 fDryRun = find_option("dry-run","n",0)!=0;
3005 if( fDryRun==0 ) fDryRun = find_option("dryrun","n",0)!=0;
3006 zChngTime = find_option("date-override",0,1);
3007 if( zChngTime==0 ) zChngTime = find_option("chngtime",0,1);
3008 zUserOvrd = find_option("user-override",0,1);
3009 db_find_and_open_repository(0,0);
3010 user_select();
3011 verify_all_options();
3012 if( g.argc<3 || g.argc>=4 ) usage(AMEND_USAGE_STMT);
3013 rid = name_to_typed_rid(g.argv[2], "ci");
@@ -3063,8 +3099,8 @@
3099 fossil_free((void *)pzCancelTags);
3100 }
3101 if( fHide && !fHasHidden ) hide_branch();
3102 if( fClose && !fHasClosed ) close_leaf(rid);
3103 if( zNewBranch && zNewBranch[0] ) change_branch(rid,zNewBranch);
3104 apply_newtags(&ctrl, rid, zUuid, zUserOvrd, fVerbose, fDryRun);
3105 show_common_info(rid, "uuid:", 1, 0);
3106 }
3107

Keyboard Shortcuts

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