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
[e63a9fd9d0]
- Fixed many uninitialized variable warnings and some potential bug found via -Wall -Werror on gcc.
by
jnc on
2007-09-25 21:21:35.
Also file
src/name.c
part of check-in
[92291035fe]
- Merged the compiler warning fixes into mainstream
by
jnc on
2007-09-25 21:28:30.
Also file
src/name.c
part of check-in
[d0305b305a]
- Merged mainline into my branch to get the newest application.
by
aku on
2007-12-05 08:07:46.
[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 tagtype>0"
+ " 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 ){
@@ -73,8 +100,10 @@
}else{
rc = 0;
}
}
+ }else{
+ rc = 0;
}
return rc;
}
@@ -121,10 +150,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;
}