Fossil SCM

Enhance the "fossil tag ls" command to allow filtering by tag type.

drh 2019-06-29 03:08 trunk merge
Commit 971a1a99ddb70d20e4b154552535ca5f68dd6f0349b20b91fb74ba002724ad1c
1 file changed +29 -7
+29 -7
--- src/tag.c
+++ src/tag.c
@@ -414,14 +414,19 @@
414414
** Options:
415415
** --raw Raw tag name.
416416
** -t|--type TYPE One of "ci", or "e".
417417
** -n|--limit N Limit to N results.
418418
**
419
-** %fossil tag list|ls ?--raw? ?CHECK-IN?
419
+** %fossil tag list|ls ?OPTIONS? ?CHECK-IN?
420420
**
421421
** List all tags, or if CHECK-IN is supplied, list
422
-** all tags and their values for CHECK-IN.
422
+** all tags and their values for CHECK-IN. The tagtype option
423
+** takes one of: propagated, singleton, cancel.
424
+**
425
+** Options:
426
+** --raw List tags raw names of tags
427
+** --tagtype TYPE List only tags of type TYPE
423428
**
424429
** The option --raw allows the manipulation of all types of tags
425430
** used for various internal purposes in fossil. It also shows
426431
** "cancel" tags for the "find" and "list" subcommands. You should
427432
** not use this option to make changes unless you are sure what
@@ -544,17 +549,33 @@
544549
}else
545550
546551
if(( strncmp(g.argv[2],"list",n)==0 )||( strncmp(g.argv[2],"ls",n)==0 )){
547552
Stmt q;
548553
int fRaw = find_option("raw","",0)!=0;
554
+ const char *zTagType = find_option("tagtype","t",1);
555
+ int nTagType = fRaw ? -1 : 0;
556
+ if( zTagType!=0 ){
557
+ int l = strlen(zTagType);
558
+ if( strncmp(zTagType,"cancel",l)==0 ){
559
+ nTagType = 0;
560
+ }else if( strncmp(zTagType,"singleton",l)==0 ){
561
+ nTagType = 1;
562
+ }else if( strncmp(zTagType,"propagated",l)==0 ){
563
+ nTagType = 2;
564
+ }else{
565
+ fossil_fatal("unrecognized tag type");
566
+ }
567
+ }
549568
if( g.argc==3 ){
550569
db_prepare(&q,
551570
"SELECT tagname FROM tag"
552571
" WHERE EXISTS(SELECT 1 FROM tagxref"
553572
" WHERE tagid=tag.tagid"
554
- " AND tagtype>0)"
555
- " ORDER BY tagname"
573
+ " AND tagtype%c%d)"
574
+ " ORDER BY tagname",
575
+ zTagType!=0 ? '=' : '>',
576
+ nTagType
556577
);
557578
while( db_step(&q)==SQLITE_ROW ){
558579
const char *zName = db_column_text(&q, 0);
559580
if( fRaw ){
560581
fossil_print("%s\n", zName);
@@ -566,14 +587,15 @@
566587
}else if( g.argc==4 ){
567588
int rid = name_to_rid(g.argv[3]);
568589
db_prepare(&q,
569590
"SELECT tagname, value FROM tagxref, tag"
570591
" WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
571
- " AND tagtype>%d"
592
+ " AND tagtype%c%d"
572593
" ORDER BY tagname",
573594
rid,
574
- fRaw ? -1 : 0
595
+ zTagType!=0 ? '=' : '>',
596
+ nTagType
575597
);
576598
while( db_step(&q)==SQLITE_ROW ){
577599
const char *zName = db_column_text(&q, 0);
578600
const char *zValue = db_column_text(&q, 1);
579601
if( fRaw==0 ){
@@ -586,11 +608,11 @@
586608
fossil_print("%s\n", zName);
587609
}
588610
}
589611
db_finalize(&q);
590612
}else{
591
- usage("list ?CHECK-IN?");
613
+ usage("list ?OPTIONS? ?CHECK-IN?");
592614
}
593615
}else
594616
{
595617
goto tag_cmd_usage;
596618
}
597619
--- src/tag.c
+++ src/tag.c
@@ -414,14 +414,19 @@
414 ** Options:
415 ** --raw Raw tag name.
416 ** -t|--type TYPE One of "ci", or "e".
417 ** -n|--limit N Limit to N results.
418 **
419 ** %fossil tag list|ls ?--raw? ?CHECK-IN?
420 **
421 ** List all tags, or if CHECK-IN is supplied, list
422 ** all tags and their values for CHECK-IN.
 
 
 
 
 
423 **
424 ** The option --raw allows the manipulation of all types of tags
425 ** used for various internal purposes in fossil. It also shows
426 ** "cancel" tags for the "find" and "list" subcommands. You should
427 ** not use this option to make changes unless you are sure what
@@ -544,17 +549,33 @@
544 }else
545
546 if(( strncmp(g.argv[2],"list",n)==0 )||( strncmp(g.argv[2],"ls",n)==0 )){
547 Stmt q;
548 int fRaw = find_option("raw","",0)!=0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
549 if( g.argc==3 ){
550 db_prepare(&q,
551 "SELECT tagname FROM tag"
552 " WHERE EXISTS(SELECT 1 FROM tagxref"
553 " WHERE tagid=tag.tagid"
554 " AND tagtype>0)"
555 " ORDER BY tagname"
 
 
556 );
557 while( db_step(&q)==SQLITE_ROW ){
558 const char *zName = db_column_text(&q, 0);
559 if( fRaw ){
560 fossil_print("%s\n", zName);
@@ -566,14 +587,15 @@
566 }else if( g.argc==4 ){
567 int rid = name_to_rid(g.argv[3]);
568 db_prepare(&q,
569 "SELECT tagname, value FROM tagxref, tag"
570 " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
571 " AND tagtype>%d"
572 " ORDER BY tagname",
573 rid,
574 fRaw ? -1 : 0
 
575 );
576 while( db_step(&q)==SQLITE_ROW ){
577 const char *zName = db_column_text(&q, 0);
578 const char *zValue = db_column_text(&q, 1);
579 if( fRaw==0 ){
@@ -586,11 +608,11 @@
586 fossil_print("%s\n", zName);
587 }
588 }
589 db_finalize(&q);
590 }else{
591 usage("list ?CHECK-IN?");
592 }
593 }else
594 {
595 goto tag_cmd_usage;
596 }
597
--- src/tag.c
+++ src/tag.c
@@ -414,14 +414,19 @@
414 ** Options:
415 ** --raw Raw tag name.
416 ** -t|--type TYPE One of "ci", or "e".
417 ** -n|--limit N Limit to N results.
418 **
419 ** %fossil tag list|ls ?OPTIONS? ?CHECK-IN?
420 **
421 ** List all tags, or if CHECK-IN is supplied, list
422 ** all tags and their values for CHECK-IN. The tagtype option
423 ** takes one of: propagated, singleton, cancel.
424 **
425 ** Options:
426 ** --raw List tags raw names of tags
427 ** --tagtype TYPE List only tags of type TYPE
428 **
429 ** The option --raw allows the manipulation of all types of tags
430 ** used for various internal purposes in fossil. It also shows
431 ** "cancel" tags for the "find" and "list" subcommands. You should
432 ** not use this option to make changes unless you are sure what
@@ -544,17 +549,33 @@
549 }else
550
551 if(( strncmp(g.argv[2],"list",n)==0 )||( strncmp(g.argv[2],"ls",n)==0 )){
552 Stmt q;
553 int fRaw = find_option("raw","",0)!=0;
554 const char *zTagType = find_option("tagtype","t",1);
555 int nTagType = fRaw ? -1 : 0;
556 if( zTagType!=0 ){
557 int l = strlen(zTagType);
558 if( strncmp(zTagType,"cancel",l)==0 ){
559 nTagType = 0;
560 }else if( strncmp(zTagType,"singleton",l)==0 ){
561 nTagType = 1;
562 }else if( strncmp(zTagType,"propagated",l)==0 ){
563 nTagType = 2;
564 }else{
565 fossil_fatal("unrecognized tag type");
566 }
567 }
568 if( g.argc==3 ){
569 db_prepare(&q,
570 "SELECT tagname FROM tag"
571 " WHERE EXISTS(SELECT 1 FROM tagxref"
572 " WHERE tagid=tag.tagid"
573 " AND tagtype%c%d)"
574 " ORDER BY tagname",
575 zTagType!=0 ? '=' : '>',
576 nTagType
577 );
578 while( db_step(&q)==SQLITE_ROW ){
579 const char *zName = db_column_text(&q, 0);
580 if( fRaw ){
581 fossil_print("%s\n", zName);
@@ -566,14 +587,15 @@
587 }else if( g.argc==4 ){
588 int rid = name_to_rid(g.argv[3]);
589 db_prepare(&q,
590 "SELECT tagname, value FROM tagxref, tag"
591 " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
592 " AND tagtype%c%d"
593 " ORDER BY tagname",
594 rid,
595 zTagType!=0 ? '=' : '>',
596 nTagType
597 );
598 while( db_step(&q)==SQLITE_ROW ){
599 const char *zName = db_column_text(&q, 0);
600 const char *zValue = db_column_text(&q, 1);
601 if( fRaw==0 ){
@@ -586,11 +608,11 @@
608 fossil_print("%s\n", zName);
609 }
610 }
611 db_finalize(&q);
612 }else{
613 usage("list ?OPTIONS? ?CHECK-IN?");
614 }
615 }else
616 {
617 goto tag_cmd_usage;
618 }
619

Keyboard Shortcuts

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