Fossil SCM

Add a new `-h' option to `fossil branch ls' to list the "hot" (first few recently modified) branches.

florian 2022-07-31 10:47 trunk
Commit fe299ee400d06551774b874e158819d0973897a0c10ca87471cd405ea3e6413f
1 file changed +26 -5
+26 -5
--- src/branch.c
+++ src/branch.c
@@ -280,10 +280,11 @@
280280
#define BRL_BOTH 0x003 /* Show both open and closed branches */
281281
#define BRL_OPEN_CLOSED_MASK 0x003
282282
#define BRL_ORDERBY_MTIME 0x004 /* Sort by MTIME. (otherwise sort by name)*/
283283
#define BRL_REVERSE 0x008 /* Reverse the sort order */
284284
#define BRL_PRIVATE 0x010 /* Show only private branches */
285
+#define BRL_LIMIT 0x020 /* Limit entries to specified number */
285286
286287
#endif /* INTERFACE */
287288
288289
/*
289290
** Prepare a query that will list branches.
@@ -290,11 +291,16 @@
290291
**
291292
** If (which<0) then the query pulls only closed branches. If
292293
** (which>0) then the query pulls all (closed and opened)
293294
** branches. Else the query pulls currently-opened branches.
294295
*/
295
-void branch_prepare_list_query(Stmt *pQuery, int brFlags, const char *zBrNameGlob){
296
+void branch_prepare_list_query(
297
+ Stmt *pQuery,
298
+ int brFlags,
299
+ const char *zBrNameGlob,
300
+ int nLimit
301
+){
296302
Blob sql;
297303
blob_init(&sql, 0, 0);
298304
brlist_create_temp_table();
299305
switch( brFlags & BRL_OPEN_CLOSED_MASK ){
300306
case BRL_CLOSED_ONLY: {
@@ -324,10 +330,13 @@
324330
blob_append_sql(&sql, " ORDER BY name COLLATE nocase");
325331
}
326332
if( brFlags & BRL_REVERSE ){
327333
blob_append_sql(&sql," DESC");
328334
}
335
+ if( brFlags & BRL_LIMIT && nLimit>0 ){
336
+ blob_append_sql(&sql," LIMIT %d",nLimit);
337
+ }
329338
db_prepare_blob(pQuery, &sql);
330339
blob_reset(&sql);
331340
}
332341
333342
/*
@@ -592,15 +601,18 @@
592601
** -a|--all List all branches. Default show only open branches
593602
** -c|--closed List closed branches.
594603
** -p List only private branches.
595604
** -r Reverse the sort order
596605
** -t Show recently changed branches first
606
+** -h ?N? Show N recently changed branches (or 5 if N omitted)
597607
**
598608
** The current branch is marked with an asterisk. Private branches are
599609
** marked with a hash sign.
600610
**
601
-** If GLOB is given, show only branches matching the pattern.
611
+** If GLOB is given, show only branches matching the pattern. With the
612
+** -h option set, no GLOB argument is allowed, but an (optional) number
613
+** of entries to output.
602614
**
603615
** > fossil branch new BRANCH-NAME BASIS ?OPTIONS?
604616
**
605617
** Create a new branch BRANCH-NAME off of check-in BASIS.
606618
** Supported options for this subcommand include:
@@ -656,24 +668,33 @@
656668
}else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){
657669
Stmt q;
658670
int vid;
659671
char *zCurrent = 0;
660672
const char *zBrNameGlob = 0;
673
+ int nLimit = 5;
661674
int brFlags = BRL_OPEN_ONLY;
662675
if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH;
663676
if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY;
664677
if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME;
665678
if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE;
666679
if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE;
667
- if( g.argc >= 4 ) zBrNameGlob = g.argv[3];
680
+ if( find_option("h",0,0)!=0 ) brFlags |= BRL_LIMIT;
681
+ if( (brFlags & BRL_LIMIT)==0 ){
682
+ if( g.argc >= 4 ) zBrNameGlob = g.argv[3];
683
+ }else{
684
+ if( g.argc>4 || g.argc==4 && (nLimit = atoi(g.argv[3]))==0 ){
685
+ fossil_fatal("only one numeric or no argument allowed following -h");
686
+ }
687
+ brFlags |= BRL_ORDERBY_MTIME;
688
+ }
668689
669690
if( g.localOpen ){
670691
vid = db_lget_int("checkout", 0);
671692
zCurrent = db_text(0, "SELECT value FROM tagxref"
672693
" WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
673694
}
674
- branch_prepare_list_query(&q, brFlags, zBrNameGlob);
695
+ branch_prepare_list_query(&q, brFlags, zBrNameGlob, nLimit);
675696
while( db_step(&q)==SQLITE_ROW ){
676697
const char *zBr = db_column_text(&q, 0);
677698
int isPriv = zCurrent!=0 && db_column_int(&q, 1)==1;
678699
int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
679700
fossil_print("%s%s%s\n",
@@ -862,11 +883,11 @@
862883
@ reopened).</li>
863884
@ </ol>
864885
style_sidebox_end();
865886
#endif
866887
867
- branch_prepare_list_query(&q, brFlags, 0);
888
+ branch_prepare_list_query(&q, brFlags, 0, 0);
868889
cnt = 0;
869890
while( db_step(&q)==SQLITE_ROW ){
870891
const char *zBr = db_column_text(&q, 0);
871892
if( cnt==0 ){
872893
if( colorTest ){
873894
--- src/branch.c
+++ src/branch.c
@@ -280,10 +280,11 @@
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.
@@ -290,11 +291,16 @@
290 **
291 ** If (which<0) then the query pulls only closed branches. If
292 ** (which>0) then the query pulls all (closed and opened)
293 ** branches. Else the query pulls currently-opened branches.
294 */
295 void branch_prepare_list_query(Stmt *pQuery, int brFlags, const char *zBrNameGlob){
 
 
 
 
 
296 Blob sql;
297 blob_init(&sql, 0, 0);
298 brlist_create_temp_table();
299 switch( brFlags & BRL_OPEN_CLOSED_MASK ){
300 case BRL_CLOSED_ONLY: {
@@ -324,10 +330,13 @@
324 blob_append_sql(&sql, " ORDER BY name COLLATE nocase");
325 }
326 if( brFlags & BRL_REVERSE ){
327 blob_append_sql(&sql," DESC");
328 }
 
 
 
329 db_prepare_blob(pQuery, &sql);
330 blob_reset(&sql);
331 }
332
333 /*
@@ -592,15 +601,18 @@
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 **
605 ** Create a new branch BRANCH-NAME off of check-in BASIS.
606 ** Supported options for this subcommand include:
@@ -656,24 +668,33 @@
656 }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){
657 Stmt q;
658 int vid;
659 char *zCurrent = 0;
660 const char *zBrNameGlob = 0;
 
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"
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",
@@ -862,11 +883,11 @@
862 @ reopened).</li>
863 @ </ol>
864 style_sidebox_end();
865 #endif
866
867 branch_prepare_list_query(&q, brFlags, 0);
868 cnt = 0;
869 while( db_step(&q)==SQLITE_ROW ){
870 const char *zBr = db_column_text(&q, 0);
871 if( cnt==0 ){
872 if( colorTest ){
873
--- src/branch.c
+++ src/branch.c
@@ -280,10 +280,11 @@
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 #define BRL_LIMIT 0x020 /* Limit entries to specified number */
286
287 #endif /* INTERFACE */
288
289 /*
290 ** Prepare a query that will list branches.
@@ -290,11 +291,16 @@
291 **
292 ** If (which<0) then the query pulls only closed branches. If
293 ** (which>0) then the query pulls all (closed and opened)
294 ** branches. Else the query pulls currently-opened branches.
295 */
296 void branch_prepare_list_query(
297 Stmt *pQuery,
298 int brFlags,
299 const char *zBrNameGlob,
300 int nLimit
301 ){
302 Blob sql;
303 blob_init(&sql, 0, 0);
304 brlist_create_temp_table();
305 switch( brFlags & BRL_OPEN_CLOSED_MASK ){
306 case BRL_CLOSED_ONLY: {
@@ -324,10 +330,13 @@
330 blob_append_sql(&sql, " ORDER BY name COLLATE nocase");
331 }
332 if( brFlags & BRL_REVERSE ){
333 blob_append_sql(&sql," DESC");
334 }
335 if( brFlags & BRL_LIMIT && nLimit>0 ){
336 blob_append_sql(&sql," LIMIT %d",nLimit);
337 }
338 db_prepare_blob(pQuery, &sql);
339 blob_reset(&sql);
340 }
341
342 /*
@@ -592,15 +601,18 @@
601 ** -a|--all List all branches. Default show only open branches
602 ** -c|--closed List closed branches.
603 ** -p List only private branches.
604 ** -r Reverse the sort order
605 ** -t Show recently changed branches first
606 ** -h ?N? Show N recently changed branches (or 5 if N omitted)
607 **
608 ** The current branch is marked with an asterisk. Private branches are
609 ** marked with a hash sign.
610 **
611 ** If GLOB is given, show only branches matching the pattern. With the
612 ** -h option set, no GLOB argument is allowed, but an (optional) number
613 ** of entries to output.
614 **
615 ** > fossil branch new BRANCH-NAME BASIS ?OPTIONS?
616 **
617 ** Create a new branch BRANCH-NAME off of check-in BASIS.
618 ** Supported options for this subcommand include:
@@ -656,24 +668,33 @@
668 }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){
669 Stmt q;
670 int vid;
671 char *zCurrent = 0;
672 const char *zBrNameGlob = 0;
673 int nLimit = 5;
674 int brFlags = BRL_OPEN_ONLY;
675 if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH;
676 if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY;
677 if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME;
678 if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE;
679 if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE;
680 if( find_option("h",0,0)!=0 ) brFlags |= BRL_LIMIT;
681 if( (brFlags & BRL_LIMIT)==0 ){
682 if( g.argc >= 4 ) zBrNameGlob = g.argv[3];
683 }else{
684 if( g.argc>4 || g.argc==4 && (nLimit = atoi(g.argv[3]))==0 ){
685 fossil_fatal("only one numeric or no argument allowed following -h");
686 }
687 brFlags |= BRL_ORDERBY_MTIME;
688 }
689
690 if( g.localOpen ){
691 vid = db_lget_int("checkout", 0);
692 zCurrent = db_text(0, "SELECT value FROM tagxref"
693 " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
694 }
695 branch_prepare_list_query(&q, brFlags, zBrNameGlob, nLimit);
696 while( db_step(&q)==SQLITE_ROW ){
697 const char *zBr = db_column_text(&q, 0);
698 int isPriv = zCurrent!=0 && db_column_int(&q, 1)==1;
699 int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
700 fossil_print("%s%s%s\n",
@@ -862,11 +883,11 @@
883 @ reopened).</li>
884 @ </ol>
885 style_sidebox_end();
886 #endif
887
888 branch_prepare_list_query(&q, brFlags, 0, 0);
889 cnt = 0;
890 while( db_step(&q)==SQLITE_ROW ){
891 const char *zBr = db_column_text(&q, 0);
892 if( cnt==0 ){
893 if( colorTest ){
894

Keyboard Shortcuts

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