Fossil

Check-in [c797abe4c3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Updated tag list subcommand to be able to deal with propagated tags on wiki, forum post, and technote artifacts, with an eye towards not breaking any historical scripting uses.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c797abe4c377d14f3c642d038d6e8f7f1cec914aac012d03966c22ab541c3474
User & Date: stephan 2021-06-04 11:39:00.853
Context
2021-06-04
12:32
Tweaked the various wiki page list queries to ensure that they do not include tags named wiki-* unless those tags appear to refer to a wiki page. Historically, the tag command has allowed entry of such tags and at least one is known to exist in another tree. (check-in: 4218b20031 user: stephan tags: trunk)
11:39
Updated tag list subcommand to be able to deal with propagated tags on wiki, forum post, and technote artifacts, with an eye towards not breaking any historical scripting uses. (check-in: c797abe4c3 user: stephan tags: trunk)
2021-06-03
23:57
Enable propagating tags for forum, wiki, and technotes. (check-in: 7c64fe0b67 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/name.c.
742
743
744
745
746
747
748
749
750
751
752




753
754
755
756
757
758
759

/*
** Given an RID of a structural artifact, which is assumed to be
** valid, this function returns one of the CFTYPE_xxx values
** describing the record type, or 0 if the RID does not refer to an
** artifact record (as determined by reading the event table).
**
** Note that this function neve returns CFTYPE_ATTACHMENT or
** CFTYPE_CLUSTER because those are not used in the event table. Thus
** it cannot be used to distinguish those artifact types from
** non-artifact file content.




*/
int whatis_rid_type(int rid){
  Stmt q = empty_Stmt;
  int type = 0;
    /* Check for entries on the timeline that reference this object */
  db_prepare(&q,
     "SELECT type FROM event WHERE objid=%d", rid);







|



>
>
>
>







742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763

/*
** Given an RID of a structural artifact, which is assumed to be
** valid, this function returns one of the CFTYPE_xxx values
** describing the record type, or 0 if the RID does not refer to an
** artifact record (as determined by reading the event table).
**
** Note that this function never returns CFTYPE_ATTACHMENT or
** CFTYPE_CLUSTER because those are not used in the event table. Thus
** it cannot be used to distinguish those artifact types from
** non-artifact file content.
**
** Potential TODO: if the rid is not found in the timeline, try to
** match it to a client file and return a hypothetical new
** CFTYPE_OPAQUE or CFTYPE_NONARTIFACT if a match is found.
*/
int whatis_rid_type(int rid){
  Stmt q = empty_Stmt;
  int type = 0;
    /* Check for entries on the timeline that reference this object */
  db_prepare(&q,
     "SELECT type FROM event WHERE objid=%d", rid);
Changes to src/tag.c.
368
369
370
371
372
373
374





375
376
377
378
379
380
381

/*
** If zTag is NULL or valid for use as a tag for the `tag add` and
** `tag cancel` commands, returns without side effects, else emits a
** fatal error message. We reject certain prefixes to avoid that
** clients cause undue grief by improperly tagging artifacts as being,
** e.g., wiki pages or tickets.





*/
static void tag_cmd_tagname_check(const char *zTag){
  if(zTag && *zTag &&
     (strncmp(zTag,"wiki-",5)==0
      || strncmp(zTag,"tkt-",4)==0
      || strncmp(zTag,"event-",6)==0)){
    fossil_fatal("Invalid prefix for tag name: %s", zTag);







>
>
>
>
>







368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386

/*
** If zTag is NULL or valid for use as a tag for the `tag add` and
** `tag cancel` commands, returns without side effects, else emits a
** fatal error message. We reject certain prefixes to avoid that
** clients cause undue grief by improperly tagging artifacts as being,
** e.g., wiki pages or tickets.
**
** Note that we intentionally allow the "sym-" prefix, partly for
** historical compatibility and partly because it can be applied
** properly, whereas the other reserved name types have special
** meanings for fossil and cannot be sensibly manually manipulated.
*/
static void tag_cmd_tagname_check(const char *zTag){
  if(zTag && *zTag &&
     (strncmp(zTag,"wiki-",5)==0
      || strncmp(zTag,"tkt-",4)==0
      || strncmp(zTag,"event-",6)==0)){
    fossil_fatal("Invalid prefix for tag name: %s", zTag);
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
**
** > fossil tag add ?OPTIONS? TAGNAME ARTIFACT-ID ?VALUE?
**
**         Add a new tag or property to an artifact referenced by
**         ARTIFACT-ID. For checkins, the tag will be usable instead
**         of a CHECK-IN in commands such as update and merge. If the
**         --propagate flag is present and ARTIFACT-ID refers to a
**         wiki page, forum post, tech-note, or check-in, the tag
**         propagates to all descendants of that artifact.
**
**         Options:
**           --raw                      Raw tag name. Ignored for
**                                      non-CHECK-IN artifacts.
**           --propagate                Propagating tag.
**           --date-override DATETIME   Set date and time added.







|







396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
**
** > fossil tag add ?OPTIONS? TAGNAME ARTIFACT-ID ?VALUE?
**
**         Add a new tag or property to an artifact referenced by
**         ARTIFACT-ID. For checkins, the tag will be usable instead
**         of a CHECK-IN in commands such as update and merge. If the
**         --propagate flag is present and ARTIFACT-ID refers to a
**         wiki page, forum post, technote, or check-in, the tag
**         propagates to all descendants of that artifact.
**
**         Options:
**           --raw                      Raw tag name. Ignored for
**                                      non-CHECK-IN artifacts.
**           --propagate                Propagating tag.
**           --date-override DATETIME   Set date and time added.
438
439
440
441
442
443
444
445
446
447
448
449



450
451
452
453

454







455
456
457
458
459
460
461
**         of results to the given value.
**
**         Options:
**           --raw           Raw tag name.
**           -t|--type TYPE  One of "ci", or "e".
**           -n|--limit N    Limit to N results.
**
** > fossil tag list|ls ?OPTIONS? ?CHECK-IN?
**
**         List all tags, or if CHECK-IN is supplied, list
**         all tags and their values for CHECK-IN.  The tagtype option
**         takes one of: propagated, singleton, cancel.



**
**         Options:
**           --raw           List tags raw names of tags
**           --tagtype TYPE  List only tags of type TYPE

**           -v|--inverse    Inverse the meaning of --tagtype TYPE.







**
** The option --raw allows the manipulation of all types of tags
** used for various internal purposes in fossil. It also shows
** "cancel" tags for the "find" and "list" subcommands. You should
** not use this option to make changes unless you are sure what
** you are doing.
**







|

|
|
|
>
>
>


|
|
>

>
>
>
>
>
>
>







443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
**         of results to the given value.
**
**         Options:
**           --raw           Raw tag name.
**           -t|--type TYPE  One of "ci", or "e".
**           -n|--limit N    Limit to N results.
**
** > fossil tag list|ls ?OPTIONS? ?ARTIFACT-ID?
**
**         List all tags or, if ARTIFACT-ID is supplied, all tags and
**         their values for that artifact. The tagtype option accepts
**         one of: propagated, singleton, cancel.  For historical
**         scripting compatibility, the internal tag types "wiki-",
**         "tkt-", and "event-" (technote) are elided by default
**         unless the --raw or --prefix options are used.
**
**         Options:
**           --raw           List raw names of tags
**           --tagtype TYPE  List only tags of type TYPE, which must
**                           be one of: cancel, singleton, propagated
**           -v|--inverse    Inverse the meaning of --tagtype TYPE.
**           --prefix        List only tags with the given prefix.
**                           Fossil-internal prefixes include "sym-"
**                           (branch name), "wiki-", "event-"
**                           (technote), and "tkt-" (ticket). The
**                           prefix is stripped from the resulting
**                           list unless --raw is provided. Ignored if
**                           ARTIFACT-ID is provided.
**
** The option --raw allows the manipulation of all types of tags
** used for various internal purposes in fossil. It also shows
** "cancel" tags for the "find" and "list" subcommands. You should
** not use this option to make changes unless you are sure what
** you are doing.
**
608
609
610
611
612
613
614

615

616
617
618
619
620
621
622
623
624
625
626
627
628

629
630
631
632
633

634
635
636
637
638
639
640
641



642
643
644
645
646
647

648



















649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
  }else

  if(( strncmp(g.argv[2],"list",n)==0 )||( strncmp(g.argv[2],"ls",n)==0 )){
    Stmt q;
    const int fRaw = find_option("raw","",0)!=0;
    const char *zTagType = find_option("tagtype","t",1);
    const int fInverse = find_option("inverse","v",0)!=0;

    int nTagType = fRaw ? -1 : 0;

    if( zTagType!=0 ){
      int l = strlen(zTagType);
      if( strncmp(zTagType,"cancel",l)==0 ){
        nTagType = 0;
      }else if( strncmp(zTagType,"singleton",l)==0 ){ 
        nTagType = 1;
      }else if( strncmp(zTagType,"propagated",l)==0 ){ 
        nTagType = 2;
      }else{
        fossil_fatal("unrecognized tag type");
      }
    }
    if( g.argc==3 ){

      db_prepare(&q,
        "SELECT tagname FROM tag"
        " WHERE EXISTS(SELECT 1 FROM tagxref"
        "               WHERE tagid=tag.tagid"
        "                 AND tagtype%s%d)"

        " ORDER BY tagname",
        zTagType!=0 ? (fInverse!=0?"<>":"=") : ">"/*safe-for-%s*/,
        nTagType
      );
      while( db_step(&q)==SQLITE_ROW ){
        const char *zName = db_column_text(&q, 0);
        if( fRaw ){
          fossil_print("%s\n", zName);



        }else if( strncmp(zName, "sym-", 4)==0 ){
          fossil_print("%s\n", &zName[4]);
        }
      }
      db_finalize(&q);
    }else if( g.argc==4 ){

      int rid = name_to_rid(g.argv[3]);



















      db_prepare(&q,
        "SELECT tagname, value FROM tagxref, tag"
        " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
        "   AND tagtype%s%d"
        " ORDER BY tagname",
        rid,
        zTagType!=0 ? (fInverse!=0?"<>":"=") : ">"/*safe-for-%s*/,
        nTagType
      );
      while( db_step(&q)==SQLITE_ROW ){
        const char *zName = db_column_text(&q, 0);
        const char *zValue = db_column_text(&q, 1);
        if( fRaw==0 ){
          if( strncmp(zName, "sym-", 4)!=0 ) continue;
          zName += 4;
        }
        if( zValue && zValue[0] ){
          fossil_print("%s=%s\n", zName, zValue);
        }else{
          fossil_print("%s\n", zName);
        }
      }







>

>













>





>
|

|





>
>
>






>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












<
|
|







624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703

704
705
706
707
708
709
710
711
712
  }else

  if(( strncmp(g.argv[2],"list",n)==0 )||( strncmp(g.argv[2],"ls",n)==0 )){
    Stmt q;
    const int fRaw = find_option("raw","",0)!=0;
    const char *zTagType = find_option("tagtype","t",1);
    const int fInverse = find_option("inverse","v",0)!=0;
    const char *zTagPrefix = find_option("prefix","",1);
    int nTagType = fRaw ? -1 : 0;

    if( zTagType!=0 ){
      int l = strlen(zTagType);
      if( strncmp(zTagType,"cancel",l)==0 ){
        nTagType = 0;
      }else if( strncmp(zTagType,"singleton",l)==0 ){ 
        nTagType = 1;
      }else if( strncmp(zTagType,"propagated",l)==0 ){ 
        nTagType = 2;
      }else{
        fossil_fatal("unrecognized tag type");
      }
    }
    if( g.argc==3 ){
      const int nTagPrefix = zTagPrefix ? (int)strlen(zTagPrefix) : 0;
      db_prepare(&q,
        "SELECT tagname FROM tag"
        " WHERE EXISTS(SELECT 1 FROM tagxref"
        "               WHERE tagid=tag.tagid"
        "                 AND tagtype%s%d)"
        " AND CASE WHEN %Q IS NULL THEN 1 ELSE tagname GLOB %Q||'*' "
        " END ORDER BY tagname",
        zTagType!=0 ? (fInverse!=0?"<>":"=") : ">"/*safe-for-%s*/,
        nTagType, zTagPrefix, zTagPrefix
      );
      while( db_step(&q)==SQLITE_ROW ){
        const char *zName = db_column_text(&q, 0);
        if( fRaw ){
          fossil_print("%s\n", zName);
        }else if( nTagPrefix>0 ){
          assert(db_column_bytes(&q,0)>=nTagPrefix);
          fossil_print("%s\n", &zName[nTagPrefix]);
        }else if( strncmp(zName, "sym-", 4)==0 ){
          fossil_print("%s\n", &zName[4]);
        }
      }
      db_finalize(&q);
    }else if( g.argc==4 ){
      char const *zObjId = g.argv[3];
      const int rid = name_to_rid(zObjId);
      const int objType = whatis_rid_type(rid);
      int nTagOffset = 0;

      zTagPrefix = 0;
      if(objType<=0){
        fossil_fatal("Cannot resolve artifact ID: %s", zObjId);
      }else if(fRaw==0){
        /* Figure out the tag prefix to strip */
        switch(objType){
          case CFTYPE_MANIFEST: zTagPrefix = "sym-"; break;
          case CFTYPE_WIKI: zTagPrefix = "wiki-"; break;
          case CFTYPE_TICKET: zTagPrefix = "tkt-"; break;
          case CFTYPE_EVENT: zTagPrefix = "event-"; break;
          default: break;
        }
        if(zTagPrefix!=0){
          nTagOffset = (int)strlen(zTagPrefix);
        }
      }
      db_prepare(&q,
        "SELECT tagname, value FROM tagxref, tag"
        " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
        "   AND tagtype%s%d"
        " ORDER BY tagname",
        rid,
        zTagType!=0 ? (fInverse!=0?"<>":"=") : ">"/*safe-for-%s*/,
        nTagType
      );
      while( db_step(&q)==SQLITE_ROW ){
        const char *zName = db_column_text(&q, 0);
        const char *zValue = db_column_text(&q, 1);

        if( zTagPrefix && strncmp(zName, zTagPrefix, nTagOffset)==0 ){
          zName += nTagOffset;
        }
        if( zValue && zValue[0] ){
          fossil_print("%s=%s\n", zName, zValue);
        }else{
          fossil_print("%s\n", zName);
        }
      }
Changes to www/changes.wiki.
12
13
14
15
16
17
18


19
20
21
22
23
24
25
     branch being merged.
  *  The [/help?cmd=open|fossil open] command allows the repository file
     to be inside the working directory without requiring the --force flag.
  *  The [/help?cmd=/wikiedit|/wikiedit] and [/help?cmd=/wikinew|/wikinew]
     pages now default to markdown format.
  *  The [/help?cmd=/login|/login] page now links to a user's forum post
     timeline if the repository has forum posts.



<a name='v2_15'></a>
<h2>Changes for Version 2.15 (2021-03-26) and Patch 2.15.1 on (2021-04-07)</h2>
  *  <b>Patch 2.15.1:</b> Fix a data exfiltration bug in the server.  <b>Upgrading to
     the patch is recommended.</b><p>
  *  The [./defcsp.md|default CSP] has been relaxed slightly to allow
     images to be loaded from any URL.  All other resources are still







>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
     branch being merged.
  *  The [/help?cmd=open|fossil open] command allows the repository file
     to be inside the working directory without requiring the --force flag.
  *  The [/help?cmd=/wikiedit|/wikiedit] and [/help?cmd=/wikinew|/wikinew]
     pages now default to markdown format.
  *  The [/help?cmd=/login|/login] page now links to a user's forum post
     timeline if the repository has forum posts.
  *  Tags may now be propagated for forum posts, wiki pages, and technotes.
     The [/help?cmd=tag|tag command] can now manipulate and list such tags.

<a name='v2_15'></a>
<h2>Changes for Version 2.15 (2021-03-26) and Patch 2.15.1 on (2021-04-07)</h2>
  *  <b>Patch 2.15.1:</b> Fix a data exfiltration bug in the server.  <b>Upgrading to
     the patch is recommended.</b><p>
  *  The [./defcsp.md|default CSP] has been relaxed slightly to allow
     images to be loaded from any URL.  All other resources are still