Fossil SCM
Enhance the options for the 'amend' command: document --date-override, and add --user-override, --verbose, and --dry-run
Commit
36369faab401d5cf9914addaa244e9424162aa8076207b96ce6510938a6d5df6
Parent
19eaa3cae4d5b30…
1 file changed
+47
-11
+47
-11
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -2489,11 +2489,18 @@ | ||
| 2489 | 2489 | |
| 2490 | 2490 | /* |
| 2491 | 2491 | ** The apply_newtags method is called after all newtags have been added |
| 2492 | 2492 | ** and the control artifact is completed and then written to the DB. |
| 2493 | 2493 | */ |
| 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 | +){ | |
| 2495 | 2502 | Stmt q; |
| 2496 | 2503 | int nChng = 0; |
| 2497 | 2504 | |
| 2498 | 2505 | db_prepare(&q, "SELECT tag, prefix, value FROM newtags" |
| 2499 | 2506 | " ORDER BY prefix || tag"); |
| @@ -2510,19 +2517,36 @@ | ||
| 2510 | 2517 | } |
| 2511 | 2518 | db_finalize(&q); |
| 2512 | 2519 | if( nChng>0 ){ |
| 2513 | 2520 | int nrid; |
| 2514 | 2521 | 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 | + } | |
| 2516 | 2527 | md5sum_blob(ctrl, &cksum); |
| 2517 | 2528 | 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 | + } | |
| 2524 | 2548 | } |
| 2525 | 2549 | } |
| 2526 | 2550 | |
| 2527 | 2551 | /* |
| 2528 | 2552 | ** This method checks that the date can be parsed. |
| @@ -2658,11 +2682,11 @@ | ||
| 2658 | 2682 | db_finalize(&q); |
| 2659 | 2683 | if( zHideFlag[0] ) hide_branch(); |
| 2660 | 2684 | if( zCloseFlag[0] ) close_leaf(rid); |
| 2661 | 2685 | if( zNewTagFlag[0] && zNewTag[0] ) add_tag(zNewTag); |
| 2662 | 2686 | if( zNewBrFlag[0] && zNewBranch[0] ) change_branch(rid,zNewBranch); |
| 2663 | - apply_newtags(&ctrl, rid, zUuid); | |
| 2687 | + apply_newtags(&ctrl, rid, zUuid, 0, 0, 0); | |
| 2664 | 2688 | cgi_redirectf("%R/ci/%S", zUuid); |
| 2665 | 2689 | } |
| 2666 | 2690 | blob_zero(&comment); |
| 2667 | 2691 | blob_append(&comment, zNewComment, -1); |
| 2668 | 2692 | zUuid[10] = 0; |
| @@ -2912,10 +2936,14 @@ | ||
| 2912 | 2936 | ** --tag TAG Add new TAG to this check-in |
| 2913 | 2937 | ** --cancel TAG Cancel TAG from this check-in |
| 2914 | 2938 | ** --branch NAME Make this check-in the start of branch NAME |
| 2915 | 2939 | ** --hide Hide branch starting from this check-in |
| 2916 | 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 | |
| 2917 | 2945 | ** |
| 2918 | 2946 | ** DATETIME may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in |
| 2919 | 2947 | ** year-month-day form, it may be truncated, the "T" may be replaced by |
| 2920 | 2948 | ** a space, and it may also name a timezone offset from UTC as "-HH:MM" |
| 2921 | 2949 | ** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z" |
| @@ -2941,11 +2969,14 @@ | ||
| 2941 | 2969 | int fPropagateColor; /* True if color propagates before amend */ |
| 2942 | 2970 | int fNewPropagateColor = 0; /* True if color propagates after amend */ |
| 2943 | 2971 | int fHasHidden = 0; /* True if hidden tag already set */ |
| 2944 | 2972 | int fHasClosed = 0; /* True if closed tag already set */ |
| 2945 | 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 */ | |
| 2946 | 2976 | const char *zChngTime; /* The change time on the control artifact */ |
| 2977 | + const char *zUserOvrd; /* The user name on the control artifact */ | |
| 2947 | 2978 | const char *zUuid; |
| 2948 | 2979 | Blob ctrl; |
| 2949 | 2980 | Blob comment; |
| 2950 | 2981 | char *zNow; |
| 2951 | 2982 | int nTags, nCancels; |
| @@ -2967,11 +2998,16 @@ | ||
| 2967 | 2998 | zNewUser = find_option("author",0,1); |
| 2968 | 2999 | pzNewTags = find_repeatable_option("tag",0,&nTags); |
| 2969 | 3000 | pzCancelTags = find_repeatable_option("cancel",0,&nCancels); |
| 2970 | 3001 | fClose = find_option("close",0,0)!=0; |
| 2971 | 3002 | 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); | |
| 2973 | 3009 | db_find_and_open_repository(0,0); |
| 2974 | 3010 | user_select(); |
| 2975 | 3011 | verify_all_options(); |
| 2976 | 3012 | if( g.argc<3 || g.argc>=4 ) usage(AMEND_USAGE_STMT); |
| 2977 | 3013 | rid = name_to_typed_rid(g.argv[2], "ci"); |
| @@ -3063,8 +3099,8 @@ | ||
| 3063 | 3099 | fossil_free((void *)pzCancelTags); |
| 3064 | 3100 | } |
| 3065 | 3101 | if( fHide && !fHasHidden ) hide_branch(); |
| 3066 | 3102 | if( fClose && !fHasClosed ) close_leaf(rid); |
| 3067 | 3103 | if( zNewBranch && zNewBranch[0] ) change_branch(rid,zNewBranch); |
| 3068 | - apply_newtags(&ctrl, rid, zUuid); | |
| 3104 | + apply_newtags(&ctrl, rid, zUuid, zUserOvrd, fVerbose, fDryRun); | |
| 3069 | 3105 | show_common_info(rid, "uuid:", 1, 0); |
| 3070 | 3106 | } |
| 3071 | 3107 |
| --- 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 |