Fossil SCM

Added (branch hide/unhide) subcommands.

stephan 2021-07-23 02:22 branch-close-subcommand
Commit 05b42e6aa680bf48851a936a524d66562f66a2d52bfe15807defde3edc98dee5
2 files changed +88 -23 +2
+88 -23
--- src/branch.c
+++ src/branch.c
@@ -444,14 +444,63 @@
444444
db_multi_exec("DROP TABLE brcmdtag");
445445
blob_reset(&manifest);
446446
db_end_transaction(doRollback);
447447
return 0;
448448
}
449
+
450
+/*
451
+** Internal helper for branch_cmd_close() and friends. zName is a
452
+** symbolic checkin name. Returns the blob.rid of the checkin or fails
453
+** fatally if the name does not resolve unambiguously. If zUuid is
454
+** not NULL, *zUuid is set to the resolved blob.uuid and must be freed
455
+** by the caller via fossil_free().
456
+*/
457
+static int branch_resolve_name(char const *zName, char **zUuid){
458
+ const int rid = name_to_uuid2(zName, "ci", zUuid);
459
+ if(0==rid){
460
+ fossil_fatal("Cannot resolve name: %s", zName);
461
+ }else if(rid<0){
462
+ fossil_fatal("Ambiguous name: %s", zName);
463
+ }
464
+ return rid;
465
+}
466
+
467
+/*
468
+** Implementation of (branch hide/unhide) subcommands. nStartAtArg is
469
+** the g.argv index to start reading branch/checkin names. fHide is
470
+** true for hiding, false for unhiding. Fails fatally on error.
471
+*/
472
+static void branch_cmd_hide(int nStartAtArg, int fHide){
473
+ int argPos = nStartAtArg; /* g.argv pos with first branch/ci name */
474
+ char * zUuid = 0; /* Resolved branch UUID. */
475
+ const int fVerbose = find_option("verbose","v",0)!=0;
476
+ const int fDryRun = find_option("dry-run","n",0)!=0;
477
+ const char *zDateOvrd = find_option("date-override",0,1);
478
+ const char *zUserOvrd = find_option("user-override",0,1);
479
+
480
+ verify_all_options();
481
+ db_begin_transaction();
482
+ for( ; argPos < g.argc; fossil_free(zUuid), ++argPos ){
483
+ const char * zName = g.argv[argPos];
484
+ const int rid = branch_resolve_name(zName, &zUuid);
485
+ /* Potential TODO: check for existing 'hidden' flag and skip this
486
+ ** entry if it already has (if fHide) or does not have (if !fHide)
487
+ ** that tag. FWIW, /ci_edit does not do so. */
488
+ branch_cmd_tag_add(rid, fHide ? "*hidden" : "-hidden");
489
+ if(fVerbose!=0){
490
+ fossil_print("%s checkin [%s] %s\n",
491
+ fHide ? "Hiding" : "Unhiding",
492
+ zName, zUuid);
493
+ }
494
+ }
495
+ branch_cmd_tag_finalize(fDryRun, fVerbose, zDateOvrd, zUserOvrd);
496
+}
449497
450498
/*
451499
** Implementation of (branch close) subcommand. nStartAtArg is the
452
-** g.argv index to start reading branch names. Fails fatally on error.
500
+** g.argv index to start reading branch/checkin names. Fails fatally
501
+** on error.
453502
*/
454503
static void branch_cmd_close(int nStartAtArg){
455504
int argPos = nStartAtArg; /* g.argv pos with first branch name */
456505
char * zUuid = 0; /* Resolved branch UUID. */
457506
const int fVerbose = find_option("verbose","v",0)!=0;
@@ -460,26 +509,26 @@
460509
const char *zUserOvrd = find_option("user-override",0,1);
461510
462511
verify_all_options();
463512
db_begin_transaction();
464513
for( ; argPos < g.argc; fossil_free(zUuid), ++argPos ){
465
- const char * zBranch = g.argv[argPos];
466
- const int rid = name_to_uuid2(zBranch, "ci", &zUuid);
467
- if(0==rid){
468
- fossil_fatal("Cannot resolve branch name: %s", zBranch);
469
- }else if(rid<0){
470
- fossil_fatal("Ambiguous branch name: %s", zBranch);
471
- }else if(!is_a_leaf(rid)){
472
- fossil_warning("Skipping non-leaf [%s] %s", zBranch, zUuid);
514
+ const char * zName = g.argv[argPos];
515
+ const int rid = branch_resolve_name(zName, &zUuid);
516
+ if(!is_a_leaf(rid)){
517
+ /* This behaviour is different from /ci_edit closing, where
518
+ ** is_a_leaf() adds a "+" tag and !is_a_leaf() adds a "*"
519
+ ** tag. We might want to change this to match for consistency's
520
+ ** sake. */
521
+ fossil_warning("Skipping non-leaf [%s] %s", zName, zUuid);
473522
continue;
474523
}else if(leaf_is_closed(rid)){
475
- fossil_warning("Skipping closed [%s] %s", zBranch, zUuid);
524
+ fossil_warning("Skipping closed [%s] %s", zName, zUuid);
476525
continue;
477526
}
478527
branch_cmd_tag_add(rid, "+closed");
479528
if(fVerbose!=0){
480
- fossil_print("Closing branch [%s] %s\n", zBranch, zUuid);
529
+ fossil_print("Closing branch [%s] %s\n", zName, zUuid);
481530
}
482531
}
483532
branch_cmd_tag_finalize(fDryRun, fVerbose, zDateOvrd, zUserOvrd);
484533
}
485534
@@ -489,13 +538,31 @@
489538
** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
490539
**
491540
** Run various subcommands to manage branches of the open repository or
492541
** of the repository identified by the -R or --repository option.
493542
**
543
+** > fossil branch close ?OPTIONS? BRANCH-NAME ?...BRANCH-NAMES?
544
+**
545
+** Close one or more branches by adding the "closed" tag
546
+** to them. It accepts arbitrary unambiguous symbolic names but
547
+** will only resolve checkin names and skips any which resolve
548
+** to non-leaf or closed checkins. Options:
549
+** -n|--dry-run do not commit changes and dump artifact
550
+** to stdout
551
+** -v|--verbose output more information
552
+** --date-override DATE DATE to use instead of 'now'
553
+** --user-override USER USER to use instead of the current default
554
+**
494555
** > fossil branch current
495556
**
496557
** Print the name of the branch for the current check-out
558
+**
559
+** > fossil branch hide|unhide ?OPTIONS? BRANCH-NAME ?...BRANCH-NAMES?
560
+**
561
+** Adds or cancels the "hidden" tag for the specified branches or
562
+** or checkin IDs. Accepts the same options as the close
563
+** subcommand.
497564
**
498565
** > fossil branch info BRANCH-NAME
499566
**
500567
** Print information about a branch
501568
**
@@ -527,22 +594,10 @@
527594
** year-month-day form, it may be truncated, the "T" may be
528595
** replaced by a space, and it may also name a timezone offset
529596
** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
530597
** Either no timezone suffix or "Z" means UTC.
531598
**
532
-** > fossil branch close ?OPTIONS? BRANCH-NAME ?...BRANCH-NAMES?
533
-**
534
-** Close one or more branches by adding the "closed" tag
535
-** to them. It accepts arbitrary unambiguous symbolic names but
536
-** will only resolve checkin names and skips any which resolve
537
-** to non-leaf or closed checkins. Options:
538
-** -n|--dry-run do not commit changes and dump artifact
539
-** to stdout
540
-** -v|--verbose output more information
541
-** --date-override DATE DATE to use instead of 'now'
542
-** --user-override USER USER to use instead of the current default
543
-**
544599
** Options valid for all subcommands:
545600
**
546601
** -R|--repository REPO Run commands on repository REPO
547602
*/
548603
void branch_cmd(void){
@@ -605,10 +660,20 @@
605660
}else if( strncmp(zCmd,"close",5)==0 ){
606661
if(g.argc<4){
607662
usage("branch close branch-name(s)...");
608663
}
609664
branch_cmd_close(3);
665
+ }else if( strncmp(zCmd,"hide",4)==0 ){
666
+ if(g.argc<4){
667
+ usage("branch hide branch-name(s)...");
668
+ }
669
+ branch_cmd_hide(3,1);
670
+ }else if( strncmp(zCmd,"unhide",6)==0 ){
671
+ if(g.argc<4){
672
+ usage("branch unhide branch-name(s)...");
673
+ }
674
+ branch_cmd_hide(3,0);
610675
}else{
611676
fossil_fatal("branch subcommand should be one of: "
612677
"close current info list ls new");
613678
}
614679
}
615680
--- src/branch.c
+++ src/branch.c
@@ -444,14 +444,63 @@
444 db_multi_exec("DROP TABLE brcmdtag");
445 blob_reset(&manifest);
446 db_end_transaction(doRollback);
447 return 0;
448 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
449
450 /*
451 ** Implementation of (branch close) subcommand. nStartAtArg is the
452 ** g.argv index to start reading branch names. Fails fatally on error.
 
453 */
454 static void branch_cmd_close(int nStartAtArg){
455 int argPos = nStartAtArg; /* g.argv pos with first branch name */
456 char * zUuid = 0; /* Resolved branch UUID. */
457 const int fVerbose = find_option("verbose","v",0)!=0;
@@ -460,26 +509,26 @@
460 const char *zUserOvrd = find_option("user-override",0,1);
461
462 verify_all_options();
463 db_begin_transaction();
464 for( ; argPos < g.argc; fossil_free(zUuid), ++argPos ){
465 const char * zBranch = g.argv[argPos];
466 const int rid = name_to_uuid2(zBranch, "ci", &zUuid);
467 if(0==rid){
468 fossil_fatal("Cannot resolve branch name: %s", zBranch);
469 }else if(rid<0){
470 fossil_fatal("Ambiguous branch name: %s", zBranch);
471 }else if(!is_a_leaf(rid)){
472 fossil_warning("Skipping non-leaf [%s] %s", zBranch, zUuid);
473 continue;
474 }else if(leaf_is_closed(rid)){
475 fossil_warning("Skipping closed [%s] %s", zBranch, zUuid);
476 continue;
477 }
478 branch_cmd_tag_add(rid, "+closed");
479 if(fVerbose!=0){
480 fossil_print("Closing branch [%s] %s\n", zBranch, zUuid);
481 }
482 }
483 branch_cmd_tag_finalize(fDryRun, fVerbose, zDateOvrd, zUserOvrd);
484 }
485
@@ -489,13 +538,31 @@
489 ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
490 **
491 ** Run various subcommands to manage branches of the open repository or
492 ** of the repository identified by the -R or --repository option.
493 **
 
 
 
 
 
 
 
 
 
 
 
 
494 ** > fossil branch current
495 **
496 ** Print the name of the branch for the current check-out
 
 
 
 
 
 
497 **
498 ** > fossil branch info BRANCH-NAME
499 **
500 ** Print information about a branch
501 **
@@ -527,22 +594,10 @@
527 ** year-month-day form, it may be truncated, the "T" may be
528 ** replaced by a space, and it may also name a timezone offset
529 ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
530 ** Either no timezone suffix or "Z" means UTC.
531 **
532 ** > fossil branch close ?OPTIONS? BRANCH-NAME ?...BRANCH-NAMES?
533 **
534 ** Close one or more branches by adding the "closed" tag
535 ** to them. It accepts arbitrary unambiguous symbolic names but
536 ** will only resolve checkin names and skips any which resolve
537 ** to non-leaf or closed checkins. Options:
538 ** -n|--dry-run do not commit changes and dump artifact
539 ** to stdout
540 ** -v|--verbose output more information
541 ** --date-override DATE DATE to use instead of 'now'
542 ** --user-override USER USER to use instead of the current default
543 **
544 ** Options valid for all subcommands:
545 **
546 ** -R|--repository REPO Run commands on repository REPO
547 */
548 void branch_cmd(void){
@@ -605,10 +660,20 @@
605 }else if( strncmp(zCmd,"close",5)==0 ){
606 if(g.argc<4){
607 usage("branch close branch-name(s)...");
608 }
609 branch_cmd_close(3);
 
 
 
 
 
 
 
 
 
 
610 }else{
611 fossil_fatal("branch subcommand should be one of: "
612 "close current info list ls new");
613 }
614 }
615
--- src/branch.c
+++ src/branch.c
@@ -444,14 +444,63 @@
444 db_multi_exec("DROP TABLE brcmdtag");
445 blob_reset(&manifest);
446 db_end_transaction(doRollback);
447 return 0;
448 }
449
450 /*
451 ** Internal helper for branch_cmd_close() and friends. zName is a
452 ** symbolic checkin name. Returns the blob.rid of the checkin or fails
453 ** fatally if the name does not resolve unambiguously. If zUuid is
454 ** not NULL, *zUuid is set to the resolved blob.uuid and must be freed
455 ** by the caller via fossil_free().
456 */
457 static int branch_resolve_name(char const *zName, char **zUuid){
458 const int rid = name_to_uuid2(zName, "ci", zUuid);
459 if(0==rid){
460 fossil_fatal("Cannot resolve name: %s", zName);
461 }else if(rid<0){
462 fossil_fatal("Ambiguous name: %s", zName);
463 }
464 return rid;
465 }
466
467 /*
468 ** Implementation of (branch hide/unhide) subcommands. nStartAtArg is
469 ** the g.argv index to start reading branch/checkin names. fHide is
470 ** true for hiding, false for unhiding. Fails fatally on error.
471 */
472 static void branch_cmd_hide(int nStartAtArg, int fHide){
473 int argPos = nStartAtArg; /* g.argv pos with first branch/ci name */
474 char * zUuid = 0; /* Resolved branch UUID. */
475 const int fVerbose = find_option("verbose","v",0)!=0;
476 const int fDryRun = find_option("dry-run","n",0)!=0;
477 const char *zDateOvrd = find_option("date-override",0,1);
478 const char *zUserOvrd = find_option("user-override",0,1);
479
480 verify_all_options();
481 db_begin_transaction();
482 for( ; argPos < g.argc; fossil_free(zUuid), ++argPos ){
483 const char * zName = g.argv[argPos];
484 const int rid = branch_resolve_name(zName, &zUuid);
485 /* Potential TODO: check for existing 'hidden' flag and skip this
486 ** entry if it already has (if fHide) or does not have (if !fHide)
487 ** that tag. FWIW, /ci_edit does not do so. */
488 branch_cmd_tag_add(rid, fHide ? "*hidden" : "-hidden");
489 if(fVerbose!=0){
490 fossil_print("%s checkin [%s] %s\n",
491 fHide ? "Hiding" : "Unhiding",
492 zName, zUuid);
493 }
494 }
495 branch_cmd_tag_finalize(fDryRun, fVerbose, zDateOvrd, zUserOvrd);
496 }
497
498 /*
499 ** Implementation of (branch close) subcommand. nStartAtArg is the
500 ** g.argv index to start reading branch/checkin names. Fails fatally
501 ** on error.
502 */
503 static void branch_cmd_close(int nStartAtArg){
504 int argPos = nStartAtArg; /* g.argv pos with first branch name */
505 char * zUuid = 0; /* Resolved branch UUID. */
506 const int fVerbose = find_option("verbose","v",0)!=0;
@@ -460,26 +509,26 @@
509 const char *zUserOvrd = find_option("user-override",0,1);
510
511 verify_all_options();
512 db_begin_transaction();
513 for( ; argPos < g.argc; fossil_free(zUuid), ++argPos ){
514 const char * zName = g.argv[argPos];
515 const int rid = branch_resolve_name(zName, &zUuid);
516 if(!is_a_leaf(rid)){
517 /* This behaviour is different from /ci_edit closing, where
518 ** is_a_leaf() adds a "+" tag and !is_a_leaf() adds a "*"
519 ** tag. We might want to change this to match for consistency's
520 ** sake. */
521 fossil_warning("Skipping non-leaf [%s] %s", zName, zUuid);
522 continue;
523 }else if(leaf_is_closed(rid)){
524 fossil_warning("Skipping closed [%s] %s", zName, zUuid);
525 continue;
526 }
527 branch_cmd_tag_add(rid, "+closed");
528 if(fVerbose!=0){
529 fossil_print("Closing branch [%s] %s\n", zName, zUuid);
530 }
531 }
532 branch_cmd_tag_finalize(fDryRun, fVerbose, zDateOvrd, zUserOvrd);
533 }
534
@@ -489,13 +538,31 @@
538 ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
539 **
540 ** Run various subcommands to manage branches of the open repository or
541 ** of the repository identified by the -R or --repository option.
542 **
543 ** > fossil branch close ?OPTIONS? BRANCH-NAME ?...BRANCH-NAMES?
544 **
545 ** Close one or more branches by adding the "closed" tag
546 ** to them. It accepts arbitrary unambiguous symbolic names but
547 ** will only resolve checkin names and skips any which resolve
548 ** to non-leaf or closed checkins. Options:
549 ** -n|--dry-run do not commit changes and dump artifact
550 ** to stdout
551 ** -v|--verbose output more information
552 ** --date-override DATE DATE to use instead of 'now'
553 ** --user-override USER USER to use instead of the current default
554 **
555 ** > fossil branch current
556 **
557 ** Print the name of the branch for the current check-out
558 **
559 ** > fossil branch hide|unhide ?OPTIONS? BRANCH-NAME ?...BRANCH-NAMES?
560 **
561 ** Adds or cancels the "hidden" tag for the specified branches or
562 ** or checkin IDs. Accepts the same options as the close
563 ** subcommand.
564 **
565 ** > fossil branch info BRANCH-NAME
566 **
567 ** Print information about a branch
568 **
@@ -527,22 +594,10 @@
594 ** year-month-day form, it may be truncated, the "T" may be
595 ** replaced by a space, and it may also name a timezone offset
596 ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
597 ** Either no timezone suffix or "Z" means UTC.
598 **
 
 
 
 
 
 
 
 
 
 
 
 
599 ** Options valid for all subcommands:
600 **
601 ** -R|--repository REPO Run commands on repository REPO
602 */
603 void branch_cmd(void){
@@ -605,10 +660,20 @@
660 }else if( strncmp(zCmd,"close",5)==0 ){
661 if(g.argc<4){
662 usage("branch close branch-name(s)...");
663 }
664 branch_cmd_close(3);
665 }else if( strncmp(zCmd,"hide",4)==0 ){
666 if(g.argc<4){
667 usage("branch hide branch-name(s)...");
668 }
669 branch_cmd_hide(3,1);
670 }else if( strncmp(zCmd,"unhide",6)==0 ){
671 if(g.argc<4){
672 usage("branch unhide branch-name(s)...");
673 }
674 branch_cmd_hide(3,0);
675 }else{
676 fossil_fatal("branch subcommand should be one of: "
677 "close current info list ls new");
678 }
679 }
680
--- www/changes.wiki
+++ www/changes.wiki
@@ -18,10 +18,12 @@
1818
the current page and list URLs suitable for pasting them into the page.
1919
* Add the --no-http-compression option to [/help?cmd=sync|fossil sync]
2020
and similar.
2121
* Print total payload bytes on a [/help?cmd=sync|fossil sync] when using
2222
the --verbose option.
23
+ * Add the <tt>close</tt>, <tt>hide</tt>, and </tt>unhide</tt> subcommands
24
+ to [/help?cmd=branch|the branch command].
2325
2426
<a name='v2_16'></a>
2527
<h2>Changes for Version 2.16 (2021-07-02)</h2>
2628
* <b>Security:</b> Fix the client-side TLS so that it verifies that the
2729
server hostname matches its certificate.
2830
--- www/changes.wiki
+++ www/changes.wiki
@@ -18,10 +18,12 @@
18 the current page and list URLs suitable for pasting them into the page.
19 * Add the --no-http-compression option to [/help?cmd=sync|fossil sync]
20 and similar.
21 * Print total payload bytes on a [/help?cmd=sync|fossil sync] when using
22 the --verbose option.
 
 
23
24 <a name='v2_16'></a>
25 <h2>Changes for Version 2.16 (2021-07-02)</h2>
26 * <b>Security:</b> Fix the client-side TLS so that it verifies that the
27 server hostname matches its certificate.
28
--- www/changes.wiki
+++ www/changes.wiki
@@ -18,10 +18,12 @@
18 the current page and list URLs suitable for pasting them into the page.
19 * Add the --no-http-compression option to [/help?cmd=sync|fossil sync]
20 and similar.
21 * Print total payload bytes on a [/help?cmd=sync|fossil sync] when using
22 the --verbose option.
23 * Add the <tt>close</tt>, <tt>hide</tt>, and </tt>unhide</tt> subcommands
24 to [/help?cmd=branch|the branch command].
25
26 <a name='v2_16'></a>
27 <h2>Changes for Version 2.16 (2021-07-02)</h2>
28 * <b>Security:</b> Fix the client-side TLS so that it verifies that the
29 server hostname matches its certificate.
30

Keyboard Shortcuts

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