Fossil SCM

branch close: added --user/date-override options, per forum feedback.

stephan 2021-07-22 07:47 branch-close-subcommand
Commit 94764e962c098ee4a61e55ceed1fc029a05f9fe294027d6da36846cc79202b0e
1 file changed +15 -10
+15 -10
--- src/branch.c
+++ src/branch.c
@@ -346,21 +346,25 @@
346346
);
347347
}
348348
349349
/*
350350
** 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.
353352
*/
354
-static void branch_cmd_close(int nStartAtArg, int fVerbose,
355
- int fDryRun){
353
+static void branch_cmd_close(int nStartAtArg){
356354
int argPos = nStartAtArg; /* g.argv pos with first branch name */
357355
Blob manifest = empty_blob; /* Control artifact */
358356
Stmt q = empty_Stmt;
359357
int nQueued = 0; /* # of branches queued for closing */
360358
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);
361363
int doRollback = fDryRun!=0; /* Roll back transaction if true */
364
+
365
+ verify_all_options();
362366
db_begin_transaction();
363367
db_multi_exec("CREATE TEMP TABLE brclose("
364368
"rid INTEGER UNIQUE ON CONFLICT IGNORE"
365369
")");
366370
db_prepare(&q, "INSERT INTO brclose(rid) VALUES(:rid)");
@@ -390,19 +394,21 @@
390394
if(!nQueued){
391395
fossil_warning("No branches queued for closing. Nothing to do.");
392396
doRollback = 1;
393397
goto br_close_end;
394398
}
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"));
396401
db_prepare(&q, "SELECT uuid FROM blob WHERE rid IN brclose");
397402
while(SQLITE_ROW==db_step(&q)){
398403
const char * zHash = db_column_text(&q, 0);
399404
blob_appendf(&manifest, "T +closed %s\n", zHash);
400405
}
401406
db_finalize(&q);
402407
user_select();
403
- blob_appendf(&manifest, "U %F\n", login_name());
408
+ blob_appendf(&manifest, "U %F\n",
409
+ zUserOvrd ? zUserOvrd : login_name());
404410
{ /* Z-card and save artifact */
405411
int newRid;
406412
Blob cksum = empty_blob;
407413
md5sum_blob(&manifest, &cksum);
408414
blob_appendf(&manifest, "Z %b\n", &cksum);
@@ -487,10 +493,12 @@
487493
** will only resolve checkin names and skips any which resolve
488494
** to non-leaf or closed checkins. Options:
489495
** -n|--dry-run do not commit changes and dump artifact
490496
** to stdout
491497
** -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
492500
**
493501
** Options valid for all subcommands:
494502
**
495503
** -R|--repository REPO Run commands on repository REPO
496504
*/
@@ -550,17 +558,14 @@
550558
}
551559
db_finalize(&q);
552560
}else if( strncmp(zCmd,"new",n)==0 ){
553561
branch_new();
554562
}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();
558563
if(g.argc<4){
559564
usage("branch close branch-name(s)...");
560565
}
561
- branch_cmd_close(3, fVerbose, fDryRun);
566
+ branch_cmd_close(3);
562567
}else{
563568
fossil_fatal("branch subcommand should be one of: "
564569
"close current info list ls new");
565570
}
566571
}
567572
--- 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

Keyboard Shortcuts

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