Diff
Not logged in

Differences From:

File src/tag.c part of check-in [4e683ef07b] - Add the ability to modify global settings (such as the proxy setting) even when there are no repositories defined. by drh on 2008-05-05 17:24:38. [view]

To:

File src/tag.c part of check-in [d1c9938025] - Change behavior of Fossil's tag handling.
  1. All subcommands of command tag prepends a prefix sym- infront of every tag name passed to them. Tags beginning with sym- are special in Fossil as they might serve as replacement of a UUID they are attached to.

    Further, tag list will only list all tags beginning with sym- but with that prefix removed during display as default.

    All subcommands can get passed an option --raw, that prevent the prepending of the prefix sym- in front of the tag name. tag list will report all tags without removing any prefix if called with option --raw.
  1. If a command takes a tag name that may be confused with a UUID, the command did interpret that parameter as a UUID instead as a tag name. Such tags might now be prefixed with a tag: to enforce the command to take them as tag name instead of a UUID. For example:
            fossil tag add abcde $uuid
            :
            fossil update tag:abcde
          
    without the prefix tag: fossil would try to update to a UUID beginning with abcde. If no such UUID was found, fossil will complain and exit.
by cle on 2008-07-27 18:35:06. [view]

@@ -306,32 +306,58 @@
 ** Usage: %fossil tag SUBCOMMAND ...
 **
 ** Run various subcommands to control tags and properties
 **
-**     %fossil tag add TAGNAME UUID ?VALUE?
-**
-**         Add a new tag or property to UUID.
-**
-**     %fossil tag branch TAGNAME UUID ?VALUE?
+**     %fossil tag add ?--raw? TAGNAME UUID ?VALUE?
+**
+**         Add a new tag or property to UUID. The tag will
+**         be usable instead of a UUID in commands like
+**         update and the like.
+**
+**     %fossil tag branch ?--raw? TAGNAME UUID ?VALUE?
 **
 **         Add a new tag or property to UUID and make that
 **         tag propagate to all direct children.
 **
-**     %fossil tag delete TAGNAME UUID
+**     %fossil tag delete ?--raw? TAGNAME UUID
 **
 **         Delete the tag TAGNAME from UUID
 **
-**     %fossil tag find TAGNAME
+**     %fossil tag find ?--raw? TAGNAME
 **
 **         List all baselines that use TAGNAME
 **
-**     %fossil tag list ?UUID?
+**     %fossil tag list ?--raw? ?UUID?
 **
 **         List all tags, or if UUID is supplied, list
 **         all tags and their values for UUID.
+**
+** The option ?--raw? is to expose the internal interface
+** for tag handling. This option is not necessary for the
+** normal use.
+**
+** If you use a tagname that might be confused with a UUID,
+** you have to explicitly disambiguate it by prefixing it
+** with "tag:". For instance:
+**
+**   fossil update cfcfcfee
+**
+** is not the same as:
+**
+**   fossil update tag:cfcfcfee
+**
+** The first will be taken as UUID and fossil will complain
+** if no such revision was found, and the second one expect
+** "cfcfcfee" to be a tag/branch name!
+**
 */
 void tag_cmd(void){
   int n;
+  int raw = find_option("raw","",0)!=0;
+  const char *prefix = raw ? "" : "sym-";
+  int preflen = strlen(prefix);
+  Blob tagname;
+
   db_find_and_open_repository(1);
   if( g.argc<3 ){
     goto tag_cmd_usage;
   }
@@ -339,42 +365,48 @@
   if( n==0 ){
     goto tag_cmd_usage;
   }
 
+  blob_set(&tagname, prefix);
+
   if( strncmp(g.argv[2],"add",n)==0 ){
     char *zValue;
     if( g.argc!=5 && g.argc!=6 ){
       usage("add TAGNAME UUID ?VALUE?");
     }
+    blob_append(&tagname, g.argv[3], strlen(g.argv[3]));
     zValue = g.argc==6 ? g.argv[5] : 0;
-    tag_add_artifact(g.argv[3], g.argv[4], zValue, 1);
+    tag_add_artifact(blob_str(&tagname), g.argv[4], zValue, 1);
   }else
 
   if( strncmp(g.argv[2],"branch",n)==0 ){
     char *zValue;
     if( g.argc!=5 && g.argc!=6 ){
       usage("branch TAGNAME UUID ?VALUE?");
     }
+    blob_append(&tagname, g.argv[3], strlen(g.argv[3]));
     zValue = g.argc==6 ? g.argv[5] : 0;
-    tag_add_artifact(g.argv[3], g.argv[4], zValue, 2);
+    tag_add_artifact(blob_str(&tagname), g.argv[4], zValue, 2);
   }else
 
   if( strncmp(g.argv[2],"delete",n)==0 ){
     if( g.argc!=5 ){
       usage("delete TAGNAME UUID");
     }
-    tag_add_artifact(g.argv[3], g.argv[4], 0, 0);
+    blob_append(&tagname, g.argv[3], strlen(g.argv[3]));
+    tag_add_artifact(blob_str(&tagname), g.argv[4], 0, 0);
   }else
 
   if( strncmp(g.argv[2],"find",n)==0 ){
     Stmt q;
     if( g.argc!=4 ){
       usage("find TAGNAME");
     }
+    blob_append(&tagname, g.argv[3], strlen(g.argv[3]));
     db_prepare(&q,
       "SELECT blob.uuid FROM tagxref, blob"
-      " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)"
-      "   AND blob.rid=tagxref.rid", g.argv[3]
+      " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%B)"
+      "   AND blob.rid=tagxref.rid", &tagname
     );
     while( db_step(&q)==SQLITE_ROW ){
       printf("%s\n", db_column_text(&q, 0));
     }
@@ -392,9 +424,12 @@
         "                 AND tagtype>0)"
         " ORDER BY tagname"
       );
       while( db_step(&q)==SQLITE_ROW ){
-        printf("%s\n", db_column_text(&q, 0));
+        const char *name = db_column_text(&q, 0);
+        if( raw || strncmp(name, prefix, preflen)==0 ){
+          printf("%s\n", name+preflen);
+        }
       }
       db_finalize(&q);
     }else if( g.argc==4 ){
       int rid = name_to_rid(g.argv[3]);
@@ -409,11 +444,15 @@
       while( db_step(&q)==SQLITE_ROW ){
         const char *zName = db_column_text(&q, 0);
         const char *zValue = db_column_text(&q, 1);
         if( zValue ){
-          printf("%s=%s\n", zName, zValue);
+          if( raw || strncmp(zName, prefix, preflen)==0 ){
+            printf("%s=%s\n", zName+preflen, zValue);
+          }
         }else{
-          printf("%s\n", zName);
+          if( raw || strncmp(zName, prefix, preflen)==0 ){
+            printf("%s\n", zName+preflen);
+          }
         }
       }
       db_finalize(&q);
     }else{
@@ -422,9 +461,12 @@
   }else
   {
     goto tag_cmd_usage;
   }
+
+  /* Cleanup */
+  blob_reset(&tagname);
   return;
 
 tag_cmd_usage:
   usage("add|branch|delete|find|list ...");
 }