Hex Artifact Content
Not logged in

Artifact c707ca1de0e81c0924977ca006929b687669b478:

File src/tag.c part of check-in [09c4adeb6f] - Rework the tag system so that propagation to children is a property of each tag and does not depend on the tag name beginning with "br". Older tag artifacts might not work. The database will need to be rebuilt after upgrading to this version. by drh on 2007-09-22 23:41:29.

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 37 20 44 2e 20 52 69 63 68  (c) 2007 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 6d 61 6e 61 67 65 20 74 61  sed to manage ta
0390: 67 73 0a 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22  gs.*/.#include "
03a0: 63 6f 6e 66 69 67 2e 68 22 0a 23 69 6e 63 6c 75  config.h".#inclu
03b0: 64 65 20 22 74 61 67 2e 68 22 0a 23 69 6e 63 6c  de "tag.h".#incl
03c0: 75 64 65 20 3c 61 73 73 65 72 74 2e 68 3e 0a 0a  ude <assert.h>..
03d0: 2f 2a 0a 2a 2a 20 50 72 6f 70 61 67 61 74 65 20  /*.** Propagate 
03e0: 74 68 65 20 74 61 67 20 67 69 76 65 6e 20 62 79  the tag given by
03f0: 20 74 61 67 69 64 20 74 6f 20 74 68 65 20 63 68   tagid to the ch
0400: 69 6c 64 72 65 6e 20 6f 66 20 70 69 64 2e 0a 2a  ildren of pid..*
0410: 2a 0a 2a 2a 20 54 68 69 73 20 72 6f 75 74 69 6e  *.** This routin
0420: 65 20 61 73 73 75 6d 65 73 20 74 68 61 74 20 74  e assumes that t
0430: 61 67 69 64 20 69 73 20 61 20 74 61 67 20 74 68  agid is a tag th
0440: 61 74 20 73 68 6f 75 6c 64 20 62 65 0a 2a 2a 20  at should be.** 
0450: 70 72 6f 70 61 67 61 74 65 64 20 61 6e 64 20 74  propagated and t
0460: 68 61 74 20 74 68 65 20 74 61 67 20 69 73 20 61  hat the tag is a
0470: 6c 72 65 61 64 79 20 70 72 65 73 65 6e 74 20 69  lready present i
0480: 6e 20 70 69 64 2e 0a 2a 2a 0a 2a 2a 20 49 66 20  n pid..**.** If 
0490: 74 61 67 74 79 70 65 20 69 73 20 32 20 74 68 65  tagtype is 2 the
04a0: 6e 20 74 68 65 20 74 61 67 20 69 73 20 62 65 69  n the tag is bei
04b0: 6e 67 20 70 72 6f 70 61 67 61 74 65 64 20 66 72  ng propagated fr
04c0: 6f 6d 20 61 6e 0a 2a 2a 20 61 6e 63 65 73 74 6f  om an.** ancesto
04d0: 72 20 6e 6f 64 65 2e 20 20 49 66 20 74 61 67 74  r node.  If tagt
04e0: 79 70 65 20 69 73 20 30 20 69 74 20 6d 65 61 6e  ype is 0 it mean
04f0: 73 20 61 20 62 72 61 6e 63 68 20 74 61 67 20 69  s a branch tag i
0500: 73 0a 2a 2a 20 62 65 69 6e 67 20 63 61 6e 63 65  s.** being cance
0510: 6c 6c 65 64 2e 0a 2a 2f 0a 76 6f 69 64 20 74 61  lled..*/.void ta
0520: 67 5f 70 72 6f 70 61 67 61 74 65 28 0a 20 20 69  g_propagate(.  i
0530: 6e 74 20 70 69 64 2c 20 20 20 20 20 20 20 20 20  nt pid,         
0540: 20 20 20 20 2f 2a 20 50 72 6f 70 61 67 61 74 65      /* Propagate
0550: 20 74 68 65 20 74 61 67 20 74 6f 20 63 68 69 6c   the tag to chil
0560: 64 72 65 6e 20 6f 66 20 74 68 69 73 20 6e 6f 64  dren of this nod
0570: 65 20 2a 2f 0a 20 20 69 6e 74 20 74 61 67 69 64  e */.  int tagid
0580: 2c 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54  ,           /* T
0590: 61 67 20 74 6f 20 70 72 6f 70 61 67 61 74 65 20  ag to propagate 
05a0: 2a 2f 0a 20 20 69 6e 74 20 74 61 67 54 79 70 65  */.  int tagType
05b0: 2c 20 20 20 20 20 20 20 20 20 2f 2a 20 32 20 66  ,         /* 2 f
05c0: 6f 72 20 61 20 70 72 6f 70 61 67 61 74 69 6e 67  or a propagating
05d0: 20 74 61 67 2e 20 20 30 20 66 6f 72 20 61 6e 20   tag.  0 for an 
05e0: 61 6e 74 69 74 61 67 20 2a 2f 0a 20 20 63 6f 6e  antitag */.  con
05f0: 73 74 20 63 68 61 72 20 2a 7a 56 61 6c 75 65 2c  st char *zValue,
0600: 20 20 2f 2a 20 56 61 6c 75 65 20 6f 66 20 74 68    /* Value of th
0610: 65 20 74 61 67 2e 20 20 4d 69 67 68 74 20 62 65  e tag.  Might be
0620: 20 4e 55 4c 4c 20 2a 2f 0a 20 20 64 6f 75 62 6c   NULL */.  doubl
0630: 65 20 6d 74 69 6d 65 20 20 20 20 20 20 20 20 20  e mtime         
0640: 2f 2a 20 54 69 6d 65 73 74 61 6d 70 20 6f 6e 20  /* Timestamp on 
0650: 74 68 65 20 74 61 67 20 2a 2f 0a 29 7b 0a 20 20  the tag */.){.  
0660: 50 51 75 65 75 65 20 71 75 65 75 65 3b 0a 20 20  PQueue queue;.  
0670: 53 74 6d 74 20 73 2c 20 69 6e 73 2c 20 65 76 65  Stmt s, ins, eve
0680: 6e 74 75 70 64 61 74 65 3b 0a 0a 20 20 61 73 73  ntupdate;..  ass
0690: 65 72 74 28 20 74 61 67 54 79 70 65 3d 3d 30 20  ert( tagType==0 
06a0: 7c 7c 20 74 61 67 54 79 70 65 3d 3d 32 20 29 3b  || tagType==2 );
06b0: 0a 20 20 70 71 75 65 75 65 5f 69 6e 69 74 28 26  .  pqueue_init(&
06c0: 71 75 65 75 65 29 3b 0a 20 20 70 71 75 65 75 65  queue);.  pqueue
06d0: 5f 69 6e 73 65 72 74 28 26 71 75 65 75 65 2c 20  _insert(&queue, 
06e0: 70 69 64 2c 20 30 2e 30 29 3b 0a 20 20 64 62 5f  pid, 0.0);.  db_
06f0: 70 72 65 70 61 72 65 28 26 73 2c 20 0a 20 20 20  prepare(&s, .   
0700: 20 20 22 53 45 4c 45 43 54 20 63 69 64 2c 20 70    "SELECT cid, p
0710: 6c 69 6e 6b 2e 6d 74 69 6d 65 2c 22 0a 20 20 20  link.mtime,".   
0720: 20 20 22 20 20 20 20 20 20 20 63 6f 61 6c 65 73    "       coales
0730: 63 65 28 73 72 63 69 64 3d 30 20 41 4e 44 20 74  ce(srcid=0 AND t
0740: 61 67 78 72 65 66 2e 6d 74 69 6d 65 3c 3a 6d 74  agxref.mtime<:mt
0750: 69 6d 65 2c 20 25 64 29 20 41 53 20 64 6f 69 74  ime, %d) AS doit
0760: 22 0a 20 20 20 20 20 22 20 20 46 52 4f 4d 20 70  ".     "  FROM p
0770: 6c 69 6e 6b 20 4c 45 46 54 20 4a 4f 49 4e 20 74  link LEFT JOIN t
0780: 61 67 78 72 65 66 20 4f 4e 20 63 69 64 3d 72 69  agxref ON cid=ri
0790: 64 20 41 4e 44 20 74 61 67 69 64 3d 25 64 22 0a  d AND tagid=%d".
07a0: 20 20 20 20 20 22 20 57 48 45 52 45 20 70 69 64       " WHERE pid
07b0: 3d 3a 70 69 64 20 41 4e 44 20 69 73 70 72 69 6d  =:pid AND isprim
07c0: 22 2c 0a 20 20 20 20 20 74 61 67 54 79 70 65 21  ",.     tagType!
07d0: 3d 30 2c 20 74 61 67 69 64 0a 20 20 29 3b 0a 20  =0, tagid.  );. 
07e0: 20 64 62 5f 62 69 6e 64 5f 64 6f 75 62 6c 65 28   db_bind_double(
07f0: 26 73 2c 20 22 3a 6d 74 69 6d 65 22 2c 20 6d 74  &s, ":mtime", mt
0800: 69 6d 65 29 3b 0a 20 20 69 66 28 20 74 61 67 54  ime);.  if( tagT
0810: 79 70 65 3d 3d 32 20 29 7b 0a 20 20 20 20 64 62  ype==2 ){.    db
0820: 5f 70 72 65 70 61 72 65 28 26 69 6e 73 2c 0a 20  _prepare(&ins,. 
0830: 20 20 20 20 20 20 22 52 45 50 4c 41 43 45 20 49        "REPLACE I
0840: 4e 54 4f 20 74 61 67 78 72 65 66 28 74 61 67 69  NTO tagxref(tagi
0850: 64 2c 20 74 61 67 74 79 70 65 2c 20 73 72 63 69  d, tagtype, srci
0860: 64 2c 20 76 61 6c 75 65 2c 20 6d 74 69 6d 65 2c  d, value, mtime,
0870: 20 72 69 64 29 22 0a 20 20 20 20 20 20 20 22 56   rid)".       "V
0880: 41 4c 55 45 53 28 25 64 2c 32 2c 30 2c 25 51 2c  ALUES(%d,2,0,%Q,
0890: 3a 6d 74 69 6d 65 2c 3a 72 69 64 29 22 2c 0a 20  :mtime,:rid)",. 
08a0: 20 20 20 20 20 20 74 61 67 69 64 2c 20 7a 56 61        tagid, zVa
08b0: 6c 75 65 0a 20 20 20 20 29 3b 0a 20 20 20 20 64  lue.    );.    d
08c0: 62 5f 62 69 6e 64 5f 64 6f 75 62 6c 65 28 26 69  b_bind_double(&i
08d0: 6e 73 2c 20 22 3a 6d 74 69 6d 65 22 2c 20 6d 74  ns, ":mtime", mt
08e0: 69 6d 65 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20  ime);.  }else{. 
08f0: 20 20 20 7a 56 61 6c 75 65 20 3d 20 30 3b 0a 20     zValue = 0;. 
0900: 20 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 69     db_prepare(&i
0910: 6e 73 2c 0a 20 20 20 20 20 20 20 22 44 45 4c 45  ns,.       "DELE
0920: 54 45 20 46 52 4f 4d 20 74 61 67 78 72 65 66 20  TE FROM tagxref 
0930: 57 48 45 52 45 20 74 61 67 69 64 3d 25 64 20 41  WHERE tagid=%d A
0940: 4e 44 20 72 69 64 3d 3a 72 69 64 22 2c 20 74 61  ND rid=:rid", ta
0950: 67 69 64 0a 20 20 20 20 29 3b 0a 20 20 7d 0a 20  gid.    );.  }. 
0960: 20 69 66 28 20 74 61 67 69 64 3d 3d 54 41 47 5f   if( tagid==TAG_
0970: 42 47 43 4f 4c 4f 52 20 29 7b 0a 20 20 20 20 64  BGCOLOR ){.    d
0980: 62 5f 70 72 65 70 61 72 65 28 26 65 76 65 6e 74  b_prepare(&event
0990: 75 70 64 61 74 65 2c 0a 20 20 20 20 20 20 22 55  update,.      "U
09a0: 50 44 41 54 45 20 65 76 65 6e 74 20 53 45 54 20  PDATE event SET 
09b0: 62 72 62 67 63 6f 6c 6f 72 3d 25 51 20 57 48 45  brbgcolor=%Q WHE
09c0: 52 45 20 6f 62 6a 69 64 3d 3a 72 69 64 22 2c 20  RE objid=:rid", 
09d0: 7a 56 61 6c 75 65 0a 20 20 20 20 29 3b 0a 20 20  zValue.    );.  
09e0: 7d 0a 20 20 77 68 69 6c 65 28 20 28 70 69 64 20  }.  while( (pid 
09f0: 3d 20 70 71 75 65 75 65 5f 65 78 74 72 61 63 74  = pqueue_extract
0a00: 28 26 71 75 65 75 65 29 29 21 3d 30 20 29 7b 0a  (&queue))!=0 ){.
0a10: 20 20 20 20 64 62 5f 62 69 6e 64 5f 69 6e 74 28      db_bind_int(
0a20: 26 73 2c 20 22 3a 70 69 64 22 2c 20 70 69 64 29  &s, ":pid", pid)
0a30: 3b 0a 20 20 20 20 77 68 69 6c 65 28 20 64 62 5f  ;.    while( db_
0a40: 73 74 65 70 28 26 73 29 3d 3d 53 51 4c 49 54 45  step(&s)==SQLITE
0a50: 5f 52 4f 57 20 29 7b 0a 20 20 20 20 20 20 69 6e  _ROW ){.      in
0a60: 74 20 64 6f 69 74 20 3d 20 64 62 5f 63 6f 6c 75  t doit = db_colu
0a70: 6d 6e 5f 69 6e 74 28 26 73 2c 20 32 29 3b 0a 20  mn_int(&s, 2);. 
0a80: 20 20 20 20 20 69 66 28 20 64 6f 69 74 20 29 7b       if( doit ){
0a90: 0a 20 20 20 20 20 20 20 20 69 6e 74 20 63 69 64  .        int cid
0aa0: 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74   = db_column_int
0ab0: 28 26 73 2c 20 30 29 3b 0a 20 20 20 20 20 20 20  (&s, 0);.       
0ac0: 20 64 6f 75 62 6c 65 20 6d 74 69 6d 65 20 3d 20   double mtime = 
0ad0: 64 62 5f 63 6f 6c 75 6d 6e 5f 64 6f 75 62 6c 65  db_column_double
0ae0: 28 26 73 2c 20 31 29 3b 0a 20 20 20 20 20 20 20  (&s, 1);.       
0af0: 20 70 71 75 65 75 65 5f 69 6e 73 65 72 74 28 26   pqueue_insert(&
0b00: 71 75 65 75 65 2c 20 63 69 64 2c 20 6d 74 69 6d  queue, cid, mtim
0b10: 65 29 3b 0a 20 20 20 20 20 20 20 20 64 62 5f 62  e);.        db_b
0b20: 69 6e 64 5f 69 6e 74 28 26 69 6e 73 2c 20 22 3a  ind_int(&ins, ":
0b30: 72 69 64 22 2c 20 63 69 64 29 3b 0a 20 20 20 20  rid", cid);.    
0b40: 20 20 20 20 64 62 5f 73 74 65 70 28 26 69 6e 73      db_step(&ins
0b50: 29 3b 0a 20 20 20 20 20 20 20 20 64 62 5f 72 65  );.        db_re
0b60: 73 65 74 28 26 69 6e 73 29 3b 0a 20 20 20 20 20  set(&ins);.     
0b70: 20 20 20 69 66 28 20 74 61 67 69 64 3d 3d 54 41     if( tagid==TA
0b80: 47 5f 42 47 43 4f 4c 4f 52 20 29 7b 0a 20 20 20  G_BGCOLOR ){.   
0b90: 20 20 20 20 20 20 20 64 62 5f 62 69 6e 64 5f 69         db_bind_i
0ba0: 6e 74 28 26 65 76 65 6e 74 75 70 64 61 74 65 2c  nt(&eventupdate,
0bb0: 20 22 3a 72 69 64 22 2c 20 63 69 64 29 3b 0a 20   ":rid", cid);. 
0bc0: 20 20 20 20 20 20 20 20 20 64 62 5f 73 74 65 70           db_step
0bd0: 28 26 65 76 65 6e 74 75 70 64 61 74 65 29 3b 0a  (&eventupdate);.
0be0: 20 20 20 20 20 20 20 20 20 20 64 62 5f 72 65 73            db_res
0bf0: 65 74 28 26 65 76 65 6e 74 75 70 64 61 74 65 29  et(&eventupdate)
0c00: 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20  ;.        }.    
0c10: 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 20 64 62    }.    }.    db
0c20: 5f 72 65 73 65 74 28 26 73 29 3b 0a 20 20 7d 0a  _reset(&s);.  }.
0c30: 20 20 70 71 75 65 75 65 5f 63 6c 65 61 72 28 26    pqueue_clear(&
0c40: 71 75 65 75 65 29 3b 0a 20 20 64 62 5f 66 69 6e  queue);.  db_fin
0c50: 61 6c 69 7a 65 28 26 69 6e 73 29 3b 0a 20 20 64  alize(&ins);.  d
0c60: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 73 29 3b 0a  b_finalize(&s);.
0c70: 20 20 69 66 28 20 74 61 67 69 64 3d 3d 54 41 47    if( tagid==TAG
0c80: 5f 42 47 43 4f 4c 4f 52 20 29 7b 0a 20 20 20 20  _BGCOLOR ){.    
0c90: 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 65 76 65  db_finalize(&eve
0ca0: 6e 74 75 70 64 61 74 65 29 3b 0a 20 20 7d 0a 7d  ntupdate);.  }.}
0cb0: 0a 0a 2f 2a 0a 2a 2a 20 50 72 6f 70 61 67 61 74  ../*.** Propagat
0cc0: 65 20 61 6c 6c 20 70 72 6f 70 61 67 61 74 61 62  e all propagatab
0cd0: 6c 65 20 74 61 67 73 20 69 6e 20 70 69 64 20 74  le tags in pid t
0ce0: 6f 20 69 74 73 20 63 68 69 6c 64 72 65 6e 2e 0a  o its children..
0cf0: 2a 2f 0a 76 6f 69 64 20 74 61 67 5f 70 72 6f 70  */.void tag_prop
0d00: 61 67 61 74 65 5f 61 6c 6c 28 69 6e 74 20 70 69  agate_all(int pi
0d10: 64 29 7b 0a 20 20 53 74 6d 74 20 71 3b 0a 20 20  d){.  Stmt q;.  
0d20: 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c 0a 20  db_prepare(&q,. 
0d30: 20 20 20 20 22 53 45 4c 45 43 54 20 74 61 67 69      "SELECT tagi
0d40: 64 2c 20 74 61 67 74 79 70 65 2c 20 6d 74 69 6d  d, tagtype, mtim
0d50: 65 2c 20 76 61 6c 75 65 20 46 52 4f 4d 20 74 61  e, value FROM ta
0d60: 67 78 72 65 66 22 0a 20 20 20 20 20 22 20 57 48  gxref".     " WH
0d70: 45 52 45 20 72 69 64 3d 25 64 22 0a 20 20 20 20  ERE rid=%d".    
0d80: 20 22 20 20 20 41 4e 44 20 28 74 61 67 74 79 70   "   AND (tagtyp
0d90: 65 3d 30 20 4f 52 20 74 61 67 74 79 70 65 3d 32  e=0 OR tagtype=2
0da0: 29 22 2c 0a 20 20 20 20 20 70 69 64 0a 20 20 29  )",.     pid.  )
0db0: 3b 0a 20 20 77 68 69 6c 65 28 20 64 62 5f 73 74  ;.  while( db_st
0dc0: 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52  ep(&q)==SQLITE_R
0dd0: 4f 57 20 29 7b 0a 20 20 20 20 69 6e 74 20 74 61  OW ){.    int ta
0de0: 67 69 64 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f  gid = db_column_
0df0: 69 6e 74 28 26 71 2c 20 30 29 3b 0a 20 20 20 20  int(&q, 0);.    
0e00: 69 6e 74 20 74 61 67 74 79 70 65 20 3d 20 64 62  int tagtype = db
0e10: 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20  _column_int(&q, 
0e20: 31 29 3b 0a 20 20 20 20 64 6f 75 62 6c 65 20 6d  1);.    double m
0e30: 74 69 6d 65 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e  time = db_column
0e40: 5f 64 6f 75 62 6c 65 28 26 71 2c 20 32 29 3b 0a  _double(&q, 2);.
0e50: 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a      const char *
0e60: 7a 56 61 6c 75 65 20 3d 20 64 62 5f 63 6f 6c 75  zValue = db_colu
0e70: 6d 6e 5f 74 65 78 74 28 26 71 2c 20 33 29 3b 0a  mn_text(&q, 3);.
0e80: 20 20 20 20 74 61 67 5f 70 72 6f 70 61 67 61 74      tag_propagat
0e90: 65 28 70 69 64 2c 20 74 61 67 69 64 2c 20 74 61  e(pid, tagid, ta
0ea0: 67 74 79 70 65 2c 20 7a 56 61 6c 75 65 2c 20 6d  gtype, zValue, m
0eb0: 74 69 6d 65 29 3b 0a 20 20 7d 0a 20 20 64 62 5f  time);.  }.  db_
0ec0: 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 7d 0a  finalize(&q);.}.
0ed0: 0a 2f 2a 0a 2a 2a 20 47 65 74 20 61 20 74 61 67  ./*.** Get a tag
0ee0: 69 64 20 66 6f 72 20 74 68 65 20 67 69 76 65 6e  id for the given
0ef0: 20 54 41 47 2e 20 20 43 72 65 61 74 65 20 61 20   TAG.  Create a 
0f00: 6e 65 77 20 74 61 67 20 69 66 20 6e 65 63 65 73  new tag if neces
0f10: 73 61 72 79 0a 2a 2a 20 69 66 20 63 72 65 61 74  sary.** if creat
0f20: 65 46 6c 61 67 20 69 73 20 31 2e 0a 2a 2f 0a 69  eFlag is 1..*/.i
0f30: 6e 74 20 74 61 67 5f 66 69 6e 64 69 64 28 63 6f  nt tag_findid(co
0f40: 6e 73 74 20 63 68 61 72 20 2a 7a 54 61 67 2c 20  nst char *zTag, 
0f50: 69 6e 74 20 63 72 65 61 74 65 46 6c 61 67 29 7b  int createFlag){
0f60: 0a 20 20 69 6e 74 20 69 64 3b 0a 20 20 69 64 20  .  int id;.  id 
0f70: 3d 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c  = db_int(0, "SEL
0f80: 45 43 54 20 74 61 67 69 64 20 46 52 4f 4d 20 74  ECT tagid FROM t
0f90: 61 67 20 57 48 45 52 45 20 74 61 67 6e 61 6d 65  ag WHERE tagname
0fa0: 3d 25 51 22 2c 20 7a 54 61 67 29 3b 0a 20 20 69  =%Q", zTag);.  i
0fb0: 66 28 20 69 64 3d 3d 30 20 26 26 20 63 72 65 61  f( id==0 && crea
0fc0: 74 65 46 6c 61 67 20 29 7b 0a 20 20 20 20 64 62  teFlag ){.    db
0fd0: 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 49 4e 53  _multi_exec("INS
0fe0: 45 52 54 20 49 4e 54 4f 20 74 61 67 28 74 61 67  ERT INTO tag(tag
0ff0: 6e 61 6d 65 29 20 56 41 4c 55 45 53 28 25 51 29  name) VALUES(%Q)
1000: 22 2c 20 7a 54 61 67 29 3b 0a 20 20 20 20 69 64  ", zTag);.    id
1010: 20 3d 20 64 62 5f 6c 61 73 74 5f 69 6e 73 65 72   = db_last_inser
1020: 74 5f 72 6f 77 69 64 28 29 3b 0a 20 20 7d 0a 20  t_rowid();.  }. 
1030: 20 72 65 74 75 72 6e 20 69 64 3b 0a 7d 0a 0a 2f   return id;.}../
1040: 2a 0a 2a 2a 20 49 6e 73 65 72 74 20 61 20 74 61  *.** Insert a ta
1050: 67 20 69 6e 74 6f 20 74 68 65 20 64 61 74 61 62  g into the datab
1060: 61 73 65 2e 0a 2a 2f 0a 76 6f 69 64 20 74 61 67  ase..*/.void tag
1070: 5f 69 6e 73 65 72 74 28 0a 20 20 63 6f 6e 73 74  _insert(.  const
1080: 20 63 68 61 72 20 2a 7a 54 61 67 2c 20 20 20 20   char *zTag,    
1090: 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74      /* Name of t
10a0: 68 65 20 74 61 67 20 28 77 2f 6f 20 74 68 65 20  he tag (w/o the 
10b0: 22 2b 22 20 6f 72 20 22 2d 22 20 70 72 65 66 69  "+" or "-" prefi
10c0: 78 20 2a 2f 0a 20 20 69 6e 74 20 74 61 67 74 79  x */.  int tagty
10d0: 70 65 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  pe,             
10e0: 2f 2a 20 30 3a 63 61 6e 63 65 6c 20 20 31 3a 73  /* 0:cancel  1:s
10f0: 69 6e 67 6c 65 74 6f 6e 20 20 32 3a 70 72 6f 70  ingleton  2:prop
1100: 61 67 61 74 65 64 20 2a 2f 0a 20 20 63 6f 6e 73  agated */.  cons
1110: 74 20 63 68 61 72 20 2a 7a 56 61 6c 75 65 2c 20  t char *zValue, 
1120: 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 69 66       /* Value if
1130: 20 74 68 65 20 74 61 67 20 69 73 20 72 65 61 6c   the tag is real
1140: 6c 79 20 61 20 70 72 6f 70 65 72 74 79 20 2a 2f  ly a property */
1150: 0a 20 20 69 6e 74 20 73 72 63 49 64 2c 20 20 20  .  int srcId,   
1160: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41              /* A
1170: 72 74 69 66 61 63 74 20 74 68 61 74 20 63 6f 6e  rtifact that con
1180: 74 61 69 6e 73 20 74 68 69 73 20 74 61 67 20 2a  tains this tag *
1190: 2f 0a 20 20 64 6f 75 62 6c 65 20 6d 74 69 6d 65  /.  double mtime
11a0: 2c 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20  ,            /* 
11b0: 54 69 6d 65 73 74 61 6d 70 2e 20 20 55 73 65 20  Timestamp.  Use 
11c0: 64 65 66 61 75 6c 74 20 69 66 20 3c 3d 30 2e 30  default if <=0.0
11d0: 20 2a 2f 0a 20 20 69 6e 74 20 72 69 64 20 20 20   */.  int rid   
11e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f                 /
11f0: 2a 20 41 72 74 69 66 61 63 74 20 74 6f 20 77 68  * Artifact to wh
1200: 69 63 68 20 74 68 65 20 74 61 67 20 69 73 20 74  ich the tag is t
1210: 6f 20 61 74 74 61 63 68 65 64 20 2a 2f 0a 29 7b  o attached */.){
1220: 0a 20 20 53 74 6d 74 20 73 3b 0a 20 20 63 6f 6e  .  Stmt s;.  con
1230: 73 74 20 63 68 61 72 20 2a 7a 43 6f 6c 3b 0a 20  st char *zCol;. 
1240: 20 69 6e 74 20 74 61 67 69 64 20 3d 20 74 61 67   int tagid = tag
1250: 5f 66 69 6e 64 69 64 28 7a 54 61 67 2c 20 31 29  _findid(zTag, 1)
1260: 3b 0a 20 20 69 66 28 20 6d 74 69 6d 65 3c 3d 30  ;.  if( mtime<=0
1270: 2e 30 20 29 7b 0a 20 20 20 20 6d 74 69 6d 65 20  .0 ){.    mtime 
1280: 3d 20 64 62 5f 64 6f 75 62 6c 65 28 30 2e 30 2c  = db_double(0.0,
1290: 20 22 53 45 4c 45 43 54 20 6a 75 6c 69 61 6e 64   "SELECT juliand
12a0: 61 79 28 27 6e 6f 77 27 29 22 29 3b 0a 20 20 7d  ay('now')");.  }
12b0: 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 73  .  db_prepare(&s
12c0: 2c 20 0a 20 20 20 20 22 52 45 50 4c 41 43 45 20  , .    "REPLACE 
12d0: 49 4e 54 4f 20 74 61 67 78 72 65 66 28 74 61 67  INTO tagxref(tag
12e0: 69 64 2c 74 61 67 74 79 70 65 2c 73 72 63 49 64  id,tagtype,srcId
12f0: 2c 76 61 6c 75 65 2c 6d 74 69 6d 65 2c 72 69 64  ,value,mtime,rid
1300: 29 22 0a 20 20 20 20 22 20 56 41 4c 55 45 53 28  )".    " VALUES(
1310: 25 64 2c 25 64 2c 25 64 2c 25 51 2c 3a 6d 74 69  %d,%d,%d,%Q,:mti
1320: 6d 65 2c 25 64 29 22 2c 0a 20 20 20 20 74 61 67  me,%d)",.    tag
1330: 69 64 2c 20 74 61 67 74 79 70 65 2c 20 73 72 63  id, tagtype, src
1340: 49 64 2c 20 7a 56 61 6c 75 65 2c 20 72 69 64 0a  Id, zValue, rid.
1350: 20 20 29 3b 0a 20 20 64 62 5f 62 69 6e 64 5f 64    );.  db_bind_d
1360: 6f 75 62 6c 65 28 26 73 2c 20 22 3a 6d 74 69 6d  ouble(&s, ":mtim
1370: 65 22 2c 20 6d 74 69 6d 65 29 3b 0a 20 20 64 62  e", mtime);.  db
1380: 5f 73 74 65 70 28 26 73 29 3b 0a 20 20 64 62 5f  _step(&s);.  db_
1390: 66 69 6e 61 6c 69 7a 65 28 26 73 29 3b 0a 20 20  finalize(&s);.  
13a0: 69 66 28 20 74 61 67 74 79 70 65 3d 3d 30 20 29  if( tagtype==0 )
13b0: 7b 0a 20 20 20 20 7a 56 61 6c 75 65 20 3d 20 30  {.    zValue = 0
13c0: 3b 0a 20 20 7d 0a 20 20 7a 43 6f 6c 20 3d 20 30  ;.  }.  zCol = 0
13d0: 3b 0a 20 20 73 77 69 74 63 68 28 20 74 61 67 69  ;.  switch( tagi
13e0: 64 20 29 7b 0a 20 20 20 20 63 61 73 65 20 54 41  d ){.    case TA
13f0: 47 5f 42 47 43 4f 4c 4f 52 3a 20 7b 0a 20 20 20  G_BGCOLOR: {.   
1400: 20 20 20 69 66 28 20 74 61 67 74 79 70 65 3d 3d     if( tagtype==
1410: 31 20 29 7b 0a 20 20 20 20 20 20 20 20 7a 43 6f  1 ){.        zCo
1420: 6c 20 3d 20 22 62 67 63 6f 6c 6f 72 22 3b 0a 20  l = "bgcolor";. 
1430: 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20       }else{.    
1440: 20 20 20 20 7a 43 6f 6c 20 3d 20 22 62 72 62 67      zCol = "brbg
1450: 63 6f 6c 6f 72 22 3b 0a 20 20 20 20 20 20 7d 0a  color";.      }.
1460: 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20        break;.   
1470: 20 7d 0a 20 20 20 20 63 61 73 65 20 54 41 47 5f   }.    case TAG_
1480: 43 4f 4d 4d 45 4e 54 3a 20 7b 0a 20 20 20 20 20  COMMENT: {.     
1490: 20 7a 43 6f 6c 20 3d 20 22 65 63 6f 6d 6d 65 6e   zCol = "ecommen
14a0: 74 22 3b 0a 20 20 20 20 20 20 62 72 65 61 6b 3b  t";.      break;
14b0: 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 73 65 20  .    }.    case 
14c0: 54 41 47 5f 55 53 45 52 3a 20 7b 0a 20 20 20 20  TAG_USER: {.    
14d0: 20 20 7a 43 6f 6c 20 3d 20 22 65 75 73 65 72 22    zCol = "euser"
14e0: 3b 0a 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20  ;.      break;. 
14f0: 20 20 20 7d 0a 20 20 7d 0a 20 20 69 66 28 20 7a     }.  }.  if( z
1500: 43 6f 6c 20 29 7b 0a 20 20 20 20 64 62 5f 6d 75  Col ){.    db_mu
1510: 6c 74 69 5f 65 78 65 63 28 22 55 50 44 41 54 45  lti_exec("UPDATE
1520: 20 65 76 65 6e 74 20 53 45 54 20 25 73 3d 25 51   event SET %s=%Q
1530: 20 57 48 45 52 45 20 6f 62 6a 69 64 3d 25 64 22   WHERE objid=%d"
1540: 2c 20 7a 43 6f 6c 2c 20 7a 56 61 6c 75 65 2c 20  , zCol, zValue, 
1550: 72 69 64 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20  rid);.  }.  if( 
1560: 74 61 67 74 79 70 65 3d 3d 30 20 7c 7c 20 74 61  tagtype==0 || ta
1570: 67 74 79 70 65 3d 3d 32 20 29 7b 0a 20 20 20 20  gtype==2 ){.    
1580: 74 61 67 5f 70 72 6f 70 61 67 61 74 65 28 72 69  tag_propagate(ri
1590: 64 2c 20 74 61 67 69 64 2c 20 74 61 67 74 79 70  d, tagid, tagtyp
15a0: 65 2c 20 7a 56 61 6c 75 65 2c 20 6d 74 69 6d 65  e, zValue, mtime
15b0: 29 3b 0a 20 20 7d 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a  );.  }.}.../*.**
15c0: 20 43 4f 4d 4d 41 4e 44 3a 20 74 65 73 74 2d 74   COMMAND: test-t
15d0: 61 67 0a 2a 2a 20 25 66 6f 73 73 69 6c 20 74 65  ag.** %fossil te
15e0: 73 74 2d 74 61 67 20 28 2b 7c 2a 7c 2d 29 54 41  st-tag (+|*|-)TA
15f0: 47 4e 41 4d 45 20 55 55 49 44 20 3f 56 41 4c 55  GNAME UUID ?VALU
1600: 45 3f 0a 2a 2a 0a 2a 2a 20 41 64 64 20 61 20 74  E?.**.** Add a t
1610: 61 67 20 6f 72 20 61 6e 74 69 2d 74 61 67 20 74  ag or anti-tag t
1620: 6f 20 74 68 65 20 72 65 62 75 69 6c 64 61 62 6c  o the rebuildabl
1630: 65 20 74 61 62 6c 65 73 20 6f 66 20 74 68 65 20  e tables of the 
1640: 6c 6f 63 61 6c 20 72 65 70 6f 73 69 74 6f 72 79  local repository
1650: 2e 0a 2a 2a 20 4e 6f 20 74 61 67 20 61 72 74 69  ..** No tag arti
1660: 66 61 63 74 20 69 73 20 63 72 65 61 74 65 64 20  fact is created 
1670: 73 6f 20 74 68 65 20 6e 65 77 20 74 61 67 20 69  so the new tag i
1680: 73 20 65 72 61 73 65 64 20 74 68 65 20 6e 65 78  s erased the nex
1690: 74 0a 2a 2a 20 74 69 6d 65 20 74 68 65 20 72 65  t.** time the re
16a0: 70 6f 73 69 74 6f 72 79 20 69 73 20 72 65 62 75  pository is rebu
16b0: 69 6c 74 2e 20 20 54 68 69 73 20 72 6f 75 74 69  ilt.  This routi
16c0: 6e 65 20 69 73 20 66 6f 72 20 74 65 73 74 69 6e  ne is for testin
16d0: 67 0a 2a 2a 20 75 73 65 20 6f 6e 6c 79 2e 0a 2a  g.** use only..*
16e0: 2f 0a 76 6f 69 64 20 74 65 73 74 74 61 67 5f 63  /.void testtag_c
16f0: 6d 64 28 76 6f 69 64 29 7b 0a 20 20 63 6f 6e 73  md(void){.  cons
1700: 74 20 63 68 61 72 20 2a 7a 54 61 67 3b 0a 20 20  t char *zTag;.  
1710: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 56 61 6c  const char *zVal
1720: 75 65 3b 0a 20 20 69 6e 74 20 72 69 64 3b 0a 20  ue;.  int rid;. 
1730: 20 69 6e 74 20 74 61 67 74 79 70 65 3b 0a 20 20   int tagtype;.  
1740: 64 62 5f 6d 75 73 74 5f 62 65 5f 77 69 74 68 69  db_must_be_withi
1750: 6e 5f 74 72 65 65 28 29 3b 0a 20 20 69 66 28 20  n_tree();.  if( 
1760: 67 2e 61 72 67 63 21 3d 34 20 26 26 20 67 2e 61  g.argc!=4 && g.a
1770: 72 67 63 21 3d 35 20 29 7b 0a 20 20 20 20 75 73  rgc!=5 ){.    us
1780: 61 67 65 28 22 54 41 47 4e 41 4d 45 20 55 55 49  age("TAGNAME UUI
1790: 44 20 3f 56 41 4c 55 45 3f 22 29 3b 0a 20 20 7d  D ?VALUE?");.  }
17a0: 0a 20 20 7a 54 61 67 20 3d 20 67 2e 61 72 67 76  .  zTag = g.argv
17b0: 5b 32 5d 3b 0a 20 20 73 77 69 74 63 68 28 20 7a  [2];.  switch( z
17c0: 54 61 67 5b 30 5d 20 29 7b 0a 20 20 20 20 63 61  Tag[0] ){.    ca
17d0: 73 65 20 27 2b 27 3a 20 20 74 61 67 74 79 70 65  se '+':  tagtype
17e0: 20 3d 20 31 3b 20 20 62 72 65 61 6b 3b 0a 20 20   = 1;  break;.  
17f0: 20 20 63 61 73 65 20 27 2a 27 3a 20 20 74 61 67    case '*':  tag
1800: 74 79 70 65 20 3d 20 32 3b 20 20 62 72 65 61 6b  type = 2;  break
1810: 3b 0a 20 20 20 20 63 61 73 65 20 27 2d 27 3a 20  ;.    case '-': 
1820: 20 74 61 67 74 79 70 65 20 3d 20 30 3b 20 20 62   tagtype = 0;  b
1830: 72 65 61 6b 3b 0a 20 20 20 20 64 65 66 61 75 6c  reak;.    defaul
1840: 74 3a 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61  t:   fossil_fata
1850: 6c 28 22 74 61 67 20 73 68 6f 75 6c 64 20 62 65  l("tag should be
1860: 67 69 6e 20 77 69 74 68 20 27 2b 27 2c 20 27 2a  gin with '+', '*
1870: 27 2c 20 6f 72 20 27 2d 27 22 29 3b 0a 20 20 7d  ', or '-'");.  }
1880: 0a 20 20 72 69 64 20 3d 20 6e 61 6d 65 5f 74 6f  .  rid = name_to
1890: 5f 72 69 64 28 67 2e 61 72 67 76 5b 33 5d 29 3b  _rid(g.argv[3]);
18a0: 0a 20 20 69 66 28 20 72 69 64 3d 3d 30 20 29 7b  .  if( rid==0 ){
18b0: 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61  .    fossil_fata
18c0: 6c 28 22 6e 6f 20 73 75 63 68 20 6f 62 6a 65 63  l("no such objec
18d0: 74 3a 20 25 73 22 2c 20 67 2e 61 72 67 76 5b 33  t: %s", g.argv[3
18e0: 5d 29 3b 0a 20 20 7d 0a 20 20 7a 56 61 6c 75 65  ]);.  }.  zValue
18f0: 20 3d 20 67 2e 61 72 67 63 3d 3d 35 20 3f 20 67   = g.argc==5 ? g
1900: 2e 61 72 67 76 5b 34 5d 20 3a 20 30 3b 0a 20 20  .argv[4] : 0;.  
1910: 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61 63  db_begin_transac
1920: 74 69 6f 6e 28 29 3b 0a 20 20 74 61 67 5f 69 6e  tion();.  tag_in
1930: 73 65 72 74 28 7a 54 61 67 2c 20 74 61 67 74 79  sert(zTag, tagty
1940: 70 65 2c 20 7a 56 61 6c 75 65 2c 20 2d 31 2c 20  pe, zValue, -1, 
1950: 30 2e 30 2c 20 72 69 64 29 3b 0a 20 20 64 62 5f  0.0, rid);.  db_
1960: 65 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28  end_transaction(
1970: 30 29 3b 20 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 41 64  0); .}../*.** Ad
1980: 64 20 61 20 63 6f 6e 74 72 6f 6c 20 72 65 63 6f  d a control reco
1990: 72 64 20 74 6f 20 74 68 65 20 72 65 70 6f 73 69  rd to the reposi
19a0: 74 6f 72 79 20 74 68 61 74 20 65 69 74 68 65 72  tory that either
19b0: 20 63 72 65 61 74 65 73 0a 2a 2a 20 6f 72 20 63   creates.** or c
19c0: 61 6e 63 65 6c 73 20 61 20 74 61 67 2e 0a 2a 2f  ancels a tag..*/
19d0: 0a 73 74 61 74 69 63 20 76 6f 69 64 20 74 61 67  .static void tag
19e0: 5f 61 64 64 5f 61 72 74 69 66 61 63 74 28 0a 20  _add_artifact(. 
19f0: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 54 61   const char *zTa
1a00: 67 6e 61 6d 65 2c 20 20 20 20 20 20 20 2f 2a 20  gname,       /* 
1a10: 54 68 65 20 74 61 67 20 74 6f 20 61 64 64 20 6f  The tag to add o
1a20: 72 20 63 61 6e 63 65 6c 20 2a 2f 0a 20 20 63 6f  r cancel */.  co
1a30: 6e 73 74 20 63 68 61 72 20 2a 7a 4f 62 6a 4e 61  nst char *zObjNa
1a40: 6d 65 2c 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d  me,       /* Nam
1a50: 65 20 6f 66 20 6f 62 6a 65 63 74 20 61 74 74 61  e of object atta
1a60: 63 68 65 64 20 74 6f 20 2a 2f 0a 20 20 63 6f 6e  ched to */.  con
1a70: 73 74 20 63 68 61 72 20 2a 7a 56 61 6c 75 65 2c  st char *zValue,
1a80: 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 6c 75           /* Valu
1a90: 65 20 66 6f 72 20 74 68 65 20 74 61 67 2e 20 20  e for the tag.  
1aa0: 4d 69 67 68 74 20 62 65 20 4e 55 4c 4c 20 2a 2f  Might be NULL */
1ab0: 0a 20 20 69 6e 74 20 74 61 67 74 79 70 65 20 20  .  int tagtype  
1ac0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f                 /
1ad0: 2a 20 30 3a 63 61 6e 63 65 6c 20 31 3a 73 69 6e  * 0:cancel 1:sin
1ae0: 67 6c 65 74 6f 6e 20 32 3a 70 72 6f 70 61 67 61  gleton 2:propaga
1af0: 74 65 64 20 2a 2f 0a 29 7b 0a 20 20 69 6e 74 20  ted */.){.  int 
1b00: 72 69 64 3b 0a 20 20 69 6e 74 20 6e 72 69 64 3b  rid;.  int nrid;
1b10: 0a 20 20 63 68 61 72 20 2a 7a 44 61 74 65 3b 0a  .  char *zDate;.
1b20: 20 20 42 6c 6f 62 20 75 75 69 64 3b 0a 20 20 42    Blob uuid;.  B
1b30: 6c 6f 62 20 63 74 72 6c 3b 0a 20 20 42 6c 6f 62  lob ctrl;.  Blob
1b40: 20 63 6b 73 75 6d 3b 0a 20 20 73 74 61 74 69 63   cksum;.  static
1b50: 20 63 6f 6e 73 74 20 63 68 61 72 20 7a 54 61 67   const char zTag
1b60: 74 79 70 65 5b 5d 20 3d 20 7b 20 27 2d 27 2c 20  type[] = { '-', 
1b70: 27 2b 27 2c 20 27 2a 27 20 7d 3b 0a 0a 20 20 61  '+', '*' };..  a
1b80: 73 73 65 72 74 28 20 74 61 67 74 79 70 65 3e 3d  ssert( tagtype>=
1b90: 30 20 26 26 20 74 61 67 74 79 70 65 3c 3d 32 20  0 && tagtype<=2 
1ba0: 29 3b 0a 20 20 75 73 65 72 5f 73 65 6c 65 63 74  );.  user_select
1bb0: 28 29 3b 0a 20 20 72 69 64 20 3d 20 6e 61 6d 65  ();.  rid = name
1bc0: 5f 74 6f 5f 72 69 64 28 7a 4f 62 6a 4e 61 6d 65  _to_rid(zObjName
1bd0: 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26  );.  blob_zero(&
1be0: 75 75 69 64 29 3b 0a 20 20 64 62 5f 62 6c 6f 62  uuid);.  db_blob
1bf0: 28 26 75 75 69 64 2c 20 22 53 45 4c 45 43 54 20  (&uuid, "SELECT 
1c00: 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62 20 57  uuid FROM blob W
1c10: 48 45 52 45 20 72 69 64 3d 25 64 22 2c 20 72 69  HERE rid=%d", ri
1c20: 64 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28  d);.  blob_zero(
1c30: 26 63 74 72 6c 29 3b 0a 20 20 0a 20 20 69 66 28  &ctrl);.  .  if(
1c40: 20 76 61 6c 69 64 61 74 65 31 36 28 7a 54 61 67   validate16(zTag
1c50: 6e 61 6d 65 2c 20 73 74 72 6c 65 6e 28 7a 54 61  name, strlen(zTa
1c60: 67 6e 61 6d 65 29 29 20 29 7b 0a 20 20 20 20 66  gname)) ){.    f
1c70: 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 69 6e 76  ossil_fatal("inv
1c80: 61 6c 69 64 20 74 61 67 20 6e 61 6d 65 20 5c 22  alid tag name \"
1c90: 25 73 5c 22 20 2d 20 6d 69 67 68 74 20 62 65 20  %s\" - might be 
1ca0: 63 6f 6e 66 75 73 65 64 20 77 69 74 68 20 61 20  confused with a 
1cb0: 55 55 49 44 22 2c 0a 20 20 20 20 20 20 20 20 20  UUID",.         
1cc0: 20 20 20 20 20 20 20 20 7a 54 61 67 6e 61 6d 65          zTagname
1cd0: 29 3b 0a 20 20 7d 0a 20 20 7a 44 61 74 65 20 3d  );.  }.  zDate =
1ce0: 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 45 4c   db_text(0, "SEL
1cf0: 45 43 54 20 64 61 74 65 74 69 6d 65 28 27 6e 6f  ECT datetime('no
1d00: 77 27 29 22 29 3b 0a 20 20 7a 44 61 74 65 5b 31  w')");.  zDate[1
1d10: 30 5d 20 3d 20 27 54 27 3b 0a 20 20 62 6c 6f 62  0] = 'T';.  blob
1d20: 5f 61 70 70 65 6e 64 66 28 26 63 74 72 6c 2c 20  _appendf(&ctrl, 
1d30: 22 44 20 25 73 5c 6e 22 2c 20 7a 44 61 74 65 29  "D %s\n", zDate)
1d40: 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66  ;.  blob_appendf
1d50: 28 26 63 74 72 6c 2c 20 22 54 20 25 63 25 46 20  (&ctrl, "T %c%F 
1d60: 25 62 22 2c 20 7a 54 61 67 74 79 70 65 5b 74 61  %b", zTagtype[ta
1d70: 67 74 79 70 65 5d 2c 20 7a 54 61 67 6e 61 6d 65  gtype], zTagname
1d80: 2c 20 26 75 75 69 64 29 3b 0a 20 20 69 66 28 20  , &uuid);.  if( 
1d90: 74 61 67 74 79 70 65 20 26 26 20 7a 56 61 6c 75  tagtype && zValu
1da0: 65 20 26 26 20 7a 56 61 6c 75 65 5b 30 5d 20 29  e && zValue[0] )
1db0: 7b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e  {.    blob_appen
1dc0: 64 66 28 26 63 74 72 6c 2c 20 22 20 25 46 5c 6e  df(&ctrl, " %F\n
1dd0: 22 2c 20 7a 56 61 6c 75 65 29 3b 0a 20 20 7d 65  ", zValue);.  }e
1de0: 6c 73 65 7b 0a 20 20 20 20 62 6c 6f 62 5f 61 70  lse{.    blob_ap
1df0: 70 65 6e 64 66 28 26 63 74 72 6c 2c 20 22 5c 6e  pendf(&ctrl, "\n
1e00: 22 29 3b 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f 61  ");.  }.  blob_a
1e10: 70 70 65 6e 64 66 28 26 63 74 72 6c 2c 20 22 55  ppendf(&ctrl, "U
1e20: 20 25 46 5c 6e 22 2c 20 67 2e 7a 4c 6f 67 69 6e   %F\n", g.zLogin
1e30: 29 3b 0a 20 20 6d 64 35 73 75 6d 5f 62 6c 6f 62  );.  md5sum_blob
1e40: 28 26 63 74 72 6c 2c 20 26 63 6b 73 75 6d 29 3b  (&ctrl, &cksum);
1e50: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28  .  blob_appendf(
1e60: 26 63 74 72 6c 2c 20 22 5a 20 25 62 5c 6e 22 2c  &ctrl, "Z %b\n",
1e70: 20 26 63 6b 73 75 6d 29 3b 0a 20 20 64 62 5f 62   &cksum);.  db_b
1e80: 65 67 69 6e 5f 74 72 61 6e 73 61 63 74 69 6f 6e  egin_transaction
1e90: 28 29 3b 0a 20 20 6e 72 69 64 20 3d 20 63 6f 6e  ();.  nrid = con
1ea0: 74 65 6e 74 5f 70 75 74 28 26 63 74 72 6c 2c 20  tent_put(&ctrl, 
1eb0: 30 2c 20 30 29 3b 0a 20 20 6d 61 6e 69 66 65 73  0, 0);.  manifes
1ec0: 74 5f 63 72 6f 73 73 6c 69 6e 6b 28 6e 72 69 64  t_crosslink(nrid
1ed0: 2c 20 26 63 74 72 6c 29 3b 0a 20 20 64 62 5f 65  , &ctrl);.  db_e
1ee0: 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30  nd_transaction(0
1ef0: 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d  );.}../*.** COMM
1f00: 41 4e 44 3a 20 74 61 67 0a 2a 2a 20 55 73 61 67  AND: tag.** Usag
1f10: 65 3a 20 25 66 6f 73 73 69 6c 20 74 61 67 20 53  e: %fossil tag S
1f20: 55 42 43 4f 4d 4d 41 4e 44 20 2e 2e 2e 0a 2a 2a  UBCOMMAND ....**
1f30: 0a 2a 2a 20 52 75 6e 20 76 61 72 69 6f 75 73 20  .** Run various 
1f40: 73 75 62 63 6f 6d 6d 61 6e 64 73 20 74 6f 20 63  subcommands to c
1f50: 6f 6e 74 72 6f 6c 20 74 61 67 73 20 61 6e 64 20  ontrol tags and 
1f60: 70 72 6f 70 65 72 74 69 65 73 0a 2a 2a 0a 2a 2a  properties.**.**
1f70: 20 20 20 20 20 25 66 6f 73 73 69 6c 20 74 61 67       %fossil tag
1f80: 20 61 64 64 20 54 41 47 4e 41 4d 45 20 55 55 49   add TAGNAME UUI
1f90: 44 20 3f 56 41 4c 55 45 3f 0a 2a 2a 0a 2a 2a 20  D ?VALUE?.**.** 
1fa0: 20 20 20 20 20 20 20 20 41 64 64 20 61 20 6e 65          Add a ne
1fb0: 77 20 74 61 67 20 6f 72 20 70 72 6f 70 65 72 74  w tag or propert
1fc0: 79 20 74 6f 20 55 55 49 44 2e 0a 2a 2a 0a 2a 2a  y to UUID..**.**
1fd0: 20 20 20 20 20 25 66 6f 73 73 69 6c 20 74 61 67       %fossil tag
1fe0: 20 62 72 61 6e 63 68 20 54 41 47 4e 41 4d 45 20   branch TAGNAME 
1ff0: 55 55 49 44 20 3f 56 41 4c 55 45 3f 0a 2a 2a 0a  UUID ?VALUE?.**.
2000: 2a 2a 20 20 20 20 20 20 20 20 20 41 64 64 20 61  **         Add a
2010: 20 6e 65 77 20 74 61 67 20 6f 72 20 70 72 6f 70   new tag or prop
2020: 65 72 74 79 20 74 6f 20 55 55 49 44 20 61 6e 64  erty to UUID and
2030: 20 6d 61 6b 65 20 74 68 61 74 0a 2a 2a 20 20 20   make that.**   
2040: 20 20 20 20 20 20 74 61 67 20 70 72 6f 70 61 67        tag propag
2050: 61 74 65 20 74 6f 20 61 6c 6c 20 64 69 72 65 63  ate to all direc
2060: 74 20 63 68 69 6c 64 72 65 6e 2e 0a 2a 2a 0a 2a  t children..**.*
2070: 2a 20 20 20 20 20 25 66 6f 73 73 69 6c 20 74 61  *     %fossil ta
2080: 67 20 64 65 6c 65 74 65 20 54 41 47 4e 41 4d 45  g delete TAGNAME
2090: 20 55 55 49 44 0a 2a 2a 0a 2a 2a 20 20 20 20 20   UUID.**.**     
20a0: 20 20 20 20 44 65 6c 65 74 65 20 74 68 65 20 74      Delete the t
20b0: 61 67 20 54 41 47 4e 41 4d 45 20 66 72 6f 6d 20  ag TAGNAME from 
20c0: 55 55 49 44 0a 2a 2a 0a 2a 2a 20 20 20 20 20 25  UUID.**.**     %
20d0: 66 6f 73 73 69 6c 20 74 61 67 20 66 69 6e 64 20  fossil tag find 
20e0: 54 41 47 4e 41 4d 45 0a 2a 2a 0a 2a 2a 20 20 20  TAGNAME.**.**   
20f0: 20 20 20 20 20 20 4c 69 73 74 20 61 6c 6c 20 62        List all b
2100: 61 73 65 6c 69 6e 65 73 20 74 68 61 74 20 75 73  aselines that us
2110: 65 20 54 41 47 4e 41 4d 45 0a 2a 2a 0a 2a 2a 20  e TAGNAME.**.** 
2120: 20 20 20 20 25 66 6f 73 73 69 6c 20 74 61 67 20      %fossil tag 
2130: 6c 69 73 74 20 3f 55 55 49 44 3f 0a 2a 2a 0a 2a  list ?UUID?.**.*
2140: 2a 20 20 20 20 20 20 20 20 20 4c 69 73 74 20 61  *         List a
2150: 6c 6c 20 74 61 67 73 2c 20 6f 72 20 69 66 20 55  ll tags, or if U
2160: 55 49 44 20 69 73 20 73 75 70 70 6c 69 65 64 2c  UID is supplied,
2170: 20 6c 69 73 74 0a 2a 2a 20 20 20 20 20 20 20 20   list.**        
2180: 20 61 6c 6c 20 74 61 67 73 20 61 6e 64 20 74 68   all tags and th
2190: 65 69 72 20 76 61 6c 75 65 73 20 66 6f 72 20 55  eir values for U
21a0: 55 49 44 2e 0a 2a 2f 0a 76 6f 69 64 20 74 61 67  UID..*/.void tag
21b0: 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 69 6e  _cmd(void){.  in
21c0: 74 20 6e 3b 0a 20 20 64 62 5f 66 69 6e 64 5f 61  t n;.  db_find_a
21d0: 6e 64 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f  nd_open_reposito
21e0: 72 79 28 29 3b 0a 20 20 69 66 28 20 67 2e 61 72  ry();.  if( g.ar
21f0: 67 63 3c 33 20 29 7b 0a 20 20 20 20 67 6f 74 6f  gc<3 ){.    goto
2200: 20 74 61 67 5f 63 6d 64 5f 75 73 61 67 65 3b 0a   tag_cmd_usage;.
2210: 20 20 7d 0a 20 20 6e 20 3d 20 73 74 72 6c 65 6e    }.  n = strlen
2220: 28 67 2e 61 72 67 76 5b 32 5d 29 3b 0a 20 20 69  (g.argv[2]);.  i
2230: 66 28 20 6e 3d 3d 30 20 29 7b 0a 20 20 20 20 67  f( n==0 ){.    g
2240: 6f 74 6f 20 74 61 67 5f 63 6d 64 5f 75 73 61 67  oto tag_cmd_usag
2250: 65 3b 0a 20 20 7d 0a 0a 20 20 69 66 28 20 73 74  e;.  }..  if( st
2260: 72 6e 63 6d 70 28 67 2e 61 72 67 76 5b 32 5d 2c  rncmp(g.argv[2],
2270: 22 61 64 64 22 2c 6e 29 3d 3d 30 20 29 7b 0a 20  "add",n)==0 ){. 
2280: 20 20 20 63 68 61 72 20 2a 7a 56 61 6c 75 65 3b     char *zValue;
2290: 0a 20 20 20 20 69 66 28 20 67 2e 61 72 67 63 21  .    if( g.argc!
22a0: 3d 35 20 26 26 20 67 2e 61 72 67 63 21 3d 36 20  =5 && g.argc!=6 
22b0: 29 7b 0a 20 20 20 20 20 20 75 73 61 67 65 28 22  ){.      usage("
22c0: 74 61 67 20 61 64 64 20 54 41 47 4e 41 4d 45 20  tag add TAGNAME 
22d0: 55 55 49 44 20 3f 56 41 4c 55 45 3f 22 29 3b 0a  UUID ?VALUE?");.
22e0: 20 20 20 20 7d 0a 20 20 20 20 7a 56 61 6c 75 65      }.    zValue
22f0: 20 3d 20 67 2e 61 72 67 63 3d 3d 36 20 3f 20 67   = g.argc==6 ? g
2300: 2e 61 72 67 76 5b 35 5d 20 3a 20 30 3b 0a 20 20  .argv[5] : 0;.  
2310: 20 20 74 61 67 5f 61 64 64 5f 61 72 74 69 66 61    tag_add_artifa
2320: 63 74 28 67 2e 61 72 67 76 5b 33 5d 2c 20 67 2e  ct(g.argv[3], g.
2330: 61 72 67 76 5b 34 5d 2c 20 7a 56 61 6c 75 65 2c  argv[4], zValue,
2340: 20 31 29 3b 0a 20 20 7d 65 6c 73 65 0a 0a 20 20   1);.  }else..  
2350: 69 66 28 20 73 74 72 6e 63 6d 70 28 67 2e 61 72  if( strncmp(g.ar
2360: 67 76 5b 32 5d 2c 22 62 72 61 6e 63 68 22 2c 6e  gv[2],"branch",n
2370: 29 3d 3d 30 20 29 7b 0a 20 20 20 20 63 68 61 72  )==0 ){.    char
2380: 20 2a 7a 56 61 6c 75 65 3b 0a 20 20 20 20 69 66   *zValue;.    if
2390: 28 20 67 2e 61 72 67 63 21 3d 35 20 26 26 20 67  ( g.argc!=5 && g
23a0: 2e 61 72 67 63 21 3d 36 20 29 7b 0a 20 20 20 20  .argc!=6 ){.    
23b0: 20 20 75 73 61 67 65 28 22 74 61 67 20 62 72 61    usage("tag bra
23c0: 6e 63 68 20 54 41 47 4e 41 4d 45 20 55 55 49 44  nch TAGNAME UUID
23d0: 20 3f 56 41 4c 55 45 3f 22 29 3b 0a 20 20 20 20   ?VALUE?");.    
23e0: 7d 0a 20 20 20 20 7a 56 61 6c 75 65 20 3d 20 67  }.    zValue = g
23f0: 2e 61 72 67 63 3d 3d 36 20 3f 20 67 2e 61 72 67  .argc==6 ? g.arg
2400: 76 5b 35 5d 20 3a 20 30 3b 0a 20 20 20 20 74 61  v[5] : 0;.    ta
2410: 67 5f 61 64 64 5f 61 72 74 69 66 61 63 74 28 67  g_add_artifact(g
2420: 2e 61 72 67 76 5b 33 5d 2c 20 67 2e 61 72 67 76  .argv[3], g.argv
2430: 5b 34 5d 2c 20 7a 56 61 6c 75 65 2c 20 32 29 3b  [4], zValue, 2);
2440: 0a 20 20 7d 65 6c 73 65 0a 0a 20 20 69 66 28 20  .  }else..  if( 
2450: 73 74 72 6e 63 6d 70 28 67 2e 61 72 67 76 5b 32  strncmp(g.argv[2
2460: 5d 2c 22 64 65 6c 65 74 65 22 2c 6e 29 3d 3d 30  ],"delete",n)==0
2470: 20 29 7b 0a 20 20 20 20 69 66 28 20 67 2e 61 72   ){.    if( g.ar
2480: 67 63 21 3d 35 20 29 7b 0a 20 20 20 20 20 20 75  gc!=5 ){.      u
2490: 73 61 67 65 28 22 74 61 67 20 64 65 6c 65 74 65  sage("tag delete
24a0: 20 54 41 47 4e 41 4d 45 20 55 55 49 44 22 29 3b   TAGNAME UUID");
24b0: 0a 20 20 20 20 7d 0a 20 20 20 20 74 61 67 5f 61  .    }.    tag_a
24c0: 64 64 5f 61 72 74 69 66 61 63 74 28 67 2e 61 72  dd_artifact(g.ar
24d0: 67 76 5b 33 5d 2c 20 67 2e 61 72 67 76 5b 34 5d  gv[3], g.argv[4]
24e0: 2c 20 30 2c 20 30 29 3b 0a 20 20 7d 65 6c 73 65  , 0, 0);.  }else
24f0: 0a 0a 20 20 69 66 28 20 73 74 72 6e 63 6d 70 28  ..  if( strncmp(
2500: 67 2e 61 72 67 76 5b 32 5d 2c 22 66 69 6e 64 22  g.argv[2],"find"
2510: 2c 6e 29 3d 3d 30 20 29 7b 0a 20 20 20 20 53 74  ,n)==0 ){.    St
2520: 6d 74 20 71 3b 0a 20 20 20 20 69 66 28 20 67 2e  mt q;.    if( g.
2530: 61 72 67 63 21 3d 34 20 29 7b 0a 20 20 20 20 20  argc!=4 ){.     
2540: 20 75 73 61 67 65 28 22 74 61 67 20 66 69 6e 64   usage("tag find
2550: 20 54 41 47 4e 41 4d 45 22 29 3b 0a 20 20 20 20   TAGNAME");.    
2560: 7d 0a 20 20 20 20 64 62 5f 70 72 65 70 61 72 65  }.    db_prepare
2570: 28 26 71 2c 0a 20 20 20 20 20 20 22 53 45 4c 45  (&q,.      "SELE
2580: 43 54 20 62 6c 6f 62 2e 75 75 69 64 20 46 52 4f  CT blob.uuid FRO
2590: 4d 20 74 61 67 78 72 65 66 2c 20 62 6c 6f 62 22  M tagxref, blob"
25a0: 0a 20 20 20 20 20 20 22 20 57 48 45 52 45 20 74  .      " WHERE t
25b0: 61 67 69 64 3d 28 53 45 4c 45 43 54 20 74 61 67  agid=(SELECT tag
25c0: 69 64 20 46 52 4f 4d 20 74 61 67 20 57 48 45 52  id FROM tag WHER
25d0: 45 20 74 61 67 6e 61 6d 65 3d 25 51 29 22 0a 20  E tagname=%Q)". 
25e0: 20 20 20 20 20 22 20 20 20 41 4e 44 20 62 6c 6f       "   AND blo
25f0: 62 2e 72 69 64 3d 74 61 67 78 72 65 66 2e 72 69  b.rid=tagxref.ri
2600: 64 22 2c 20 67 2e 61 72 67 76 5b 33 5d 0a 20 20  d", g.argv[3].  
2610: 20 20 29 3b 0a 20 20 20 20 77 68 69 6c 65 28 20    );.    while( 
2620: 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c  db_step(&q)==SQL
2630: 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 20  ITE_ROW ){.     
2640: 20 70 72 69 6e 74 66 28 22 25 73 5c 6e 22 2c 20   printf("%s\n", 
2650: 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26  db_column_text(&
2660: 71 2c 20 30 29 29 3b 0a 20 20 20 20 7d 0a 20 20  q, 0));.    }.  
2670: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71    db_finalize(&q
2680: 29 3b 0a 20 20 7d 65 6c 73 65 0a 0a 20 20 69 66  );.  }else..  if
2690: 28 20 73 74 72 6e 63 6d 70 28 67 2e 61 72 67 76  ( strncmp(g.argv
26a0: 5b 32 5d 2c 22 6c 69 73 74 22 2c 6e 29 3d 3d 30  [2],"list",n)==0
26b0: 20 29 7b 0a 20 20 20 20 53 74 6d 74 20 71 3b 0a   ){.    Stmt q;.
26c0: 20 20 20 20 69 66 28 20 67 2e 61 72 67 63 3d 3d      if( g.argc==
26d0: 33 20 29 7b 0a 20 20 20 20 20 20 64 62 5f 70 72  3 ){.      db_pr
26e0: 65 70 61 72 65 28 26 71 2c 20 0a 20 20 20 20 20  epare(&q, .     
26f0: 20 20 20 22 53 45 4c 45 43 54 20 74 61 67 6e 61     "SELECT tagna
2700: 6d 65 22 0a 20 20 20 20 20 20 20 20 22 20 20 46  me".        "  F
2710: 52 4f 4d 20 74 61 67 22 0a 20 20 20 20 20 20 20  ROM tag".       
2720: 20 22 20 57 48 45 52 45 20 45 58 49 53 54 53 28   " WHERE EXISTS(
2730: 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 74 61  SELECT 1 FROM ta
2740: 67 78 72 65 66 22 0a 20 20 20 20 20 20 20 20 22  gxref".        "
2750: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 57                 W
2760: 48 45 52 45 20 74 61 67 69 64 3d 74 61 67 2e 74  HERE tagid=tag.t
2770: 61 67 69 64 22 0a 20 20 20 20 20 20 20 20 22 20  agid".        " 
2780: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2790: 41 4e 44 20 74 61 67 74 79 70 65 3e 30 29 22 0a  AND tagtype>0)".
27a0: 20 20 20 20 20 20 20 20 22 20 4f 52 44 45 52 20          " ORDER 
27b0: 42 59 20 74 61 67 6e 61 6d 65 22 0a 20 20 20 20  BY tagname".    
27c0: 20 20 29 3b 0a 20 20 20 20 20 20 77 68 69 6c 65    );.      while
27d0: 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53  ( db_step(&q)==S
27e0: 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20  QLITE_ROW ){.   
27f0: 20 20 20 20 20 70 72 69 6e 74 66 28 22 25 73 5c       printf("%s\
2800: 6e 22 2c 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65  n", db_column_te
2810: 78 74 28 26 71 2c 20 30 29 29 3b 0a 20 20 20 20  xt(&q, 0));.    
2820: 20 20 7d 0a 20 20 20 20 20 20 64 62 5f 66 69 6e    }.      db_fin
2830: 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 20 20 7d  alize(&q);.    }
2840: 65 6c 73 65 20 69 66 28 20 67 2e 61 72 67 63 3d  else if( g.argc=
2850: 3d 34 20 29 7b 0a 20 20 20 20 20 20 69 6e 74 20  =4 ){.      int 
2860: 72 69 64 20 3d 20 6e 61 6d 65 5f 74 6f 5f 72 69  rid = name_to_ri
2870: 64 28 67 2e 61 72 67 76 5b 33 5d 29 3b 0a 20 20  d(g.argv[3]);.  
2880: 20 20 20 20 64 62 5f 70 72 65 70 61 72 65 28 26      db_prepare(&
2890: 71 2c 0a 20 20 20 20 20 20 20 20 22 53 45 4c 45  q,.        "SELE
28a0: 43 54 20 74 61 67 6e 61 6d 65 2c 20 76 61 6c 75  CT tagname, valu
28b0: 65 22 0a 20 20 20 20 20 20 20 20 22 20 20 46 52  e".        "  FR
28c0: 4f 4d 20 74 61 67 78 72 65 66 2c 20 74 61 67 22  OM tagxref, tag"
28d0: 0a 20 20 20 20 20 20 20 20 22 20 57 48 45 52 45  .        " WHERE
28e0: 20 74 61 67 78 72 65 66 2e 72 69 64 3d 25 64 20   tagxref.rid=%d 
28f0: 41 4e 44 20 74 61 67 78 72 65 66 2e 74 61 67 69  AND tagxref.tagi
2900: 64 3d 74 61 67 2e 74 61 67 69 64 22 0a 20 20 20  d=tag.tagid".   
2910: 20 20 20 20 20 22 20 20 20 41 4e 44 20 74 61 67       "   AND tag
2920: 74 79 70 65 3e 30 22 0a 20 20 20 20 20 20 20 20  type>0".        
2930: 22 20 4f 52 44 45 52 20 42 59 20 74 61 67 6e 61  " ORDER BY tagna
2940: 6d 65 22 2c 0a 20 20 20 20 20 20 20 20 72 69 64  me",.        rid
2950: 0a 20 20 20 20 20 20 29 3b 0a 20 20 20 20 20 20  .      );.      
2960: 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26  while( db_step(&
2970: 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29  q)==SQLITE_ROW )
2980: 7b 0a 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20  {.        const 
2990: 63 68 61 72 20 2a 7a 4e 61 6d 65 20 3d 20 64 62  char *zName = db
29a0: 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c  _column_text(&q,
29b0: 20 30 29 3b 0a 20 20 20 20 20 20 20 20 63 6f 6e   0);.        con
29c0: 73 74 20 63 68 61 72 20 2a 7a 56 61 6c 75 65 20  st char *zValue 
29d0: 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74  = db_column_text
29e0: 28 26 71 2c 20 31 29 3b 0a 20 20 20 20 20 20 20  (&q, 1);.       
29f0: 20 69 66 28 20 7a 56 61 6c 75 65 20 29 7b 0a 20   if( zValue ){. 
2a00: 20 20 20 20 20 20 20 20 20 70 72 69 6e 74 66 28           printf(
2a10: 22 25 73 3d 25 73 5c 6e 22 2c 20 7a 4e 61 6d 65  "%s=%s\n", zName
2a20: 2c 20 7a 56 61 6c 75 65 29 3b 0a 20 20 20 20 20  , zValue);.     
2a30: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20     }else{.      
2a40: 20 20 20 20 70 72 69 6e 74 66 28 22 25 73 5c 6e      printf("%s\n
2a50: 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20  ", zName);.     
2a60: 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a 20 20 20     }.      }.   
2a70: 20 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26     db_finalize(&
2a80: 71 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20  q);.    }else{. 
2a90: 20 20 20 20 20 75 73 61 67 65 28 22 74 61 67 20       usage("tag 
2aa0: 6c 69 73 74 20 3f 55 55 49 44 3f 22 29 3b 0a 20  list ?UUID?");. 
2ab0: 20 20 20 7d 0a 20 20 7d 65 6c 73 65 0a 20 20 7b     }.  }else.  {
2ac0: 0a 20 20 20 20 67 6f 74 6f 20 74 61 67 5f 63 6d  .    goto tag_cm
2ad0: 64 5f 75 73 61 67 65 3b 0a 20 20 7d 0a 20 20 72  d_usage;.  }.  r
2ae0: 65 74 75 72 6e 3b 0a 0a 74 61 67 5f 63 6d 64 5f  eturn;..tag_cmd_
2af0: 75 73 61 67 65 3a 0a 20 20 75 73 61 67 65 28 22  usage:.  usage("
2b00: 61 64 64 7c 62 72 61 6e 63 68 7c 64 65 6c 65 74  add|branch|delet
2b10: 65 7c 66 69 6e 64 7c 6c 69 73 74 20 2e 2e 2e 22  e|find|list ..."
2b20: 29 3b 0a 7d 0a                                   );.}.