Hex Artifact Content
Not logged in

Artifact ba487d186bbd05812e6e01f47ae53faab89631ce:

File src/name.c part of check-in [41cf3e7c1d] - Remove string_xform.c from the makefile. Require a "sym-" prefix on tags used to name baselines or branches. The prefix is omitted when the tag is used for this purpose; it is only there to avoid ambiguity with other built-in tag names. by drh on 2008-02-06 03:05:42.

0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20  /*.** Copyright 
0010: 28 63 29 20 32 30 30 36 20 44 2e 20 52 69 63 68  (c) 2006 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54  ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66  his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f  ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75  u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20  te it and/or.** 
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20  modify it under 
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65  the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76  lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c  ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65  ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69  ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73  s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20  tributed in the 
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c  hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20  l be useful,.** 
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20  but WITHOUT ANY 
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75  WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69  t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a  ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54  * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52  Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55   A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20  RPOSE.  See the 
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50  GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f  ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a  r more details..
01e0: 2a 2a 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c  ** .** You shoul
01f0: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20  d have received 
0200: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e  a copy of the GN
0210: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63  U General Public
0220: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e  .** License alon
0230: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72  g with this libr
0240: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69  ary; if not, wri
0250: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65  te to the.** Fre
0260: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
0270: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20  ation, Inc., 59 
0280: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53  Temple Place - S
0290: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73  uite 330,.** Bos
02a0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31  ton, MA  02111-1
02b0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20  307, USA..**.** 
02c0: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69  Author contact i
02d0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20  nformation:.**  
02e0: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a   drh@hwaci.com.*
02f0: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68  *   http://www.h
0300: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a  waci.com/drh/.**
0310: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  .***************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0360: 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 66 69 6c 65  .**.** This file
0370: 20 63 6f 6e 74 61 69 6e 73 20 63 6f 64 65 20 75   contains code u
0380: 73 65 64 20 74 6f 20 63 6f 6e 76 65 72 74 20 75  sed to convert u
0390: 73 65 72 2d 73 75 70 70 6c 69 65 64 20 6f 62 6a  ser-supplied obj
03a0: 65 63 74 20 6e 61 6d 65 73 20 69 6e 74 6f 0a 2a  ect names into.*
03b0: 2a 20 63 61 6e 6f 6e 69 63 61 6c 20 55 55 49 44  * canonical UUID
03c0: 73 2e 0a 2a 2a 0a 2a 2a 20 41 20 75 73 65 72 2d  s..**.** A user-
03d0: 73 75 70 70 6c 69 65 64 20 6f 62 6a 65 63 74 20  supplied object 
03e0: 6e 61 6d 65 20 69 73 20 61 6e 79 20 75 6e 69 71  name is any uniq
03f0: 75 65 20 70 72 65 66 69 78 20 6f 66 20 61 20 76  ue prefix of a v
0400: 61 6c 69 64 20 55 55 49 44 20 62 75 74 0a 2a 2a  alid UUID but.**
0410: 20 6e 6f 74 20 6e 65 63 65 73 73 61 72 69 6c 79   not necessarily
0420: 20 69 6e 20 63 61 6e 6f 6e 69 63 61 6c 20 66 6f   in canonical fo
0430: 72 6d 2e 20 20 0a 2a 2f 0a 23 69 6e 63 6c 75 64  rm.  .*/.#includ
0440: 65 20 22 63 6f 6e 66 69 67 2e 68 22 0a 23 69 6e  e "config.h".#in
0450: 63 6c 75 64 65 20 22 6e 61 6d 65 2e 68 22 0a 23  clude "name.h".#
0460: 69 6e 63 6c 75 64 65 20 3c 61 73 73 65 72 74 2e  include <assert.
0470: 68 3e 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 72  h>../*.** This r
0480: 6f 75 74 69 6e 65 20 74 61 6b 65 73 20 61 20 75  outine takes a u
0490: 73 65 72 2d 65 6e 74 65 72 65 64 20 55 55 49 44  ser-entered UUID
04a0: 20 77 68 69 63 68 20 6d 69 67 68 74 20 62 65 20   which might be 
04b0: 69 6e 20 6d 69 78 65 64 0a 2a 2a 20 63 61 73 65  in mixed.** case
04c0: 20 61 6e 64 20 6d 69 67 68 74 20 6f 6e 6c 79 20   and might only 
04d0: 62 65 20 61 20 70 72 65 66 69 78 20 6f 66 20 74  be a prefix of t
04e0: 68 65 20 66 75 6c 6c 20 55 55 49 44 20 61 6e 64  he full UUID and
04f0: 20 63 6f 6e 76 65 72 74 73 20 69 74 0a 2a 2a 20   converts it.** 
0500: 69 6e 74 6f 20 74 68 65 20 66 75 6c 6c 2d 6c 65  into the full-le
0510: 6e 67 74 68 20 55 55 49 44 20 69 6e 20 63 61 6e  ngth UUID in can
0520: 6f 6e 69 63 61 6c 20 66 6f 72 6d 2e 0a 2a 2a 0a  onical form..**.
0530: 2a 2a 20 49 66 20 74 68 65 20 69 6e 70 75 74 20  ** If the input 
0540: 69 73 20 6e 6f 74 20 61 20 55 55 49 44 20 6f 72  is not a UUID or
0550: 20 61 20 55 55 49 44 20 70 72 65 66 69 78 2c 20   a UUID prefix, 
0560: 74 68 65 6e 20 74 72 79 20 74 6f 20 72 65 73 6f  then try to reso
0570: 6c 76 65 0a 2a 2a 20 74 68 65 20 6e 61 6d 65 20  lve.** the name 
0580: 61 73 20 61 20 74 61 67 2e 0a 2a 2a 0a 2a 2a 20  as a tag..**.** 
0590: 52 65 74 75 72 6e 20 74 68 65 20 6e 75 6d 62 65  Return the numbe
05a0: 72 20 6f 66 20 65 72 72 6f 72 73 2e 0a 2a 2f 0a  r of errors..*/.
05b0: 69 6e 74 20 6e 61 6d 65 5f 74 6f 5f 75 75 69 64  int name_to_uuid
05c0: 28 42 6c 6f 62 20 2a 70 4e 61 6d 65 2c 20 69 6e  (Blob *pName, in
05d0: 74 20 69 45 72 72 50 72 69 6f 72 69 74 79 29 7b  t iErrPriority){
05e0: 0a 20 20 69 6e 74 20 72 63 3b 0a 20 20 69 6e 74  .  int rc;.  int
05f0: 20 73 7a 3b 0a 20 20 73 7a 20 3d 20 62 6c 6f 62   sz;.  sz = blob
0600: 5f 73 69 7a 65 28 70 4e 61 6d 65 29 3b 0a 20 20  _size(pName);.  
0610: 69 66 28 20 73 7a 3e 55 55 49 44 5f 53 49 5a 45  if( sz>UUID_SIZE
0620: 20 7c 7c 20 73 7a 3c 34 20 7c 7c 20 21 76 61 6c   || sz<4 || !val
0630: 69 64 61 74 65 31 36 28 62 6c 6f 62 5f 62 75 66  idate16(blob_buf
0640: 66 65 72 28 70 4e 61 6d 65 29 2c 20 73 7a 29 20  fer(pName), sz) 
0650: 29 7b 0a 20 20 20 20 53 74 6d 74 20 71 3b 0a 20  ){.    Stmt q;. 
0660: 20 20 20 42 6c 6f 62 20 75 75 69 64 3b 0a 0a 20     Blob uuid;.. 
0670: 20 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71     db_prepare(&q
0680: 2c 0a 20 20 20 20 20 20 22 53 45 4c 45 43 54 20  ,.      "SELECT 
0690: 28 53 45 4c 45 43 54 20 75 75 69 64 20 46 52 4f  (SELECT uuid FRO
06a0: 4d 20 62 6c 6f 62 20 57 48 45 52 45 20 72 69 64  M blob WHERE rid
06b0: 3d 6f 62 6a 69 64 29 22 0a 20 20 20 20 20 20 22  =objid)".      "
06c0: 20 20 46 52 4f 4d 20 74 61 67 78 72 65 66 20 4a    FROM tagxref J
06d0: 4f 49 4e 20 65 76 65 6e 74 20 4f 4e 20 72 69 64  OIN event ON rid
06e0: 3d 6f 62 6a 69 64 22 0a 20 20 20 20 20 20 22 20  =objid".      " 
06f0: 57 48 45 52 45 20 74 61 67 69 64 3d 28 53 45 4c  WHERE tagid=(SEL
0700: 45 43 54 20 74 61 67 69 64 20 46 52 4f 4d 20 74  ECT tagid FROM t
0710: 61 67 20 57 48 45 52 45 20 74 61 67 6e 61 6d 65  ag WHERE tagname
0720: 3d 27 73 79 6d 2d 27 7c 7c 25 42 29 22 0a 20 20  ='sym-'||%B)".  
0730: 20 20 20 20 22 20 20 20 41 4e 44 20 74 61 67 74      "   AND tagt
0740: 79 70 65 3e 30 22 0a 20 20 20 20 20 20 22 20 20  ype>0".      "  
0750: 20 41 4e 44 20 76 61 6c 75 65 20 49 53 20 4e 55   AND value IS NU
0760: 4c 4c 22 0a 20 20 20 20 20 20 22 20 4f 52 44 45  LL".      " ORDE
0770: 52 20 42 59 20 65 76 65 6e 74 2e 6d 74 69 6d 65  R BY event.mtime
0780: 20 44 45 53 43 22 2c 0a 20 20 20 20 20 20 70 4e   DESC",.      pN
0790: 61 6d 65 0a 20 20 20 20 29 3b 0a 20 20 20 20 62  ame.    );.    b
07a0: 6c 6f 62 5f 7a 65 72 6f 28 26 75 75 69 64 29 3b  lob_zero(&uuid);
07b0: 0a 20 20 20 20 69 66 28 20 64 62 5f 73 74 65 70  .    if( db_step
07c0: 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57  (&q)==SQLITE_ROW
07d0: 20 29 7b 0a 20 20 20 20 20 20 64 62 5f 63 6f 6c   ){.      db_col
07e0: 75 6d 6e 5f 62 6c 6f 62 28 26 71 2c 20 30 2c 20  umn_blob(&q, 0, 
07f0: 26 75 75 69 64 29 3b 0a 20 20 20 20 7d 0a 20 20  &uuid);.    }.  
0800: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71    db_finalize(&q
0810: 29 3b 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f  );.    if( blob_
0820: 73 69 7a 65 28 26 75 75 69 64 29 3d 3d 30 20 29  size(&uuid)==0 )
0830: 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 65  {.      fossil_e
0840: 72 72 6f 72 28 69 45 72 72 50 72 69 6f 72 69 74  rror(iErrPriorit
0850: 79 2c 20 22 6e 6f 74 20 61 20 76 61 6c 69 64 20  y, "not a valid 
0860: 6f 62 6a 65 63 74 20 6e 61 6d 65 3a 20 25 62 22  object name: %b"
0870: 2c 20 70 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20  , pName);.      
0880: 62 6c 6f 62 5f 72 65 73 65 74 28 26 75 75 69 64  blob_reset(&uuid
0890: 29 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20  );.      return 
08a0: 31 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20  1;.    }else{.  
08b0: 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 70      blob_reset(p
08c0: 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 2a 70 4e  Name);.      *pN
08d0: 61 6d 65 20 3d 20 75 75 69 64 3b 0a 20 20 20 20  ame = uuid;.    
08e0: 20 20 72 65 74 75 72 6e 20 30 3b 0a 20 20 20 20    return 0;.    
08f0: 7d 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f 6d 61 74  }.  }.  blob_mat
0900: 65 72 69 61 6c 69 7a 65 28 70 4e 61 6d 65 29 3b  erialize(pName);
0910: 0a 20 20 63 61 6e 6f 6e 69 63 61 6c 31 36 28 62  .  canonical16(b
0920: 6c 6f 62 5f 62 75 66 66 65 72 28 70 4e 61 6d 65  lob_buffer(pName
0930: 29 2c 20 73 7a 29 3b 0a 20 20 69 66 28 20 73 7a  ), sz);.  if( sz
0940: 3d 3d 55 55 49 44 5f 53 49 5a 45 20 29 7b 0a 20  ==UUID_SIZE ){. 
0950: 20 20 20 72 63 20 3d 20 64 62 5f 69 6e 74 28 31     rc = db_int(1
0960: 2c 20 22 53 45 4c 45 43 54 20 30 20 46 52 4f 4d  , "SELECT 0 FROM
0970: 20 62 6c 6f 62 20 57 48 45 52 45 20 75 75 69 64   blob WHERE uuid
0980: 3d 25 42 22 2c 20 70 4e 61 6d 65 29 3b 0a 20 20  =%B", pName);.  
0990: 20 20 69 66 28 20 72 63 20 29 7b 0a 20 20 20 20    if( rc ){.    
09a0: 20 20 66 6f 73 73 69 6c 5f 65 72 72 6f 72 28 69    fossil_error(i
09b0: 45 72 72 50 72 69 6f 72 69 74 79 2c 20 22 75 6e  ErrPriority, "un
09c0: 6b 6e 6f 77 6e 20 6f 62 6a 65 63 74 3a 20 25 62  known object: %b
09d0: 22 2c 20 70 4e 61 6d 65 29 3b 0a 20 20 20 20 20  ", pName);.     
09e0: 20 62 6c 6f 62 5f 72 65 73 65 74 28 70 4e 61 6d   blob_reset(pNam
09f0: 65 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 65 6c 73  e);.    }.  }els
0a00: 65 20 69 66 28 20 73 7a 3c 55 55 49 44 5f 53 49  e if( sz<UUID_SI
0a10: 5a 45 20 26 26 20 73 7a 3e 3d 34 20 29 7b 0a 20  ZE && sz>=4 ){. 
0a20: 20 20 20 63 68 61 72 20 7a 4f 72 69 67 5b 55 55     char zOrig[UU
0a30: 49 44 5f 53 49 5a 45 2b 31 5d 3b 0a 20 20 20 20  ID_SIZE+1];.    
0a40: 6d 65 6d 63 70 79 28 7a 4f 72 69 67 2c 20 62 6c  memcpy(zOrig, bl
0a50: 6f 62 5f 62 75 66 66 65 72 28 70 4e 61 6d 65 29  ob_buffer(pName)
0a60: 2c 20 73 7a 29 3b 0a 20 20 20 20 7a 4f 72 69 67  , sz);.    zOrig
0a70: 5b 73 7a 5d 20 3d 20 30 3b 0a 20 20 20 20 62 6c  [sz] = 0;.    bl
0a80: 6f 62 5f 72 65 73 65 74 28 70 4e 61 6d 65 29 3b  ob_reset(pName);
0a90: 0a 20 20 20 20 64 62 5f 62 6c 6f 62 28 70 4e 61  .    db_blob(pNa
0aa0: 6d 65 2c 20 22 53 45 4c 45 43 54 20 75 75 69 64  me, "SELECT uuid
0ab0: 20 46 52 4f 4d 20 62 6c 6f 62 20 57 48 45 52 45   FROM blob WHERE
0ac0: 20 75 75 69 64 3e 3d 27 25 73 27 22 2c 20 7a 4f   uuid>='%s'", zO
0ad0: 72 69 67 29 3b 0a 20 20 20 20 69 66 28 20 62 6c  rig);.    if( bl
0ae0: 6f 62 5f 73 69 7a 65 28 70 4e 61 6d 65 29 21 3d  ob_size(pName)!=
0af0: 55 55 49 44 5f 53 49 5a 45 20 29 7b 0a 20 20 20  UUID_SIZE ){.   
0b00: 20 20 20 66 6f 73 73 69 6c 5f 65 72 72 6f 72 28     fossil_error(
0b10: 69 45 72 72 50 72 69 6f 72 69 74 79 2c 20 22 6e  iErrPriority, "n
0b20: 6f 20 6d 61 74 63 68 3a 20 25 73 22 2c 20 7a 4f  o match: %s", zO
0b30: 72 69 67 29 3b 0a 20 20 20 20 20 20 72 63 20 3d  rig);.      rc =
0b40: 20 31 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20   1;.    }else{. 
0b50: 20 20 20 20 20 7a 4f 72 69 67 5b 73 7a 2d 31 5d       zOrig[sz-1]
0b60: 2b 2b 3b 0a 20 20 20 20 20 20 69 66 28 20 64 62  ++;.      if( db
0b70: 5f 65 78 69 73 74 73 28 22 53 45 4c 45 43 54 20  _exists("SELECT 
0b80: 31 20 46 52 4f 4d 20 62 6c 6f 62 20 57 48 45 52  1 FROM blob WHER
0b90: 45 20 75 75 69 64 3e 25 42 20 41 4e 44 20 75 75  E uuid>%B AND uu
0ba0: 69 64 3c 27 25 73 27 22 2c 0a 20 20 20 20 20 20  id<'%s'",.      
0bb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 70 4e                pN
0bc0: 61 6d 65 2c 20 7a 4f 72 69 67 29 20 29 7b 0a 20  ame, zOrig) ){. 
0bd0: 20 20 20 20 20 20 20 20 7a 4f 72 69 67 5b 73 7a          zOrig[sz
0be0: 2d 31 5d 2d 2d 3b 0a 20 20 20 20 20 20 20 20 20  -1]--;.         
0bf0: 66 6f 73 73 69 6c 5f 65 72 72 6f 72 28 69 45 72  fossil_error(iEr
0c00: 72 50 72 69 6f 72 69 74 79 2c 20 22 6e 6f 6e 2d  rPriority, "non-
0c10: 75 6e 69 71 75 65 20 6e 61 6d 65 20 70 72 65 66  unique name pref
0c20: 69 78 3a 20 25 73 22 2c 20 7a 4f 72 69 67 29 3b  ix: %s", zOrig);
0c30: 0a 20 20 20 20 20 20 20 20 20 72 63 20 3d 20 31  .         rc = 1
0c40: 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20  ;.      }else{. 
0c50: 20 20 20 20 20 20 20 20 72 63 20 3d 20 30 3b 0a          rc = 0;.
0c60: 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20        }.    }.  
0c70: 7d 65 6c 73 65 7b 0a 20 20 20 20 72 63 20 3d 20  }else{.    rc = 
0c80: 30 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20  0;.  }.  return 
0c90: 72 63 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d  rc;.}../*.** COM
0ca0: 4d 41 4e 44 3a 20 20 74 65 73 74 2d 6e 61 6d 65  MAND:  test-name
0cb0: 2d 74 6f 2d 75 75 69 64 0a 2a 2a 0a 2a 2a 20 43  -to-uuid.**.** C
0cc0: 6f 6e 76 65 72 74 20 61 20 6e 61 6d 65 20 74 6f  onvert a name to
0cd0: 20 61 20 66 75 6c 6c 20 55 55 49 44 2e 0a 2a 2f   a full UUID..*/
0ce0: 0a 76 6f 69 64 20 74 65 73 74 5f 6e 61 6d 65 5f  .void test_name_
0cf0: 74 6f 5f 75 75 69 64 28 76 6f 69 64 29 7b 0a 20  to_uuid(void){. 
0d00: 20 69 6e 74 20 69 3b 0a 20 20 42 6c 6f 62 20 6e   int i;.  Blob n
0d10: 61 6d 65 3b 0a 20 20 64 62 5f 6d 75 73 74 5f 62  ame;.  db_must_b
0d20: 65 5f 77 69 74 68 69 6e 5f 74 72 65 65 28 29 3b  e_within_tree();
0d30: 0a 20 20 66 6f 72 28 69 3d 32 3b 20 69 3c 67 2e  .  for(i=2; i<g.
0d40: 61 72 67 63 3b 20 69 2b 2b 29 7b 0a 20 20 20 20  argc; i++){.    
0d50: 62 6c 6f 62 5f 69 6e 69 74 28 26 6e 61 6d 65 2c  blob_init(&name,
0d60: 20 67 2e 61 72 67 76 5b 69 5d 2c 20 2d 31 29 3b   g.argv[i], -1);
0d70: 0a 20 20 20 20 70 72 69 6e 74 66 28 22 25 73 20  .    printf("%s 
0d80: 2d 3e 20 22 2c 20 67 2e 61 72 67 76 5b 69 5d 29  -> ", g.argv[i])
0d90: 3b 0a 20 20 20 20 69 66 28 20 6e 61 6d 65 5f 74  ;.    if( name_t
0da0: 6f 5f 75 75 69 64 28 26 6e 61 6d 65 2c 20 31 29  o_uuid(&name, 1)
0db0: 20 29 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66   ){.      printf
0dc0: 28 22 45 52 52 4f 52 3a 20 25 73 5c 6e 22 2c 20  ("ERROR: %s\n", 
0dd0: 67 2e 7a 45 72 72 4d 73 67 29 3b 0a 20 20 20 20  g.zErrMsg);.    
0de0: 20 20 66 6f 73 73 69 6c 5f 65 72 72 6f 72 5f 72    fossil_error_r
0df0: 65 73 65 74 28 29 3b 0a 20 20 20 20 7d 65 6c 73  eset();.    }els
0e00: 65 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28  e{.      printf(
0e10: 22 25 73 5c 6e 22 2c 20 62 6c 6f 62 5f 62 75 66  "%s\n", blob_buf
0e20: 66 65 72 28 26 6e 61 6d 65 29 29 3b 0a 20 20 20  fer(&name));.   
0e30: 20 7d 0a 20 20 20 20 62 6c 6f 62 5f 72 65 73 65   }.    blob_rese
0e40: 74 28 26 6e 61 6d 65 29 3b 0a 20 20 7d 0a 7d 0a  t(&name);.  }.}.
0e50: 0a 2f 2a 0a 2a 2a 20 43 6f 6e 76 65 72 74 20 61  ./*.** Convert a
0e60: 20 6e 61 6d 65 20 74 6f 20 61 20 72 69 64 2e 20   name to a rid. 
0e70: 20 49 66 20 74 68 65 20 6e 61 6d 65 20 69 73 20   If the name is 
0e80: 61 20 73 6d 61 6c 6c 20 69 6e 74 65 67 65 72 20  a small integer 
0e90: 76 61 6c 75 65 20 74 68 65 6e 0a 2a 2a 20 6a 75  value then.** ju
0ea0: 73 74 20 75 73 65 20 61 74 6f 69 28 29 20 74 6f  st use atoi() to
0eb0: 20 64 6f 20 74 68 65 20 63 6f 6e 76 65 72 73 69   do the conversi
0ec0: 6f 6e 2e 20 20 49 66 20 74 68 65 20 6e 61 6d 65  on.  If the name
0ed0: 20 63 6f 6e 74 61 69 6e 73 20 61 6c 70 68 61 62   contains alphab
0ee0: 65 74 69 63 0a 2a 2a 20 63 68 61 72 61 63 74 65  etic.** characte
0ef0: 72 73 20 6f 72 20 69 73 20 6e 6f 74 20 61 6e 20  rs or is not an 
0f00: 65 78 69 73 74 69 6e 67 20 72 69 64 2c 20 74 68  existing rid, th
0f10: 65 6e 20 75 73 65 20 6e 61 6d 65 5f 74 6f 5f 75  en use name_to_u
0f20: 75 69 64 20 74 68 65 6e 0a 2a 2a 20 63 6f 6e 76  uid then.** conv
0f30: 65 72 74 20 74 68 65 20 75 75 69 64 20 74 6f 20  ert the uuid to 
0f40: 61 20 72 69 64 2e 0a 2a 2a 0a 2a 2a 20 54 68 69  a rid..**.** Thi
0f50: 73 20 72 6f 75 74 69 6e 65 20 69 73 20 75 73 65  s routine is use
0f60: 64 20 69 6e 20 74 65 73 74 20 72 6f 75 74 69 6e  d in test routin
0f70: 65 73 20 74 6f 20 72 65 73 6f 6c 76 65 20 63 6f  es to resolve co
0f80: 6d 6d 61 6e 64 2d 6c 69 6e 65 20 69 6e 70 75 74  mmand-line input
0f90: 73 0a 2a 2a 20 69 6e 74 6f 20 61 20 72 69 64 2e  s.** into a rid.
0fa0: 0a 2a 2f 0a 69 6e 74 20 6e 61 6d 65 5f 74 6f 5f  .*/.int name_to_
0fb0: 72 69 64 28 63 6f 6e 73 74 20 63 68 61 72 20 2a  rid(const char *
0fc0: 7a 4e 61 6d 65 29 7b 0a 20 20 69 6e 74 20 69 3b  zName){.  int i;
0fd0: 0a 20 20 69 6e 74 20 72 69 64 3b 0a 20 20 42 6c  .  int rid;.  Bl
0fe0: 6f 62 20 6e 61 6d 65 3b 0a 20 20 66 6f 72 28 69  ob name;.  for(i
0ff0: 3d 30 3b 20 7a 4e 61 6d 65 5b 69 5d 20 26 26 20  =0; zName[i] && 
1000: 69 73 64 69 67 69 74 28 7a 4e 61 6d 65 5b 69 5d  isdigit(zName[i]
1010: 29 3b 20 69 2b 2b 29 7b 7d 0a 20 20 69 66 28 20  ); i++){}.  if( 
1020: 7a 4e 61 6d 65 5b 69 5d 3d 3d 30 20 29 7b 0a 20  zName[i]==0 ){. 
1030: 20 20 20 72 69 64 20 3d 20 61 74 6f 69 28 7a 4e     rid = atoi(zN
1040: 61 6d 65 29 3b 0a 20 20 20 20 69 66 28 20 64 62  ame);.    if( db
1050: 5f 65 78 69 73 74 73 28 22 53 45 4c 45 43 54 20  _exists("SELECT 
1060: 31 20 46 52 4f 4d 20 62 6c 6f 62 20 57 48 45 52  1 FROM blob WHER
1070: 45 20 72 69 64 3d 25 64 22 2c 20 72 69 64 29 20  E rid=%d", rid) 
1080: 29 7b 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20  ){.      return 
1090: 72 69 64 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20  rid;.    }.  }. 
10a0: 20 62 6c 6f 62 5f 69 6e 69 74 28 26 6e 61 6d 65   blob_init(&name
10b0: 2c 20 7a 4e 61 6d 65 2c 20 2d 31 29 3b 0a 20 20  , zName, -1);.  
10c0: 69 66 28 20 6e 61 6d 65 5f 74 6f 5f 75 75 69 64  if( name_to_uuid
10d0: 28 26 6e 61 6d 65 2c 20 31 29 20 29 7b 0a 20 20  (&name, 1) ){.  
10e0: 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22    fossil_fatal("
10f0: 25 73 22 2c 20 67 2e 7a 45 72 72 4d 73 67 29 3b  %s", g.zErrMsg);
1100: 0a 20 20 7d 0a 20 20 72 69 64 20 3d 20 64 62 5f  .  }.  rid = db_
1110: 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 20 72  int(0, "SELECT r
1120: 69 64 20 46 52 4f 4d 20 62 6c 6f 62 20 57 48 45  id FROM blob WHE
1130: 52 45 20 75 75 69 64 3d 25 42 22 2c 20 26 6e 61  RE uuid=%B", &na
1140: 6d 65 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65  me);.  blob_rese
1150: 74 28 26 6e 61 6d 65 29 3b 0a 20 20 72 65 74 75  t(&name);.  retu
1160: 72 6e 20 72 69 64 3b 0a 7d 0a                    rn rid;.}.