Fossil SCM
Enhance the "fossil tag ls" command to allow filtering by tag type.
Commit
971a1a99ddb70d20e4b154552535ca5f68dd6f0349b20b91fb74ba002724ad1c
Parent
cdd5e576dddb052…
1 file changed
+29
-7
+29
-7
| --- src/tag.c | ||
| +++ src/tag.c | ||
| @@ -414,14 +414,19 @@ | ||
| 414 | 414 | ** Options: |
| 415 | 415 | ** --raw Raw tag name. |
| 416 | 416 | ** -t|--type TYPE One of "ci", or "e". |
| 417 | 417 | ** -n|--limit N Limit to N results. |
| 418 | 418 | ** |
| 419 | -** %fossil tag list|ls ?--raw? ?CHECK-IN? | |
| 419 | +** %fossil tag list|ls ?OPTIONS? ?CHECK-IN? | |
| 420 | 420 | ** |
| 421 | 421 | ** 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 | |
| 423 | 428 | ** |
| 424 | 429 | ** The option --raw allows the manipulation of all types of tags |
| 425 | 430 | ** used for various internal purposes in fossil. It also shows |
| 426 | 431 | ** "cancel" tags for the "find" and "list" subcommands. You should |
| 427 | 432 | ** not use this option to make changes unless you are sure what |
| @@ -544,17 +549,33 @@ | ||
| 544 | 549 | }else |
| 545 | 550 | |
| 546 | 551 | if(( strncmp(g.argv[2],"list",n)==0 )||( strncmp(g.argv[2],"ls",n)==0 )){ |
| 547 | 552 | Stmt q; |
| 548 | 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 | + } | |
| 549 | 568 | if( g.argc==3 ){ |
| 550 | 569 | db_prepare(&q, |
| 551 | 570 | "SELECT tagname FROM tag" |
| 552 | 571 | " WHERE EXISTS(SELECT 1 FROM tagxref" |
| 553 | 572 | " 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 | |
| 556 | 577 | ); |
| 557 | 578 | while( db_step(&q)==SQLITE_ROW ){ |
| 558 | 579 | const char *zName = db_column_text(&q, 0); |
| 559 | 580 | if( fRaw ){ |
| 560 | 581 | fossil_print("%s\n", zName); |
| @@ -566,14 +587,15 @@ | ||
| 566 | 587 | }else if( g.argc==4 ){ |
| 567 | 588 | int rid = name_to_rid(g.argv[3]); |
| 568 | 589 | db_prepare(&q, |
| 569 | 590 | "SELECT tagname, value FROM tagxref, tag" |
| 570 | 591 | " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid" |
| 571 | - " AND tagtype>%d" | |
| 592 | + " AND tagtype%c%d" | |
| 572 | 593 | " ORDER BY tagname", |
| 573 | 594 | rid, |
| 574 | - fRaw ? -1 : 0 | |
| 595 | + zTagType!=0 ? '=' : '>', | |
| 596 | + nTagType | |
| 575 | 597 | ); |
| 576 | 598 | while( db_step(&q)==SQLITE_ROW ){ |
| 577 | 599 | const char *zName = db_column_text(&q, 0); |
| 578 | 600 | const char *zValue = db_column_text(&q, 1); |
| 579 | 601 | if( fRaw==0 ){ |
| @@ -586,11 +608,11 @@ | ||
| 586 | 608 | fossil_print("%s\n", zName); |
| 587 | 609 | } |
| 588 | 610 | } |
| 589 | 611 | db_finalize(&q); |
| 590 | 612 | }else{ |
| 591 | - usage("list ?CHECK-IN?"); | |
| 613 | + usage("list ?OPTIONS? ?CHECK-IN?"); | |
| 592 | 614 | } |
| 593 | 615 | }else |
| 594 | 616 | { |
| 595 | 617 | goto tag_cmd_usage; |
| 596 | 618 | } |
| 597 | 619 |
| --- 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 |