Fossil SCM

Added (branch reopen) subcommand, the inverse of (branch close), per forum feedback.

stephan 2021-07-23 06:12 branch-close-subcommand
Commit 6f3ab14165a851f4ab5a2e0418dd680996247b9e853ab872b4917b593ae385c1
1 file changed +28 -15
+28 -15
--- src/branch.c
+++ src/branch.c
@@ -502,15 +502,16 @@
502502
}
503503
branch_cmd_tag_finalize(fDryRun, fVerbose, zDateOvrd, zUserOvrd);
504504
}
505505
506506
/*
507
-** Implementation of (branch close) subcommand. nStartAtArg is the
508
-** g.argv index to start reading branch/checkin names. Fails fatally
509
-** on error.
507
+** Implementation of (branch close|reopen) subcommands. nStartAtArg is
508
+** the g.argv index to start reading branch/checkin names. The given
509
+** checkins are closed if fClose is true, else their "closed" tag (if
510
+** any) is cancelled. Fails fatally on error.
510511
*/
511
-static void branch_cmd_close(int nStartAtArg){
512
+static void branch_cmd_close(int nStartAtArg, int fClose){
512513
int argPos = nStartAtArg; /* g.argv pos with first branch name */
513514
char * zUuid = 0; /* Resolved branch UUID. */
514515
const int fVerbose = find_option("verbose","v",0)!=0;
515516
const int fDryRun = find_option("dry-run","n",0)!=0;
516517
const char *zDateOvrd = find_option("date-override",0,1);
@@ -519,24 +520,31 @@
519520
verify_all_options();
520521
db_begin_transaction();
521522
for( ; argPos < g.argc; fossil_free(zUuid), ++argPos ){
522523
const char * zName = g.argv[argPos];
523524
const int rid = branch_resolve_name(zName, &zUuid);
525
+ const int isClosed = leaf_is_closed(rid);
524526
if(!is_a_leaf(rid)){
525527
/* This behaviour is different from /ci_edit closing, where
526528
** is_a_leaf() adds a "+" tag and !is_a_leaf() adds a "*"
527529
** tag. We might want to change this to match for consistency's
528
- ** sake. */
530
+ ** sake, but it currently seems unnecessary to close/re-open a
531
+ ** non-leaf. */
529532
fossil_warning("Skipping non-leaf [%s] %s", zName, zUuid);
530533
continue;
531
- }else if(leaf_is_closed(rid)){
532
- fossil_warning("Skipping closed [%s] %s", zName, zUuid);
534
+ }else if(fClose && isClosed){
535
+ fossil_warning("Skipping closed leaf [%s] %s", zName, zUuid);
536
+ continue;
537
+ }else if(!fClose && !isClosed){
538
+ fossil_warning("Skipping non-closed leaf [%s] %s", zName, zUuid);
533539
continue;
534540
}
535
- branch_cmd_tag_add(rid, "+closed");
541
+ branch_cmd_tag_add(rid, fClose ? "+closed" : "-closed");
536542
if(fVerbose!=0){
537
- fossil_print("Closing branch [%s] %s\n", zName, zUuid);
543
+ fossil_print("%s branch [%s] %s\n",
544
+ fClose ? "Closing" : "Re-opening",
545
+ zName, zUuid);
538546
}
539547
}
540548
branch_cmd_tag_finalize(fDryRun, fVerbose, zDateOvrd, zUserOvrd);
541549
}
542550
@@ -546,16 +554,16 @@
546554
** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
547555
**
548556
** Run various subcommands to manage branches of the open repository or
549557
** of the repository identified by the -R or --repository option.
550558
**
551
-** > fossil branch close ?OPTIONS? BRANCH-NAME ?...BRANCH-NAMES?
559
+** > fossil branch close|reopen ?OPTIONS? BRANCH-NAME ?...BRANCH-NAMES?
552560
**
553
-** Close one or more branches by adding the "closed" tag
554
-** to them. It accepts arbitrary unambiguous symbolic names but
561
+** Adds or cancels the "closed" tag to one or more branches.
562
+** It accepts arbitrary unambiguous symbolic names but
555563
** will only resolve checkin names and skips any which resolve
556
-** to non-leaf or closed checkins. Options:
564
+** to non-leaf checkins. Options:
557565
** -n|--dry-run do not commit changes and dump artifact
558566
** to stdout
559567
** -v|--verbose output more information
560568
** --date-override DATE DATE to use instead of 'now'
561569
** --user-override USER USER to use instead of the current default
@@ -667,11 +675,16 @@
667675
branch_new();
668676
}else if( strncmp(zCmd,"close",5)==0 ){
669677
if(g.argc<4){
670678
usage("branch close branch-name(s)...");
671679
}
672
- branch_cmd_close(3);
680
+ branch_cmd_close(3, 1);
681
+ }else if( strncmp(zCmd,"reopen",6)==0 ){
682
+ if(g.argc<4){
683
+ usage("branch reopen branch-name(s)...");
684
+ }
685
+ branch_cmd_close(3, 0);
673686
}else if( strncmp(zCmd,"hide",4)==0 ){
674687
if(g.argc<4){
675688
usage("branch hide branch-name(s)...");
676689
}
677690
branch_cmd_hide(3,1);
@@ -680,11 +693,11 @@
680693
usage("branch unhide branch-name(s)...");
681694
}
682695
branch_cmd_hide(3,0);
683696
}else{
684697
fossil_fatal("branch subcommand should be one of: "
685
- "close current info list ls new");
698
+ "close current hide info list ls new reopen unhide");
686699
}
687700
}
688701
689702
/*
690703
** This is the new-style branch-list page that shows the branch names
691704
--- src/branch.c
+++ src/branch.c
@@ -502,15 +502,16 @@
502 }
503 branch_cmd_tag_finalize(fDryRun, fVerbose, zDateOvrd, zUserOvrd);
504 }
505
506 /*
507 ** Implementation of (branch close) subcommand. nStartAtArg is the
508 ** g.argv index to start reading branch/checkin names. Fails fatally
509 ** on error.
 
510 */
511 static void branch_cmd_close(int nStartAtArg){
512 int argPos = nStartAtArg; /* g.argv pos with first branch name */
513 char * zUuid = 0; /* Resolved branch UUID. */
514 const int fVerbose = find_option("verbose","v",0)!=0;
515 const int fDryRun = find_option("dry-run","n",0)!=0;
516 const char *zDateOvrd = find_option("date-override",0,1);
@@ -519,24 +520,31 @@
519 verify_all_options();
520 db_begin_transaction();
521 for( ; argPos < g.argc; fossil_free(zUuid), ++argPos ){
522 const char * zName = g.argv[argPos];
523 const int rid = branch_resolve_name(zName, &zUuid);
 
524 if(!is_a_leaf(rid)){
525 /* This behaviour is different from /ci_edit closing, where
526 ** is_a_leaf() adds a "+" tag and !is_a_leaf() adds a "*"
527 ** tag. We might want to change this to match for consistency's
528 ** sake. */
 
529 fossil_warning("Skipping non-leaf [%s] %s", zName, zUuid);
530 continue;
531 }else if(leaf_is_closed(rid)){
532 fossil_warning("Skipping closed [%s] %s", zName, zUuid);
 
 
 
533 continue;
534 }
535 branch_cmd_tag_add(rid, "+closed");
536 if(fVerbose!=0){
537 fossil_print("Closing branch [%s] %s\n", zName, zUuid);
 
 
538 }
539 }
540 branch_cmd_tag_finalize(fDryRun, fVerbose, zDateOvrd, zUserOvrd);
541 }
542
@@ -546,16 +554,16 @@
546 ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
547 **
548 ** Run various subcommands to manage branches of the open repository or
549 ** of the repository identified by the -R or --repository option.
550 **
551 ** > fossil branch close ?OPTIONS? BRANCH-NAME ?...BRANCH-NAMES?
552 **
553 ** Close one or more branches by adding the "closed" tag
554 ** to them. It accepts arbitrary unambiguous symbolic names but
555 ** will only resolve checkin names and skips any which resolve
556 ** to non-leaf or closed checkins. Options:
557 ** -n|--dry-run do not commit changes and dump artifact
558 ** to stdout
559 ** -v|--verbose output more information
560 ** --date-override DATE DATE to use instead of 'now'
561 ** --user-override USER USER to use instead of the current default
@@ -667,11 +675,16 @@
667 branch_new();
668 }else if( strncmp(zCmd,"close",5)==0 ){
669 if(g.argc<4){
670 usage("branch close branch-name(s)...");
671 }
672 branch_cmd_close(3);
 
 
 
 
 
673 }else if( strncmp(zCmd,"hide",4)==0 ){
674 if(g.argc<4){
675 usage("branch hide branch-name(s)...");
676 }
677 branch_cmd_hide(3,1);
@@ -680,11 +693,11 @@
680 usage("branch unhide branch-name(s)...");
681 }
682 branch_cmd_hide(3,0);
683 }else{
684 fossil_fatal("branch subcommand should be one of: "
685 "close current info list ls new");
686 }
687 }
688
689 /*
690 ** This is the new-style branch-list page that shows the branch names
691
--- src/branch.c
+++ src/branch.c
@@ -502,15 +502,16 @@
502 }
503 branch_cmd_tag_finalize(fDryRun, fVerbose, zDateOvrd, zUserOvrd);
504 }
505
506 /*
507 ** Implementation of (branch close|reopen) subcommands. nStartAtArg is
508 ** the g.argv index to start reading branch/checkin names. The given
509 ** checkins are closed if fClose is true, else their "closed" tag (if
510 ** any) is cancelled. Fails fatally on error.
511 */
512 static void branch_cmd_close(int nStartAtArg, int fClose){
513 int argPos = nStartAtArg; /* g.argv pos with first branch name */
514 char * zUuid = 0; /* Resolved branch UUID. */
515 const int fVerbose = find_option("verbose","v",0)!=0;
516 const int fDryRun = find_option("dry-run","n",0)!=0;
517 const char *zDateOvrd = find_option("date-override",0,1);
@@ -519,24 +520,31 @@
520 verify_all_options();
521 db_begin_transaction();
522 for( ; argPos < g.argc; fossil_free(zUuid), ++argPos ){
523 const char * zName = g.argv[argPos];
524 const int rid = branch_resolve_name(zName, &zUuid);
525 const int isClosed = leaf_is_closed(rid);
526 if(!is_a_leaf(rid)){
527 /* This behaviour is different from /ci_edit closing, where
528 ** is_a_leaf() adds a "+" tag and !is_a_leaf() adds a "*"
529 ** tag. We might want to change this to match for consistency's
530 ** sake, but it currently seems unnecessary to close/re-open a
531 ** non-leaf. */
532 fossil_warning("Skipping non-leaf [%s] %s", zName, zUuid);
533 continue;
534 }else if(fClose && isClosed){
535 fossil_warning("Skipping closed leaf [%s] %s", zName, zUuid);
536 continue;
537 }else if(!fClose && !isClosed){
538 fossil_warning("Skipping non-closed leaf [%s] %s", zName, zUuid);
539 continue;
540 }
541 branch_cmd_tag_add(rid, fClose ? "+closed" : "-closed");
542 if(fVerbose!=0){
543 fossil_print("%s branch [%s] %s\n",
544 fClose ? "Closing" : "Re-opening",
545 zName, zUuid);
546 }
547 }
548 branch_cmd_tag_finalize(fDryRun, fVerbose, zDateOvrd, zUserOvrd);
549 }
550
@@ -546,16 +554,16 @@
554 ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
555 **
556 ** Run various subcommands to manage branches of the open repository or
557 ** of the repository identified by the -R or --repository option.
558 **
559 ** > fossil branch close|reopen ?OPTIONS? BRANCH-NAME ?...BRANCH-NAMES?
560 **
561 ** Adds or cancels the "closed" tag to one or more branches.
562 ** It accepts arbitrary unambiguous symbolic names but
563 ** will only resolve checkin names and skips any which resolve
564 ** to non-leaf checkins. Options:
565 ** -n|--dry-run do not commit changes and dump artifact
566 ** to stdout
567 ** -v|--verbose output more information
568 ** --date-override DATE DATE to use instead of 'now'
569 ** --user-override USER USER to use instead of the current default
@@ -667,11 +675,16 @@
675 branch_new();
676 }else if( strncmp(zCmd,"close",5)==0 ){
677 if(g.argc<4){
678 usage("branch close branch-name(s)...");
679 }
680 branch_cmd_close(3, 1);
681 }else if( strncmp(zCmd,"reopen",6)==0 ){
682 if(g.argc<4){
683 usage("branch reopen branch-name(s)...");
684 }
685 branch_cmd_close(3, 0);
686 }else if( strncmp(zCmd,"hide",4)==0 ){
687 if(g.argc<4){
688 usage("branch hide branch-name(s)...");
689 }
690 branch_cmd_hide(3,1);
@@ -680,11 +693,11 @@
693 usage("branch unhide branch-name(s)...");
694 }
695 branch_cmd_hide(3,0);
696 }else{
697 fossil_fatal("branch subcommand should be one of: "
698 "close current hide info list ls new reopen unhide");
699 }
700 }
701
702 /*
703 ** This is the new-style branch-list page that shows the branch names
704

Keyboard Shortcuts

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