Fossil SCM

Mark private branches in the CLI output of "fossil branch list", and output only those when "-p" is given. Clarify that private branches do not appear in a merge manifest.

danield 2021-09-10 13:11 trunk
Commit cf04bcb2b112bbc8b6ccd5a0c36bfcb75c9c166ba80fa11341d70555c747b790
2 files changed +16 -6 +2 -1
+16 -6
--- src/branch.c
+++ src/branch.c
@@ -233,10 +233,11 @@
233233
** mtime Time of last checkin on this branch
234234
** isclosed True if the branch is closed
235235
** mergeto Another branch this branch was merged into
236236
** nckin Number of checkins on this branch
237237
** ckin Hash of the last checkin on this branch
238
+** isprivate True if the branch is private
238239
** bgclr Background color for this branch
239240
*/
240241
static const char createBrlistQuery[] =
241242
@ CREATE TEMP TABLE IF NOT EXISTS tmp_brlist AS
242243
@ SELECT
@@ -252,11 +253,12 @@
252253
@ AND tagxref.rid=plink.cid
253254
@ AND tagxref.tagid=(SELECT tagid FROM tag WHERE tagname='branch')
254255
@ AND tagtype>0) AS mergeto,
255256
@ count(*) AS nckin,
256257
@ (SELECT uuid FROM blob WHERE rid=tagxref.rid) AS ckin,
257
-@ event.bgcolor AS bgclr
258
+@ event.bgcolor AS bgclr,
259
+@ EXISTS(SELECT 1 FROM private WHERE rid=tagxref.rid) AS isprivate
258260
@ FROM tagxref, tag, event
259261
@ WHERE tagxref.tagid=tag.tagid
260262
@ AND tagxref.tagtype>0
261263
@ AND tag.tagname='branch'
262264
@ AND event.objid=tagxref.rid
@@ -277,10 +279,11 @@
277279
#define BRL_OPEN_ONLY 0x002 /* Show only open branches */
278280
#define BRL_BOTH 0x003 /* Show both open and closed branches */
279281
#define BRL_OPEN_CLOSED_MASK 0x003
280282
#define BRL_ORDERBY_MTIME 0x004 /* Sort by MTIME. (otherwise sort by name)*/
281283
#define BRL_REVERSE 0x008 /* Reverse the sort order */
284
+#define BRL_PRIVATE 0x010 /* Show only private branches */
282285
283286
#endif /* INTERFACE */
284287
285288
/*
286289
** Prepare a query that will list branches.
@@ -294,27 +297,28 @@
294297
blob_init(&sql, 0, 0);
295298
brlist_create_temp_table();
296299
switch( brFlags & BRL_OPEN_CLOSED_MASK ){
297300
case BRL_CLOSED_ONLY: {
298301
blob_append_sql(&sql,
299
- "SELECT name FROM tmp_brlist WHERE isclosed"
302
+ "SELECT name, isprivate FROM tmp_brlist WHERE isclosed"
300303
);
301304
break;
302305
}
303306
case BRL_BOTH: {
304307
blob_append_sql(&sql,
305
- "SELECT name FROM tmp_brlist WHERE 1"
308
+ "SELECT name, isprivate FROM tmp_brlist WHERE 1"
306309
);
307310
break;
308311
}
309312
case BRL_OPEN_ONLY: {
310313
blob_append_sql(&sql,
311
- "SELECT name FROM tmp_brlist WHERE NOT isclosed"
314
+ "SELECT name, isprivate FROM tmp_brlist WHERE NOT isclosed"
312315
);
313316
break;
314317
}
315318
}
319
+ if( brFlags & BRL_PRIVATE ) blob_append_sql(&sql, " AND isprivate");
316320
if(zBrNameGlob) blob_append_sql(&sql, " AND (name GLOB %Q)", zBrNameGlob);
317321
if( brFlags & BRL_ORDERBY_MTIME ){
318322
blob_append_sql(&sql, " ORDER BY -mtime");
319323
}else{
320324
blob_append_sql(&sql, " ORDER BY name COLLATE nocase");
@@ -585,14 +589,16 @@
585589
** > fossil branch list|ls ?OPTIONS? ?GLOB?
586590
**
587591
** List all branches. Options:
588592
** -a|--all List all branches. Default show only open branches
589593
** -c|--closed List closed branches.
594
+** -p List only private branches.
590595
** -r Reverse the sort order
591596
** -t Show recently changed branches first
592597
**
593
-** The current branch is marked with an asterisk.
598
+** The current branch is marked with an asterisk. Private branches are
599
+** marked with a hash sign.
594600
**
595601
** If GLOB is given, show only branches matching the pattern.
596602
**
597603
** > fossil branch new BRANCH-NAME BASIS ?OPTIONS?
598604
**
@@ -655,10 +661,11 @@
655661
int brFlags = BRL_OPEN_ONLY;
656662
if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH;
657663
if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY;
658664
if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME;
659665
if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE;
666
+ if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE;
660667
if( g.argc >= 4 ) zBrNameGlob = g.argv[3];
661668
662669
if( g.localOpen ){
663670
vid = db_lget_int("checkout", 0);
664671
zCurrent = db_text(0, "SELECT value FROM tagxref"
@@ -665,12 +672,15 @@
665672
" WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
666673
}
667674
branch_prepare_list_query(&q, brFlags, zBrNameGlob);
668675
while( db_step(&q)==SQLITE_ROW ){
669676
const char *zBr = db_column_text(&q, 0);
677
+ int isPriv = zCurrent!=0 && db_column_int(&q, 1)==1;
670678
int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
671
- fossil_print("%s%s\n", (isCur ? "* " : " "), zBr);
679
+ fossil_print("%s%s%s\n",
680
+ ( (brFlags & BRL_PRIVATE) ? " " : ( isPriv ? "#" : " ") ),
681
+ (isCur ? "* " : " "), zBr);
672682
}
673683
db_finalize(&q);
674684
}else if( strncmp(zCmd,"new",n)==0 ){
675685
branch_new();
676686
}else if( strncmp(zCmd,"close",5)==0 ){
677687
--- src/branch.c
+++ src/branch.c
@@ -233,10 +233,11 @@
233 ** mtime Time of last checkin on this branch
234 ** isclosed True if the branch is closed
235 ** mergeto Another branch this branch was merged into
236 ** nckin Number of checkins on this branch
237 ** ckin Hash of the last checkin on this branch
 
238 ** bgclr Background color for this branch
239 */
240 static const char createBrlistQuery[] =
241 @ CREATE TEMP TABLE IF NOT EXISTS tmp_brlist AS
242 @ SELECT
@@ -252,11 +253,12 @@
252 @ AND tagxref.rid=plink.cid
253 @ AND tagxref.tagid=(SELECT tagid FROM tag WHERE tagname='branch')
254 @ AND tagtype>0) AS mergeto,
255 @ count(*) AS nckin,
256 @ (SELECT uuid FROM blob WHERE rid=tagxref.rid) AS ckin,
257 @ event.bgcolor AS bgclr
 
258 @ FROM tagxref, tag, event
259 @ WHERE tagxref.tagid=tag.tagid
260 @ AND tagxref.tagtype>0
261 @ AND tag.tagname='branch'
262 @ AND event.objid=tagxref.rid
@@ -277,10 +279,11 @@
277 #define BRL_OPEN_ONLY 0x002 /* Show only open branches */
278 #define BRL_BOTH 0x003 /* Show both open and closed branches */
279 #define BRL_OPEN_CLOSED_MASK 0x003
280 #define BRL_ORDERBY_MTIME 0x004 /* Sort by MTIME. (otherwise sort by name)*/
281 #define BRL_REVERSE 0x008 /* Reverse the sort order */
 
282
283 #endif /* INTERFACE */
284
285 /*
286 ** Prepare a query that will list branches.
@@ -294,27 +297,28 @@
294 blob_init(&sql, 0, 0);
295 brlist_create_temp_table();
296 switch( brFlags & BRL_OPEN_CLOSED_MASK ){
297 case BRL_CLOSED_ONLY: {
298 blob_append_sql(&sql,
299 "SELECT name FROM tmp_brlist WHERE isclosed"
300 );
301 break;
302 }
303 case BRL_BOTH: {
304 blob_append_sql(&sql,
305 "SELECT name FROM tmp_brlist WHERE 1"
306 );
307 break;
308 }
309 case BRL_OPEN_ONLY: {
310 blob_append_sql(&sql,
311 "SELECT name FROM tmp_brlist WHERE NOT isclosed"
312 );
313 break;
314 }
315 }
 
316 if(zBrNameGlob) blob_append_sql(&sql, " AND (name GLOB %Q)", zBrNameGlob);
317 if( brFlags & BRL_ORDERBY_MTIME ){
318 blob_append_sql(&sql, " ORDER BY -mtime");
319 }else{
320 blob_append_sql(&sql, " ORDER BY name COLLATE nocase");
@@ -585,14 +589,16 @@
585 ** > fossil branch list|ls ?OPTIONS? ?GLOB?
586 **
587 ** List all branches. Options:
588 ** -a|--all List all branches. Default show only open branches
589 ** -c|--closed List closed branches.
 
590 ** -r Reverse the sort order
591 ** -t Show recently changed branches first
592 **
593 ** The current branch is marked with an asterisk.
 
594 **
595 ** If GLOB is given, show only branches matching the pattern.
596 **
597 ** > fossil branch new BRANCH-NAME BASIS ?OPTIONS?
598 **
@@ -655,10 +661,11 @@
655 int brFlags = BRL_OPEN_ONLY;
656 if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH;
657 if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY;
658 if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME;
659 if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE;
 
660 if( g.argc >= 4 ) zBrNameGlob = g.argv[3];
661
662 if( g.localOpen ){
663 vid = db_lget_int("checkout", 0);
664 zCurrent = db_text(0, "SELECT value FROM tagxref"
@@ -665,12 +672,15 @@
665 " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
666 }
667 branch_prepare_list_query(&q, brFlags, zBrNameGlob);
668 while( db_step(&q)==SQLITE_ROW ){
669 const char *zBr = db_column_text(&q, 0);
 
670 int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
671 fossil_print("%s%s\n", (isCur ? "* " : " "), zBr);
 
 
672 }
673 db_finalize(&q);
674 }else if( strncmp(zCmd,"new",n)==0 ){
675 branch_new();
676 }else if( strncmp(zCmd,"close",5)==0 ){
677
--- src/branch.c
+++ src/branch.c
@@ -233,10 +233,11 @@
233 ** mtime Time of last checkin on this branch
234 ** isclosed True if the branch is closed
235 ** mergeto Another branch this branch was merged into
236 ** nckin Number of checkins on this branch
237 ** ckin Hash of the last checkin on this branch
238 ** isprivate True if the branch is private
239 ** bgclr Background color for this branch
240 */
241 static const char createBrlistQuery[] =
242 @ CREATE TEMP TABLE IF NOT EXISTS tmp_brlist AS
243 @ SELECT
@@ -252,11 +253,12 @@
253 @ AND tagxref.rid=plink.cid
254 @ AND tagxref.tagid=(SELECT tagid FROM tag WHERE tagname='branch')
255 @ AND tagtype>0) AS mergeto,
256 @ count(*) AS nckin,
257 @ (SELECT uuid FROM blob WHERE rid=tagxref.rid) AS ckin,
258 @ event.bgcolor AS bgclr,
259 @ EXISTS(SELECT 1 FROM private WHERE rid=tagxref.rid) AS isprivate
260 @ FROM tagxref, tag, event
261 @ WHERE tagxref.tagid=tag.tagid
262 @ AND tagxref.tagtype>0
263 @ AND tag.tagname='branch'
264 @ AND event.objid=tagxref.rid
@@ -277,10 +279,11 @@
279 #define BRL_OPEN_ONLY 0x002 /* Show only open branches */
280 #define BRL_BOTH 0x003 /* Show both open and closed branches */
281 #define BRL_OPEN_CLOSED_MASK 0x003
282 #define BRL_ORDERBY_MTIME 0x004 /* Sort by MTIME. (otherwise sort by name)*/
283 #define BRL_REVERSE 0x008 /* Reverse the sort order */
284 #define BRL_PRIVATE 0x010 /* Show only private branches */
285
286 #endif /* INTERFACE */
287
288 /*
289 ** Prepare a query that will list branches.
@@ -294,27 +297,28 @@
297 blob_init(&sql, 0, 0);
298 brlist_create_temp_table();
299 switch( brFlags & BRL_OPEN_CLOSED_MASK ){
300 case BRL_CLOSED_ONLY: {
301 blob_append_sql(&sql,
302 "SELECT name, isprivate FROM tmp_brlist WHERE isclosed"
303 );
304 break;
305 }
306 case BRL_BOTH: {
307 blob_append_sql(&sql,
308 "SELECT name, isprivate FROM tmp_brlist WHERE 1"
309 );
310 break;
311 }
312 case BRL_OPEN_ONLY: {
313 blob_append_sql(&sql,
314 "SELECT name, isprivate FROM tmp_brlist WHERE NOT isclosed"
315 );
316 break;
317 }
318 }
319 if( brFlags & BRL_PRIVATE ) blob_append_sql(&sql, " AND isprivate");
320 if(zBrNameGlob) blob_append_sql(&sql, " AND (name GLOB %Q)", zBrNameGlob);
321 if( brFlags & BRL_ORDERBY_MTIME ){
322 blob_append_sql(&sql, " ORDER BY -mtime");
323 }else{
324 blob_append_sql(&sql, " ORDER BY name COLLATE nocase");
@@ -585,14 +589,16 @@
589 ** > fossil branch list|ls ?OPTIONS? ?GLOB?
590 **
591 ** List all branches. Options:
592 ** -a|--all List all branches. Default show only open branches
593 ** -c|--closed List closed branches.
594 ** -p List only private branches.
595 ** -r Reverse the sort order
596 ** -t Show recently changed branches first
597 **
598 ** The current branch is marked with an asterisk. Private branches are
599 ** marked with a hash sign.
600 **
601 ** If GLOB is given, show only branches matching the pattern.
602 **
603 ** > fossil branch new BRANCH-NAME BASIS ?OPTIONS?
604 **
@@ -655,10 +661,11 @@
661 int brFlags = BRL_OPEN_ONLY;
662 if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH;
663 if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY;
664 if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME;
665 if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE;
666 if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE;
667 if( g.argc >= 4 ) zBrNameGlob = g.argv[3];
668
669 if( g.localOpen ){
670 vid = db_lget_int("checkout", 0);
671 zCurrent = db_text(0, "SELECT value FROM tagxref"
@@ -665,12 +672,15 @@
672 " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
673 }
674 branch_prepare_list_query(&q, brFlags, zBrNameGlob);
675 while( db_step(&q)==SQLITE_ROW ){
676 const char *zBr = db_column_text(&q, 0);
677 int isPriv = zCurrent!=0 && db_column_int(&q, 1)==1;
678 int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
679 fossil_print("%s%s%s\n",
680 ( (brFlags & BRL_PRIVATE) ? " " : ( isPriv ? "#" : " ") ),
681 (isCur ? "* " : " "), zBr);
682 }
683 db_finalize(&q);
684 }else if( strncmp(zCmd,"new",n)==0 ){
685 branch_new();
686 }else if( strncmp(zCmd,"close",5)==0 ){
687
--- www/private.wiki
+++ www/private.wiki
@@ -31,11 +31,12 @@
3131
fossil update trunk
3232
fossil merge private
3333
fossil commit
3434
</pre></blockquote>
3535
36
-The private branch remains private, but all of the changes associated with
36
+The private branch remains private and is not recorded as a parent
37
+in the merge manifest's P-card, but all of the changes associated with
3738
the private branch are now folded into the public branch and are hence
3839
visible to other users of the project.
3940
4041
A private branch created with Fossil version 1.30 or newer can also be
4142
converted into a public branch using the <code>fossil publish</code>
4243
--- www/private.wiki
+++ www/private.wiki
@@ -31,11 +31,12 @@
31 fossil update trunk
32 fossil merge private
33 fossil commit
34 </pre></blockquote>
35
36 The private branch remains private, but all of the changes associated with
 
37 the private branch are now folded into the public branch and are hence
38 visible to other users of the project.
39
40 A private branch created with Fossil version 1.30 or newer can also be
41 converted into a public branch using the <code>fossil publish</code>
42
--- www/private.wiki
+++ www/private.wiki
@@ -31,11 +31,12 @@
31 fossil update trunk
32 fossil merge private
33 fossil commit
34 </pre></blockquote>
35
36 The private branch remains private and is not recorded as a parent
37 in the merge manifest's P-card, but all of the changes associated with
38 the private branch are now folded into the public branch and are hence
39 visible to other users of the project.
40
41 A private branch created with Fossil version 1.30 or newer can also be
42 converted into a public branch using the <code>fossil publish</code>
43

Keyboard Shortcuts

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