Fossil SCM
branch close: added --user/date-override options, per forum feedback.
Commit
94764e962c098ee4a61e55ceed1fc029a05f9fe294027d6da36846cc79202b0e
Parent
25197505b1f0fbe…
1 file changed
+15
-10
+15
-10
| --- src/branch.c | ||
| +++ src/branch.c | ||
| @@ -346,21 +346,25 @@ | ||
| 346 | 346 | ); |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /* |
| 350 | 350 | ** Implementation of (branch close) subcommand. nStartAtArg is the |
| 351 | -** g.argv index to start reading branch names. If fDryRun is true then | |
| 352 | -** the change is run in dry-run mode. Fails fatally on error. | |
| 351 | +** g.argv index to start reading branch names. Fails fatally on error. | |
| 353 | 352 | */ |
| 354 | -static void branch_cmd_close(int nStartAtArg, int fVerbose, | |
| 355 | - int fDryRun){ | |
| 353 | +static void branch_cmd_close(int nStartAtArg){ | |
| 356 | 354 | int argPos = nStartAtArg; /* g.argv pos with first branch name */ |
| 357 | 355 | Blob manifest = empty_blob; /* Control artifact */ |
| 358 | 356 | Stmt q = empty_Stmt; |
| 359 | 357 | int nQueued = 0; /* # of branches queued for closing */ |
| 360 | 358 | char * zUuid = 0; /* Resolved branch UUID. */ |
| 359 | + const int fVerbose = find_option("verbose","v",0)!=0; | |
| 360 | + const int fDryRun = find_option("dry-run","n",0)!=0; | |
| 361 | + const char *zDateOvrd = find_option("date-override",0,1); | |
| 362 | + const char *zUserOvrd = find_option("user-override",0,1); | |
| 361 | 363 | int doRollback = fDryRun!=0; /* Roll back transaction if true */ |
| 364 | + | |
| 365 | + verify_all_options(); | |
| 362 | 366 | db_begin_transaction(); |
| 363 | 367 | db_multi_exec("CREATE TEMP TABLE brclose(" |
| 364 | 368 | "rid INTEGER UNIQUE ON CONFLICT IGNORE" |
| 365 | 369 | ")"); |
| 366 | 370 | db_prepare(&q, "INSERT INTO brclose(rid) VALUES(:rid)"); |
| @@ -390,19 +394,21 @@ | ||
| 390 | 394 | if(!nQueued){ |
| 391 | 395 | fossil_warning("No branches queued for closing. Nothing to do."); |
| 392 | 396 | doRollback = 1; |
| 393 | 397 | goto br_close_end; |
| 394 | 398 | } |
| 395 | - blob_appendf(&manifest, "D %z\n", date_in_standard_format("now")); | |
| 399 | + blob_appendf(&manifest, "D %z\n", | |
| 400 | + date_in_standard_format( zDateOvrd ? zDateOvrd : "now")); | |
| 396 | 401 | db_prepare(&q, "SELECT uuid FROM blob WHERE rid IN brclose"); |
| 397 | 402 | while(SQLITE_ROW==db_step(&q)){ |
| 398 | 403 | const char * zHash = db_column_text(&q, 0); |
| 399 | 404 | blob_appendf(&manifest, "T +closed %s\n", zHash); |
| 400 | 405 | } |
| 401 | 406 | db_finalize(&q); |
| 402 | 407 | user_select(); |
| 403 | - blob_appendf(&manifest, "U %F\n", login_name()); | |
| 408 | + blob_appendf(&manifest, "U %F\n", | |
| 409 | + zUserOvrd ? zUserOvrd : login_name()); | |
| 404 | 410 | { /* Z-card and save artifact */ |
| 405 | 411 | int newRid; |
| 406 | 412 | Blob cksum = empty_blob; |
| 407 | 413 | md5sum_blob(&manifest, &cksum); |
| 408 | 414 | blob_appendf(&manifest, "Z %b\n", &cksum); |
| @@ -487,10 +493,12 @@ | ||
| 487 | 493 | ** will only resolve checkin names and skips any which resolve |
| 488 | 494 | ** to non-leaf or closed checkins. Options: |
| 489 | 495 | ** -n|--dry-run do not commit changes and dump artifact |
| 490 | 496 | ** to stdout |
| 491 | 497 | ** -v|--verbose output more information |
| 498 | +** --date-override DATE DATE to use instead of 'now' | |
| 499 | +** --user-override USER USER to use instead of the current default | |
| 492 | 500 | ** |
| 493 | 501 | ** Options valid for all subcommands: |
| 494 | 502 | ** |
| 495 | 503 | ** -R|--repository REPO Run commands on repository REPO |
| 496 | 504 | */ |
| @@ -550,17 +558,14 @@ | ||
| 550 | 558 | } |
| 551 | 559 | db_finalize(&q); |
| 552 | 560 | }else if( strncmp(zCmd,"new",n)==0 ){ |
| 553 | 561 | branch_new(); |
| 554 | 562 | }else if( strncmp(zCmd,"close",5)==0 ){ |
| 555 | - const int fDryRun = find_option("dry-run","n",0)!=0; | |
| 556 | - const int fVerbose = find_option("verbose","v",0)!=0; | |
| 557 | - verify_all_options(); | |
| 558 | 563 | if(g.argc<4){ |
| 559 | 564 | usage("branch close branch-name(s)..."); |
| 560 | 565 | } |
| 561 | - branch_cmd_close(3, fVerbose, fDryRun); | |
| 566 | + branch_cmd_close(3); | |
| 562 | 567 | }else{ |
| 563 | 568 | fossil_fatal("branch subcommand should be one of: " |
| 564 | 569 | "close current info list ls new"); |
| 565 | 570 | } |
| 566 | 571 | } |
| 567 | 572 |
| --- src/branch.c | |
| +++ src/branch.c | |
| @@ -346,21 +346,25 @@ | |
| 346 | ); |
| 347 | } |
| 348 | |
| 349 | /* |
| 350 | ** Implementation of (branch close) subcommand. nStartAtArg is the |
| 351 | ** g.argv index to start reading branch names. If fDryRun is true then |
| 352 | ** the change is run in dry-run mode. Fails fatally on error. |
| 353 | */ |
| 354 | static void branch_cmd_close(int nStartAtArg, int fVerbose, |
| 355 | int fDryRun){ |
| 356 | int argPos = nStartAtArg; /* g.argv pos with first branch name */ |
| 357 | Blob manifest = empty_blob; /* Control artifact */ |
| 358 | Stmt q = empty_Stmt; |
| 359 | int nQueued = 0; /* # of branches queued for closing */ |
| 360 | char * zUuid = 0; /* Resolved branch UUID. */ |
| 361 | int doRollback = fDryRun!=0; /* Roll back transaction if true */ |
| 362 | db_begin_transaction(); |
| 363 | db_multi_exec("CREATE TEMP TABLE brclose(" |
| 364 | "rid INTEGER UNIQUE ON CONFLICT IGNORE" |
| 365 | ")"); |
| 366 | db_prepare(&q, "INSERT INTO brclose(rid) VALUES(:rid)"); |
| @@ -390,19 +394,21 @@ | |
| 390 | if(!nQueued){ |
| 391 | fossil_warning("No branches queued for closing. Nothing to do."); |
| 392 | doRollback = 1; |
| 393 | goto br_close_end; |
| 394 | } |
| 395 | blob_appendf(&manifest, "D %z\n", date_in_standard_format("now")); |
| 396 | db_prepare(&q, "SELECT uuid FROM blob WHERE rid IN brclose"); |
| 397 | while(SQLITE_ROW==db_step(&q)){ |
| 398 | const char * zHash = db_column_text(&q, 0); |
| 399 | blob_appendf(&manifest, "T +closed %s\n", zHash); |
| 400 | } |
| 401 | db_finalize(&q); |
| 402 | user_select(); |
| 403 | blob_appendf(&manifest, "U %F\n", login_name()); |
| 404 | { /* Z-card and save artifact */ |
| 405 | int newRid; |
| 406 | Blob cksum = empty_blob; |
| 407 | md5sum_blob(&manifest, &cksum); |
| 408 | blob_appendf(&manifest, "Z %b\n", &cksum); |
| @@ -487,10 +493,12 @@ | |
| 487 | ** will only resolve checkin names and skips any which resolve |
| 488 | ** to non-leaf or closed checkins. Options: |
| 489 | ** -n|--dry-run do not commit changes and dump artifact |
| 490 | ** to stdout |
| 491 | ** -v|--verbose output more information |
| 492 | ** |
| 493 | ** Options valid for all subcommands: |
| 494 | ** |
| 495 | ** -R|--repository REPO Run commands on repository REPO |
| 496 | */ |
| @@ -550,17 +558,14 @@ | |
| 550 | } |
| 551 | db_finalize(&q); |
| 552 | }else if( strncmp(zCmd,"new",n)==0 ){ |
| 553 | branch_new(); |
| 554 | }else if( strncmp(zCmd,"close",5)==0 ){ |
| 555 | const int fDryRun = find_option("dry-run","n",0)!=0; |
| 556 | const int fVerbose = find_option("verbose","v",0)!=0; |
| 557 | verify_all_options(); |
| 558 | if(g.argc<4){ |
| 559 | usage("branch close branch-name(s)..."); |
| 560 | } |
| 561 | branch_cmd_close(3, fVerbose, fDryRun); |
| 562 | }else{ |
| 563 | fossil_fatal("branch subcommand should be one of: " |
| 564 | "close current info list ls new"); |
| 565 | } |
| 566 | } |
| 567 |
| --- src/branch.c | |
| +++ src/branch.c | |
| @@ -346,21 +346,25 @@ | |
| 346 | ); |
| 347 | } |
| 348 | |
| 349 | /* |
| 350 | ** Implementation of (branch close) subcommand. nStartAtArg is the |
| 351 | ** g.argv index to start reading branch names. Fails fatally on error. |
| 352 | */ |
| 353 | static void branch_cmd_close(int nStartAtArg){ |
| 354 | int argPos = nStartAtArg; /* g.argv pos with first branch name */ |
| 355 | Blob manifest = empty_blob; /* Control artifact */ |
| 356 | Stmt q = empty_Stmt; |
| 357 | int nQueued = 0; /* # of branches queued for closing */ |
| 358 | char * zUuid = 0; /* Resolved branch UUID. */ |
| 359 | const int fVerbose = find_option("verbose","v",0)!=0; |
| 360 | const int fDryRun = find_option("dry-run","n",0)!=0; |
| 361 | const char *zDateOvrd = find_option("date-override",0,1); |
| 362 | const char *zUserOvrd = find_option("user-override",0,1); |
| 363 | int doRollback = fDryRun!=0; /* Roll back transaction if true */ |
| 364 | |
| 365 | verify_all_options(); |
| 366 | db_begin_transaction(); |
| 367 | db_multi_exec("CREATE TEMP TABLE brclose(" |
| 368 | "rid INTEGER UNIQUE ON CONFLICT IGNORE" |
| 369 | ")"); |
| 370 | db_prepare(&q, "INSERT INTO brclose(rid) VALUES(:rid)"); |
| @@ -390,19 +394,21 @@ | |
| 394 | if(!nQueued){ |
| 395 | fossil_warning("No branches queued for closing. Nothing to do."); |
| 396 | doRollback = 1; |
| 397 | goto br_close_end; |
| 398 | } |
| 399 | blob_appendf(&manifest, "D %z\n", |
| 400 | date_in_standard_format( zDateOvrd ? zDateOvrd : "now")); |
| 401 | db_prepare(&q, "SELECT uuid FROM blob WHERE rid IN brclose"); |
| 402 | while(SQLITE_ROW==db_step(&q)){ |
| 403 | const char * zHash = db_column_text(&q, 0); |
| 404 | blob_appendf(&manifest, "T +closed %s\n", zHash); |
| 405 | } |
| 406 | db_finalize(&q); |
| 407 | user_select(); |
| 408 | blob_appendf(&manifest, "U %F\n", |
| 409 | zUserOvrd ? zUserOvrd : login_name()); |
| 410 | { /* Z-card and save artifact */ |
| 411 | int newRid; |
| 412 | Blob cksum = empty_blob; |
| 413 | md5sum_blob(&manifest, &cksum); |
| 414 | blob_appendf(&manifest, "Z %b\n", &cksum); |
| @@ -487,10 +493,12 @@ | |
| 493 | ** will only resolve checkin names and skips any which resolve |
| 494 | ** to non-leaf or closed checkins. Options: |
| 495 | ** -n|--dry-run do not commit changes and dump artifact |
| 496 | ** to stdout |
| 497 | ** -v|--verbose output more information |
| 498 | ** --date-override DATE DATE to use instead of 'now' |
| 499 | ** --user-override USER USER to use instead of the current default |
| 500 | ** |
| 501 | ** Options valid for all subcommands: |
| 502 | ** |
| 503 | ** -R|--repository REPO Run commands on repository REPO |
| 504 | */ |
| @@ -550,17 +558,14 @@ | |
| 558 | } |
| 559 | db_finalize(&q); |
| 560 | }else if( strncmp(zCmd,"new",n)==0 ){ |
| 561 | branch_new(); |
| 562 | }else if( strncmp(zCmd,"close",5)==0 ){ |
| 563 | if(g.argc<4){ |
| 564 | usage("branch close branch-name(s)..."); |
| 565 | } |
| 566 | branch_cmd_close(3); |
| 567 | }else{ |
| 568 | fossil_fatal("branch subcommand should be one of: " |
| 569 | "close current info list ls new"); |
| 570 | } |
| 571 | } |
| 572 |