Overview
SHA1 Hash: | d1c993802524c5a47d2e6219f9f1380f6ccff857 |
---|---|
Date: | 2008-07-27 18:35:06 |
User: | cle |
Edited Comment: | Change behavior of Fossil's tag handling.
|
Original Comment: | 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 removeing any prefix if called with option "--raw". 2. 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. |
Timelines: | ancestors | descendants | both | trunk |
Other Links: | files | ZIP archive | manifest |
Tags And Properties
- branch=trunk inherited from [a28c83647d]
- comment=Change behavior of Fossil's tag handling. 1. All subcommands of command <tt>tag</tt> prepends a prefix <tt>sym-</tt> infront of every tag name passed to them. Tags beginning with <tt>sym-</tt> are special in Fossil as they might serve as replacement of a UUID they are attached to.<br><br> Further, <tt>tag list</tt> will only list all tags beginning with <tt>sym-</tt> but with that prefix removed during display as default.<br><br> All subcommands can get passed an option <tt>--raw</tt>, that prevent the prepending of the prefix <tt>sym-</tt> in front of the tag name. <tt>tag list</tt> will report all tags without removing any prefix if called with option <tt>--raw</tt>. 2. 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 <tt>tag:</tt> to enforce the command to take them as tag name instead of a UUID. For example: <verbatim> fossil tag add abcde $uuid : fossil update tag:abcde </verbatim> without the prefix <tt>tag:</tt> fossil would try to update to a UUID beginning with <tt>abcde</tt>. If no such UUID was found, fossil will complain and exit. added by [2437a34e4b] on 2008-07-28 06:36:09
- sym-trunk inherited from [a28c83647d]
Changes
[hide diffs]Modified src/name.c from [ba487d186b] to [825efda6ea].
@@ -46,27 +46,34 @@ int sz; sz = blob_size(pName); if( sz>UUID_SIZE || sz<4 || !validate16(blob_buffer(pName), sz) ){ Stmt q; Blob uuid; + static const char prefix[] = "tag:"; + static const int preflen = sizeof(prefix)-1; + const char *zName = blob_str(pName); + + if( strncmp(zName, prefix, preflen)==0 ){ + zName += preflen; + } db_prepare(&q, "SELECT (SELECT uuid FROM blob WHERE rid=objid)" " FROM tagxref JOIN event ON rid=objid" - " WHERE tagid=(SELECT tagid FROM tag WHERE tagname='sym-'||%B)" + " WHERE tagid=(SELECT tagid FROM tag WHERE tagname='sym-'||%Q)" " AND tagtype>0" " AND value IS NULL" " ORDER BY event.mtime DESC", - pName + zName ); blob_zero(&uuid); if( db_step(&q)==SQLITE_ROW ){ db_column_blob(&q, 0, &uuid); } db_finalize(&q); if( blob_size(&uuid)==0 ){ - fossil_error(iErrPriority, "not a valid object name: %b", pName); + fossil_error(iErrPriority, "not a valid object name: %s", zName); blob_reset(&uuid); return 1; }else{ blob_reset(pName); *pName = uuid;
Modified src/tag.c from [29b50a2f4d] to [ec276e4852].
@@ -305,77 +305,109 @@ ** COMMAND: tag ** 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; } n = strlen(g.argv[2]); 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)); } db_finalize(&q); @@ -391,11 +423,14 @@ " WHERE tagid=tag.tagid" " 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]); db_prepare(&q, @@ -408,13 +443,17 @@ ); 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{ usage("tag list ?UUID?"); @@ -421,10 +460,13 @@ } }else { goto tag_cmd_usage; } + + /* Cleanup */ + blob_reset(&tagname); return; tag_cmd_usage: usage("add|branch|delete|find|list ..."); }