Fossil SCM

Filter branch ls output by user with check-ins on the branches.

preben 2023-09-28 10:42 trunk
Commit d0f15a1b655b9a5fca41a08a70529cab08400b1b84af5e17002c20281b56ef70
2 files changed +27 -11 +1 -1
+27 -11
--- src/branch.c
+++ src/branch.c
@@ -297,11 +297,12 @@
297297
*/
298298
void branch_prepare_list_query(
299299
Stmt *pQuery,
300300
int brFlags,
301301
const char *zBrNameGlob,
302
- int nLimitMRU
302
+ int nLimitMRU,
303
+ const char *zUser
303304
){
304305
Blob sql;
305306
blob_init(&sql, 0, 0);
306307
brlist_create_temp_table();
307308
/* Ignore nLimitMRU if no chronological sort requested. */
@@ -330,11 +331,16 @@
330331
break;
331332
}
332333
}
333334
if( brFlags & BRL_PRIVATE ) blob_append_sql(&sql, " AND isprivate");
334335
if( brFlags & BRL_MERGED ) blob_append_sql(&sql, " AND mergeto IS NOT NULL");
335
- if(zBrNameGlob) blob_append_sql(&sql, " AND (name GLOB %Q)", zBrNameGlob);
336
+ if( zBrNameGlob ) blob_append_sql(&sql, " AND (name GLOB %Q)", zBrNameGlob);
337
+ if( zUser && zUser[0] ) blob_append_sql(&sql,
338
+ " AND EXISTS (SELECT 1 FROM event WHERE type='ci' AND (user=%Q OR euser=%Q)"
339
+ " AND objid in (SELECT rid FROM tagxref WHERE value=tmp_brlist.name))",
340
+ zUser, zUser
341
+ );
336342
if( brFlags & BRL_ORDERBY_MTIME ){
337343
blob_append_sql(&sql, " ORDER BY -mtime");
338344
}else{
339345
blob_append_sql(&sql, " ORDER BY name COLLATE nocase");
340346
}
@@ -614,17 +620,19 @@
614620
** > fossil branch lsh ?OPTIONS? ?LIMIT?
615621
**
616622
** List all branches.
617623
**
618624
** Options:
619
-** -a|--all List all branches. Default show only open branches
620
-** -c|--closed List closed branches
621
-** -m|--merged List branches merged into the current branch
622
-** -M|--unmerged List branches not merged into the current branch
623
-** -p List only private branches
624
-** -r Reverse the sort order
625
-** -t Show recently changed branches first
625
+** -a|--all List all branches. Default show only open branches
626
+** -c|--closed List closed branches
627
+** -m|--merged List branches merged into the current branch
628
+** -M|--unmerged List branches not merged into the current branch
629
+** -p List only private branches
630
+** -r Reverse the sort order
631
+** -t Show recently changed branches first
632
+** --username USER List only branches with check-ins by USER
633
+** --self List only branches with check-ins by the default user
626634
**
627635
** The current branch is marked with an asterisk. Private branches are
628636
** marked with a hash sign.
629637
**
630638
** If GLOB is given, show only branches matching the pattern.
@@ -692,19 +700,27 @@
692700
strcmp(zCmd, "lsh")==0 ){
693701
Stmt q;
694702
int vid;
695703
char *zCurrent = 0;
696704
const char *zBrNameGlob = 0;
705
+ const char *zUser = find_option("username",0,1);
697706
int nLimit = 0;
698707
int brFlags = BRL_OPEN_ONLY;
699708
if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH;
700709
if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY;
701710
if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME;
702711
if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE;
703712
if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE;
704713
if( find_option("merged","m",0)!=0 ) brFlags |= BRL_MERGED;
705714
if( find_option("unmerged","M",0)!=0 ) brFlags |= BRL_UNMERGED;
715
+ if( find_option("self","0",0)!=0 ){
716
+ if( zUser ){
717
+ fossil_fatal("flags --username and --self are mutually exclusive");
718
+ }
719
+ user_select();
720
+ zUser = login_name();
721
+ }
706722
707723
if ( (brFlags & BRL_MERGED) && (brFlags & BRL_UNMERGED) ){
708724
fossil_fatal("flags --merged and --unmerged are mutually exclusive");
709725
}
710726
if( strcmp(zCmd, "lsh")==0 ){
@@ -720,11 +736,11 @@
720736
if( g.localOpen ){
721737
vid = db_lget_int("checkout", 0);
722738
zCurrent = db_text(0, "SELECT value FROM tagxref"
723739
" WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
724740
}
725
- branch_prepare_list_query(&q, brFlags, zBrNameGlob, nLimit);
741
+ branch_prepare_list_query(&q, brFlags, zBrNameGlob, nLimit, zUser);
726742
while( db_step(&q)==SQLITE_ROW ){
727743
const char *zBr = db_column_text(&q, 0);
728744
int isPriv = zCurrent!=0 && db_column_int(&q, 1)==1;
729745
const char *zMergeTo = db_column_text(&q, 2);
730746
int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
@@ -922,11 +938,11 @@
922938
@ reopened).</li>
923939
@ </ol>
924940
style_sidebox_end();
925941
#endif
926942
927
- branch_prepare_list_query(&q, brFlags, 0, 0);
943
+ branch_prepare_list_query(&q, brFlags, 0, 0, 0);
928944
cnt = 0;
929945
while( db_step(&q)==SQLITE_ROW ){
930946
const char *zBr = db_column_text(&q, 0);
931947
if( cnt==0 ){
932948
if( colorTest ){
933949
--- src/branch.c
+++ src/branch.c
@@ -297,11 +297,12 @@
297 */
298 void branch_prepare_list_query(
299 Stmt *pQuery,
300 int brFlags,
301 const char *zBrNameGlob,
302 int nLimitMRU
 
303 ){
304 Blob sql;
305 blob_init(&sql, 0, 0);
306 brlist_create_temp_table();
307 /* Ignore nLimitMRU if no chronological sort requested. */
@@ -330,11 +331,16 @@
330 break;
331 }
332 }
333 if( brFlags & BRL_PRIVATE ) blob_append_sql(&sql, " AND isprivate");
334 if( brFlags & BRL_MERGED ) blob_append_sql(&sql, " AND mergeto IS NOT NULL");
335 if(zBrNameGlob) blob_append_sql(&sql, " AND (name GLOB %Q)", zBrNameGlob);
 
 
 
 
 
336 if( brFlags & BRL_ORDERBY_MTIME ){
337 blob_append_sql(&sql, " ORDER BY -mtime");
338 }else{
339 blob_append_sql(&sql, " ORDER BY name COLLATE nocase");
340 }
@@ -614,17 +620,19 @@
614 ** > fossil branch lsh ?OPTIONS? ?LIMIT?
615 **
616 ** List all branches.
617 **
618 ** Options:
619 ** -a|--all List all branches. Default show only open branches
620 ** -c|--closed List closed branches
621 ** -m|--merged List branches merged into the current branch
622 ** -M|--unmerged List branches not merged into the current branch
623 ** -p List only private branches
624 ** -r Reverse the sort order
625 ** -t Show recently changed branches first
 
 
626 **
627 ** The current branch is marked with an asterisk. Private branches are
628 ** marked with a hash sign.
629 **
630 ** If GLOB is given, show only branches matching the pattern.
@@ -692,19 +700,27 @@
692 strcmp(zCmd, "lsh")==0 ){
693 Stmt q;
694 int vid;
695 char *zCurrent = 0;
696 const char *zBrNameGlob = 0;
 
697 int nLimit = 0;
698 int brFlags = BRL_OPEN_ONLY;
699 if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH;
700 if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY;
701 if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME;
702 if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE;
703 if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE;
704 if( find_option("merged","m",0)!=0 ) brFlags |= BRL_MERGED;
705 if( find_option("unmerged","M",0)!=0 ) brFlags |= BRL_UNMERGED;
 
 
 
 
 
 
 
706
707 if ( (brFlags & BRL_MERGED) && (brFlags & BRL_UNMERGED) ){
708 fossil_fatal("flags --merged and --unmerged are mutually exclusive");
709 }
710 if( strcmp(zCmd, "lsh")==0 ){
@@ -720,11 +736,11 @@
720 if( g.localOpen ){
721 vid = db_lget_int("checkout", 0);
722 zCurrent = db_text(0, "SELECT value FROM tagxref"
723 " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
724 }
725 branch_prepare_list_query(&q, brFlags, zBrNameGlob, nLimit);
726 while( db_step(&q)==SQLITE_ROW ){
727 const char *zBr = db_column_text(&q, 0);
728 int isPriv = zCurrent!=0 && db_column_int(&q, 1)==1;
729 const char *zMergeTo = db_column_text(&q, 2);
730 int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
@@ -922,11 +938,11 @@
922 @ reopened).</li>
923 @ </ol>
924 style_sidebox_end();
925 #endif
926
927 branch_prepare_list_query(&q, brFlags, 0, 0);
928 cnt = 0;
929 while( db_step(&q)==SQLITE_ROW ){
930 const char *zBr = db_column_text(&q, 0);
931 if( cnt==0 ){
932 if( colorTest ){
933
--- src/branch.c
+++ src/branch.c
@@ -297,11 +297,12 @@
297 */
298 void branch_prepare_list_query(
299 Stmt *pQuery,
300 int brFlags,
301 const char *zBrNameGlob,
302 int nLimitMRU,
303 const char *zUser
304 ){
305 Blob sql;
306 blob_init(&sql, 0, 0);
307 brlist_create_temp_table();
308 /* Ignore nLimitMRU if no chronological sort requested. */
@@ -330,11 +331,16 @@
331 break;
332 }
333 }
334 if( brFlags & BRL_PRIVATE ) blob_append_sql(&sql, " AND isprivate");
335 if( brFlags & BRL_MERGED ) blob_append_sql(&sql, " AND mergeto IS NOT NULL");
336 if( zBrNameGlob ) blob_append_sql(&sql, " AND (name GLOB %Q)", zBrNameGlob);
337 if( zUser && zUser[0] ) blob_append_sql(&sql,
338 " AND EXISTS (SELECT 1 FROM event WHERE type='ci' AND (user=%Q OR euser=%Q)"
339 " AND objid in (SELECT rid FROM tagxref WHERE value=tmp_brlist.name))",
340 zUser, zUser
341 );
342 if( brFlags & BRL_ORDERBY_MTIME ){
343 blob_append_sql(&sql, " ORDER BY -mtime");
344 }else{
345 blob_append_sql(&sql, " ORDER BY name COLLATE nocase");
346 }
@@ -614,17 +620,19 @@
620 ** > fossil branch lsh ?OPTIONS? ?LIMIT?
621 **
622 ** List all branches.
623 **
624 ** Options:
625 ** -a|--all List all branches. Default show only open branches
626 ** -c|--closed List closed branches
627 ** -m|--merged List branches merged into the current branch
628 ** -M|--unmerged List branches not merged into the current branch
629 ** -p List only private branches
630 ** -r Reverse the sort order
631 ** -t Show recently changed branches first
632 ** --username USER List only branches with check-ins by USER
633 ** --self List only branches with check-ins by the default user
634 **
635 ** The current branch is marked with an asterisk. Private branches are
636 ** marked with a hash sign.
637 **
638 ** If GLOB is given, show only branches matching the pattern.
@@ -692,19 +700,27 @@
700 strcmp(zCmd, "lsh")==0 ){
701 Stmt q;
702 int vid;
703 char *zCurrent = 0;
704 const char *zBrNameGlob = 0;
705 const char *zUser = find_option("username",0,1);
706 int nLimit = 0;
707 int brFlags = BRL_OPEN_ONLY;
708 if( find_option("all","a",0)!=0 ) brFlags = BRL_BOTH;
709 if( find_option("closed","c",0)!=0 ) brFlags = BRL_CLOSED_ONLY;
710 if( find_option("t",0,0)!=0 ) brFlags |= BRL_ORDERBY_MTIME;
711 if( find_option("r",0,0)!=0 ) brFlags |= BRL_REVERSE;
712 if( find_option("p",0,0)!=0 ) brFlags |= BRL_PRIVATE;
713 if( find_option("merged","m",0)!=0 ) brFlags |= BRL_MERGED;
714 if( find_option("unmerged","M",0)!=0 ) brFlags |= BRL_UNMERGED;
715 if( find_option("self","0",0)!=0 ){
716 if( zUser ){
717 fossil_fatal("flags --username and --self are mutually exclusive");
718 }
719 user_select();
720 zUser = login_name();
721 }
722
723 if ( (brFlags & BRL_MERGED) && (brFlags & BRL_UNMERGED) ){
724 fossil_fatal("flags --merged and --unmerged are mutually exclusive");
725 }
726 if( strcmp(zCmd, "lsh")==0 ){
@@ -720,11 +736,11 @@
736 if( g.localOpen ){
737 vid = db_lget_int("checkout", 0);
738 zCurrent = db_text(0, "SELECT value FROM tagxref"
739 " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
740 }
741 branch_prepare_list_query(&q, brFlags, zBrNameGlob, nLimit, zUser);
742 while( db_step(&q)==SQLITE_ROW ){
743 const char *zBr = db_column_text(&q, 0);
744 int isPriv = zCurrent!=0 && db_column_int(&q, 1)==1;
745 const char *zMergeTo = db_column_text(&q, 2);
746 int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
@@ -922,11 +938,11 @@
938 @ reopened).</li>
939 @ </ol>
940 style_sidebox_end();
941 #endif
942
943 branch_prepare_list_query(&q, brFlags, 0, 0, 0);
944 cnt = 0;
945 while( db_step(&q)==SQLITE_ROW ){
946 const char *zBr = db_column_text(&q, 0);
947 if( cnt==0 ){
948 if( colorTest ){
949
--- src/json_branch.c
+++ src/json_branch.c
@@ -128,11 +128,11 @@
128128
cson_object_set(pay,"current",json_new_string(zCurrent));
129129
}
130130
}
131131
132132
133
- branch_prepare_list_query(&q, branchListFlags, 0, 0);
133
+ branch_prepare_list_query(&q, branchListFlags, 0, 0, 0); /* Allow a user? */
134134
cson_object_set(pay,"branches",listV);
135135
while((SQLITE_ROW==db_step(&q))){
136136
cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
137137
if(v){
138138
cson_array_append(list,v);
139139
--- src/json_branch.c
+++ src/json_branch.c
@@ -128,11 +128,11 @@
128 cson_object_set(pay,"current",json_new_string(zCurrent));
129 }
130 }
131
132
133 branch_prepare_list_query(&q, branchListFlags, 0, 0);
134 cson_object_set(pay,"branches",listV);
135 while((SQLITE_ROW==db_step(&q))){
136 cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
137 if(v){
138 cson_array_append(list,v);
139
--- src/json_branch.c
+++ src/json_branch.c
@@ -128,11 +128,11 @@
128 cson_object_set(pay,"current",json_new_string(zCurrent));
129 }
130 }
131
132
133 branch_prepare_list_query(&q, branchListFlags, 0, 0, 0); /* Allow a user? */
134 cson_object_set(pay,"branches",listV);
135 while((SQLITE_ROW==db_step(&q))){
136 cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
137 if(v){
138 cson_array_append(list,v);
139

Keyboard Shortcuts

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