Diff
Not logged in

Differences From:

File src/name.c part of check-in [dbda8d6ce9] - Initial check-in of m1 sources. by drh on 2007-07-21 14:10:57. [view]

To:

File src/name.c part of check-in [3b5514ed82] - The "tag" command allows tag artifacts to be inserted for creating and cancelling tags and properties. Timeline responds to bgcolor, br-bgcolor, comment, and user properties. by drh on 2007-09-22 15:50:14. [view]

@@ -35,17 +35,44 @@
 ** This routine takes a user-entered UUID which might be in mixed
 ** case and might only be a prefix of the full UUID and converts it
 ** into the full-length UUID in canonical form.
 **
+** If the input is not a UUID or a UUID prefix, then try to resolve
+** the name as a tag.
+**
 ** Return the number of errors.
 */
 int name_to_uuid(Blob *pName, int iErrPriority){
   int rc;
   int sz;
   sz = blob_size(pName);
   if( sz>UUID_SIZE || sz<4 || !validate16(blob_buffer(pName), sz) ){
-    fossil_error(iErrPriority, "not a valid object name: %b", pName);
-    return 1;
+    Stmt q;
+    Blob uuid;
+
+    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=%B)"
+      "   AND addflag"
+      "   AND value IS NULL"
+      " ORDER BY event.mtime DESC",
+      pName
+    );
+    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);
+      blob_reset(&uuid);
+      return 1;
+    }else{
+      blob_reset(pName);
+      *pName = uuid;
+      return 0;
+    }
   }
   blob_materialize(pName);
   canonical16(blob_buffer(pName), sz);
   if( sz==UUID_SIZE ){
@@ -121,10 +148,10 @@
     }
   }
   blob_init(&name, zName, -1);
   if( name_to_uuid(&name, 1) ){
-    fossil_panic("%s", g.zErrMsg);
+    fossil_fatal("%s", g.zErrMsg);
   }
   rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name);
   blob_reset(&name);
   return rid;
 }