Diff
Not logged in

Differences From:

File src/name.c part of check-in [e8c4f69c50] - Change all mentions of "UUID" in the documentation and help screens into either "artifact ID" or "baseline ID" or "ticket ID" as appropriate. "UUID" has a widely recognized meaning that is different from its meaning in fossil. "UUID" is still used in code comments and in variable names. by drh on 2008-10-24 13:27:53. [view]

To:

File src/name.c part of check-in [9acf0bcdbe] - Correctly detect when an artifact prefix does not match any artifact. Provide better error messages for non-matching and ambiguous artifact prefixes. Fix for ticket d0a7fc67e9. by drh on 2008-10-26 15:59:38. [view]

@@ -70,31 +70,38 @@
   canonical16(blob_buffer(pName), sz);
   if( sz==UUID_SIZE ){
     rc = db_int(1, "SELECT 0 FROM blob WHERE uuid=%B", pName);
     if( rc ){
-      fossil_error(iErrPriority, "unknown object: %b", pName);
+      fossil_error(iErrPriority, "no such artifact: %b", pName);
       blob_reset(pName);
     }
   }else if( sz<UUID_SIZE && sz>=4 ){
+    Stmt q;
     char zOrig[UUID_SIZE+1];
     memcpy(zOrig, blob_buffer(pName), sz);
     zOrig[sz] = 0;
     blob_reset(pName);
-    db_blob(pName, "SELECT uuid FROM blob WHERE uuid>='%s'", zOrig);
-    if( blob_size(pName)!=UUID_SIZE ){
-      fossil_error(iErrPriority, "no match: %s", zOrig);
-      rc = 1;
-    }else{
-      zOrig[sz-1]++;
-      if( db_exists("SELECT 1 FROM blob WHERE uuid>%B AND uuid<'%s'",
-                    pName, zOrig) ){
-         zOrig[sz-1]--;
-         fossil_error(iErrPriority, "non-unique name prefix: %s", zOrig);
-         rc = 1;
-      }else{
-         rc = 0;
-      }
+    db_prepare(&q, "SELECT uuid FROM blob"
+                   " WHERE uuid>='%s'"
+                   "   AND substr(uuid,1,%d)='%s'",
+                   zOrig, sz, zOrig);
+    if( db_step(&q)!=SQLITE_ROW ){
+      db_finalize(&q);
+      fossil_error(iErrPriority, "no artifacts match the prefix \"%s\"", zOrig);
+      return 1;
+    }
+    blob_append(pName, db_column_text(&q, 0), db_column_bytes(&q, 0));
+    if( db_step(&q)==SQLITE_ROW ){
+      fossil_error(iErrPriority,
+         "multiple artifacts match the prefix \"%s\"",
+         zOrig
+      );
+      blob_reset(pName);
+      db_finalize(&q);
+      return 1;
     }
+    db_finalize(&q);
+    rc = 0;
   }else{
     rc = 0;
   }
   return rc;