Hex Artifact Content
Not logged in

Artifact 8550ff74c54e31fda1e6ecbf4f774ec1af1a33c6:

File src/name.c part of check-in [0e924820bf] - Tidy up tagview code. by eric on 2008-08-24 20:16:43.

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 42 6c 6f 62 20 75 75 69 64  ){.    Blob uuid
0660: 3b 0a 20 20 20 20 73 74 61 74 69 63 20 63 6f 6e  ;.    static con
0670: 73 74 20 63 68 61 72 20 70 72 65 66 69 78 5b 5d  st char prefix[]
0680: 20 3d 20 22 74 61 67 3a 22 3b 0a 20 20 20 20 73   = "tag:";.    s
0690: 74 61 74 69 63 20 63 6f 6e 73 74 20 69 6e 74 20  tatic const int 
06a0: 70 72 65 66 6c 65 6e 20 3d 20 73 69 7a 65 6f 66  preflen = sizeof
06b0: 28 70 72 65 66 69 78 29 2d 31 3b 0a 20 20 20 20  (prefix)-1;.    
06c0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d  const char *zNam
06d0: 65 20 3d 20 62 6c 6f 62 5f 73 74 72 28 70 4e 61  e = blob_str(pNa
06e0: 6d 65 29 3b 0a 0a 20 20 20 20 69 66 28 20 73 74  me);..    if( st
06f0: 72 6e 63 6d 70 28 7a 4e 61 6d 65 2c 20 70 72 65  rncmp(zName, pre
0700: 66 69 78 2c 20 70 72 65 66 6c 65 6e 29 3d 3d 30  fix, preflen)==0
0710: 20 29 7b 0a 20 20 20 20 20 20 7a 4e 61 6d 65 20   ){.      zName 
0720: 2b 3d 20 70 72 65 66 6c 65 6e 3b 0a 20 20 20 20  += preflen;.    
0730: 7d 0a 0a 20 20 20 20 73 79 6d 5f 74 61 67 5f 74  }..    sym_tag_t
0740: 6f 5f 75 75 69 64 28 7a 4e 61 6d 65 2c 20 26 75  o_uuid(zName, &u
0750: 75 69 64 29 3b 0a 20 20 20 20 69 66 28 20 62 6c  uid);.    if( bl
0760: 6f 62 5f 73 69 7a 65 28 26 75 75 69 64 29 3d 3d  ob_size(&uuid)==
0770: 30 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69  0 ){.      fossi
0780: 6c 5f 65 72 72 6f 72 28 69 45 72 72 50 72 69 6f  l_error(iErrPrio
0790: 72 69 74 79 2c 20 22 6e 6f 74 20 61 20 76 61 6c  rity, "not a val
07a0: 69 64 20 6f 62 6a 65 63 74 20 6e 61 6d 65 3a 20  id object name: 
07b0: 25 73 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20  %s", zName);.   
07c0: 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 75     blob_reset(&u
07d0: 75 69 64 29 3b 0a 20 20 20 20 20 20 72 65 74 75  uid);.      retu
07e0: 72 6e 20 31 3b 0a 20 20 20 20 7d 65 6c 73 65 7b  rn 1;.    }else{
07f0: 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 65  .      blob_rese
0800: 74 28 70 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20  t(pName);.      
0810: 2a 70 4e 61 6d 65 20 3d 20 75 75 69 64 3b 0a 20  *pName = uuid;. 
0820: 20 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0a 20       return 0;. 
0830: 20 20 20 7d 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f     }.  }.  blob_
0840: 6d 61 74 65 72 69 61 6c 69 7a 65 28 70 4e 61 6d  materialize(pNam
0850: 65 29 3b 0a 20 20 63 61 6e 6f 6e 69 63 61 6c 31  e);.  canonical1
0860: 36 28 62 6c 6f 62 5f 62 75 66 66 65 72 28 70 4e  6(blob_buffer(pN
0870: 61 6d 65 29 2c 20 73 7a 29 3b 0a 20 20 69 66 28  ame), sz);.  if(
0880: 20 73 7a 3d 3d 55 55 49 44 5f 53 49 5a 45 20 29   sz==UUID_SIZE )
0890: 7b 0a 20 20 20 20 72 63 20 3d 20 64 62 5f 69 6e  {.    rc = db_in
08a0: 74 28 31 2c 20 22 53 45 4c 45 43 54 20 30 20 46  t(1, "SELECT 0 F
08b0: 52 4f 4d 20 62 6c 6f 62 20 57 48 45 52 45 20 75  ROM blob WHERE u
08c0: 75 69 64 3d 25 42 22 2c 20 70 4e 61 6d 65 29 3b  uid=%B", pName);
08d0: 0a 20 20 20 20 69 66 28 20 72 63 20 29 7b 0a 20  .    if( rc ){. 
08e0: 20 20 20 20 20 66 6f 73 73 69 6c 5f 65 72 72 6f       fossil_erro
08f0: 72 28 69 45 72 72 50 72 69 6f 72 69 74 79 2c 20  r(iErrPriority, 
0900: 22 75 6e 6b 6e 6f 77 6e 20 6f 62 6a 65 63 74 3a  "unknown object:
0910: 20 25 62 22 2c 20 70 4e 61 6d 65 29 3b 0a 20 20   %b", pName);.  
0920: 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 70      blob_reset(p
0930: 4e 61 6d 65 29 3b 0a 20 20 20 20 7d 0a 20 20 7d  Name);.    }.  }
0940: 65 6c 73 65 20 69 66 28 20 73 7a 3c 55 55 49 44  else if( sz<UUID
0950: 5f 53 49 5a 45 20 26 26 20 73 7a 3e 3d 34 20 29  _SIZE && sz>=4 )
0960: 7b 0a 20 20 20 20 63 68 61 72 20 7a 4f 72 69 67  {.    char zOrig
0970: 5b 55 55 49 44 5f 53 49 5a 45 2b 31 5d 3b 0a 20  [UUID_SIZE+1];. 
0980: 20 20 20 6d 65 6d 63 70 79 28 7a 4f 72 69 67 2c     memcpy(zOrig,
0990: 20 62 6c 6f 62 5f 62 75 66 66 65 72 28 70 4e 61   blob_buffer(pNa
09a0: 6d 65 29 2c 20 73 7a 29 3b 0a 20 20 20 20 7a 4f  me), sz);.    zO
09b0: 72 69 67 5b 73 7a 5d 20 3d 20 30 3b 0a 20 20 20  rig[sz] = 0;.   
09c0: 20 62 6c 6f 62 5f 72 65 73 65 74 28 70 4e 61 6d   blob_reset(pNam
09d0: 65 29 3b 0a 20 20 20 20 64 62 5f 62 6c 6f 62 28  e);.    db_blob(
09e0: 70 4e 61 6d 65 2c 20 22 53 45 4c 45 43 54 20 75  pName, "SELECT u
09f0: 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62 20 57 48  uid FROM blob WH
0a00: 45 52 45 20 75 75 69 64 3e 3d 27 25 73 27 22 2c  ERE uuid>='%s'",
0a10: 20 7a 4f 72 69 67 29 3b 0a 20 20 20 20 69 66 28   zOrig);.    if(
0a20: 20 62 6c 6f 62 5f 73 69 7a 65 28 70 4e 61 6d 65   blob_size(pName
0a30: 29 21 3d 55 55 49 44 5f 53 49 5a 45 20 29 7b 0a  )!=UUID_SIZE ){.
0a40: 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 65 72 72        fossil_err
0a50: 6f 72 28 69 45 72 72 50 72 69 6f 72 69 74 79 2c  or(iErrPriority,
0a60: 20 22 6e 6f 20 6d 61 74 63 68 3a 20 25 73 22 2c   "no match: %s",
0a70: 20 7a 4f 72 69 67 29 3b 0a 20 20 20 20 20 20 72   zOrig);.      r
0a80: 63 20 3d 20 31 3b 0a 20 20 20 20 7d 65 6c 73 65  c = 1;.    }else
0a90: 7b 0a 20 20 20 20 20 20 7a 4f 72 69 67 5b 73 7a  {.      zOrig[sz
0aa0: 2d 31 5d 2b 2b 3b 0a 20 20 20 20 20 20 69 66 28  -1]++;.      if(
0ab0: 20 64 62 5f 65 78 69 73 74 73 28 22 53 45 4c 45   db_exists("SELE
0ac0: 43 54 20 31 20 46 52 4f 4d 20 62 6c 6f 62 20 57  CT 1 FROM blob W
0ad0: 48 45 52 45 20 75 75 69 64 3e 25 42 20 41 4e 44  HERE uuid>%B AND
0ae0: 20 75 75 69 64 3c 27 25 73 27 22 2c 0a 20 20 20   uuid<'%s'",.   
0af0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0b00: 20 70 4e 61 6d 65 2c 20 7a 4f 72 69 67 29 20 29   pName, zOrig) )
0b10: 7b 0a 20 20 20 20 20 20 20 20 20 7a 4f 72 69 67  {.         zOrig
0b20: 5b 73 7a 2d 31 5d 2d 2d 3b 0a 20 20 20 20 20 20  [sz-1]--;.      
0b30: 20 20 20 66 6f 73 73 69 6c 5f 65 72 72 6f 72 28     fossil_error(
0b40: 69 45 72 72 50 72 69 6f 72 69 74 79 2c 20 22 6e  iErrPriority, "n
0b50: 6f 6e 2d 75 6e 69 71 75 65 20 6e 61 6d 65 20 70  on-unique name p
0b60: 72 65 66 69 78 3a 20 25 73 22 2c 20 7a 4f 72 69  refix: %s", zOri
0b70: 67 29 3b 0a 20 20 20 20 20 20 20 20 20 72 63 20  g);.         rc 
0b80: 3d 20 31 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65  = 1;.      }else
0b90: 7b 0a 20 20 20 20 20 20 20 20 20 72 63 20 3d 20  {.         rc = 
0ba0: 30 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d  0;.      }.    }
0bb0: 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 72 63  .  }else{.    rc
0bc0: 20 3d 20 30 3b 0a 20 20 7d 0a 20 20 72 65 74 75   = 0;.  }.  retu
0bd0: 72 6e 20 72 63 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20  rn rc;.}../*.** 
0be0: 54 68 69 73 20 72 6f 75 74 69 6e 65 20 74 61 6b  This routine tak
0bf0: 65 73 20 61 20 6e 61 6d 65 20 77 68 69 63 68 20  es a name which 
0c00: 6d 69 67 68 74 20 62 65 20 61 20 73 79 6d 62 6f  might be a symbo
0c10: 6c 69 63 20 74 61 67 20 61 6e 64 0a 2a 2a 20 61  lic tag and.** a
0c20: 74 74 65 6d 70 74 73 20 74 6f 20 70 72 6f 64 75  ttempts to produ
0c30: 63 65 20 61 20 55 55 49 44 2e 20 54 68 65 20 55  ce a UUID. The U
0c40: 55 49 44 20 28 69 66 20 61 6e 79 29 20 69 73 20  UID (if any) is 
0c50: 72 65 74 75 72 6e 65 64 20 69 6e 20 74 68 65 0a  returned in the.
0c60: 2a 2a 20 62 6c 6f 62 20 70 6f 69 6e 74 65 64 20  ** blob pointed 
0c70: 74 6f 20 62 79 20 74 68 65 20 73 65 63 6f 6e 64  to by the second
0c80: 20 61 72 67 75 6d 65 6e 74 2e 0a 2a 2a 0a 2a 2a   argument..**.**
0c90: 20 52 65 74 75 72 6e 20 61 73 20 66 6f 6c 6c 6f   Return as follo
0ca0: 77 73 3a 0a 2a 2a 20 20 20 20 20 20 30 20 20 20  ws:.**      0   
0cb0: 4e 61 6d 65 20 69 73 20 6e 6f 74 20 61 20 74 61  Name is not a ta
0cc0: 67 0a 2a 2a 20 20 20 20 20 20 31 20 20 20 41 20  g.**      1   A 
0cd0: 73 69 6e 67 6c 65 20 55 55 49 44 20 77 61 73 20  single UUID was 
0ce0: 66 6f 75 6e 64 0a 2a 2a 20 20 20 20 20 20 32 20  found.**      2 
0cf0: 20 20 4d 6f 72 65 20 74 68 61 6e 20 6f 6e 65 20    More than one 
0d00: 55 55 49 44 20 77 61 73 20 66 6f 75 6e 64 2c 20  UUID was found, 
0d10: 73 6f 20 74 68 69 73 20 69 73 20 70 72 65 73 75  so this is presu
0d20: 6d 61 62 6c 79 20 61 0a 2a 2a 20 20 20 20 20 20  mably a.**      
0d30: 20 20 20 20 70 72 6f 70 61 67 61 74 69 6e 67 20      propagating 
0d40: 74 61 67 2e 20 54 68 65 20 72 65 74 75 72 6e 20  tag. The return 
0d50: 55 55 49 44 20 69 73 20 74 68 65 20 6d 6f 73 74  UUID is the most
0d60: 20 72 65 63 65 6e 74 2c 0a 2a 2a 20 20 20 20 20   recent,.**     
0d70: 20 20 20 20 20 77 68 69 63 68 20 69 73 20 6d 6f       which is mo
0d80: 73 74 20 6c 69 6b 65 6c 79 20 74 6f 20 62 65 20  st likely to be 
0d90: 74 68 65 20 6f 6e 65 20 77 61 6e 74 65 64 2e 0a  the one wanted..
0da0: 2a 2f 0a 69 6e 74 20 74 61 67 5f 74 6f 5f 75 75  */.int tag_to_uu
0db0: 69 64 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70  id(const char *p
0dc0: 4e 61 6d 65 2c 20 42 6c 6f 62 20 2a 70 55 75 69  Name, Blob *pUui
0dd0: 64 2c 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 50  d,const char *pP
0de0: 72 65 66 69 78 29 7b 0a 20 20 53 74 6d 74 20 71  refix){.  Stmt q
0df0: 3b 0a 20 20 69 6e 74 20 63 6f 75 6e 74 20 3d 20  ;.  int count = 
0e00: 30 3b 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28  0;.  db_prepare(
0e10: 26 71 2c 0a 20 20 20 20 22 53 45 4c 45 43 54 20  &q,.    "SELECT 
0e20: 28 53 45 4c 45 43 54 20 75 75 69 64 20 46 52 4f  (SELECT uuid FRO
0e30: 4d 20 62 6c 6f 62 20 57 48 45 52 45 20 72 69 64  M blob WHERE rid
0e40: 3d 6f 62 6a 69 64 29 22 0a 20 20 20 20 22 20 20  =objid)".    "  
0e50: 46 52 4f 4d 20 74 61 67 78 72 65 66 20 4a 4f 49  FROM tagxref JOI
0e60: 4e 20 65 76 65 6e 74 20 4f 4e 20 72 69 64 3d 6f  N event ON rid=o
0e70: 62 6a 69 64 22 0a 20 20 20 20 22 20 57 48 45 52  bjid".    " WHER
0e80: 45 20 74 61 67 69 64 3d 28 53 45 4c 45 43 54 20  E tagid=(SELECT 
0e90: 74 61 67 69 64 20 46 52 4f 4d 20 74 61 67 20 57  tagid FROM tag W
0ea0: 48 45 52 45 20 74 61 67 6e 61 6d 65 3d 25 51 7c  HERE tagname=%Q|
0eb0: 7c 25 51 29 22 0a 20 20 20 20 22 20 20 20 41 4e  |%Q)".    "   AN
0ec0: 44 20 74 61 67 74 79 70 65 3e 30 22 0a 20 20 20  D tagtype>0".   
0ed0: 20 22 20 20 20 41 4e 44 20 76 61 6c 75 65 20 49   "   AND value I
0ee0: 53 20 4e 55 4c 4c 22 0a 20 20 20 20 22 20 4f 52  S NULL".    " OR
0ef0: 44 45 52 20 42 59 20 65 76 65 6e 74 2e 6d 74 69  DER BY event.mti
0f00: 6d 65 20 44 45 53 43 22 2c 0a 20 20 20 20 70 50  me DESC",.    pP
0f10: 72 65 66 69 78 2c 0a 20 20 20 20 70 4e 61 6d 65  refix,.    pName
0f20: 0a 20 20 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72  .  );.  blob_zer
0f30: 6f 28 70 55 75 69 64 29 3b 0a 20 20 77 68 69 6c  o(pUuid);.  whil
0f40: 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d  e( db_step(&q)==
0f50: 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20  SQLITE_ROW ){.  
0f60: 20 20 63 6f 75 6e 74 2b 2b 3b 0a 20 20 20 20 69    count++;.    i
0f70: 66 28 63 6f 75 6e 74 3e 31 29 7b 0a 20 20 20 20  f(count>1){.    
0f80: 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 7d 0a 20    break;.    }. 
0f90: 20 20 20 64 62 5f 63 6f 6c 75 6d 6e 5f 62 6c 6f     db_column_blo
0fa0: 62 28 26 71 2c 20 30 2c 20 70 55 75 69 64 29 3b  b(&q, 0, pUuid);
0fb0: 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69  .  }.  db_finali
0fc0: 7a 65 28 26 71 29 3b 0a 20 20 72 65 74 75 72 6e  ze(&q);.  return
0fd0: 20 63 6f 75 6e 74 3b 0a 7d 0a 69 6e 74 20 73 79   count;.}.int sy
0fe0: 6d 5f 74 61 67 5f 74 6f 5f 75 75 69 64 28 63 6f  m_tag_to_uuid(co
0ff0: 6e 73 74 20 63 68 61 72 20 2a 70 4e 61 6d 65 2c  nst char *pName,
1000: 20 42 6c 6f 62 20 2a 70 55 75 69 64 29 7b 0a 20   Blob *pUuid){. 
1010: 20 20 20 72 65 74 75 72 6e 20 74 61 67 5f 74 6f     return tag_to
1020: 5f 75 75 69 64 28 70 4e 61 6d 65 2c 70 55 75 69  _uuid(pName,pUui
1030: 64 2c 22 73 79 6d 2d 22 29 3b 0a 7d 0a 0a 2f 2a  d,"sym-");.}../*
1040: 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 20 74 65  .** COMMAND:  te
1050: 73 74 2d 6e 61 6d 65 2d 74 6f 2d 75 75 69 64 0a  st-name-to-uuid.
1060: 2a 2a 0a 2a 2a 20 43 6f 6e 76 65 72 74 20 61 20  **.** Convert a 
1070: 6e 61 6d 65 20 74 6f 20 61 20 66 75 6c 6c 20 55  name to a full U
1080: 55 49 44 2e 0a 2a 2f 0a 76 6f 69 64 20 74 65 73  UID..*/.void tes
1090: 74 5f 6e 61 6d 65 5f 74 6f 5f 75 75 69 64 28 76  t_name_to_uuid(v
10a0: 6f 69 64 29 7b 0a 20 20 69 6e 74 20 69 3b 0a 20  oid){.  int i;. 
10b0: 20 42 6c 6f 62 20 6e 61 6d 65 3b 0a 20 20 64 62   Blob name;.  db
10c0: 5f 6d 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f  _must_be_within_
10d0: 74 72 65 65 28 29 3b 0a 20 20 66 6f 72 28 69 3d  tree();.  for(i=
10e0: 32 3b 20 69 3c 67 2e 61 72 67 63 3b 20 69 2b 2b  2; i<g.argc; i++
10f0: 29 7b 0a 20 20 20 20 62 6c 6f 62 5f 69 6e 69 74  ){.    blob_init
1100: 28 26 6e 61 6d 65 2c 20 67 2e 61 72 67 76 5b 69  (&name, g.argv[i
1110: 5d 2c 20 2d 31 29 3b 0a 20 20 20 20 70 72 69 6e  ], -1);.    prin
1120: 74 66 28 22 25 73 20 2d 3e 20 22 2c 20 67 2e 61  tf("%s -> ", g.a
1130: 72 67 76 5b 69 5d 29 3b 0a 20 20 20 20 69 66 28  rgv[i]);.    if(
1140: 20 6e 61 6d 65 5f 74 6f 5f 75 75 69 64 28 26 6e   name_to_uuid(&n
1150: 61 6d 65 2c 20 31 29 20 29 7b 0a 20 20 20 20 20  ame, 1) ){.     
1160: 20 70 72 69 6e 74 66 28 22 45 52 52 4f 52 3a 20   printf("ERROR: 
1170: 25 73 5c 6e 22 2c 20 67 2e 7a 45 72 72 4d 73 67  %s\n", g.zErrMsg
1180: 29 3b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f  );.      fossil_
1190: 65 72 72 6f 72 5f 72 65 73 65 74 28 29 3b 0a 20  error_reset();. 
11a0: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20     }else{.      
11b0: 70 72 69 6e 74 66 28 22 25 73 5c 6e 22 2c 20 62  printf("%s\n", b
11c0: 6c 6f 62 5f 62 75 66 66 65 72 28 26 6e 61 6d 65  lob_buffer(&name
11d0: 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 62 6c  ));.    }.    bl
11e0: 6f 62 5f 72 65 73 65 74 28 26 6e 61 6d 65 29 3b  ob_reset(&name);
11f0: 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 6f  .  }.}../*.** Co
1200: 6e 76 65 72 74 20 61 20 6e 61 6d 65 20 74 6f 20  nvert a name to 
1210: 61 20 72 69 64 2e 20 20 49 66 20 74 68 65 20 6e  a rid.  If the n
1220: 61 6d 65 20 69 73 20 61 20 73 6d 61 6c 6c 20 69  ame is a small i
1230: 6e 74 65 67 65 72 20 76 61 6c 75 65 20 74 68 65  nteger value the
1240: 6e 0a 2a 2a 20 6a 75 73 74 20 75 73 65 20 61 74  n.** just use at
1250: 6f 69 28 29 20 74 6f 20 64 6f 20 74 68 65 20 63  oi() to do the c
1260: 6f 6e 76 65 72 73 69 6f 6e 2e 20 20 49 66 20 74  onversion.  If t
1270: 68 65 20 6e 61 6d 65 20 63 6f 6e 74 61 69 6e 73  he name contains
1280: 20 61 6c 70 68 61 62 65 74 69 63 0a 2a 2a 20 63   alphabetic.** c
1290: 68 61 72 61 63 74 65 72 73 20 6f 72 20 69 73 20  haracters or is 
12a0: 6e 6f 74 20 61 6e 20 65 78 69 73 74 69 6e 67 20  not an existing 
12b0: 72 69 64 2c 20 74 68 65 6e 20 75 73 65 20 6e 61  rid, then use na
12c0: 6d 65 5f 74 6f 5f 75 75 69 64 20 74 68 65 6e 0a  me_to_uuid then.
12d0: 2a 2a 20 63 6f 6e 76 65 72 74 20 74 68 65 20 75  ** convert the u
12e0: 75 69 64 20 74 6f 20 61 20 72 69 64 2e 0a 2a 2a  uid to a rid..**
12f0: 0a 2a 2a 20 54 68 69 73 20 72 6f 75 74 69 6e 65  .** This routine
1300: 20 69 73 20 75 73 65 64 20 69 6e 20 74 65 73 74   is used in test
1310: 20 72 6f 75 74 69 6e 65 73 20 74 6f 20 72 65 73   routines to res
1320: 6f 6c 76 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e  olve command-lin
1330: 65 20 69 6e 70 75 74 73 0a 2a 2a 20 69 6e 74 6f  e inputs.** into
1340: 20 61 20 72 69 64 2e 0a 2a 2f 0a 69 6e 74 20 6e   a rid..*/.int n
1350: 61 6d 65 5f 74 6f 5f 72 69 64 28 63 6f 6e 73 74  ame_to_rid(const
1360: 20 63 68 61 72 20 2a 7a 4e 61 6d 65 29 7b 0a 20   char *zName){. 
1370: 20 69 6e 74 20 69 3b 0a 20 20 69 6e 74 20 72 69   int i;.  int ri
1380: 64 3b 0a 20 20 42 6c 6f 62 20 6e 61 6d 65 3b 0a  d;.  Blob name;.
1390: 20 20 66 6f 72 28 69 3d 30 3b 20 7a 4e 61 6d 65    for(i=0; zName
13a0: 5b 69 5d 20 26 26 20 69 73 64 69 67 69 74 28 7a  [i] && isdigit(z
13b0: 4e 61 6d 65 5b 69 5d 29 3b 20 69 2b 2b 29 7b 7d  Name[i]); i++){}
13c0: 0a 20 20 69 66 28 20 7a 4e 61 6d 65 5b 69 5d 3d  .  if( zName[i]=
13d0: 3d 30 20 29 7b 0a 20 20 20 20 72 69 64 20 3d 20  =0 ){.    rid = 
13e0: 61 74 6f 69 28 7a 4e 61 6d 65 29 3b 0a 20 20 20  atoi(zName);.   
13f0: 20 69 66 28 20 64 62 5f 65 78 69 73 74 73 28 22   if( db_exists("
1400: 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 62 6c  SELECT 1 FROM bl
1410: 6f 62 20 57 48 45 52 45 20 72 69 64 3d 25 64 22  ob WHERE rid=%d"
1420: 2c 20 72 69 64 29 20 29 7b 0a 20 20 20 20 20 20  , rid) ){.      
1430: 72 65 74 75 72 6e 20 72 69 64 3b 0a 20 20 20 20  return rid;.    
1440: 7d 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f 69 6e 69  }.  }.  blob_ini
1450: 74 28 26 6e 61 6d 65 2c 20 7a 4e 61 6d 65 2c 20  t(&name, zName, 
1460: 2d 31 29 3b 0a 20 20 69 66 28 20 6e 61 6d 65 5f  -1);.  if( name_
1470: 74 6f 5f 75 75 69 64 28 26 6e 61 6d 65 2c 20 31  to_uuid(&name, 1
1480: 29 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f  ) ){.    fossil_
1490: 66 61 74 61 6c 28 22 25 73 22 2c 20 67 2e 7a 45  fatal("%s", g.zE
14a0: 72 72 4d 73 67 29 3b 0a 20 20 7d 0a 20 20 72 69  rrMsg);.  }.  ri
14b0: 64 20 3d 20 64 62 5f 69 6e 74 28 30 2c 20 22 53  d = db_int(0, "S
14c0: 45 4c 45 43 54 20 72 69 64 20 46 52 4f 4d 20 62  ELECT rid FROM b
14d0: 6c 6f 62 20 57 48 45 52 45 20 75 75 69 64 3d 25  lob WHERE uuid=%
14e0: 42 22 2c 20 26 6e 61 6d 65 29 3b 0a 20 20 62 6c  B", &name);.  bl
14f0: 6f 62 5f 72 65 73 65 74 28 26 6e 61 6d 65 29 3b  ob_reset(&name);
1500: 0a 20 20 72 65 74 75 72 6e 20 72 69 64 3b 0a 7d  .  return rid;.}
1510: 0a                                               .