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 6e 74 20 72 63 3b 0a 0a 20 20 69 ;. int rc;.. i
1270: 66 28 20 6d 74 69 6d 65 3c 3d 30 2e 30 20 29 7b f( mtime<=0.0 ){
1280: 0a 20 20 20 20 6d 74 69 6d 65 20 3d 20 64 62 5f . mtime = db_
1290: 64 6f 75 62 6c 65 28 30 2e 30 2c 20 22 53 45 4c double(0.0, "SEL
12a0: 45 43 54 20 6a 75 6c 69 61 6e 64 61 79 28 27 6e ECT julianday('n
12b0: 6f 77 27 29 22 29 3b 0a 20 20 7d 0a 20 20 64 62 ow')");. }. db
12c0: 5f 70 72 65 70 61 72 65 28 26 73 2c 0a 20 20 20 _prepare(&s,.
12d0: 20 22 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 "SELECT 1 FROM
12e0: 74 61 67 78 72 65 66 22 0a 20 20 20 20 22 20 57 tagxref". " W
12f0: 48 45 52 45 20 74 61 67 69 64 3d 25 64 22 0a 20 HERE tagid=%d".
1300: 20 20 20 22 20 20 20 41 4e 44 20 72 69 64 3d 25 " AND rid=%
1310: 64 22 0a 20 20 20 20 22 20 20 20 41 4e 44 20 6d d". " AND m
1320: 74 69 6d 65 3e 3d 3a 6d 74 69 6d 65 22 2c 0a 20 time>=:mtime",.
1330: 20 20 20 74 61 67 69 64 2c 20 72 69 64 0a 20 20 tagid, rid.
1340: 29 3b 0a 20 20 64 62 5f 62 69 6e 64 5f 64 6f 75 );. db_bind_dou
1350: 62 6c 65 28 26 73 2c 20 22 3a 6d 74 69 6d 65 22 ble(&s, ":mtime"
1360: 2c 20 6d 74 69 6d 65 29 3b 0a 20 20 72 63 20 3d , mtime);. rc =
1370: 20 64 62 5f 73 74 65 70 28 26 73 29 3b 0a 20 20 db_step(&s);.
1380: 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 73 29 3b db_finalize(&s);
1390: 0a 20 20 69 66 28 20 72 63 3d 3d 53 51 4c 49 54 . if( rc==SQLIT
13a0: 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 2f 2a 20 E_ROW ){. /*
13b0: 41 6e 6f 74 68 65 72 20 65 6e 74 72 79 20 74 68 Another entry th
13c0: 69 73 20 69 73 20 6d 6f 72 65 20 72 65 63 65 6e is is more recen
13d0: 74 20 61 6c 72 65 61 64 79 20 65 78 69 73 74 73 t already exists
13e0: 2e 20 20 44 6f 20 6e 6f 74 68 69 6e 67 20 2a 2f . Do nothing */
13f0: 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 7d . return;. }
1400: 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 73 . db_prepare(&s
1410: 2c 20 0a 20 20 20 20 22 52 45 50 4c 41 43 45 20 , . "REPLACE
1420: 49 4e 54 4f 20 74 61 67 78 72 65 66 28 74 61 67 INTO tagxref(tag
1430: 69 64 2c 74 61 67 74 79 70 65 2c 73 72 63 49 64 id,tagtype,srcId
1440: 2c 76 61 6c 75 65 2c 6d 74 69 6d 65 2c 72 69 64 ,value,mtime,rid
1450: 29 22 0a 20 20 20 20 22 20 56 41 4c 55 45 53 28 )". " VALUES(
1460: 25 64 2c 25 64 2c 25 64 2c 25 51 2c 3a 6d 74 69 %d,%d,%d,%Q,:mti
1470: 6d 65 2c 25 64 29 22 2c 0a 20 20 20 20 74 61 67 me,%d)",. tag
1480: 69 64 2c 20 74 61 67 74 79 70 65 2c 20 73 72 63 id, tagtype, src
1490: 49 64 2c 20 7a 56 61 6c 75 65 2c 20 72 69 64 0a Id, zValue, rid.
14a0: 20 20 29 3b 0a 20 20 64 62 5f 62 69 6e 64 5f 64 );. db_bind_d
14b0: 6f 75 62 6c 65 28 26 73 2c 20 22 3a 6d 74 69 6d ouble(&s, ":mtim
14c0: 65 22 2c 20 6d 74 69 6d 65 29 3b 0a 20 20 64 62 e", mtime);. db
14d0: 5f 73 74 65 70 28 26 73 29 3b 0a 20 20 64 62 5f _step(&s);. db_
14e0: 66 69 6e 61 6c 69 7a 65 28 26 73 29 3b 0a 20 20 finalize(&s);.
14f0: 69 66 28 20 74 61 67 74 79 70 65 3d 3d 30 20 29 if( tagtype==0 )
1500: 7b 0a 20 20 20 20 7a 56 61 6c 75 65 20 3d 20 30 {. zValue = 0
1510: 3b 0a 20 20 7d 0a 20 20 7a 43 6f 6c 20 3d 20 30 ;. }. zCol = 0
1520: 3b 0a 20 20 73 77 69 74 63 68 28 20 74 61 67 69 ;. switch( tagi
1530: 64 20 29 7b 0a 20 20 20 20 63 61 73 65 20 54 41 d ){. case TA
1540: 47 5f 42 47 43 4f 4c 4f 52 3a 20 7b 0a 20 20 20 G_BGCOLOR: {.
1550: 20 20 20 69 66 28 20 74 61 67 74 79 70 65 3d 3d if( tagtype==
1560: 31 20 29 7b 0a 20 20 20 20 20 20 20 20 7a 43 6f 1 ){. zCo
1570: 6c 20 3d 20 22 62 67 63 6f 6c 6f 72 22 3b 0a 20 l = "bgcolor";.
1580: 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 }else{.
1590: 20 20 20 20 7a 43 6f 6c 20 3d 20 22 62 72 62 67 zCol = "brbg
15a0: 63 6f 6c 6f 72 22 3b 0a 20 20 20 20 20 20 7d 0a color";. }.
15b0: 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 break;.
15c0: 20 7d 0a 20 20 20 20 63 61 73 65 20 54 41 47 5f }. case TAG_
15d0: 43 4f 4d 4d 45 4e 54 3a 20 7b 0a 20 20 20 20 20 COMMENT: {.
15e0: 20 7a 43 6f 6c 20 3d 20 22 65 63 6f 6d 6d 65 6e zCol = "ecommen
15f0: 74 22 3b 0a 20 20 20 20 20 20 62 72 65 61 6b 3b t";. break;
1600: 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 73 65 20 . }. case
1610: 54 41 47 5f 55 53 45 52 3a 20 7b 0a 20 20 20 20 TAG_USER: {.
1620: 20 20 7a 43 6f 6c 20 3d 20 22 65 75 73 65 72 22 zCol = "euser"
1630: 3b 0a 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 ;. break;.
1640: 20 20 20 7d 0a 20 20 7d 0a 20 20 69 66 28 20 7a }. }. if( z
1650: 43 6f 6c 20 29 7b 0a 20 20 20 20 64 62 5f 6d 75 Col ){. db_mu
1660: 6c 74 69 5f 65 78 65 63 28 22 55 50 44 41 54 45 lti_exec("UPDATE
1670: 20 65 76 65 6e 74 20 53 45 54 20 25 73 3d 25 51 event SET %s=%Q
1680: 20 57 48 45 52 45 20 6f 62 6a 69 64 3d 25 64 22 WHERE objid=%d"
1690: 2c 20 7a 43 6f 6c 2c 20 7a 56 61 6c 75 65 2c 20 , zCol, zValue,
16a0: 72 69 64 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 rid);. }. if(
16b0: 74 61 67 74 79 70 65 3d 3d 30 20 7c 7c 20 74 61 tagtype==0 || ta
16c0: 67 74 79 70 65 3d 3d 32 20 29 7b 0a 20 20 20 20 gtype==2 ){.
16d0: 74 61 67 5f 70 72 6f 70 61 67 61 74 65 28 72 69 tag_propagate(ri
16e0: 64 2c 20 74 61 67 69 64 2c 20 74 61 67 74 79 70 d, tagid, tagtyp
16f0: 65 2c 20 7a 56 61 6c 75 65 2c 20 6d 74 69 6d 65 e, zValue, mtime
1700: 29 3b 0a 20 20 7d 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a );. }.}.../*.**
1710: 20 43 4f 4d 4d 41 4e 44 3a 20 74 65 73 74 2d 74 COMMAND: test-t
1720: 61 67 0a 2a 2a 20 25 66 6f 73 73 69 6c 20 74 65 ag.** %fossil te
1730: 73 74 2d 74 61 67 20 28 2b 7c 2a 7c 2d 29 54 41 st-tag (+|*|-)TA
1740: 47 4e 41 4d 45 20 55 55 49 44 20 3f 56 41 4c 55 GNAME UUID ?VALU
1750: 45 3f 0a 2a 2a 0a 2a 2a 20 41 64 64 20 61 20 74 E?.**.** Add a t
1760: 61 67 20 6f 72 20 61 6e 74 69 2d 74 61 67 20 74 ag or anti-tag t
1770: 6f 20 74 68 65 20 72 65 62 75 69 6c 64 61 62 6c o the rebuildabl
1780: 65 20 74 61 62 6c 65 73 20 6f 66 20 74 68 65 20 e tables of the
1790: 6c 6f 63 61 6c 20 72 65 70 6f 73 69 74 6f 72 79 local repository
17a0: 2e 0a 2a 2a 20 4e 6f 20 74 61 67 20 61 72 74 69 ..** No tag arti
17b0: 66 61 63 74 20 69 73 20 63 72 65 61 74 65 64 20 fact is created
17c0: 73 6f 20 74 68 65 20 6e 65 77 20 74 61 67 20 69 so the new tag i
17d0: 73 20 65 72 61 73 65 64 20 74 68 65 20 6e 65 78 s erased the nex
17e0: 74 0a 2a 2a 20 74 69 6d 65 20 74 68 65 20 72 65 t.** time the re
17f0: 70 6f 73 69 74 6f 72 79 20 69 73 20 72 65 62 75 pository is rebu
1800: 69 6c 74 2e 20 20 54 68 69 73 20 72 6f 75 74 69 ilt. This routi
1810: 6e 65 20 69 73 20 66 6f 72 20 74 65 73 74 69 6e ne is for testin
1820: 67 0a 2a 2a 20 75 73 65 20 6f 6e 6c 79 2e 0a 2a g.** use only..*
1830: 2f 0a 76 6f 69 64 20 74 65 73 74 74 61 67 5f 63 /.void testtag_c
1840: 6d 64 28 76 6f 69 64 29 7b 0a 20 20 63 6f 6e 73 md(void){. cons
1850: 74 20 63 68 61 72 20 2a 7a 54 61 67 3b 0a 20 20 t char *zTag;.
1860: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 56 61 6c const char *zVal
1870: 75 65 3b 0a 20 20 69 6e 74 20 72 69 64 3b 0a 20 ue;. int rid;.
1880: 20 69 6e 74 20 74 61 67 74 79 70 65 3b 0a 20 20 int tagtype;.
1890: 64 62 5f 6d 75 73 74 5f 62 65 5f 77 69 74 68 69 db_must_be_withi
18a0: 6e 5f 74 72 65 65 28 29 3b 0a 20 20 69 66 28 20 n_tree();. if(
18b0: 67 2e 61 72 67 63 21 3d 34 20 26 26 20 67 2e 61 g.argc!=4 && g.a
18c0: 72 67 63 21 3d 35 20 29 7b 0a 20 20 20 20 75 73 rgc!=5 ){. us
18d0: 61 67 65 28 22 54 41 47 4e 41 4d 45 20 55 55 49 age("TAGNAME UUI
18e0: 44 20 3f 56 41 4c 55 45 3f 22 29 3b 0a 20 20 7d D ?VALUE?");. }
18f0: 0a 20 20 7a 54 61 67 20 3d 20 67 2e 61 72 67 76 . zTag = g.argv
1900: 5b 32 5d 3b 0a 20 20 73 77 69 74 63 68 28 20 7a [2];. switch( z
1910: 54 61 67 5b 30 5d 20 29 7b 0a 20 20 20 20 63 61 Tag[0] ){. ca
1920: 73 65 20 27 2b 27 3a 20 20 74 61 67 74 79 70 65 se '+': tagtype
1930: 20 3d 20 31 3b 20 20 62 72 65 61 6b 3b 0a 20 20 = 1; break;.
1940: 20 20 63 61 73 65 20 27 2a 27 3a 20 20 74 61 67 case '*': tag
1950: 74 79 70 65 20 3d 20 32 3b 20 20 62 72 65 61 6b type = 2; break
1960: 3b 0a 20 20 20 20 63 61 73 65 20 27 2d 27 3a 20 ;. case '-':
1970: 20 74 61 67 74 79 70 65 20 3d 20 30 3b 20 20 62 tagtype = 0; b
1980: 72 65 61 6b 3b 0a 20 20 20 20 64 65 66 61 75 6c reak;. defaul
1990: 74 3a 20 20 20 0a 20 20 20 20 20 20 66 6f 73 73 t: . foss
19a0: 69 6c 5f 66 61 74 61 6c 28 22 74 61 67 20 73 68 il_fatal("tag sh
19b0: 6f 75 6c 64 20 62 65 67 69 6e 20 77 69 74 68 20 ould begin with
19c0: 27 2b 27 2c 20 27 2a 27 2c 20 6f 72 20 27 2d 27 '+', '*', or '-'
19d0: 22 29 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e ");. return
19e0: 3b 0a 20 20 7d 0a 20 20 72 69 64 20 3d 20 6e 61 ;. }. rid = na
19f0: 6d 65 5f 74 6f 5f 72 69 64 28 67 2e 61 72 67 76 me_to_rid(g.argv
1a00: 5b 33 5d 29 3b 0a 20 20 69 66 28 20 72 69 64 3d [3]);. if( rid=
1a10: 3d 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c =0 ){. fossil
1a20: 5f 66 61 74 61 6c 28 22 6e 6f 20 73 75 63 68 20 _fatal("no such
1a30: 6f 62 6a 65 63 74 3a 20 25 73 22 2c 20 67 2e 61 object: %s", g.a
1a40: 72 67 76 5b 33 5d 29 3b 0a 20 20 7d 0a 20 20 7a rgv[3]);. }. z
1a50: 56 61 6c 75 65 20 3d 20 67 2e 61 72 67 63 3d 3d Value = g.argc==
1a60: 35 20 3f 20 67 2e 61 72 67 76 5b 34 5d 20 3a 20 5 ? g.argv[4] :
1a70: 30 3b 0a 20 20 64 62 5f 62 65 67 69 6e 5f 74 72 0;. db_begin_tr
1a80: 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a 20 20 74 ansaction();. t
1a90: 61 67 5f 69 6e 73 65 72 74 28 7a 54 61 67 2c 20 ag_insert(zTag,
1aa0: 74 61 67 74 79 70 65 2c 20 7a 56 61 6c 75 65 2c tagtype, zValue,
1ab0: 20 2d 31 2c 20 30 2e 30 2c 20 72 69 64 29 3b 0a -1, 0.0, rid);.
1ac0: 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 db_end_transac
1ad0: 74 69 6f 6e 28 30 29 3b 20 0a 7d 0a 0a 2f 2a 0a tion(0); .}../*.
1ae0: 2a 2a 20 50 72 65 70 61 72 65 20 61 6e 20 61 72 ** Prepare an ar
1af0: 74 69 66 61 63 74 20 74 68 61 74 20 64 65 73 63 tifact that desc
1b00: 72 69 62 65 73 20 61 20 66 6f 72 6b 20 66 72 6f ribes a fork fro
1b10: 6d 20 61 20 63 65 72 74 61 69 6e 20 55 55 49 44 m a certain UUID
1b20: 2e 0a 2a 2a 20 46 75 72 74 68 65 72 6d 6f 72 65 ..** Furthermore
1b30: 20 61 20 70 72 6f 70 61 67 61 74 69 6e 67 20 73 a propagating s
1b40: 79 6d 62 6f 6c 69 63 20 74 61 67 20 77 69 6c 6c ymbolic tag will
1b50: 20 62 65 20 69 6e 73 65 72 74 65 64 20 61 6e 64 be inserted and
1b60: 0a 2a 2a 20 61 6c 6c 20 6f 74 68 65 72 20 70 72 .** all other pr
1b70: 6f 70 61 67 61 74 69 6e 67 20 73 79 6d 62 6f 6c opagating symbol
1b80: 69 63 20 74 61 67 73 20 77 69 6c 6c 20 62 65 20 ic tags will be
1b90: 63 61 6e 63 65 6c 6c 65 64 2e 0a 2a 2a 0a 2a 2a cancelled..**.**
1ba0: 20 54 68 65 20 63 68 61 6e 67 65 73 20 61 72 65 The changes are
1bb0: 20 61 70 70 65 6e 64 65 64 20 61 74 20 74 68 65 appended at the
1bc0: 20 42 6c 6f 62 20 70 43 74 72 6c 2e 20 48 6f 77 Blob pCtrl. How
1bd0: 65 76 65 72 20 74 68 65 20 6d 61 6e 69 66 65 73 ever the manifes
1be0: 74 0a 2a 2a 20 69 73 20 6e 6f 74 20 63 6f 6d 70 t.** is not comp
1bf0: 6c 65 74 65 20 61 74 20 74 68 61 74 20 73 74 61 lete at that sta
1c00: 67 65 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f ge..*/.static vo
1c10: 69 64 20 74 61 67 5f 70 72 65 70 61 72 65 5f 66 id tag_prepare_f
1c20: 6f 72 6b 28 0a 20 20 42 6c 6f 62 20 2a 70 43 74 ork(. Blob *pCt
1c30: 72 6c 2c 20 0a 20 20 63 6f 6e 73 74 20 63 68 61 rl, . const cha
1c40: 72 20 2a 7a 54 61 67 6e 61 6d 65 2c 0a 20 20 69 r *zTagname,. i
1c50: 6e 74 20 72 69 64 0a 29 7b 0a 20 20 53 74 6d 74 nt rid.){. Stmt
1c60: 20 71 3b 0a 20 20 4d 61 6e 69 66 65 73 74 20 6f q;. Manifest o
1c70: 72 69 67 69 6e 3b 0a 20 20 42 6c 6f 62 20 6f 72 rigin;. Blob or
1c80: 69 67 69 6e 43 6f 6e 74 65 6e 74 3b 0a 20 20 63 iginContent;. c
1c90: 68 61 72 20 2a 7a 44 61 74 65 3b 0a 20 20 69 6e har *zDate;. in
1ca0: 74 20 69 3b 0a 0a 20 20 62 6c 6f 62 5f 61 70 70 t i;.. blob_app
1cb0: 65 6e 64 66 28 70 43 74 72 6c 2c 20 22 43 20 43 endf(pCtrl, "C C
1cc0: 72 65 61 74 65 5c 5c 73 6e 61 6d 65 64 5c 5c 73 reate\\snamed\\s
1cd0: 66 6f 72 6b 5c 5c 73 25 73 5c 6e 22 2c 20 7a 54 fork\\s%s\n", zT
1ce0: 61 67 6e 61 6d 65 2b 34 29 3b 0a 20 20 63 6f 6e agname+4);. con
1cf0: 74 65 6e 74 5f 67 65 74 28 72 69 64 2c 20 26 6f tent_get(rid, &o
1d00: 72 69 67 69 6e 43 6f 6e 74 65 6e 74 29 3b 0a 20 riginContent);.
1d10: 20 6d 61 6e 69 66 65 73 74 5f 70 61 72 73 65 28 manifest_parse(
1d20: 26 6f 72 69 67 69 6e 2c 20 26 6f 72 69 67 69 6e &origin, &origin
1d30: 43 6f 6e 74 65 6e 74 29 3b 0a 20 20 7a 44 61 74 Content);. zDat
1d40: 65 20 3d 20 64 62 5f 74 65 78 74 28 30 2c 20 22 e = db_text(0, "
1d50: 53 45 4c 45 43 54 20 64 61 74 65 74 69 6d 65 28 SELECT datetime(
1d60: 27 6e 6f 77 27 29 22 29 3b 0a 20 20 7a 44 61 74 'now')");. zDat
1d70: 65 5b 31 30 5d 20 3d 20 27 54 27 3b 0a 20 20 62 e[10] = 'T';. b
1d80: 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 43 74 72 lob_appendf(pCtr
1d90: 6c 2c 20 22 44 20 25 73 5c 6e 22 2c 20 7a 44 61 l, "D %s\n", zDa
1da0: 74 65 29 3b 0a 20 20 66 6f 72 28 69 3d 30 3b 20 te);. for(i=0;
1db0: 69 3c 6f 72 69 67 69 6e 2e 6e 46 69 6c 65 3b 20 i<origin.nFile;
1dc0: 2b 2b 69 29 7b 0a 20 20 20 20 62 6c 6f 62 5f 61 ++i){. blob_a
1dd0: 70 70 65 6e 64 66 28 70 43 74 72 6c 2c 20 22 46 ppendf(pCtrl, "F
1de0: 20 25 73 20 25 73 20 25 73 5c 6e 22 2c 0a 20 20 %s %s %s\n",.
1df0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6f o
1e00: 72 69 67 69 6e 2e 61 46 69 6c 65 5b 69 5d 2e 7a rigin.aFile[i].z
1e10: 4e 61 6d 65 2c 0a 20 20 20 20 20 20 20 20 20 20 Name,.
1e20: 20 20 20 20 20 20 20 6f 72 69 67 69 6e 2e 61 46 origin.aF
1e30: 69 6c 65 5b 69 5d 2e 7a 55 75 69 64 2c 0a 20 20 ile[i].zUuid,.
1e40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6f o
1e50: 72 69 67 69 6e 2e 61 46 69 6c 65 5b 69 5d 2e 7a rigin.aFile[i].z
1e60: 50 65 72 6d 29 3b 0a 20 20 7d 0a 20 20 69 66 28 Perm);. }. if(
1e70: 20 6f 72 69 67 69 6e 2e 6e 50 61 72 65 6e 74 3e origin.nParent>
1e80: 30 20 29 7b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 0 ){. blob_ap
1e90: 70 65 6e 64 66 28 70 43 74 72 6c 2c 20 22 50 20 pendf(pCtrl, "P
1ea0: 25 73 5c 6e 22 2c 20 6f 72 69 67 69 6e 2e 61 7a %s\n", origin.az
1eb0: 50 61 72 65 6e 74 5b 30 5d 29 3b 0a 20 20 7d 0a Parent[0]);. }.
1ec0: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 blob_appendf(p
1ed0: 43 74 72 6c 2c 20 22 52 20 25 73 5c 6e 22 2c 20 Ctrl, "R %s\n",
1ee0: 6f 72 69 67 69 6e 2e 7a 52 65 70 6f 43 6b 73 75 origin.zRepoCksu
1ef0: 6d 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e m);. blob_appen
1f00: 64 66 28 70 43 74 72 6c 2c 20 22 54 20 2a 25 46 df(pCtrl, "T *%F
1f10: 20 2a 22 2c 20 7a 54 61 67 6e 61 6d 65 29 3b 0a *", zTagname);.
1f20: 0a 20 20 2f 2a 20 43 61 6e 63 65 6c 20 61 6e 79 . /* Cancel any
1f30: 20 73 79 6d 2d 20 74 61 67 73 20 74 68 61 74 20 sym- tags that
1f40: 70 72 6f 70 61 67 61 74 65 20 2a 2f 0a 20 20 64 propagate */. d
1f50: 62 5f 70 72 65 70 61 72 65 28 26 71 2c 0a 20 20 b_prepare(&q,.
1f60: 20 20 20 20 22 53 45 4c 45 43 54 20 74 61 67 6e "SELECT tagn
1f70: 61 6d 65 20 46 52 4f 4d 20 74 61 67 78 72 65 66 ame FROM tagxref
1f80: 2c 20 74 61 67 22 0a 20 20 20 20 20 20 22 20 57 , tag". " W
1f90: 48 45 52 45 20 74 61 67 78 72 65 66 2e 72 69 64 HERE tagxref.rid
1fa0: 3d 25 64 20 41 4e 44 20 74 61 67 78 72 65 66 2e =%d AND tagxref.
1fb0: 74 61 67 69 64 3d 74 61 67 2e 74 61 67 69 64 22 tagid=tag.tagid"
1fc0: 0a 20 20 20 20 20 20 22 20 20 20 41 4e 44 20 74 . " AND t
1fd0: 61 67 74 79 70 65 3e 30 20 41 4e 44 20 74 61 67 agtype>0 AND tag
1fe0: 6e 61 6d 65 20 4c 49 4b 45 20 27 73 79 6d 2d 25 name LIKE 'sym-%
1ff0: 25 27 22 0a 20 20 20 20 20 20 22 20 4f 52 44 45 %'". " ORDE
2000: 52 20 42 59 20 74 61 67 6e 61 6d 65 22 2c 0a 20 R BY tagname",.
2010: 20 20 20 20 20 72 69 64 29 3b 0a 20 20 77 68 69 rid);. whi
2020: 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d le( db_step(&q)=
2030: 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 =SQLITE_ROW ){.
2040: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a const char *z
2050: 54 61 67 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f Tag = db_column_
2060: 74 65 78 74 28 26 71 2c 20 30 29 3b 0a 20 20 20 text(&q, 0);.
2070: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 43 blob_appendf(pC
2080: 74 72 6c 2c 20 22 5c 6e 54 20 2d 25 73 20 2a 22 trl, "\nT -%s *"
2090: 2c 20 7a 54 61 67 29 3b 0a 20 20 7d 0a 20 20 64 , zTag);. }. d
20a0: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a b_finalize(&q);.
20b0: 0a 20 20 2f 2a 20 43 6c 65 61 6e 75 70 20 2a 2f . /* Cleanup */
20c0: 0a 20 20 6d 61 6e 69 66 65 73 74 5f 63 6c 65 61 . manifest_clea
20d0: 72 28 26 6f 72 69 67 69 6e 29 3b 0a 7d 0a 0a 2f r(&origin);.}../
20e0: 2a 0a 2a 2a 20 41 64 64 20 61 20 63 6f 6e 74 72 *.** Add a contr
20f0: 6f 6c 20 72 65 63 6f 72 64 20 74 6f 20 74 68 65 ol record to the
2100: 20 72 65 70 6f 73 69 74 6f 72 79 20 74 68 61 74 repository that
2110: 20 65 69 74 68 65 72 20 63 72 65 61 74 65 73 0a either creates.
2120: 2a 2a 20 6f 72 20 63 61 6e 63 65 6c 73 20 61 20 ** or cancels a
2130: 74 61 67 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 tag..*/.static v
2140: 6f 69 64 20 74 61 67 5f 61 64 64 5f 61 72 74 69 oid tag_add_arti
2150: 66 61 63 74 28 0a 20 20 63 6f 6e 73 74 20 63 68 fact(. const ch
2160: 61 72 20 2a 7a 54 61 67 6e 61 6d 65 2c 20 20 20 ar *zTagname,
2170: 20 20 20 20 2f 2a 20 54 68 65 20 74 61 67 20 74 /* The tag t
2180: 6f 20 61 64 64 20 6f 72 20 63 61 6e 63 65 6c 20 o add or cancel
2190: 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 */. const char
21a0: 2a 7a 4f 62 6a 4e 61 6d 65 2c 20 20 20 20 20 20 *zObjName,
21b0: 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 6f 62 6a 65 /* Name of obje
21c0: 63 74 20 61 74 74 61 63 68 65 64 20 74 6f 20 2a ct attached to *
21d0: 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a /. const char *
21e0: 7a 56 61 6c 75 65 2c 20 20 20 20 20 20 20 20 20 zValue,
21f0: 2f 2a 20 56 61 6c 75 65 20 66 6f 72 20 74 68 65 /* Value for the
2200: 20 74 61 67 2e 20 20 4d 69 67 68 74 20 62 65 20 tag. Might be
2210: 4e 55 4c 4c 20 2a 2f 0a 20 20 69 6e 74 20 74 61 NULL */. int ta
2220: 67 74 79 70 65 2c 20 20 20 20 20 20 20 20 20 20 gtype,
2230: 20 20 20 20 20 20 2f 2a 20 30 3a 63 61 6e 63 65 /* 0:cance
2240: 6c 20 31 3a 73 69 6e 67 6c 65 74 6f 6e 20 32 3a l 1:singleton 2:
2250: 70 72 6f 70 61 67 61 74 65 64 20 2a 2f 0a 20 20 propagated */.
2260: 69 6e 74 20 66 6f 72 6b 20 20 20 20 20 20 20 20 int fork
2270: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 /* S
2280: 68 6f 75 6c 64 20 61 20 66 6f 72 6b 20 63 72 65 hould a fork cre
2290: 61 74 65 64 20 66 72 6f 6d 20 7a 4f 62 6a 4e 61 ated from zObjNa
22a0: 6d 65 3f 20 2a 2f 0a 29 7b 0a 20 20 69 6e 74 20 me? */.){. int
22b0: 72 69 64 3b 0a 20 20 69 6e 74 20 6e 72 69 64 3b rid;. int nrid;
22c0: 0a 20 20 63 68 61 72 20 2a 7a 44 61 74 65 3b 0a . char *zDate;.
22d0: 20 20 42 6c 6f 62 20 75 75 69 64 3b 0a 20 20 42 Blob uuid;. B
22e0: 6c 6f 62 20 63 74 72 6c 3b 0a 20 20 42 6c 6f 62 lob ctrl;. Blob
22f0: 20 63 6b 73 75 6d 3b 0a 20 20 73 74 61 74 69 63 cksum;. static
2300: 20 63 6f 6e 73 74 20 63 68 61 72 20 7a 54 61 67 const char zTag
2310: 74 79 70 65 5b 5d 20 3d 20 7b 20 27 2d 27 2c 20 type[] = { '-',
2320: 27 2b 27 2c 20 27 2a 27 20 7d 3b 0a 0a 20 20 61 '+', '*' };.. a
2330: 73 73 65 72 74 28 20 74 61 67 74 79 70 65 3e 3d ssert( tagtype>=
2340: 30 20 26 26 20 74 61 67 74 79 70 65 3c 3d 32 20 0 && tagtype<=2
2350: 29 3b 0a 20 20 75 73 65 72 5f 73 65 6c 65 63 74 );. user_select
2360: 28 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 ();. blob_zero(
2370: 26 75 75 69 64 29 3b 0a 20 20 62 6c 6f 62 5f 61 &uuid);. blob_a
2380: 70 70 65 6e 64 28 26 75 75 69 64 2c 20 7a 4f 62 ppend(&uuid, zOb
2390: 6a 4e 61 6d 65 2c 20 2d 31 29 3b 0a 20 20 69 66 jName, -1);. if
23a0: 28 20 6e 61 6d 65 5f 74 6f 5f 75 75 69 64 28 26 ( name_to_uuid(&
23b0: 75 75 69 64 2c 20 39 29 20 29 7b 0a 20 20 20 20 uuid, 9) ){.
23c0: 72 65 74 75 72 6e 3b 0a 20 20 7d 0a 20 20 72 69 return;. }. ri
23d0: 64 20 3d 20 6e 61 6d 65 5f 74 6f 5f 72 69 64 28 d = name_to_rid(
23e0: 62 6c 6f 62 5f 73 74 72 28 26 75 75 69 64 29 29 blob_str(&uuid))
23f0: 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 63 ;. blob_zero(&c
2400: 74 72 6c 29 3b 0a 0a 20 20 69 66 28 20 76 61 6c trl);.. if( val
2410: 69 64 61 74 65 31 36 28 7a 54 61 67 6e 61 6d 65 idate16(zTagname
2420: 2c 20 73 74 72 6c 65 6e 28 7a 54 61 67 6e 61 6d , strlen(zTagnam
2430: 65 29 29 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 e)) ){. fossi
2440: 6c 5f 66 61 74 61 6c 28 22 69 6e 76 61 6c 69 64 l_fatal("invalid
2450: 20 74 61 67 20 6e 61 6d 65 20 5c 22 25 73 5c 22 tag name \"%s\"
2460: 20 2d 20 6d 69 67 68 74 20 62 65 20 63 6f 6e 66 - might be conf
2470: 75 73 65 64 20 77 69 74 68 20 61 20 55 55 49 44 used with a UUID
2480: 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ",.
2490: 20 20 20 20 7a 54 61 67 6e 61 6d 65 29 3b 0a 20 zTagname);.
24a0: 20 7d 0a 20 20 69 66 28 20 66 6f 72 6b 20 29 7b }. if( fork ){
24b0: 0a 20 20 20 20 74 61 67 5f 70 72 65 70 61 72 65 . tag_prepare
24c0: 5f 66 6f 72 6b 28 26 63 74 72 6c 2c 20 7a 54 61 _fork(&ctrl, zTa
24d0: 67 6e 61 6d 65 2c 20 72 69 64 29 3b 0a 20 20 7d gname, rid);. }
24e0: 65 6c 73 65 7b 0a 20 20 20 20 7a 44 61 74 65 20 else{. zDate
24f0: 3d 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 45 = db_text(0, "SE
2500: 4c 45 43 54 20 64 61 74 65 74 69 6d 65 28 27 6e LECT datetime('n
2510: 6f 77 27 29 22 29 3b 0a 20 20 20 20 7a 44 61 74 ow')");. zDat
2520: 65 5b 31 30 5d 20 3d 20 27 54 27 3b 0a 20 20 20 e[10] = 'T';.
2530: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 63 blob_appendf(&c
2540: 74 72 6c 2c 20 22 44 20 25 73 5c 6e 22 2c 20 7a trl, "D %s\n", z
2550: 44 61 74 65 29 3b 0a 20 20 20 20 62 6c 6f 62 5f Date);. blob_
2560: 61 70 70 65 6e 64 66 28 26 63 74 72 6c 2c 20 22 appendf(&ctrl, "
2570: 54 20 25 63 25 46 20 25 62 22 2c 20 7a 54 61 67 T %c%F %b", zTag
2580: 74 79 70 65 5b 74 61 67 74 79 70 65 5d 2c 20 7a type[tagtype], z
2590: 54 61 67 6e 61 6d 65 2c 20 26 75 75 69 64 29 3b Tagname, &uuid);
25a0: 0a 20 20 7d 0a 20 20 69 66 28 20 74 61 67 74 79 . }. if( tagty
25b0: 70 65 20 26 26 20 7a 56 61 6c 75 65 20 26 26 20 pe && zValue &&
25c0: 7a 56 61 6c 75 65 5b 30 5d 20 29 7b 0a 20 20 20 zValue[0] ){.
25d0: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 63 blob_appendf(&c
25e0: 74 72 6c 2c 20 22 20 25 46 5c 6e 22 2c 20 7a 56 trl, " %F\n", zV
25f0: 61 6c 75 65 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a alue);. }else{.
2600: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 blob_appendf
2610: 28 26 63 74 72 6c 2c 20 22 5c 6e 22 29 3b 0a 20 (&ctrl, "\n");.
2620: 20 7d 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 }. blob_append
2630: 66 28 26 63 74 72 6c 2c 20 22 55 20 25 46 5c 6e f(&ctrl, "U %F\n
2640: 22 2c 20 67 2e 7a 4c 6f 67 69 6e 29 3b 0a 20 20 ", g.zLogin);.
2650: 6d 64 35 73 75 6d 5f 62 6c 6f 62 28 26 63 74 72 md5sum_blob(&ctr
2660: 6c 2c 20 26 63 6b 73 75 6d 29 3b 0a 20 20 62 6c l, &cksum);. bl
2670: 6f 62 5f 61 70 70 65 6e 64 66 28 26 63 74 72 6c ob_appendf(&ctrl
2680: 2c 20 22 5a 20 25 62 5c 6e 22 2c 20 26 63 6b 73 , "Z %b\n", &cks
2690: 75 6d 29 3b 0a 20 20 64 62 5f 62 65 67 69 6e 5f um);. db_begin_
26a0: 74 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a 20 transaction();.
26b0: 20 6e 72 69 64 20 3d 20 63 6f 6e 74 65 6e 74 5f nrid = content_
26c0: 70 75 74 28 26 63 74 72 6c 2c 20 30 2c 20 30 29 put(&ctrl, 0, 0)
26d0: 3b 0a 20 20 6d 61 6e 69 66 65 73 74 5f 63 72 6f ;. manifest_cro
26e0: 73 73 6c 69 6e 6b 28 6e 72 69 64 2c 20 26 63 74 sslink(nrid, &ct
26f0: 72 6c 29 3b 0a 20 20 64 62 5f 65 6e 64 5f 74 72 rl);. db_end_tr
2700: 61 6e 73 61 63 74 69 6f 6e 28 30 29 3b 0a 20 20 ansaction(0);.
2710: 0a 20 20 2f 2a 20 44 6f 20 61 6e 20 61 75 74 6f . /* Do an auto
2720: 73 79 6e 63 20 70 75 73 68 20 69 66 20 72 65 71 sync push if req
2730: 75 65 73 74 65 64 20 2a 2f 0a 20 20 61 75 74 6f uested */. auto
2740: 73 79 6e 63 28 41 55 54 4f 53 59 4e 43 5f 50 55 sync(AUTOSYNC_PU
2750: 53 48 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f SH);.}../*.** CO
2760: 4d 4d 41 4e 44 3a 20 74 61 67 0a 2a 2a 20 55 73 MMAND: tag.** Us
2770: 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 74 61 67 age: %fossil tag
2780: 20 53 55 42 43 4f 4d 4d 41 4e 44 20 2e 2e 2e 0a SUBCOMMAND ....
2790: 2a 2a 0a 2a 2a 20 52 75 6e 20 76 61 72 69 6f 75 **.** Run variou
27a0: 73 20 73 75 62 63 6f 6d 6d 61 6e 64 73 20 74 6f s subcommands to
27b0: 20 63 6f 6e 74 72 6f 6c 20 74 61 67 73 20 61 6e control tags an
27c0: 64 20 70 72 6f 70 65 72 74 69 65 73 0a 2a 2a 0a d properties.**.
27d0: 2a 2a 20 20 20 20 20 25 66 6f 73 73 69 6c 20 74 ** %fossil t
27e0: 61 67 20 61 64 64 20 3f 2d 2d 72 61 77 3f 20 54 ag add ?--raw? T
27f0: 41 47 4e 41 4d 45 20 55 55 49 44 20 3f 56 41 4c AGNAME UUID ?VAL
2800: 55 45 3f 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 UE?.**.**
2810: 20 20 41 64 64 20 61 20 6e 65 77 20 74 61 67 20 Add a new tag
2820: 6f 72 20 70 72 6f 70 65 72 74 79 20 74 6f 20 55 or property to U
2830: 55 49 44 2e 20 54 68 65 20 74 61 67 20 77 69 6c UID. The tag wil
2840: 6c 0a 2a 2a 20 20 20 20 20 20 20 20 20 62 65 20 l.** be
2850: 75 73 61 62 6c 65 20 69 6e 73 74 65 61 64 20 6f usable instead o
2860: 66 20 61 20 55 55 49 44 20 69 6e 20 63 6f 6d 6d f a UUID in comm
2870: 61 6e 64 73 20 6c 69 6b 65 0a 2a 2a 20 20 20 20 ands like.**
2880: 20 20 20 20 20 75 70 64 61 74 65 20 61 6e 64 20 update and
2890: 73 75 63 68 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 such..**.**
28a0: 25 66 6f 73 73 69 6c 20 74 61 67 20 62 72 61 6e %fossil tag bran
28b0: 63 68 20 3f 2d 2d 72 61 77 3f 20 54 41 47 4e 41 ch ?--raw? TAGNA
28c0: 4d 45 20 55 55 49 44 20 3f 56 41 4c 55 45 3f 0a ME UUID ?VALUE?.
28d0: 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 20 41 20 **.** A
28e0: 66 6f 72 6b 20 6f 66 20 55 55 49 44 20 77 69 6c fork of UUID wil
28f0: 6c 20 62 65 20 63 72 65 61 74 65 64 2e 20 54 68 l be created. Th
2900: 65 6e 20 74 68 65 20 6e 65 77 20 74 61 67 0a 2a en the new tag.*
2910: 2a 20 20 20 20 20 20 20 20 20 6f 72 20 70 72 6f * or pro
2920: 70 65 72 74 79 20 77 69 6c 6c 20 62 65 20 61 64 perty will be ad
2930: 64 65 64 20 74 6f 20 74 68 65 20 66 6f 72 6b 20 ded to the fork
2940: 74 68 61 74 0a 2a 2a 20 20 20 20 20 20 20 20 20 that.**
2950: 70 72 6f 70 61 67 61 74 65 20 74 6f 20 61 6c 6c propagate to all
2960: 20 64 69 72 65 63 74 20 63 68 69 6c 64 72 65 6e direct children
2970: 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 20 ..**.**
2980: 41 64 64 69 74 69 6f 6e 61 6c 6c 79 20 61 6c 6c Additionally all
2990: 20 73 79 6d 62 6f 6c 69 63 20 74 61 67 73 20 6f symbolic tags o
29a0: 66 20 74 68 61 74 20 66 6f 72 6b 0a 2a 2a 20 20 f that fork.**
29b0: 20 20 20 20 20 20 20 69 6e 68 65 72 69 74 65 64 inherited
29c0: 20 66 72 6f 6d 20 55 55 49 44 20 77 69 6c 6c 20 from UUID will
29d0: 62 65 20 63 61 6e 63 65 6c 6c 65 64 2e 0a 2a 2a be cancelled..**
29e0: 0a 2a 2a 20 20 20 20 20 20 20 20 20 48 6f 77 65 .** Howe
29f0: 76 65 72 2c 20 69 66 20 74 68 65 20 6f 70 74 69 ver, if the opti
2a00: 6f 6e 20 27 2d 2d 72 61 77 27 20 77 61 73 20 67 on '--raw' was g
2a10: 69 76 65 6e 2c 20 6e 6f 0a 2a 2a 20 20 20 20 20 iven, no.**
2a20: 20 20 20 20 66 6f 72 6b 20 77 69 6c 6c 20 62 65 fork will be
2a30: 20 63 72 65 61 74 65 64 20 62 75 74 20 74 68 65 created but the
2a40: 20 74 61 67 2f 70 72 6f 70 65 72 74 79 20 77 69 tag/property wi
2a50: 6c 6c 20 62 65 0a 2a 2a 20 20 20 20 20 20 20 20 ll be.**
2a60: 20 61 64 64 65 64 20 74 6f 20 55 55 49 44 20 64 added to UUID d
2a70: 69 72 65 63 74 6c 79 20 61 6e 64 20 6e 6f 20 74 irectly and no t
2a80: 61 67 20 77 69 6c 6c 20 62 65 0a 2a 2a 20 20 20 ag will be.**
2a90: 20 20 20 20 20 20 63 61 6e 63 65 6c 65 64 2e 0a canceled..
2aa0: 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 20 50 6c **.** Pl
2ab0: 65 61 73 65 20 73 65 65 20 74 68 65 20 64 65 73 ease see the des
2ac0: 63 72 69 70 74 69 6f 6e 20 6f 66 20 27 2d 2d 72 cription of '--r
2ad0: 61 77 27 20 62 65 6c 6f 77 20 74 6f 6f 2e 0a 2a aw' below too..*
2ae0: 2a 0a 2a 2a 20 20 20 20 20 25 66 6f 73 73 69 6c *.** %fossil
2af0: 20 74 61 67 20 63 61 6e 63 65 6c 20 3f 2d 2d 72 tag cancel ?--r
2b00: 61 77 3f 20 54 41 47 4e 41 4d 45 20 55 55 49 44 aw? TAGNAME UUID
2b10: 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 20 43 .**.** C
2b20: 61 6e 63 65 6c 20 74 68 65 20 74 61 67 20 54 41 ancel the tag TA
2b30: 47 4e 41 4d 45 20 66 72 6f 6d 20 55 55 49 44 0a GNAME from UUID.
2b40: 2a 2a 0a 2a 2a 20 20 20 20 20 25 66 6f 73 73 69 **.** %fossi
2b50: 6c 20 74 61 67 20 66 69 6e 64 20 3f 2d 2d 72 61 l tag find ?--ra
2b60: 77 3f 20 54 41 47 4e 41 4d 45 0a 2a 2a 0a 2a 2a w? TAGNAME.**.**
2b70: 20 20 20 20 20 20 20 20 20 4c 69 73 74 20 61 6c List al
2b80: 6c 20 62 61 73 65 6c 69 6e 65 73 20 74 68 61 74 l baselines that
2b90: 20 75 73 65 20 54 41 47 4e 41 4d 45 0a 2a 2a 0a use TAGNAME.**.
2ba0: 2a 2a 20 20 20 20 20 25 66 6f 73 73 69 6c 20 74 ** %fossil t
2bb0: 61 67 20 6c 69 73 74 20 3f 2d 2d 72 61 77 3f 20 ag list ?--raw?
2bc0: 3f 55 55 49 44 3f 0a 2a 2a 0a 2a 2a 20 20 20 20 ?UUID?.**.**
2bd0: 20 20 20 20 20 4c 69 73 74 20 61 6c 6c 20 74 61 List all ta
2be0: 67 73 2c 20 6f 72 20 69 66 20 55 55 49 44 20 69 gs, or if UUID i
2bf0: 73 20 73 75 70 70 6c 69 65 64 2c 20 6c 69 73 74 s supplied, list
2c00: 0a 2a 2a 20 20 20 20 20 20 20 20 20 61 6c 6c 20 .** all
2c10: 74 61 67 73 20 61 6e 64 20 74 68 65 69 72 20 76 tags and their v
2c20: 61 6c 75 65 73 20 66 6f 72 20 55 55 49 44 2e 0a alues for UUID..
2c30: 2a 2a 0a 2a 2a 20 54 68 65 20 6f 70 74 69 6f 6e **.** The option
2c40: 20 3f 2d 2d 72 61 77 3f 20 69 73 20 74 6f 20 65 ?--raw? is to e
2c50: 78 70 6f 73 65 20 74 68 65 20 69 6e 74 65 72 6e xpose the intern
2c60: 61 6c 20 69 6e 74 65 72 66 61 63 65 20 0a 2a 2a al interface .**
2c70: 20 66 6f 72 20 74 61 67 20 68 61 6e 64 6c 69 6e for tag handlin
2c80: 67 2e 20 54 68 69 73 20 6f 70 74 69 6f 6e 20 69 g. This option i
2c90: 73 20 6e 6f 74 20 6e 65 63 65 73 73 61 72 79 20 s not necessary
2ca0: 66 6f 72 20 74 68 65 0a 2a 2a 20 6e 6f 72 6d 61 for the.** norma
2cb0: 6c 20 75 73 65 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 l use..**.** If
2cc0: 79 6f 75 20 75 73 65 20 61 20 74 61 67 6e 61 6d you use a tagnam
2cd0: 65 20 74 68 61 74 20 6d 69 67 68 74 20 62 65 20 e that might be
2ce0: 63 6f 6e 66 75 73 65 64 20 77 69 74 68 20 61 20 confused with a
2cf0: 55 55 49 44 2c 0a 2a 2a 20 79 6f 75 20 68 61 76 UUID,.** you hav
2d00: 65 20 74 6f 20 65 78 70 6c 69 63 69 74 6c 79 20 e to explicitly
2d10: 64 69 73 61 6d 62 69 67 75 61 74 65 20 69 74 20 disambiguate it
2d20: 62 79 20 70 72 65 66 69 78 69 6e 67 20 69 74 0a by prefixing it.
2d30: 2a 2a 20 77 69 74 68 20 22 74 61 67 3a 22 2e 20 ** with "tag:".
2d40: 46 6f 72 20 69 6e 73 74 61 6e 63 65 3a 0a 2a 2a For instance:.**
2d50: 0a 2a 2a 20 20 20 66 6f 73 73 69 6c 20 75 70 64 .** fossil upd
2d60: 61 74 65 20 63 66 63 66 63 66 65 65 0a 2a 2a 0a ate cfcfcfee.**.
2d70: 2a 2a 20 69 73 20 6e 6f 74 20 74 68 65 20 73 61 ** is not the sa
2d80: 6d 65 20 61 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 66 me as:.**.** f
2d90: 6f 73 73 69 6c 20 75 70 64 61 74 65 20 74 61 67 ossil update tag
2da0: 3a 63 66 63 66 63 66 65 65 0a 2a 2a 0a 2a 2a 20 :cfcfcfee.**.**
2db0: 54 68 65 20 66 69 72 73 74 20 77 69 6c 6c 20 62 The first will b
2dc0: 65 20 74 61 6b 65 6e 20 61 73 20 55 55 49 44 20 e taken as UUID
2dd0: 61 6e 64 20 66 6f 73 73 69 6c 20 77 69 6c 6c 20 and fossil will
2de0: 63 6f 6d 70 6c 61 69 6e 0a 2a 2a 20 69 66 20 6e complain.** if n
2df0: 6f 20 73 75 63 68 20 72 65 76 69 73 69 6f 6e 20 o such revision
2e00: 77 61 73 20 66 6f 75 6e 64 2c 20 61 6e 64 20 74 was found, and t
2e10: 68 65 20 73 65 63 6f 6e 64 20 6f 6e 65 20 65 78 he second one ex
2e20: 70 65 63 74 0a 2a 2a 20 22 63 66 63 66 63 66 65 pect.** "cfcfcfe
2e30: 65 22 20 74 6f 20 62 65 20 61 20 74 61 67 2f 62 e" to be a tag/b
2e40: 72 61 6e 63 68 20 6e 61 6d 65 21 0a 2a 2a 0a 2a ranch name!.**.*
2e50: 2f 0a 76 6f 69 64 20 74 61 67 5f 63 6d 64 28 76 /.void tag_cmd(v
2e60: 6f 69 64 29 7b 0a 20 20 69 6e 74 20 6e 3b 0a 20 oid){. int n;.
2e70: 20 69 6e 74 20 72 61 77 20 3d 20 66 69 6e 64 5f int raw = find_
2e80: 6f 70 74 69 6f 6e 28 22 72 61 77 22 2c 22 22 2c option("raw","",
2e90: 30 29 21 3d 30 3b 0a 20 20 63 6f 6e 73 74 20 63 0)!=0;. const c
2ea0: 68 61 72 20 2a 70 72 65 66 69 78 20 3d 20 72 61 har *prefix = ra
2eb0: 77 20 3f 20 22 22 20 3a 20 22 73 79 6d 2d 22 3b w ? "" : "sym-";
2ec0: 0a 20 20 69 6e 74 20 70 72 65 66 6c 65 6e 20 3d . int preflen =
2ed0: 20 73 74 72 6c 65 6e 28 70 72 65 66 69 78 29 3b strlen(prefix);
2ee0: 0a 20 20 42 6c 6f 62 20 74 61 67 6e 61 6d 65 3b . Blob tagname;
2ef0: 0a 0a 20 20 64 62 5f 66 69 6e 64 5f 61 6e 64 5f .. db_find_and_
2f00: 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28 open_repository(
2f10: 31 29 3b 0a 20 20 69 66 28 20 67 2e 61 72 67 63 1);. if( g.argc
2f20: 3c 33 20 29 7b 0a 20 20 20 20 67 6f 74 6f 20 74 <3 ){. goto t
2f30: 61 67 5f 63 6d 64 5f 75 73 61 67 65 3b 0a 20 20 ag_cmd_usage;.
2f40: 7d 0a 20 20 6e 20 3d 20 73 74 72 6c 65 6e 28 67 }. n = strlen(g
2f50: 2e 61 72 67 76 5b 32 5d 29 3b 0a 20 20 69 66 28 .argv[2]);. if(
2f60: 20 6e 3d 3d 30 20 29 7b 0a 20 20 20 20 67 6f 74 n==0 ){. got
2f70: 6f 20 74 61 67 5f 63 6d 64 5f 75 73 61 67 65 3b o tag_cmd_usage;
2f80: 0a 20 20 7d 0a 0a 20 20 62 6c 6f 62 5f 73 65 74 . }.. blob_set
2f90: 28 26 74 61 67 6e 61 6d 65 2c 20 70 72 65 66 69 (&tagname, prefi
2fa0: 78 29 3b 0a 0a 20 20 69 66 28 20 73 74 72 6e 63 x);.. if( strnc
2fb0: 6d 70 28 67 2e 61 72 67 76 5b 32 5d 2c 22 61 64 mp(g.argv[2],"ad
2fc0: 64 22 2c 6e 29 3d 3d 30 20 29 7b 0a 20 20 20 20 d",n)==0 ){.
2fd0: 63 68 61 72 20 2a 7a 56 61 6c 75 65 3b 0a 20 20 char *zValue;.
2fe0: 20 20 69 66 28 20 67 2e 61 72 67 63 21 3d 35 20 if( g.argc!=5
2ff0: 26 26 20 67 2e 61 72 67 63 21 3d 36 20 29 7b 0a && g.argc!=6 ){.
3000: 20 20 20 20 20 20 75 73 61 67 65 28 22 61 64 64 usage("add
3010: 20 3f 2d 2d 72 61 77 3f 20 54 41 47 4e 41 4d 45 ?--raw? TAGNAME
3020: 20 55 55 49 44 20 3f 56 41 4c 55 45 3f 22 29 3b UUID ?VALUE?");
3030: 0a 20 20 20 20 7d 0a 20 20 20 20 62 6c 6f 62 5f . }. blob_
3040: 61 70 70 65 6e 64 28 26 74 61 67 6e 61 6d 65 2c append(&tagname,
3050: 20 67 2e 61 72 67 76 5b 33 5d 2c 20 73 74 72 6c g.argv[3], strl
3060: 65 6e 28 67 2e 61 72 67 76 5b 33 5d 29 29 3b 0a en(g.argv[3]));.
3070: 20 20 20 20 7a 56 61 6c 75 65 20 3d 20 67 2e 61 zValue = g.a
3080: 72 67 63 3d 3d 36 20 3f 20 67 2e 61 72 67 76 5b rgc==6 ? g.argv[
3090: 35 5d 20 3a 20 30 3b 0a 20 20 20 20 74 61 67 5f 5] : 0;. tag_
30a0: 61 64 64 5f 61 72 74 69 66 61 63 74 28 62 6c 6f add_artifact(blo
30b0: 62 5f 73 74 72 28 26 74 61 67 6e 61 6d 65 29 2c b_str(&tagname),
30c0: 20 67 2e 61 72 67 76 5b 34 5d 2c 20 7a 56 61 6c g.argv[4], zVal
30d0: 75 65 2c 20 31 2c 20 30 29 3b 0a 20 20 7d 65 6c ue, 1, 0);. }el
30e0: 73 65 0a 0a 20 20 69 66 28 20 73 74 72 6e 63 6d se.. if( strncm
30f0: 70 28 67 2e 61 72 67 76 5b 32 5d 2c 22 62 72 61 p(g.argv[2],"bra
3100: 6e 63 68 22 2c 6e 29 3d 3d 30 20 29 7b 0a 20 20 nch",n)==0 ){.
3110: 20 20 63 68 61 72 20 2a 7a 56 61 6c 75 65 3b 0a char *zValue;.
3120: 20 20 20 20 69 66 28 20 67 2e 61 72 67 63 21 3d if( g.argc!=
3130: 35 20 26 26 20 67 2e 61 72 67 63 21 3d 36 20 29 5 && g.argc!=6 )
3140: 7b 0a 20 20 20 20 20 20 75 73 61 67 65 28 22 62 {. usage("b
3150: 72 61 6e 63 68 20 3f 2d 2d 72 61 77 3f 20 54 41 ranch ?--raw? TA
3160: 47 4e 41 4d 45 20 55 55 49 44 20 3f 56 41 4c 55 GNAME UUID ?VALU
3170: 45 3f 22 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 E?");. }.
3180: 62 6c 6f 62 5f 61 70 70 65 6e 64 28 26 74 61 67 blob_append(&tag
3190: 6e 61 6d 65 2c 20 67 2e 61 72 67 76 5b 33 5d 2c name, g.argv[3],
31a0: 20 73 74 72 6c 65 6e 28 67 2e 61 72 67 76 5b 33 strlen(g.argv[3
31b0: 5d 29 29 3b 0a 20 20 20 20 7a 56 61 6c 75 65 20 ]));. zValue
31c0: 3d 20 67 2e 61 72 67 63 3d 3d 36 20 3f 20 67 2e = g.argc==6 ? g.
31d0: 61 72 67 76 5b 35 5d 20 3a 20 30 3b 0a 20 20 20 argv[5] : 0;.
31e0: 20 74 61 67 5f 61 64 64 5f 61 72 74 69 66 61 63 tag_add_artifac
31f0: 74 28 62 6c 6f 62 5f 73 74 72 28 26 74 61 67 6e t(blob_str(&tagn
3200: 61 6d 65 29 2c 20 67 2e 61 72 67 76 5b 34 5d 2c ame), g.argv[4],
3210: 20 7a 56 61 6c 75 65 2c 20 32 2c 20 72 61 77 3d zValue, 2, raw=
3220: 3d 30 29 3b 0a 20 20 20 20 69 66 28 20 21 72 61 =0);. if( !ra
3230: 77 20 29 7b 0a 20 20 20 20 20 20 63 6f 6e 73 74 w ){. const
3240: 20 63 68 61 72 20 2a 7a 55 75 69 64 20 3d 20 64 char *zUuid = d
3250: 62 5f 74 65 78 74 28 30 2c 20 22 53 45 4c 45 43 b_text(0, "SELEC
3260: 54 20 75 75 69 64 2c 20 4d 41 58 28 72 6f 77 69 T uuid, MAX(rowi
3270: 64 29 20 46 52 4f 4d 20 62 6c 6f 62 22 29 3b 0a d) FROM blob");.
3280: 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 4e 65 printf("Ne
3290: 77 5f 46 6f 72 6b 20 5c 22 25 73 5c 22 3a 20 25 w_Fork \"%s\": %
32a0: 73 5c 6e 22 2c 20 67 2e 61 72 67 76 5b 33 5d 2c s\n", g.argv[3],
32b0: 20 7a 55 75 69 64 29 3b 0a 20 20 20 20 7d 0a 20 zUuid);. }.
32c0: 20 7d 65 6c 73 65 0a 0a 20 20 69 66 28 20 73 74 }else.. if( st
32d0: 72 6e 63 6d 70 28 67 2e 61 72 67 76 5b 32 5d 2c rncmp(g.argv[2],
32e0: 22 63 61 6e 63 65 6c 22 2c 6e 29 3d 3d 30 20 29 "cancel",n)==0 )
32f0: 7b 0a 20 20 20 20 69 66 28 20 67 2e 61 72 67 63 {. if( g.argc
3300: 21 3d 35 20 29 7b 0a 20 20 20 20 20 20 75 73 61 !=5 ){. usa
3310: 67 65 28 22 63 61 6e 63 65 6c 20 3f 2d 2d 72 61 ge("cancel ?--ra
3320: 77 3f 20 54 41 47 4e 41 4d 45 20 55 55 49 44 22 w? TAGNAME UUID"
3330: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 62 6c 6f );. }. blo
3340: 62 5f 61 70 70 65 6e 64 28 26 74 61 67 6e 61 6d b_append(&tagnam
3350: 65 2c 20 67 2e 61 72 67 76 5b 33 5d 2c 20 73 74 e, g.argv[3], st
3360: 72 6c 65 6e 28 67 2e 61 72 67 76 5b 33 5d 29 29 rlen(g.argv[3]))
3370: 3b 0a 20 20 20 20 74 61 67 5f 61 64 64 5f 61 72 ;. tag_add_ar
3380: 74 69 66 61 63 74 28 62 6c 6f 62 5f 73 74 72 28 tifact(blob_str(
3390: 26 74 61 67 6e 61 6d 65 29 2c 20 67 2e 61 72 67 &tagname), g.arg
33a0: 76 5b 34 5d 2c 20 30 2c 20 30 2c 20 30 29 3b 0a v[4], 0, 0, 0);.
33b0: 20 20 7d 65 6c 73 65 0a 0a 20 20 69 66 28 20 73 }else.. if( s
33c0: 74 72 6e 63 6d 70 28 67 2e 61 72 67 76 5b 32 5d trncmp(g.argv[2]
33d0: 2c 22 66 69 6e 64 22 2c 6e 29 3d 3d 30 20 29 7b ,"find",n)==0 ){
33e0: 0a 20 20 20 20 53 74 6d 74 20 71 3b 0a 20 20 20 . Stmt q;.
33f0: 20 69 66 28 20 67 2e 61 72 67 63 21 3d 34 20 29 if( g.argc!=4 )
3400: 7b 0a 20 20 20 20 20 20 75 73 61 67 65 28 22 66 {. usage("f
3410: 69 6e 64 20 3f 2d 2d 72 61 77 3f 20 54 41 47 4e ind ?--raw? TAGN
3420: 41 4d 45 22 29 3b 0a 20 20 20 20 7d 0a 20 20 20 AME");. }.
3430: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 26 74 61 blob_append(&ta
3440: 67 6e 61 6d 65 2c 20 67 2e 61 72 67 76 5b 33 5d gname, g.argv[3]
3450: 2c 20 73 74 72 6c 65 6e 28 67 2e 61 72 67 76 5b , strlen(g.argv[
3460: 33 5d 29 29 3b 0a 20 20 20 20 64 62 5f 70 72 65 3]));. db_pre
3470: 70 61 72 65 28 26 71 2c 0a 20 20 20 20 20 20 22 pare(&q,. "
3480: 53 45 4c 45 43 54 20 62 6c 6f 62 2e 75 75 69 64 SELECT blob.uuid
3490: 20 46 52 4f 4d 20 74 61 67 78 72 65 66 2c 20 62 FROM tagxref, b
34a0: 6c 6f 62 22 0a 20 20 20 20 20 20 22 20 57 48 45 lob". " WHE
34b0: 52 45 20 74 61 67 69 64 3d 28 53 45 4c 45 43 54 RE tagid=(SELECT
34c0: 20 74 61 67 69 64 20 46 52 4f 4d 20 74 61 67 20 tagid FROM tag
34d0: 57 48 45 52 45 20 74 61 67 6e 61 6d 65 3d 25 42 WHERE tagname=%B
34e0: 29 22 0a 20 20 20 20 20 20 22 20 20 20 41 4e 44 )". " AND
34f0: 20 62 6c 6f 62 2e 72 69 64 3d 74 61 67 78 72 65 blob.rid=tagxre
3500: 66 2e 72 69 64 22 2c 20 26 74 61 67 6e 61 6d 65 f.rid", &tagname
3510: 0a 20 20 20 20 29 3b 0a 20 20 20 20 77 68 69 6c . );. whil
3520: 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d e( db_step(&q)==
3530: 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 SQLITE_ROW ){.
3540: 20 20 20 20 70 72 69 6e 74 66 28 22 25 73 5c 6e printf("%s\n
3550: 22 2c 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 ", db_column_tex
3560: 74 28 26 71 2c 20 30 29 29 3b 0a 20 20 20 20 7d t(&q, 0));. }
3570: 0a 20 20 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 . db_finalize
3580: 28 26 71 29 3b 0a 20 20 7d 65 6c 73 65 0a 0a 20 (&q);. }else..
3590: 20 69 66 28 20 73 74 72 6e 63 6d 70 28 67 2e 61 if( strncmp(g.a
35a0: 72 67 76 5b 32 5d 2c 22 6c 69 73 74 22 2c 6e 29 rgv[2],"list",n)
35b0: 3d 3d 30 20 29 7b 0a 20 20 20 20 53 74 6d 74 20 ==0 ){. Stmt
35c0: 71 3b 0a 20 20 20 20 69 66 28 20 67 2e 61 72 67 q;. if( g.arg
35d0: 63 3d 3d 33 20 29 7b 0a 20 20 20 20 20 20 64 62 c==3 ){. db
35e0: 5f 70 72 65 70 61 72 65 28 26 71 2c 20 0a 20 20 _prepare(&q, .
35f0: 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 74 61 "SELECT ta
3600: 67 6e 61 6d 65 20 46 52 4f 4d 20 74 61 67 22 0a gname FROM tag".
3610: 20 20 20 20 20 20 20 20 22 20 57 48 45 52 45 20 " WHERE
3620: 45 58 49 53 54 53 28 53 45 4c 45 43 54 20 31 20 EXISTS(SELECT 1
3630: 46 52 4f 4d 20 74 61 67 78 72 65 66 22 0a 20 20 FROM tagxref".
3640: 20 20 20 20 20 20 22 20 20 20 20 20 20 20 20 20 "
3650: 20 20 20 20 20 20 57 48 45 52 45 20 74 61 67 69 WHERE tagi
3660: 64 3d 74 61 67 2e 74 61 67 69 64 22 0a 20 20 20 d=tag.tagid".
3670: 20 20 20 20 20 22 20 20 20 20 20 20 20 20 20 20 "
3680: 20 20 20 20 20 20 20 41 4e 44 20 74 61 67 74 79 AND tagty
3690: 70 65 3e 30 29 22 0a 20 20 20 20 20 20 20 20 22 pe>0)". "
36a0: 20 4f 52 44 45 52 20 42 59 20 74 61 67 6e 61 6d ORDER BY tagnam
36b0: 65 22 0a 20 20 20 20 20 20 29 3b 0a 20 20 20 20 e". );.
36c0: 20 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 while( db_step
36d0: 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 (&q)==SQLITE_ROW
36e0: 20 29 7b 0a 20 20 20 20 20 20 20 20 63 6f 6e 73 ){. cons
36f0: 74 20 63 68 61 72 20 2a 6e 61 6d 65 20 3d 20 64 t char *name = d
3700: 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 b_column_text(&q
3710: 2c 20 30 29 3b 0a 20 20 20 20 20 20 20 20 69 66 , 0);. if
3720: 28 20 72 61 77 20 7c 7c 20 73 74 72 6e 63 6d 70 ( raw || strncmp
3730: 28 6e 61 6d 65 2c 20 70 72 65 66 69 78 2c 20 70 (name, prefix, p
3740: 72 65 66 6c 65 6e 29 3d 3d 30 20 29 7b 0a 20 20 reflen)==0 ){.
3750: 20 20 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 printf("
3760: 25 73 5c 6e 22 2c 20 6e 61 6d 65 2b 70 72 65 66 %s\n", name+pref
3770: 6c 65 6e 29 3b 0a 20 20 20 20 20 20 20 20 7d 0a len);. }.
3780: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 64 62 }. db
3790: 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 _finalize(&q);.
37a0: 20 20 20 7d 65 6c 73 65 20 69 66 28 20 67 2e 61 }else if( g.a
37b0: 72 67 63 3d 3d 34 20 29 7b 0a 20 20 20 20 20 20 rgc==4 ){.
37c0: 69 6e 74 20 72 69 64 20 3d 20 6e 61 6d 65 5f 74 int rid = name_t
37d0: 6f 5f 72 69 64 28 67 2e 61 72 67 76 5b 33 5d 29 o_rid(g.argv[3])
37e0: 3b 0a 20 20 20 20 20 20 64 62 5f 70 72 65 70 61 ;. db_prepa
37f0: 72 65 28 26 71 2c 0a 20 20 20 20 20 20 20 20 22 re(&q,. "
3800: 53 45 4c 45 43 54 20 74 61 67 6e 61 6d 65 2c 20 SELECT tagname,
3810: 76 61 6c 75 65 20 46 52 4f 4d 20 74 61 67 78 72 value FROM tagxr
3820: 65 66 2c 20 74 61 67 22 0a 20 20 20 20 20 20 20 ef, tag".
3830: 20 22 20 57 48 45 52 45 20 74 61 67 78 72 65 66 " WHERE tagxref
3840: 2e 72 69 64 3d 25 64 20 41 4e 44 20 74 61 67 78 .rid=%d AND tagx
3850: 72 65 66 2e 74 61 67 69 64 3d 74 61 67 2e 74 61 ref.tagid=tag.ta
3860: 67 69 64 22 0a 20 20 20 20 20 20 20 20 22 20 20 gid". "
3870: 20 41 4e 44 20 74 61 67 74 79 70 65 3e 30 22 0a AND tagtype>0".
3880: 20 20 20 20 20 20 20 20 22 20 4f 52 44 45 52 20 " ORDER
3890: 42 59 20 74 61 67 6e 61 6d 65 22 2c 0a 20 20 20 BY tagname",.
38a0: 20 20 20 20 20 72 69 64 0a 20 20 20 20 20 20 29 rid. )
38b0: 3b 0a 20 20 20 20 20 20 77 68 69 6c 65 28 20 64 ;. while( d
38c0: 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 b_step(&q)==SQLI
38d0: 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 20 20 TE_ROW ){.
38e0: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e const char *zN
38f0: 61 6d 65 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f ame = db_column_
3900: 74 65 78 74 28 26 71 2c 20 30 29 3b 0a 20 20 20 text(&q, 0);.
3910: 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 const char
3920: 2a 7a 56 61 6c 75 65 20 3d 20 64 62 5f 63 6f 6c *zValue = db_col
3930: 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 31 29 3b umn_text(&q, 1);
3940: 0a 20 20 20 20 20 20 20 20 69 66 28 20 7a 56 61 . if( zVa
3950: 6c 75 65 20 29 7b 0a 20 20 20 20 20 20 20 20 20 lue ){.
3960: 20 69 66 28 20 72 61 77 20 7c 7c 20 73 74 72 6e if( raw || strn
3970: 63 6d 70 28 7a 4e 61 6d 65 2c 20 70 72 65 66 69 cmp(zName, prefi
3980: 78 2c 20 70 72 65 66 6c 65 6e 29 3d 3d 30 20 29 x, preflen)==0 )
3990: 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 70 72 {. pr
39a0: 69 6e 74 66 28 22 25 73 3d 25 73 5c 6e 22 2c 20 intf("%s=%s\n",
39b0: 7a 4e 61 6d 65 2b 70 72 65 66 6c 65 6e 2c 20 7a zName+preflen, z
39c0: 56 61 6c 75 65 29 3b 0a 20 20 20 20 20 20 20 20 Value);.
39d0: 20 20 7d 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 }. }els
39e0: 65 7b 0a 20 20 20 20 20 20 20 20 20 20 69 66 28 e{. if(
39f0: 20 72 61 77 20 7c 7c 20 73 74 72 6e 63 6d 70 28 raw || strncmp(
3a00: 7a 4e 61 6d 65 2c 20 70 72 65 66 69 78 2c 20 70 zName, prefix, p
3a10: 72 65 66 6c 65 6e 29 3d 3d 30 20 29 7b 0a 20 20 reflen)==0 ){.
3a20: 20 20 20 20 20 20 20 20 20 20 70 72 69 6e 74 66 printf
3a30: 28 22 25 73 5c 6e 22 2c 20 7a 4e 61 6d 65 2b 70 ("%s\n", zName+p
3a40: 72 65 66 6c 65 6e 29 3b 0a 20 20 20 20 20 20 20 reflen);.
3a50: 20 20 20 7d 0a 20 20 20 20 20 20 20 20 7d 0a 20 }. }.
3a60: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 64 62 5f }. db_
3a70: 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 finalize(&q);.
3a80: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 75 }else{. u
3a90: 73 61 67 65 28 22 74 61 67 20 6c 69 73 74 20 3f sage("tag list ?
3aa0: 55 55 49 44 3f 22 29 3b 0a 20 20 20 20 7d 0a 20 UUID?");. }.
3ab0: 20 7d 65 6c 73 65 0a 20 20 7b 0a 20 20 20 20 67 }else. {. g
3ac0: 6f 74 6f 20 74 61 67 5f 63 6d 64 5f 75 73 61 67 oto tag_cmd_usag
3ad0: 65 3b 0a 20 20 7d 0a 0a 20 20 2f 2a 20 43 6c 65 e;. }.. /* Cle
3ae0: 61 6e 75 70 20 2a 2f 0a 20 20 62 6c 6f 62 5f 72 anup */. blob_r
3af0: 65 73 65 74 28 26 74 61 67 6e 61 6d 65 29 3b 0a eset(&tagname);.
3b00: 20 20 72 65 74 75 72 6e 3b 0a 0a 74 61 67 5f 63 return;..tag_c
3b10: 6d 64 5f 75 73 61 67 65 3a 0a 20 20 75 73 61 67 md_usage:. usag
3b20: 65 28 22 61 64 64 7c 62 72 61 6e 63 68 7c 63 61 e("add|branch|ca
3b30: 6e 63 65 6c 7c 66 69 6e 64 7c 6c 69 73 74 20 2e ncel|find|list .
3b40: 2e 2e 22 29 3b 0a 7d 0a ..");.}.