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 65 72 67 65 20 74 68 65 sed to merge the
0390: 20 63 68 61 6e 67 65 73 20 69 6e 20 74 68 65 20 changes in the
03a0: 63 75 72 72 65 6e 74 0a 2a 2a 20 63 68 65 63 6b current.** check
03b0: 6f 75 74 20 69 6e 74 6f 20 61 20 64 69 66 66 65 out into a diffe
03c0: 72 65 6e 74 20 76 65 72 73 69 6f 6e 20 61 6e 64 rent version and
03d0: 20 73 77 69 74 63 68 20 74 6f 20 74 68 61 74 20 switch to that
03e0: 76 65 72 73 69 6f 6e 2e 0a 2a 2f 0a 23 69 6e 63 version..*/.#inc
03f0: 6c 75 64 65 20 22 63 6f 6e 66 69 67 2e 68 22 0a lude "config.h".
0400: 23 69 6e 63 6c 75 64 65 20 22 75 70 64 61 74 65 #include "update
0410: 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 3c 61 73 .h".#include <as
0420: 73 65 72 74 2e 68 3e 0a 0a 2f 2a 0a 2a 2a 20 52 sert.h>../*.** R
0430: 65 74 75 72 6e 20 74 72 75 65 20 69 66 20 61 72 eturn true if ar
0440: 74 69 66 61 63 74 20 72 69 64 20 69 73 20 61 20 tifact rid is a
0450: 76 65 72 73 69 6f 6e 0a 2a 2f 0a 69 6e 74 20 69 version.*/.int i
0460: 73 5f 61 5f 76 65 72 73 69 6f 6e 28 69 6e 74 20 s_a_version(int
0470: 72 69 64 29 7b 0a 20 20 72 65 74 75 72 6e 20 64 rid){. return d
0480: 62 5f 65 78 69 73 74 73 28 22 53 45 4c 45 43 54 b_exists("SELECT
0490: 20 31 20 46 52 4f 4d 20 70 6c 69 6e 6b 20 57 48 1 FROM plink WH
04a0: 45 52 45 20 63 69 64 3d 25 64 22 2c 20 72 69 64 ERE cid=%d", rid
04b0: 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d );.}../*.** COMM
04c0: 41 4e 44 3a 20 75 70 64 61 74 65 0a 2a 2a 0a 2a AND: update.**.*
04d0: 2a 20 55 73 61 67 65 3a 20 25 66 6f 73 73 69 6c * Usage: %fossil
04e0: 20 75 70 64 61 74 65 20 3f 56 45 52 53 49 4f 4e update ?VERSION
04f0: 3f 20 3f 46 49 4c 45 53 2e 2e 2e 3f 0a 2a 2a 0a ? ?FILES...?.**.
0500: 2a 2a 20 43 68 61 6e 67 65 20 74 68 65 20 76 65 ** Change the ve
0510: 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 63 75 72 rsion of the cur
0520: 72 65 6e 74 20 63 68 65 63 6b 6f 75 74 20 74 6f rent checkout to
0530: 20 56 45 52 53 49 4f 4e 2e 20 20 41 6e 79 20 75 VERSION. Any u
0540: 6e 63 6f 6d 6d 69 74 74 65 64 0a 2a 2a 20 63 68 ncommitted.** ch
0550: 61 6e 67 65 73 20 61 72 65 20 72 65 74 61 69 6e anges are retain
0560: 65 64 20 61 6e 64 20 61 70 70 6c 69 65 64 20 74 ed and applied t
0570: 6f 20 74 68 65 20 6e 65 77 20 63 68 65 63 6b 6f o the new checko
0580: 75 74 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 56 45 ut..**.** The VE
0590: 52 53 49 4f 4e 20 61 72 67 75 6d 65 6e 74 20 63 RSION argument c
05a0: 61 6e 20 62 65 20 61 20 73 70 65 63 69 66 69 63 an be a specific
05b0: 20 76 65 72 73 69 6f 6e 20 6f 72 20 74 61 67 20 version or tag
05c0: 6f 72 20 62 72 61 6e 63 68 20 6e 61 6d 65 2e 0a or branch name..
05d0: 2a 2a 20 49 66 20 74 68 65 20 56 45 52 53 49 4f ** If the VERSIO
05e0: 4e 20 61 72 67 75 6d 65 6e 74 20 69 73 20 6f 6d N argument is om
05f0: 69 74 74 65 64 2c 20 74 68 65 6e 20 74 68 65 20 itted, then the
0600: 6c 65 61 66 20 6f 66 20 74 68 65 20 74 68 65 20 leaf of the the
0610: 73 75 62 74 72 65 65 0a 2a 2a 20 74 68 61 74 20 subtree.** that
0620: 62 65 67 69 6e 73 20 61 74 20 74 68 65 20 63 75 begins at the cu
0630: 72 72 65 6e 74 20 76 65 72 73 69 6f 6e 20 69 73 rrent version is
0640: 20 75 73 65 64 2c 20 69 66 20 74 68 65 72 65 20 used, if there
0650: 69 73 20 6f 6e 6c 79 20 61 20 73 69 6e 67 6c 65 is only a single
0660: 0a 2a 2a 20 6c 65 61 66 2e 20 20 56 45 52 53 49 .** leaf. VERSI
0670: 4f 4e 20 63 61 6e 20 61 6c 73 6f 20 62 65 20 22 ON can also be "
0680: 63 75 72 72 65 6e 74 22 20 74 6f 20 73 65 6c 65 current" to sele
0690: 63 74 20 74 68 65 20 6c 65 61 66 20 6f 66 20 74 ct the leaf of t
06a0: 68 65 20 63 75 72 72 65 6e 74 0a 2a 2a 20 76 65 he current.** ve
06b0: 72 73 69 6f 6e 20 6f 72 20 22 6c 61 74 65 73 74 rsion or "latest
06c0: 22 20 74 6f 20 73 65 6c 65 63 74 20 74 68 65 20 " to select the
06d0: 6d 6f 73 74 20 72 65 63 65 6e 74 20 63 68 65 63 most recent chec
06e0: 6b 2d 69 6e 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 6f k-in..**.** If o
06f0: 6e 65 20 6f 72 20 6d 6f 72 65 20 46 49 4c 45 53 ne or more FILES
0700: 20 61 72 65 20 6c 69 73 74 65 64 20 61 66 74 65 are listed afte
0710: 72 20 74 68 65 20 56 45 52 53 49 4f 4e 20 74 68 r the VERSION th
0720: 65 6e 20 6f 6e 6c 79 20 74 68 65 0a 2a 2a 20 6e en only the.** n
0730: 61 6d 65 64 20 66 69 6c 65 73 20 61 72 65 20 63 amed files are c
0740: 61 6e 64 69 64 61 74 65 73 20 74 6f 20 62 65 20 andidates to be
0750: 75 70 64 61 74 65 64 2e 20 20 49 66 20 46 49 4c updated. If FIL
0760: 45 53 20 69 73 20 6f 6d 69 74 74 65 64 2c 20 61 ES is omitted, a
0770: 6c 6c 0a 2a 2a 20 66 69 6c 65 73 20 69 6e 20 74 ll.** files in t
0780: 68 65 20 63 75 72 72 65 6e 74 20 63 68 65 63 6b he current check
0790: 6f 75 74 20 61 72 65 20 73 75 62 6a 65 63 74 20 out are subject
07a0: 74 6f 20 62 65 20 75 70 64 61 74 65 64 2e 0a 2a to be updated..*
07b0: 2a 0a 2a 2a 20 54 68 65 20 2d 6e 20 6f 72 20 2d *.** The -n or -
07c0: 2d 6e 6f 63 68 61 6e 67 65 20 6f 70 74 69 6f 6e -nochange option
07d0: 20 63 61 75 73 65 73 20 74 68 69 73 20 63 6f 6d causes this com
07e0: 6d 61 6e 64 20 74 6f 20 64 6f 20 61 20 22 64 72 mand to do a "dr
07f0: 79 20 72 75 6e 22 2e 20 20 49 74 0a 2a 2a 20 70 y run". It.** p
0800: 72 69 6e 74 73 20 6f 75 74 20 77 68 61 74 20 77 rints out what w
0810: 6f 75 6c 64 20 68 61 76 65 20 68 61 70 70 65 6e ould have happen
0820: 65 64 20 62 75 74 20 64 6f 65 73 20 6e 6f 74 20 ed but does not
0830: 61 63 74 75 61 6c 6c 79 20 6d 61 6b 65 20 61 6e actually make an
0840: 79 0a 2a 2a 20 63 68 61 6e 67 65 73 20 74 6f 20 y.** changes to
0850: 74 68 65 20 63 75 72 72 65 6e 74 20 63 68 65 63 the current chec
0860: 6b 6f 75 74 20 6f 72 20 74 68 65 20 72 65 70 6f kout or the repo
0870: 73 69 74 6f 72 79 2e 0a 2a 2a 0a 2a 2a 20 54 68 sitory..**.** Th
0880: 65 20 2d 76 20 6f 72 20 2d 2d 76 65 72 62 6f 73 e -v or --verbos
0890: 65 20 6f 70 74 69 6f 6e 20 70 72 69 6e 74 73 20 e option prints
08a0: 73 74 61 74 75 73 20 69 6e 66 6f 72 6d 61 74 69 status informati
08b0: 6f 6e 20 61 62 6f 75 74 20 75 6e 63 68 61 6e 67 on about unchang
08c0: 65 64 0a 2a 2a 20 66 69 6c 65 73 20 69 6e 20 61 ed.** files in a
08d0: 64 64 69 74 69 6f 6e 20 74 6f 20 74 68 6f 73 65 ddition to those
08e0: 20 66 69 6c 65 20 74 68 61 74 20 61 63 74 75 61 file that actua
08f0: 6c 6c 79 20 64 6f 20 63 68 61 6e 67 65 2e 0a 2a lly do change..*
0900: 2f 0a 76 6f 69 64 20 75 70 64 61 74 65 5f 63 6d /.void update_cm
0910: 64 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 76 d(void){. int v
0920: 69 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 id;
0930: 20 2f 2a 20 43 75 72 72 65 6e 74 20 76 65 72 73 /* Current vers
0940: 69 6f 6e 20 2a 2f 0a 20 20 69 6e 74 20 74 69 64 ion */. int tid
0950: 3d 30 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f =0; /
0960: 2a 20 54 61 72 67 65 74 20 76 65 72 73 69 6f 6e * Target version
0970: 20 2d 20 76 65 72 73 69 6f 6e 20 77 65 20 61 72 - version we ar
0980: 65 20 63 68 61 6e 67 69 6e 67 20 74 6f 20 2a 2f e changing to */
0990: 0a 20 20 53 74 6d 74 20 71 3b 0a 20 20 69 6e 74 . Stmt q;. int
09a0: 20 6c 61 74 65 73 74 46 6c 61 67 3b 20 20 20 20 latestFlag;
09b0: 20 20 20 2f 2a 20 2d 2d 6c 61 74 65 73 74 2e 20 /* --latest.
09c0: 20 50 69 63 6b 20 74 68 65 20 6c 61 74 65 73 74 Pick the latest
09d0: 20 76 65 72 73 69 6f 6e 20 69 66 20 74 72 75 65 version if true
09e0: 20 2a 2f 0a 20 20 69 6e 74 20 6e 6f 63 68 61 6e */. int nochan
09f0: 67 65 46 6c 61 67 3b 20 20 20 20 20 2f 2a 20 2d geFlag; /* -
0a00: 6e 20 6f 72 20 2d 2d 6e 6f 63 68 61 6e 67 65 2e n or --nochange.
0a10: 20 20 44 6f 20 61 20 64 72 79 20 72 75 6e 20 2a Do a dry run *
0a20: 2f 0a 20 20 69 6e 74 20 76 65 72 62 6f 73 65 46 /. int verboseF
0a30: 6c 61 67 3b 20 20 20 20 20 20 2f 2a 20 2d 76 20 lag; /* -v
0a40: 6f 72 20 2d 2d 76 65 72 62 6f 73 65 2e 20 20 4f or --verbose. O
0a50: 75 74 70 75 74 20 65 78 74 72 61 20 69 6e 66 6f utput extra info
0a60: 72 6d 61 74 69 6f 6e 20 2a 2f 0a 0a 20 20 75 72 rmation */.. ur
0a70: 6c 5f 70 72 6f 78 79 5f 6f 70 74 69 6f 6e 73 28 l_proxy_options(
0a80: 29 3b 0a 20 20 6c 61 74 65 73 74 46 6c 61 67 20 );. latestFlag
0a90: 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 6c = find_option("l
0aa0: 61 74 65 73 74 22 2c 30 2c 20 30 29 21 3d 30 3b atest",0, 0)!=0;
0ab0: 0a 20 20 6e 6f 63 68 61 6e 67 65 46 6c 61 67 20 . nochangeFlag
0ac0: 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 6e = find_option("n
0ad0: 6f 63 68 61 6e 67 65 22 2c 22 6e 22 2c 30 29 21 ochange","n",0)!
0ae0: 3d 30 3b 0a 20 20 76 65 72 62 6f 73 65 46 6c 61 =0;. verboseFla
0af0: 67 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 g = find_option(
0b00: 22 76 65 72 62 6f 73 65 22 2c 22 76 22 2c 30 29 "verbose","v",0)
0b10: 21 3d 30 3b 0a 20 20 64 62 5f 6d 75 73 74 5f 62 !=0;. db_must_b
0b20: 65 5f 77 69 74 68 69 6e 5f 74 72 65 65 28 29 3b e_within_tree();
0b30: 0a 20 20 76 69 64 20 3d 20 64 62 5f 6c 67 65 74 . vid = db_lget
0b40: 5f 69 6e 74 28 22 63 68 65 63 6b 6f 75 74 22 2c _int("checkout",
0b50: 20 30 29 3b 0a 20 20 69 66 28 20 76 69 64 3d 3d 0);. if( vid==
0b60: 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 0 ){. fossil_
0b70: 66 61 74 61 6c 28 22 63 61 6e 6e 6f 74 20 66 69 fatal("cannot fi
0b80: 6e 64 20 63 75 72 72 65 6e 74 20 76 65 72 73 69 nd current versi
0b90: 6f 6e 22 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 on");. }. if(
0ba0: 64 62 5f 65 78 69 73 74 73 28 22 53 45 4c 45 43 db_exists("SELEC
0bb0: 54 20 31 20 46 52 4f 4d 20 76 6d 65 72 67 65 22 T 1 FROM vmerge"
0bc0: 29 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f ) ){. fossil_
0bd0: 66 61 74 61 6c 28 22 63 61 6e 6e 6f 74 20 75 70 fatal("cannot up
0be0: 64 61 74 65 20 61 6e 20 75 6e 63 6f 6d 6d 69 74 date an uncommit
0bf0: 74 65 64 20 6d 65 72 67 65 22 29 3b 0a 20 20 7d ted merge");. }
0c00: 0a 0a 20 20 69 66 28 20 67 2e 61 72 67 63 3e 3d .. if( g.argc>=
0c10: 33 20 29 7b 0a 20 20 20 20 69 66 28 20 73 74 72 3 ){. if( str
0c20: 63 6d 70 28 67 2e 61 72 67 76 5b 32 5d 2c 20 22 cmp(g.argv[2], "
0c30: 63 75 72 72 65 6e 74 22 29 3d 3d 30 20 29 7b 0a current")==0 ){.
0c40: 20 20 20 20 20 20 2f 2a 20 49 66 20 56 45 52 53 /* If VERS
0c50: 49 4f 4e 20 69 73 20 22 63 75 72 72 65 6e 74 22 ION is "current"
0c60: 2c 20 74 68 65 6e 20 75 73 65 20 74 68 65 20 73 , then use the s
0c70: 61 6d 65 20 61 6c 67 6f 72 69 74 68 6d 20 74 6f ame algorithm to
0c80: 20 66 69 6e 64 20 74 68 65 0a 20 20 20 20 20 20 find the.
0c90: 2a 2a 20 74 61 72 67 65 74 20 61 73 20 69 66 20 ** target as if
0ca0: 56 45 52 53 49 4f 4e 20 77 65 72 65 20 6f 6d 69 VERSION were omi
0cb0: 74 74 65 64 2e 20 2a 2f 0a 20 20 20 20 7d 65 6c tted. */. }el
0cc0: 73 65 20 69 66 28 20 73 74 72 63 6d 70 28 67 2e se if( strcmp(g.
0cd0: 61 72 67 76 5b 32 5d 2c 20 22 6c 61 74 65 73 74 argv[2], "latest
0ce0: 22 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 2f ")==0 ){. /
0cf0: 2a 20 49 66 20 56 45 52 53 49 4f 4e 20 69 73 20 * If VERSION is
0d00: 22 6c 61 74 65 73 74 22 2c 20 74 68 65 6e 20 75 "latest", then u
0d10: 73 65 20 74 68 65 20 73 61 6d 65 20 61 6c 67 6f se the same algo
0d20: 72 69 74 68 6d 20 74 6f 20 66 69 6e 64 20 74 68 rithm to find th
0d30: 65 0a 20 20 20 20 20 20 2a 2a 20 74 61 72 67 65 e. ** targe
0d40: 74 20 61 73 20 69 66 20 56 45 52 53 49 4f 4e 20 t as if VERSION
0d50: 77 65 72 65 20 6f 6d 69 74 74 65 64 20 61 6e 64 were omitted and
0d60: 20 74 68 65 20 2d 2d 6c 61 74 65 73 74 20 66 6c the --latest fl
0d70: 61 67 20 69 73 20 70 72 65 73 65 6e 74 2e 0a 20 ag is present..
0d80: 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 6c 61 */. la
0d90: 74 65 73 74 46 6c 61 67 20 3d 20 31 3b 0a 20 20 testFlag = 1;.
0da0: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 74 }else{. t
0db0: 69 64 20 3d 20 6e 61 6d 65 5f 74 6f 5f 72 69 64 id = name_to_rid
0dc0: 28 67 2e 61 72 67 76 5b 32 5d 29 3b 0a 20 20 20 (g.argv[2]);.
0dd0: 20 20 20 69 66 28 20 74 69 64 3d 3d 30 20 29 7b if( tid==0 ){
0de0: 0a 20 20 20 20 20 20 20 20 66 6f 73 73 69 6c 5f . fossil_
0df0: 66 61 74 61 6c 28 22 6e 6f 20 73 75 63 68 20 76 fatal("no such v
0e00: 65 72 73 69 6f 6e 3a 20 25 73 22 2c 20 67 2e 61 ersion: %s", g.a
0e10: 72 67 76 5b 32 5d 29 3b 0a 20 20 20 20 20 20 7d rgv[2]);. }
0e20: 65 6c 73 65 20 69 66 28 20 21 69 73 5f 61 5f 76 else if( !is_a_v
0e30: 65 72 73 69 6f 6e 28 74 69 64 29 20 29 7b 0a 20 ersion(tid) ){.
0e40: 20 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 fossil_fa
0e50: 74 61 6c 28 22 6e 6f 20 73 75 63 68 20 76 65 72 tal("no such ver
0e60: 73 69 6f 6e 3a 20 25 73 22 2c 20 67 2e 61 72 67 sion: %s", g.arg
0e70: 76 5b 32 5d 29 3b 0a 20 20 20 20 20 20 7d 0a 20 v[2]);. }.
0e80: 20 20 20 7d 0a 20 20 7d 0a 20 20 69 66 28 20 21 }. }. if( !
0e90: 6e 6f 63 68 61 6e 67 65 46 6c 61 67 20 29 20 61 nochangeFlag ) a
0ea0: 75 74 6f 73 79 6e 63 28 41 55 54 4f 53 59 4e 43 utosync(AUTOSYNC
0eb0: 5f 50 55 4c 4c 29 3b 0a 20 20 0a 20 20 69 66 28 _PULL);. . if(
0ec0: 20 74 69 64 3d 3d 30 20 29 7b 0a 20 20 20 20 63 tid==0 ){. c
0ed0: 6f 6d 70 75 74 65 5f 6c 65 61 76 65 73 28 76 69 ompute_leaves(vi
0ee0: 64 2c 20 31 29 3b 0a 20 20 20 20 69 66 28 20 21 d, 1);. if( !
0ef0: 6c 61 74 65 73 74 46 6c 61 67 20 26 26 20 64 62 latestFlag && db
0f00: 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 20 _int(0, "SELECT
0f10: 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 6c 65 count(*) FROM le
0f20: 61 76 65 73 22 29 3e 31 20 29 7b 0a 20 20 20 20 aves")>1 ){.
0f30: 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c db_prepare(&q,
0f40: 20 0a 20 20 20 20 20 20 20 20 22 25 73 20 22 0a . "%s ".
0f50: 20 20 20 20 20 20 20 20 22 20 20 20 41 4e 44 20 " AND
0f60: 65 76 65 6e 74 2e 6f 62 6a 69 64 20 49 4e 20 6c event.objid IN l
0f70: 65 61 76 65 73 22 0a 20 20 20 20 20 20 20 20 22 eaves". "
0f80: 20 4f 52 44 45 52 20 42 59 20 65 76 65 6e 74 2e ORDER BY event.
0f90: 6d 74 69 6d 65 20 44 45 53 43 22 2c 0a 20 20 20 mtime DESC",.
0fa0: 20 20 20 20 20 74 69 6d 65 6c 69 6e 65 5f 71 75 timeline_qu
0fb0: 65 72 79 5f 66 6f 72 5f 74 74 79 28 29 0a 20 20 ery_for_tty().
0fc0: 20 20 20 20 29 3b 0a 20 20 20 20 20 20 70 72 69 );. pri
0fd0: 6e 74 5f 74 69 6d 65 6c 69 6e 65 28 26 71 2c 20 nt_timeline(&q,
0fe0: 31 30 30 29 3b 0a 20 20 20 20 20 20 64 62 5f 66 100);. db_f
0ff0: 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 20 inalize(&q);.
1000: 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 fossil_fatal(
1010: 22 4d 75 6c 74 69 70 6c 65 20 64 65 73 63 65 6e "Multiple descen
1020: 64 61 6e 74 73 22 29 3b 0a 20 20 20 20 7d 0a 20 dants");. }.
1030: 20 20 20 74 69 64 20 3d 20 64 62 5f 69 6e 74 28 tid = db_int(
1040: 30 2c 20 22 53 45 4c 45 43 54 20 72 69 64 20 46 0, "SELECT rid F
1050: 52 4f 4d 20 6c 65 61 76 65 73 2c 20 65 76 65 6e ROM leaves, even
1060: 74 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 t".
1070: 20 20 20 20 20 20 20 22 20 57 48 45 52 45 20 65 " WHERE e
1080: 76 65 6e 74 2e 6f 62 6a 69 64 3d 6c 65 61 76 65 vent.objid=leave
1090: 73 2e 72 69 64 22 0a 20 20 20 20 20 20 20 20 20 s.rid".
10a0: 20 20 20 20 20 20 20 20 20 20 20 22 20 4f 52 44 " ORD
10b0: 45 52 20 42 59 20 65 76 65 6e 74 2e 6d 74 69 6d ER BY event.mtim
10c0: 65 20 44 45 53 43 22 29 3b 20 0a 20 20 7d 0a 0a e DESC"); . }..
10d0: 20 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 db_begin_trans
10e0: 61 63 74 69 6f 6e 28 29 3b 0a 20 20 76 66 69 6c action();. vfil
10f0: 65 5f 63 68 65 63 6b 5f 73 69 67 6e 61 74 75 72 e_check_signatur
1100: 65 28 76 69 64 29 3b 0a 20 20 75 6e 64 6f 5f 62 e(vid);. undo_b
1110: 65 67 69 6e 28 29 3b 0a 20 20 6c 6f 61 64 5f 76 egin();. load_v
1120: 66 69 6c 65 5f 66 72 6f 6d 5f 72 69 64 28 74 69 file_from_rid(ti
1130: 64 29 3b 0a 0a 20 20 2f 2a 0a 20 20 2a 2a 20 54 d);.. /*. ** T
1140: 68 65 20 72 65 63 6f 72 64 2e 66 6e 20 66 69 65 he record.fn fie
1150: 6c 64 20 69 73 20 75 73 65 64 20 74 6f 20 6d 61 ld is used to ma
1160: 74 63 68 20 66 69 6c 65 73 20 61 67 61 69 6e 73 tch files agains
1170: 74 20 65 61 63 68 20 6f 74 68 65 72 2e 20 20 54 t each other. T
1180: 68 65 0a 20 20 2a 2a 20 46 56 20 74 61 62 6c 65 he. ** FV table
1190: 20 63 6f 6e 74 61 69 6e 73 20 6f 6e 65 20 72 6f contains one ro
11a0: 77 20 66 6f 72 20 65 61 63 68 20 65 61 63 68 20 w for each each
11b0: 75 6e 69 71 75 65 20 66 69 6c 65 6e 61 6d 65 20 unique filename
11c0: 69 6e 0a 20 20 2a 2a 20 69 6e 20 74 68 65 20 63 in. ** in the c
11d0: 75 72 72 65 6e 74 20 63 68 65 63 6b 6f 75 74 2c urrent checkout,
11e0: 20 74 68 65 20 70 69 76 6f 74 2c 20 61 6e 64 20 the pivot, and
11f0: 74 68 65 20 76 65 72 73 69 6f 6e 20 62 65 69 6e the version bein
1200: 67 20 6d 65 72 67 65 64 2e 0a 20 20 2a 2f 0a 20 g merged.. */.
1210: 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a db_multi_exec(.
1220: 20 20 20 20 22 44 52 4f 50 20 54 41 42 4c 45 20 "DROP TABLE
1230: 49 46 20 45 58 49 53 54 53 20 66 76 3b 22 0a 20 IF EXISTS fv;".
1240: 20 20 20 22 43 52 45 41 54 45 20 54 45 4d 50 20 "CREATE TEMP
1250: 54 41 42 4c 45 20 66 76 28 22 0a 20 20 20 20 22 TABLE fv(". "
1260: 20 20 66 6e 20 54 45 58 54 20 50 52 49 4d 41 52 fn TEXT PRIMAR
1270: 59 20 4b 45 59 2c 22 20 20 20 20 20 20 2f 2a 20 Y KEY," /*
1280: 54 68 65 20 66 69 6c 65 6e 61 6d 65 20 72 65 6c The filename rel
1290: 61 74 69 76 65 20 74 6f 20 72 6f 6f 74 20 2a 2f ative to root */
12a0: 0a 20 20 20 20 22 20 20 69 64 76 20 49 4e 54 45 . " idv INTE
12b0: 47 45 52 2c 22 20 20 20 20 20 20 20 20 20 20 20 GER,"
12c0: 20 20 20 2f 2a 20 56 46 49 4c 45 20 65 6e 74 72 /* VFILE entr
12d0: 79 20 66 6f 72 20 63 75 72 72 65 6e 74 20 76 65 y for current ve
12e0: 72 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 22 20 20 rsion */. "
12f0: 69 64 74 20 49 4e 54 45 47 45 52 2c 22 20 20 20 idt INTEGER,"
1300: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 46 /* VF
1310: 49 4c 45 20 65 6e 74 72 79 20 66 6f 72 20 74 61 ILE entry for ta
1320: 72 67 65 74 20 76 65 72 73 69 6f 6e 20 2a 2f 0a rget version */.
1330: 20 20 20 20 22 20 20 63 68 6e 67 65 64 20 42 4f " chnged BO
1340: 4f 4c 45 41 4e 2c 22 20 20 20 20 20 20 20 20 20 OLEAN,"
1350: 20 20 2f 2a 20 54 72 75 65 20 69 66 20 63 75 72 /* True if cur
1360: 72 65 6e 74 20 76 65 72 73 69 6f 6e 20 68 61 73 rent version has
1370: 20 62 65 65 6e 20 65 64 69 74 65 64 20 2a 2f 0a been edited */.
1380: 20 20 20 20 22 20 20 72 69 64 76 20 49 4e 54 45 " ridv INTE
1390: 47 45 52 2c 22 20 20 20 20 20 20 20 20 20 20 20 GER,"
13a0: 20 20 2f 2a 20 52 65 63 6f 72 64 20 49 44 20 66 /* Record ID f
13b0: 6f 72 20 63 75 72 72 65 6e 74 20 76 65 72 73 69 or current versi
13c0: 6f 6e 20 2a 2f 0a 20 20 20 20 22 20 20 72 69 64 on */. " rid
13d0: 74 20 49 4e 54 45 47 45 52 20 22 20 20 20 20 20 t INTEGER "
13e0: 20 20 20 20 20 20 20 20 2f 2a 20 52 65 63 6f 72 /* Recor
13f0: 64 20 49 44 20 66 6f 72 20 74 61 72 67 65 74 20 d ID for target
1400: 2a 2f 0a 20 20 20 20 22 29 3b 22 0a 20 20 20 20 */. ");".
1410: 22 49 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 "INSERT OR IGNOR
1420: 45 20 49 4e 54 4f 20 66 76 22 0a 20 20 20 20 22 E INTO fv". "
1430: 20 53 45 4c 45 43 54 20 70 61 74 68 6e 61 6d 65 SELECT pathname
1440: 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 20 , 0, 0, 0, 0, 0
1450: 46 52 4f 4d 20 76 66 69 6c 65 22 0a 20 20 29 3b FROM vfile". );
1460: 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 . db_prepare(&q
1470: 2c 0a 20 20 20 20 22 53 45 4c 45 43 54 20 69 64 ,. "SELECT id
1480: 2c 20 70 61 74 68 6e 61 6d 65 2c 20 72 69 64 20 , pathname, rid
1490: 46 52 4f 4d 20 76 66 69 6c 65 22 0a 20 20 20 20 FROM vfile".
14a0: 22 20 57 48 45 52 45 20 76 69 64 3d 25 64 22 2c " WHERE vid=%d",
14b0: 20 74 69 64 0a 20 20 29 3b 0a 20 20 77 68 69 6c tid. );. whil
14c0: 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d e( db_step(&q)==
14d0: 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 SQLITE_ROW ){.
14e0: 20 20 69 6e 74 20 69 64 20 3d 20 64 62 5f 63 6f int id = db_co
14f0: 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 30 29 3b lumn_int(&q, 0);
1500: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 . const char
1510: 2a 66 6e 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f *fn = db_column_
1520: 74 65 78 74 28 26 71 2c 20 31 29 3b 0a 20 20 20 text(&q, 1);.
1530: 20 69 6e 74 20 72 69 64 20 3d 20 64 62 5f 63 6f int rid = db_co
1540: 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 32 29 3b lumn_int(&q, 2);
1550: 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 . db_multi_ex
1560: 65 63 28 0a 20 20 20 20 20 20 22 55 50 44 41 54 ec(. "UPDAT
1570: 45 20 66 76 20 53 45 54 20 69 64 74 3d 25 64 2c E fv SET idt=%d,
1580: 20 72 69 64 74 3d 25 64 20 57 48 45 52 45 20 66 ridt=%d WHERE f
1590: 6e 3d 25 51 22 2c 0a 20 20 20 20 20 20 69 64 2c n=%Q",. id,
15a0: 20 72 69 64 2c 20 66 6e 0a 20 20 20 20 29 3b 0a rid, fn. );.
15b0: 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a }. db_finaliz
15c0: 65 28 26 71 29 3b 0a 20 20 64 62 5f 70 72 65 70 e(&q);. db_prep
15d0: 61 72 65 28 26 71 2c 0a 20 20 20 20 22 53 45 4c are(&q,. "SEL
15e0: 45 43 54 20 69 64 2c 20 70 61 74 68 6e 61 6d 65 ECT id, pathname
15f0: 2c 20 72 69 64 2c 20 63 68 6e 67 65 64 20 46 52 , rid, chnged FR
1600: 4f 4d 20 76 66 69 6c 65 22 0a 20 20 20 20 22 20 OM vfile". "
1610: 57 48 45 52 45 20 76 69 64 3d 25 64 22 2c 20 76 WHERE vid=%d", v
1620: 69 64 0a 20 20 29 3b 0a 20 20 77 68 69 6c 65 28 id. );. while(
1630: 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 db_step(&q)==SQ
1640: 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 LITE_ROW ){.
1650: 69 6e 74 20 69 64 20 3d 20 64 62 5f 63 6f 6c 75 int id = db_colu
1660: 6d 6e 5f 69 6e 74 28 26 71 2c 20 30 29 3b 0a 20 mn_int(&q, 0);.
1670: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 const char *f
1680: 6e 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 n = db_column_te
1690: 78 74 28 26 71 2c 20 31 29 3b 0a 20 20 20 20 69 xt(&q, 1);. i
16a0: 6e 74 20 72 69 64 20 3d 20 64 62 5f 63 6f 6c 75 nt rid = db_colu
16b0: 6d 6e 5f 69 6e 74 28 26 71 2c 20 32 29 3b 0a 20 mn_int(&q, 2);.
16c0: 20 20 20 69 6e 74 20 63 68 6e 67 65 64 20 3d 20 int chnged =
16d0: 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 db_column_int(&q
16e0: 2c 20 33 29 3b 0a 20 20 20 20 64 62 5f 6d 75 6c , 3);. db_mul
16f0: 74 69 5f 65 78 65 63 28 0a 20 20 20 20 20 20 22 ti_exec(. "
1700: 55 50 44 41 54 45 20 66 76 20 53 45 54 20 69 64 UPDATE fv SET id
1710: 76 3d 25 64 2c 20 72 69 64 76 3d 25 64 2c 20 63 v=%d, ridv=%d, c
1720: 68 6e 67 65 64 3d 25 64 20 57 48 45 52 45 20 66 hnged=%d WHERE f
1730: 6e 3d 25 51 22 2c 0a 20 20 20 20 20 20 69 64 2c n=%Q",. id,
1740: 20 72 69 64 2c 20 63 68 6e 67 65 64 2c 20 66 6e rid, chnged, fn
1750: 0a 20 20 20 20 29 3b 0a 20 20 7d 0a 20 20 64 62 . );. }. db
1760: 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 0a _finalize(&q);..
1770: 20 20 2f 2a 20 49 66 20 46 49 4c 45 53 20 61 70 /* If FILES ap
1780: 70 65 61 72 20 6f 6e 20 74 68 65 20 63 6f 6d 6d pear on the comm
1790: 61 6e 64 2d 6c 69 6e 65 2c 20 72 65 6d 6f 76 65 and-line, remove
17a0: 20 66 72 6f 6d 20 74 68 65 20 22 66 76 22 20 74 from the "fv" t
17b0: 61 62 6c 65 0a 20 20 2a 2a 20 65 76 65 72 79 20 able. ** every
17c0: 65 6e 74 72 79 20 74 68 61 74 20 69 73 20 6e 6f entry that is no
17d0: 74 20 6e 61 6d 65 64 20 6f 6e 20 74 68 65 20 63 t named on the c
17e0: 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 2e 0a 20 20 2a ommand-line.. *
17f0: 2f 0a 20 20 69 66 28 20 67 2e 61 72 67 63 3e 3d /. if( g.argc>=
1800: 34 20 29 7b 0a 20 20 20 20 42 6c 6f 62 20 73 71 4 ){. Blob sq
1810: 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 l;
1820: 2f 2a 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 /* SQL statement
1830: 20 74 6f 20 70 75 72 67 65 20 75 6e 77 61 6e 74 to purge unwant
1840: 65 64 20 65 6e 74 72 69 65 73 20 2a 2f 0a 20 20 ed entries */.
1850: 20 20 63 68 61 72 20 2a 7a 53 65 70 20 3d 20 22 char *zSep = "
1860: 28 22 3b 20 20 20 20 20 20 2f 2a 20 53 65 70 61 ("; /* Sepa
1870: 72 61 74 6f 72 20 69 6e 20 74 68 65 20 6c 69 73 rator in the lis
1880: 74 20 6f 66 20 66 69 6c 65 6e 61 6d 65 73 20 2a t of filenames *
1890: 2f 0a 20 20 20 20 42 6c 6f 62 20 74 72 65 65 6e /. Blob treen
18a0: 61 6d 65 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 ame; /*
18b0: 4e 6f 72 6d 61 6c 69 7a 65 64 20 66 69 6c 65 6e Normalized filen
18c0: 61 6d 65 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 ame */. int i
18d0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
18e0: 20 20 2f 2a 20 4c 6f 6f 70 20 63 6f 75 6e 74 65 /* Loop counte
18f0: 72 20 2a 2f 0a 0a 20 20 20 20 62 6c 6f 62 5f 7a r */.. blob_z
1900: 65 72 6f 28 26 73 71 6c 29 3b 0a 20 20 20 20 62 ero(&sql);. b
1910: 6c 6f 62 5f 61 70 70 65 6e 64 28 26 73 71 6c 2c lob_append(&sql,
1920: 20 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 66 76 "DELETE FROM fv
1930: 20 57 48 45 52 45 20 66 6e 20 4e 4f 54 20 49 4e WHERE fn NOT IN
1940: 20 22 2c 20 2d 31 29 3b 0a 20 20 20 20 66 6f 72 ", -1);. for
1950: 28 69 3d 33 3b 20 69 3c 67 2e 61 72 67 63 3b 20 (i=3; i<g.argc;
1960: 69 2b 2b 29 7b 0a 20 20 20 20 20 20 66 69 6c 65 i++){. file
1970: 5f 74 72 65 65 5f 6e 61 6d 65 28 67 2e 61 72 67 _tree_name(g.arg
1980: 76 5b 69 5d 2c 20 26 74 72 65 65 6e 61 6d 65 2c v[i], &treename,
1990: 20 31 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 1);. blob_
19a0: 61 70 70 65 6e 64 66 28 26 73 71 6c 2c 20 22 25 appendf(&sql, "%
19b0: 73 27 25 71 27 22 2c 20 7a 53 65 70 2c 20 62 6c s'%q'", zSep, bl
19c0: 6f 62 5f 73 74 72 28 26 74 72 65 65 6e 61 6d 65 ob_str(&treename
19d0: 29 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 ));. blob_r
19e0: 65 73 65 74 28 26 74 72 65 65 6e 61 6d 65 29 3b eset(&treename);
19f0: 0a 20 20 20 20 20 20 7a 53 65 70 20 3d 20 22 2c . zSep = ",
1a00: 22 3b 0a 20 20 20 20 7d 0a 20 20 20 20 62 6c 6f ";. }. blo
1a10: 62 5f 61 70 70 65 6e 64 28 26 73 71 6c 2c 20 22 b_append(&sql, "
1a20: 29 22 2c 20 2d 31 29 3b 0a 20 20 20 20 64 62 5f )", -1);. db_
1a30: 6d 75 6c 74 69 5f 65 78 65 63 28 62 6c 6f 62 5f multi_exec(blob_
1a40: 73 74 72 28 26 73 71 6c 29 29 3b 0a 20 20 20 20 str(&sql));.
1a50: 62 6c 6f 62 5f 72 65 73 65 74 28 26 73 71 6c 29 blob_reset(&sql)
1a60: 3b 0a 20 20 7d 0a 0a 20 20 64 62 5f 70 72 65 70 ;. }.. db_prep
1a70: 61 72 65 28 26 71 2c 20 0a 20 20 20 20 22 53 45 are(&q, . "SE
1a80: 4c 45 43 54 20 66 6e 2c 20 69 64 76 2c 20 72 69 LECT fn, idv, ri
1a90: 64 76 2c 20 69 64 74 2c 20 72 69 64 74 2c 20 63 dv, idt, ridt, c
1aa0: 68 6e 67 65 64 20 46 52 4f 4d 20 66 76 20 4f 52 hnged FROM fv OR
1ab0: 44 45 52 20 42 59 20 31 22 0a 20 20 29 3b 0a 20 DER BY 1". );.
1ac0: 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 while( db_step(
1ad0: 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 &q)==SQLITE_ROW
1ae0: 29 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 ){. const cha
1af0: 72 20 2a 7a 4e 61 6d 65 20 3d 20 64 62 5f 63 6f r *zName = db_co
1b00: 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30 29 lumn_text(&q, 0)
1b10: 3b 20 20 2f 2a 20 54 68 65 20 66 69 6c 65 6e 61 ; /* The filena
1b20: 6d 65 20 66 72 6f 6d 20 72 6f 6f 74 20 2a 2f 0a me from root */.
1b30: 20 20 20 20 69 6e 74 20 69 64 76 20 3d 20 64 62 int idv = db
1b40: 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 _column_int(&q,
1b50: 31 29 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 1);
1b60: 2f 2a 20 56 46 49 4c 45 20 65 6e 74 72 79 20 66 /* VFILE entry f
1b70: 6f 72 20 63 75 72 72 65 6e 74 20 2a 2f 0a 20 20 or current */.
1b80: 20 20 69 6e 74 20 72 69 64 76 20 3d 20 64 62 5f int ridv = db_
1b90: 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 32 column_int(&q, 2
1ba0: 29 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ); /*
1bb0: 20 52 65 63 6f 72 64 49 44 20 66 6f 72 20 63 75 RecordID for cu
1bc0: 72 72 65 6e 74 20 2a 2f 0a 20 20 20 20 69 6e 74 rrent */. int
1bd0: 20 69 64 74 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e idt = db_column
1be0: 5f 69 6e 74 28 26 71 2c 20 33 29 3b 20 20 20 20 _int(&q, 3);
1bf0: 20 20 20 20 20 20 20 20 20 2f 2a 20 56 46 49 4c /* VFIL
1c00: 45 20 65 6e 74 72 79 20 66 6f 72 20 74 61 72 67 E entry for targ
1c10: 65 74 20 2a 2f 0a 20 20 20 20 69 6e 74 20 72 69 et */. int ri
1c20: 64 74 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 dt = db_column_i
1c30: 6e 74 28 26 71 2c 20 34 29 3b 20 20 20 20 20 20 nt(&q, 4);
1c40: 20 20 20 20 20 20 2f 2a 20 52 65 63 6f 72 64 49 /* RecordI
1c50: 44 20 66 6f 72 20 74 61 72 67 65 74 20 2a 2f 0a D for target */.
1c60: 20 20 20 20 69 6e 74 20 63 68 6e 67 65 64 20 3d int chnged =
1c70: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 db_column_int(&
1c80: 71 2c 20 35 29 3b 20 20 20 20 20 20 20 20 20 20 q, 5);
1c90: 2f 2a 20 43 75 72 72 65 6e 74 20 69 73 20 65 64 /* Current is ed
1ca0: 69 74 65 64 20 2a 2f 0a 20 20 20 20 63 68 61 72 ited */. char
1cb0: 20 2a 7a 46 75 6c 6c 50 61 74 68 3b 20 20 20 20 *zFullPath;
1cc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1cd0: 20 20 20 20 20 20 20 20 2f 2a 20 46 75 6c 6c 20 /* Full
1ce0: 70 61 74 68 6e 61 6d 65 20 6f 66 20 74 68 65 20 pathname of the
1cf0: 66 69 6c 65 20 2a 2f 0a 0a 20 20 20 20 7a 46 75 file */.. zFu
1d00: 6c 6c 50 61 74 68 20 3d 20 6d 70 72 69 6e 74 66 llPath = mprintf
1d10: 28 22 25 73 2f 25 73 22 2c 20 67 2e 7a 4c 6f 63 ("%s/%s", g.zLoc
1d20: 61 6c 52 6f 6f 74 2c 20 7a 4e 61 6d 65 29 3b 0a alRoot, zName);.
1d30: 20 20 20 20 69 66 28 20 69 64 76 3e 30 20 26 26 if( idv>0 &&
1d40: 20 72 69 64 76 3d 3d 30 20 26 26 20 69 64 74 3e ridv==0 && idt>
1d50: 30 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 43 6f 0 ){. /* Co
1d60: 6e 66 6c 69 63 74 2e 20 20 54 68 69 73 20 66 69 nflict. This fi
1d70: 6c 65 20 68 61 73 20 62 65 65 6e 20 61 64 64 65 le has been adde
1d80: 64 20 74 6f 20 74 68 65 20 63 75 72 72 65 6e 74 d to the current
1d90: 20 63 68 65 63 6b 6f 75 74 0a 20 20 20 20 20 20 checkout.
1da0: 2a 2a 20 62 75 74 20 61 6c 73 6f 20 65 78 69 73 ** but also exis
1db0: 74 73 20 69 6e 20 74 68 65 20 74 61 72 67 65 74 ts in the target
1dc0: 20 63 68 65 63 6b 6f 75 74 2e 20 20 55 73 65 20 checkout. Use
1dd0: 74 68 65 20 63 75 72 72 65 6e 74 20 76 65 72 73 the current vers
1de0: 69 6f 6e 2e 0a 20 20 20 20 20 20 2a 2f 0a 20 20 ion.. */.
1df0: 20 20 20 20 70 72 69 6e 74 66 28 22 43 4f 4e 46 printf("CONF
1e00: 4c 49 43 54 20 25 73 5c 6e 22 2c 20 7a 4e 61 6d LICT %s\n", zNam
1e10: 65 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 e);. }else if
1e20: 28 20 69 64 74 3e 30 20 26 26 20 69 64 76 3d 3d ( idt>0 && idv==
1e30: 30 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 46 69 0 ){. /* Fi
1e40: 6c 65 20 61 64 64 65 64 20 69 6e 20 74 68 65 20 le added in the
1e50: 74 61 72 67 65 74 2e 20 2a 2f 0a 20 20 20 20 20 target. */.
1e60: 20 70 72 69 6e 74 66 28 22 41 44 44 20 25 73 5c printf("ADD %s\
1e70: 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 n", zName);.
1e80: 20 20 75 6e 64 6f 5f 73 61 76 65 28 7a 4e 61 6d undo_save(zNam
1e90: 65 29 3b 0a 20 20 20 20 20 20 69 66 28 20 21 6e e);. if( !n
1ea0: 6f 63 68 61 6e 67 65 46 6c 61 67 20 29 20 76 66 ochangeFlag ) vf
1eb0: 69 6c 65 5f 74 6f 5f 64 69 73 6b 28 30 2c 20 69 ile_to_disk(0, i
1ec0: 64 74 2c 20 30 29 3b 0a 20 20 20 20 7d 65 6c 73 dt, 0);. }els
1ed0: 65 20 69 66 28 20 69 64 74 3e 30 20 26 26 20 69 e if( idt>0 && i
1ee0: 64 76 3e 30 20 26 26 20 72 69 64 74 21 3d 72 69 dv>0 && ridt!=ri
1ef0: 64 76 20 26 26 20 63 68 6e 67 65 64 3d 3d 30 20 dv && chnged==0
1f00: 29 7b 0a 20 20 20 20 20 20 2f 2a 20 54 68 65 20 ){. /* The
1f10: 66 69 6c 65 20 69 73 20 75 6e 65 64 69 74 65 64 file is unedited
1f20: 2e 20 20 43 68 61 6e 67 65 20 69 74 20 74 6f 20 . Change it to
1f30: 74 68 65 20 74 61 72 67 65 74 20 76 65 72 73 69 the target versi
1f40: 6f 6e 20 2a 2f 0a 20 20 20 20 20 20 70 72 69 6e on */. prin
1f50: 74 66 28 22 55 50 44 41 54 45 20 25 73 5c 6e 22 tf("UPDATE %s\n"
1f60: 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 , zName);.
1f70: 75 6e 64 6f 5f 73 61 76 65 28 7a 4e 61 6d 65 29 undo_save(zName)
1f80: 3b 0a 20 20 20 20 20 20 69 66 28 20 21 6e 6f 63 ;. if( !noc
1f90: 68 61 6e 67 65 46 6c 61 67 20 29 20 76 66 69 6c hangeFlag ) vfil
1fa0: 65 5f 74 6f 5f 64 69 73 6b 28 30 2c 20 69 64 74 e_to_disk(0, idt
1fb0: 2c 20 30 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 , 0);. }else
1fc0: 69 66 28 20 69 64 74 3e 30 20 26 26 20 69 64 76 if( idt>0 && idv
1fd0: 3e 30 20 26 26 20 66 69 6c 65 5f 73 69 7a 65 28 >0 && file_size(
1fe0: 7a 46 75 6c 6c 50 61 74 68 29 3c 30 20 29 7b 0a zFullPath)<0 ){.
1ff0: 20 20 20 20 20 20 2f 2a 20 54 68 65 20 66 69 6c /* The fil
2000: 65 20 6d 69 73 73 69 6e 67 20 66 72 6f 6d 20 74 e missing from t
2010: 68 65 20 6c 6f 63 61 6c 20 63 68 65 63 6b 2d 6f he local check-o
2020: 75 74 2e 20 52 65 73 74 6f 72 65 20 69 74 20 74 ut. Restore it t
2030: 6f 20 74 68 65 0a 20 20 20 20 20 20 2a 2a 20 76 o the. ** v
2040: 65 72 73 69 6f 6e 20 74 68 61 74 20 61 70 70 65 ersion that appe
2050: 61 72 73 20 69 6e 20 74 68 65 20 74 61 72 67 65 ars in the targe
2060: 74 2e 20 2a 2f 0a 20 20 20 20 20 20 70 72 69 6e t. */. prin
2070: 74 66 28 22 55 50 44 41 54 45 20 25 73 5c 6e 22 tf("UPDATE %s\n"
2080: 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 , zName);.
2090: 75 6e 64 6f 5f 73 61 76 65 28 7a 4e 61 6d 65 29 undo_save(zName)
20a0: 3b 0a 20 20 20 20 20 20 69 66 28 20 21 6e 6f 63 ;. if( !noc
20b0: 68 61 6e 67 65 46 6c 61 67 20 29 20 76 66 69 6c hangeFlag ) vfil
20c0: 65 5f 74 6f 5f 64 69 73 6b 28 30 2c 20 69 64 74 e_to_disk(0, idt
20d0: 2c 20 30 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 , 0);. }else
20e0: 69 66 28 20 69 64 74 3d 3d 30 20 26 26 20 69 64 if( idt==0 && id
20f0: 76 3e 30 20 29 7b 0a 20 20 20 20 20 20 69 66 28 v>0 ){. if(
2100: 20 72 69 64 76 3d 3d 30 20 29 7b 0a 20 20 20 20 ridv==0 ){.
2110: 20 20 20 20 2f 2a 20 41 64 64 65 64 20 69 6e 20 /* Added in
2120: 63 75 72 72 65 6e 74 20 63 68 65 63 6b 6f 75 74 current checkout
2130: 2e 20 20 43 6f 6e 74 69 6e 75 65 20 74 6f 20 68 . Continue to h
2140: 6f 6c 64 20 74 68 65 20 66 69 6c 65 20 61 73 0a old the file as.
2150: 20 20 20 20 20 20 20 20 2a 2a 20 61 73 20 61 6e ** as an
2160: 20 61 64 64 69 74 69 6f 6e 20 2a 2f 0a 20 20 20 addition */.
2170: 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 db_multi_ex
2180: 65 63 28 22 55 50 44 41 54 45 20 76 66 69 6c 65 ec("UPDATE vfile
2190: 20 53 45 54 20 76 69 64 3d 25 64 20 57 48 45 52 SET vid=%d WHER
21a0: 45 20 69 64 3d 25 64 22 2c 20 74 69 64 2c 20 69 E id=%d", tid, i
21b0: 64 76 29 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 dv);. }else
21c0: 20 69 66 28 20 63 68 6e 67 65 64 20 29 7b 0a 20 if( chnged ){.
21d0: 20 20 20 20 20 20 20 2f 2a 20 45 64 69 74 65 64 /* Edited
21e0: 20 6c 6f 63 61 6c 6c 79 20 62 75 74 20 64 65 6c locally but del
21f0: 65 74 65 64 20 66 72 6f 6d 20 74 68 65 20 74 61 eted from the ta
2200: 72 67 65 74 2e 20 20 44 65 6c 65 74 65 20 69 74 rget. Delete it
2210: 2e 20 2a 2f 0a 20 20 20 20 20 20 20 20 70 72 69 . */. pri
2220: 6e 74 66 28 22 43 4f 4e 46 4c 49 43 54 20 25 73 ntf("CONFLICT %s
2230: 5c 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 \n", zName);.
2240: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 }else{.
2250: 20 20 63 68 61 72 20 2a 7a 46 75 6c 6c 50 61 74 char *zFullPat
2260: 68 3b 0a 20 20 20 20 20 20 20 20 70 72 69 6e 74 h;. print
2270: 66 28 22 52 45 4d 4f 56 45 20 25 73 5c 6e 22 2c f("REMOVE %s\n",
2280: 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 20 zName);.
2290: 20 75 6e 64 6f 5f 73 61 76 65 28 7a 4e 61 6d 65 undo_save(zName
22a0: 29 3b 0a 20 20 20 20 20 20 20 20 7a 46 75 6c 6c );. zFull
22b0: 50 61 74 68 20 3d 20 6d 70 72 69 6e 74 66 28 22 Path = mprintf("
22c0: 25 73 2f 25 73 22 2c 20 67 2e 7a 4c 6f 63 61 6c %s/%s", g.zLocal
22d0: 52 6f 6f 74 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 Root, zName);.
22e0: 20 20 20 20 20 20 69 66 28 20 21 6e 6f 63 68 61 if( !nocha
22f0: 6e 67 65 46 6c 61 67 20 29 20 75 6e 6c 69 6e 6b ngeFlag ) unlink
2300: 28 7a 46 75 6c 6c 50 61 74 68 29 3b 0a 20 20 20 (zFullPath);.
2310: 20 20 20 20 20 66 72 65 65 28 7a 46 75 6c 6c 50 free(zFullP
2320: 61 74 68 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 ath);. }.
2330: 20 20 7d 65 6c 73 65 20 69 66 28 20 69 64 74 3e }else if( idt>
2340: 30 20 26 26 20 69 64 76 3e 30 20 26 26 20 72 69 0 && idv>0 && ri
2350: 64 74 21 3d 72 69 64 76 20 26 26 20 63 68 6e 67 dt!=ridv && chng
2360: 65 64 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 4d ed ){. /* M
2370: 65 72 67 65 20 74 68 65 20 63 68 61 6e 67 65 73 erge the changes
2380: 20 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20 in the current
2390: 74 72 65 65 20 69 6e 74 6f 20 74 68 65 20 74 61 tree into the ta
23a0: 72 67 65 74 20 76 65 72 73 69 6f 6e 20 2a 2f 0a rget version */.
23b0: 20 20 20 20 20 20 42 6c 6f 62 20 65 2c 20 72 2c Blob e, r,
23c0: 20 74 2c 20 76 3b 0a 20 20 20 20 20 20 69 6e 74 t, v;. int
23d0: 20 72 63 3b 0a 20 20 20 20 20 20 70 72 69 6e 74 rc;. print
23e0: 66 28 22 4d 45 52 47 45 20 25 73 5c 6e 22 2c 20 f("MERGE %s\n",
23f0: 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 75 6e zName);. un
2400: 64 6f 5f 73 61 76 65 28 7a 4e 61 6d 65 29 3b 0a do_save(zName);.
2410: 20 20 20 20 20 20 63 6f 6e 74 65 6e 74 5f 67 65 content_ge
2420: 74 28 72 69 64 74 2c 20 26 74 29 3b 0a 20 20 20 t(ridt, &t);.
2430: 20 20 20 63 6f 6e 74 65 6e 74 5f 67 65 74 28 72 content_get(r
2440: 69 64 76 2c 20 26 76 29 3b 0a 20 20 20 20 20 20 idv, &v);.
2450: 62 6c 6f 62 5f 7a 65 72 6f 28 26 65 29 3b 0a 20 blob_zero(&e);.
2460: 20 20 20 20 20 62 6c 6f 62 5f 72 65 61 64 5f 66 blob_read_f
2470: 72 6f 6d 5f 66 69 6c 65 28 26 65 2c 20 7a 46 75 rom_file(&e, zFu
2480: 6c 6c 50 61 74 68 29 3b 0a 20 20 20 20 20 20 72 llPath);. r
2490: 63 20 3d 20 62 6c 6f 62 5f 6d 65 72 67 65 28 26 c = blob_merge(&
24a0: 76 2c 20 26 65 2c 20 26 74 2c 20 26 72 29 3b 0a v, &e, &t, &r);.
24b0: 20 20 20 20 20 20 69 66 28 20 72 63 3e 3d 30 20 if( rc>=0
24c0: 29 7b 0a 20 20 20 20 20 20 20 20 69 66 28 20 21 ){. if( !
24d0: 6e 6f 63 68 61 6e 67 65 46 6c 61 67 20 29 20 62 nochangeFlag ) b
24e0: 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f 66 69 6c lob_write_to_fil
24f0: 65 28 26 72 2c 20 7a 46 75 6c 6c 50 61 74 68 29 e(&r, zFullPath)
2500: 3b 0a 20 20 20 20 20 20 20 20 69 66 28 20 72 63 ;. if( rc
2510: 3e 30 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 >0 ){.
2520: 70 72 69 6e 74 66 28 22 2a 2a 2a 2a 2a 20 25 64 printf("***** %d
2530: 20 6d 65 72 67 65 20 63 6f 6e 66 6c 69 63 74 73 merge conflicts
2540: 20 69 6e 20 25 73 5c 6e 22 2c 20 72 63 2c 20 7a in %s\n", rc, z
2550: 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 20 20 7d Name);. }
2560: 0a 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 . }else{.
2570: 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 2a 2a printf("**
2580: 2a 2a 2a 20 43 61 6e 6e 6f 74 20 6d 65 72 67 65 *** Cannot merge
2590: 20 62 69 6e 61 72 79 20 66 69 6c 65 20 25 73 5c binary file %s\
25a0: 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 n", zName);.
25b0: 20 20 7d 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 }. blob_r
25c0: 65 73 65 74 28 26 76 29 3b 0a 20 20 20 20 20 20 eset(&v);.
25d0: 62 6c 6f 62 5f 72 65 73 65 74 28 26 65 29 3b 0a blob_reset(&e);.
25e0: 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 blob_reset
25f0: 28 26 74 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 (&t);. blob
2600: 5f 72 65 73 65 74 28 26 72 29 3b 0a 20 20 20 20 _reset(&r);.
2610: 7d 65 6c 73 65 20 69 66 28 20 76 65 72 62 6f 73 }else if( verbos
2620: 65 46 6c 61 67 20 29 7b 0a 20 20 20 20 20 20 70 eFlag ){. p
2630: 72 69 6e 74 66 28 22 55 4e 43 48 41 4e 47 45 44 rintf("UNCHANGED
2640: 20 25 73 5c 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a %s\n", zName);.
2650: 20 20 20 20 7d 0a 20 20 20 20 66 72 65 65 28 7a }. free(z
2660: 46 75 6c 6c 50 61 74 68 29 3b 0a 20 20 7d 0a 20 FullPath);. }.
2670: 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 db_finalize(&q)
2680: 3b 0a 20 20 0a 20 20 2f 2a 0a 20 20 2a 2a 20 43 ;. . /*. ** C
2690: 6c 65 61 6e 20 75 70 20 74 68 65 20 6d 69 64 20 lean up the mid
26a0: 61 6e 64 20 70 69 64 20 56 46 49 4c 45 20 65 6e and pid VFILE en
26b0: 74 72 69 65 73 2e 20 20 54 68 65 6e 20 63 6f 6d tries. Then com
26c0: 6d 69 74 20 74 68 65 20 63 68 61 6e 67 65 73 2e mit the changes.
26d0: 0a 20 20 2a 2f 0a 20 20 69 66 28 20 6e 6f 63 68 . */. if( noch
26e0: 61 6e 67 65 46 6c 61 67 20 29 7b 0a 20 20 20 20 angeFlag ){.
26f0: 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 74 69 db_end_transacti
2700: 6f 6e 28 31 29 3b 20 20 2f 2a 20 57 69 74 68 20 on(1); /* With
2710: 2d 2d 6e 6f 63 68 61 6e 67 65 2c 20 72 6f 6c 6c --nochange, roll
2720: 62 61 63 6b 20 63 68 61 6e 67 65 73 20 2a 2f 0a back changes */.
2730: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 69 66 28 }else{. if(
2740: 20 67 2e 61 72 67 63 3c 3d 33 20 29 7b 0a 20 20 g.argc<=3 ){.
2750: 20 20 20 20 2f 2a 20 41 6c 6c 20 66 69 6c 65 73 /* All files
2760: 20 75 70 64 61 74 65 64 2e 20 20 53 68 69 66 74 updated. Shift
2770: 20 74 68 65 20 63 75 72 72 65 6e 74 20 63 68 65 the current che
2780: 63 6b 6f 75 74 20 74 6f 20 74 68 65 20 74 61 72 ckout to the tar
2790: 67 65 74 2e 20 2a 2f 0a 20 20 20 20 20 20 64 62 get. */. db
27a0: 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 44 45 4c _multi_exec("DEL
27b0: 45 54 45 20 46 52 4f 4d 20 76 66 69 6c 65 20 57 ETE FROM vfile W
27c0: 48 45 52 45 20 76 69 64 21 3d 25 64 22 2c 20 74 HERE vid!=%d", t
27d0: 69 64 29 3b 0a 20 20 20 20 20 20 6d 61 6e 69 66 id);. manif
27e0: 65 73 74 5f 74 6f 5f 64 69 73 6b 28 74 69 64 29 est_to_disk(tid)
27f0: 3b 0a 20 20 20 20 20 20 64 62 5f 6c 73 65 74 5f ;. db_lset_
2800: 69 6e 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 20 int("checkout",
2810: 74 69 64 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b tid);. }else{
2820: 0a 20 20 20 20 20 20 2f 2a 20 41 20 73 75 62 73 . /* A subs
2830: 65 74 20 6f 66 20 66 69 6c 65 73 20 68 61 76 65 et of files have
2840: 20 62 65 65 6e 20 63 68 65 63 6b 65 64 20 6f 75 been checked ou
2850: 74 2e 20 20 4b 65 65 70 20 74 68 65 20 63 75 72 t. Keep the cur
2860: 72 65 6e 74 0a 20 20 20 20 20 20 2a 2a 20 63 68 rent. ** ch
2870: 65 63 6b 6f 75 74 20 75 6e 63 68 61 6e 67 65 64 eckout unchanged
2880: 2e 20 2a 2f 0a 20 20 20 20 20 20 64 62 5f 6d 75 . */. db_mu
2890: 6c 74 69 5f 65 78 65 63 28 22 44 45 4c 45 54 45 lti_exec("DELETE
28a0: 20 46 52 4f 4d 20 76 66 69 6c 65 20 57 48 45 52 FROM vfile WHER
28b0: 45 20 76 69 64 21 3d 25 64 22 2c 20 76 69 64 29 E vid!=%d", vid)
28c0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 64 62 5f 65 ;. }. db_e
28d0: 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 nd_transaction(0
28e0: 29 3b 0a 20 20 7d 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a );. }.}.../*.**
28f0: 20 47 65 74 20 74 68 65 20 63 6f 6e 74 65 6e 74 Get the content
2900: 73 20 6f 66 20 61 20 66 69 6c 65 20 77 69 74 68 s of a file with
2910: 69 6e 20 61 20 67 69 76 65 6e 20 72 65 76 69 73 in a given revis
2920: 69 6f 6e 2e 0a 2a 2f 0a 69 6e 74 20 68 69 73 74 ion..*/.int hist
2930: 6f 72 69 63 61 6c 5f 76 65 72 73 69 6f 6e 5f 6f orical_version_o
2940: 66 5f 66 69 6c 65 28 0a 20 20 63 6f 6e 73 74 20 f_file(. const
2950: 63 68 61 72 20 2a 72 65 76 69 73 69 6f 6e 2c 20 char *revision,
2960: 20 20 20 2f 2a 20 54 68 65 20 62 61 73 65 6c 69 /* The baseli
2970: 6e 65 20 6e 61 6d 65 20 63 6f 6e 74 61 69 6e 69 ne name containi
2980: 6e 67 20 74 68 65 20 66 69 6c 65 20 2a 2f 0a 20 ng the file */.
2990: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 69 6c const char *fil
29a0: 65 2c 20 20 20 20 20 20 20 20 2f 2a 20 46 75 6c e, /* Ful
29b0: 6c 20 74 72 65 65 6e 61 6d 65 20 6f 66 20 74 68 l treename of th
29c0: 65 20 66 69 6c 65 20 2a 2f 0a 20 20 42 6c 6f 62 e file */. Blob
29d0: 20 2a 63 6f 6e 74 65 6e 74 2c 20 20 20 20 20 20 *content,
29e0: 20 20 20 20 20 2f 2a 20 50 75 74 20 74 68 65 20 /* Put the
29f0: 63 6f 6e 74 65 6e 74 20 68 65 72 65 20 2a 2f 0a content here */.
2a00: 20 20 69 6e 74 20 65 72 72 43 6f 64 65 20 20 20 int errCode
2a10: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 45 72 /* Er
2a20: 72 6f 72 20 63 6f 64 65 20 69 66 20 66 69 6c 65 ror code if file
2a30: 20 6e 6f 74 20 66 6f 75 6e 64 2e 20 20 50 61 6e not found. Pan
2a40: 69 63 20 69 66 20 30 2e 20 2a 2f 0a 29 7b 0a 20 ic if 0. */.){.
2a50: 20 42 6c 6f 62 20 6d 66 69 6c 65 3b 0a 20 20 4d Blob mfile;. M
2a60: 61 6e 69 66 65 73 74 20 6d 3b 0a 20 20 69 6e 74 anifest m;. int
2a70: 20 69 2c 20 72 69 64 3d 30 3b 0a 20 20 0a 20 20 i, rid=0;. .
2a80: 69 66 28 20 72 65 76 69 73 69 6f 6e 20 29 7b 0a if( revision ){.
2a90: 20 20 20 20 72 69 64 20 3d 20 6e 61 6d 65 5f 74 rid = name_t
2aa0: 6f 5f 72 69 64 28 72 65 76 69 73 69 6f 6e 29 3b o_rid(revision);
2ab0: 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 72 69 . }else{. ri
2ac0: 64 20 3d 20 64 62 5f 6c 67 65 74 5f 69 6e 74 28 d = db_lget_int(
2ad0: 22 63 68 65 63 6b 6f 75 74 22 2c 20 30 29 3b 0a "checkout", 0);.
2ae0: 20 20 7d 0a 20 20 69 66 28 20 21 69 73 5f 61 5f }. if( !is_a_
2af0: 76 65 72 73 69 6f 6e 28 72 69 64 29 20 29 7b 0a version(rid) ){.
2b00: 20 20 20 20 69 66 28 20 65 72 72 43 6f 64 65 3e if( errCode>
2b10: 30 20 29 20 72 65 74 75 72 6e 20 65 72 72 43 6f 0 ) return errCo
2b20: 64 65 3b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 de;. fossil_f
2b30: 61 74 61 6c 28 22 6e 6f 20 73 75 63 68 20 63 68 atal("no such ch
2b40: 65 63 6b 2d 6f 75 74 3a 20 25 73 22 2c 20 72 65 eck-out: %s", re
2b50: 76 69 73 69 6f 6e 29 3b 0a 20 20 7d 0a 20 20 63 vision);. }. c
2b60: 6f 6e 74 65 6e 74 5f 67 65 74 28 72 69 64 2c 20 ontent_get(rid,
2b70: 26 6d 66 69 6c 65 29 3b 0a 20 20 0a 20 20 69 66 &mfile);. . if
2b80: 28 20 6d 61 6e 69 66 65 73 74 5f 70 61 72 73 65 ( manifest_parse
2b90: 28 26 6d 2c 20 26 6d 66 69 6c 65 29 20 29 7b 0a (&m, &mfile) ){.
2ba0: 20 20 20 20 66 6f 72 28 69 3d 30 3b 20 69 3c 6d for(i=0; i<m
2bb0: 2e 6e 46 69 6c 65 3b 20 69 2b 2b 29 7b 0a 20 20 .nFile; i++){.
2bc0: 20 20 20 20 69 66 28 20 73 74 72 63 6d 70 28 6d if( strcmp(m
2bd0: 2e 61 46 69 6c 65 5b 69 5d 2e 7a 4e 61 6d 65 2c .aFile[i].zName,
2be0: 20 66 69 6c 65 29 3d 3d 30 20 29 7b 0a 20 20 20 file)==0 ){.
2bf0: 20 20 20 20 20 72 69 64 20 3d 20 75 75 69 64 5f rid = uuid_
2c00: 74 6f 5f 72 69 64 28 6d 2e 61 46 69 6c 65 5b 69 to_rid(m.aFile[i
2c10: 5d 2e 7a 55 75 69 64 2c 20 30 29 3b 0a 20 20 20 ].zUuid, 0);.
2c20: 20 20 20 20 20 72 65 74 75 72 6e 20 63 6f 6e 74 return cont
2c30: 65 6e 74 5f 67 65 74 28 72 69 64 2c 20 63 6f 6e ent_get(rid, con
2c40: 74 65 6e 74 29 3b 0a 20 20 20 20 20 20 7d 0a 20 tent);. }.
2c50: 20 20 20 7d 0a 20 20 20 20 69 66 28 20 65 72 72 }. if( err
2c60: 43 6f 64 65 3c 3d 30 20 29 7b 0a 20 20 20 20 20 Code<=0 ){.
2c70: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 66 fossil_fatal("f
2c80: 69 6c 65 20 25 73 20 64 6f 65 73 20 6e 6f 74 20 ile %s does not
2c90: 65 78 69 73 74 20 69 6e 20 62 61 73 65 6c 69 6e exist in baselin
2ca0: 65 3a 20 25 73 22 2c 20 66 69 6c 65 2c 20 72 65 e: %s", file, re
2cb0: 76 69 73 69 6f 6e 29 3b 0a 20 20 20 20 7d 0a 20 vision);. }.
2cc0: 20 7d 65 6c 73 65 20 69 66 28 20 65 72 72 43 6f }else if( errCo
2cd0: 64 65 3c 3d 30 20 29 7b 0a 20 20 20 20 66 6f 73 de<=0 ){. fos
2ce0: 73 69 6c 5f 70 61 6e 69 63 28 22 63 6f 75 6c 64 sil_panic("could
2cf0: 20 6e 6f 74 20 70 61 72 73 65 20 6d 61 6e 69 66 not parse manif
2d00: 65 73 74 20 66 6f 72 20 62 61 73 65 6c 69 6e 65 est for baseline
2d10: 3a 20 25 73 22 2c 20 72 65 76 69 73 69 6f 6e 29 : %s", revision)
2d20: 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 65 ;. }. return e
2d30: 72 72 43 6f 64 65 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a rrCode;.}.../*.*
2d40: 2a 20 43 4f 4d 4d 41 4e 44 3a 20 72 65 76 65 72 * COMMAND: rever
2d50: 74 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 t.**.** Usage: %
2d60: 66 6f 73 73 69 6c 20 72 65 76 65 72 74 20 3f 2d fossil revert ?-
2d70: 72 20 52 45 56 49 53 49 4f 4e 3f 20 46 49 4c 45 r REVISION? FILE
2d80: 20 2e 2e 2e 0a 2a 2a 0a 2a 2a 20 52 65 76 65 72 ....**.** Rever
2d90: 74 20 74 6f 20 74 68 65 20 63 75 72 72 65 6e 74 t to the current
2da0: 20 72 65 70 6f 73 69 74 6f 72 79 20 76 65 72 73 repository vers
2db0: 69 6f 6e 20 6f 66 20 46 49 4c 45 2c 20 6f 72 20 ion of FILE, or
2dc0: 74 6f 0a 2a 2a 20 74 68 65 20 76 65 72 73 69 6f to.** the versio
2dd0: 6e 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 n associated wit
2de0: 68 20 62 61 73 65 6c 69 6e 65 20 52 45 56 49 53 h baseline REVIS
2df0: 49 4f 4e 20 69 66 20 74 68 65 20 2d 72 20 66 6c ION if the -r fl
2e00: 61 67 0a 2a 2a 20 61 70 70 65 61 72 73 2e 0a 2a ag.** appears..*
2e10: 2a 0a 2a 2a 20 49 66 20 61 20 66 69 6c 65 20 69 *.** If a file i
2e20: 73 20 72 65 76 65 72 74 65 64 20 61 63 63 69 64 s reverted accid
2e30: 65 6e 74 6c 79 2c 20 69 74 20 63 61 6e 20 62 65 ently, it can be
2e40: 20 72 65 73 74 6f 72 65 64 20 75 73 69 6e 67 0a restored using.
2e50: 2a 2a 20 74 68 65 20 22 66 6f 73 73 69 6c 20 75 ** the "fossil u
2e60: 6e 64 6f 22 20 63 6f 6d 6d 61 6e 64 2e 0a 2a 2f ndo" command..*/
2e70: 0a 76 6f 69 64 20 72 65 76 65 72 74 5f 63 6d 64 .void revert_cmd
2e80: 28 76 6f 69 64 29 7b 0a 20 20 63 68 61 72 20 2a (void){. char *
2e90: 7a 46 69 6c 65 3b 0a 20 20 63 6f 6e 73 74 20 63 zFile;. const c
2ea0: 68 61 72 20 2a 7a 52 65 76 69 73 69 6f 6e 3b 0a har *zRevision;.
2eb0: 20 20 42 6c 6f 62 20 66 6e 61 6d 65 3b 0a 20 20 Blob fname;.
2ec0: 42 6c 6f 62 20 72 65 63 6f 72 64 3b 0a 20 20 69 Blob record;. i
2ed0: 6e 74 20 69 3b 0a 20 20 69 6e 74 20 65 72 72 43 nt i;. int errC
2ee0: 6f 64 65 3b 0a 20 20 69 6e 74 20 72 69 64 20 3d ode;. int rid =
2ef0: 20 30 3b 0a 20 20 0a 20 20 7a 52 65 76 69 73 69 0;. . zRevisi
2f00: 6f 6e 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e on = find_option
2f10: 28 22 72 65 76 69 73 69 6f 6e 22 2c 20 22 72 22 ("revision", "r"
2f20: 2c 20 31 29 3b 0a 20 20 76 65 72 69 66 79 5f 61 , 1);. verify_a
2f30: 6c 6c 5f 6f 70 74 69 6f 6e 73 28 29 3b 0a 20 20 ll_options();.
2f40: 0a 20 20 69 66 28 20 67 2e 61 72 67 63 3c 33 20 . if( g.argc<3
2f50: 29 7b 0a 20 20 20 20 75 73 61 67 65 28 22 3f 4f ){. usage("?O
2f60: 50 54 49 4f 4e 53 3f 20 46 49 4c 45 20 2e 2e 2e PTIONS? FILE ...
2f70: 22 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 6d 75 73 ");. }. db_mus
2f80: 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72 65 65 t_be_within_tree
2f90: 28 29 3b 0a 20 20 64 62 5f 62 65 67 69 6e 5f 74 ();. db_begin_t
2fa0: 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a 20 20 ransaction();.
2fb0: 75 6e 64 6f 5f 62 65 67 69 6e 28 29 3b 0a 0a 20 undo_begin();..
2fc0: 20 66 6f 72 28 69 3d 32 3b 20 69 3c 67 2e 61 72 for(i=2; i<g.ar
2fd0: 67 63 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 7a 46 gc; i++){. zF
2fe0: 69 6c 65 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 ile = mprintf("%
2ff0: 2f 22 2c 20 67 2e 61 72 67 76 5b 69 5d 29 3b 0a /", g.argv[i]);.
3000: 20 20 20 20 66 69 6c 65 5f 74 72 65 65 5f 6e 61 file_tree_na
3010: 6d 65 28 7a 46 69 6c 65 2c 20 26 66 6e 61 6d 65 me(zFile, &fname
3020: 2c 20 31 29 3b 0a 0a 20 20 20 20 69 66 28 20 7a , 1);.. if( z
3030: 52 65 76 69 73 69 6f 6e 21 3d 30 20 29 7b 0a 20 Revision!=0 ){.
3040: 20 20 20 20 20 65 72 72 43 6f 64 65 20 3d 20 68 errCode = h
3050: 69 73 74 6f 72 69 63 61 6c 5f 76 65 72 73 69 6f istorical_versio
3060: 6e 5f 6f 66 5f 66 69 6c 65 28 7a 52 65 76 69 73 n_of_file(zRevis
3070: 69 6f 6e 2c 20 62 6c 6f 62 5f 73 74 72 28 26 66 ion, blob_str(&f
3080: 6e 61 6d 65 29 2c 0a 20 20 20 20 20 20 20 20 20 name),.
3090: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
30a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
30b0: 20 20 26 72 65 63 6f 72 64 2c 20 32 29 3b 0a 20 &record, 2);.
30c0: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 }else{.
30d0: 72 69 64 20 3d 20 64 62 5f 69 6e 74 28 30 2c 20 rid = db_int(0,
30e0: 22 53 45 4c 45 43 54 20 72 69 64 20 46 52 4f 4d "SELECT rid FROM
30f0: 20 76 66 69 6c 65 20 57 48 45 52 45 20 70 61 74 vfile WHERE pat
3100: 68 6e 61 6d 65 3d 25 42 22 2c 20 26 66 6e 61 6d hname=%B", &fnam
3110: 65 29 3b 0a 20 20 20 20 20 20 69 66 28 20 72 69 e);. if( ri
3120: 64 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 20 20 d==0 ){.
3130: 65 72 72 43 6f 64 65 20 3d 20 32 3b 0a 20 20 20 errCode = 2;.
3140: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 }else{.
3150: 20 20 63 6f 6e 74 65 6e 74 5f 67 65 74 28 72 69 content_get(ri
3160: 64 2c 20 26 72 65 63 6f 72 64 29 3b 0a 20 20 20 d, &record);.
3170: 20 20 20 20 20 65 72 72 43 6f 64 65 20 3d 20 30 errCode = 0
3180: 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a ;. }. }.
3190: 0a 20 20 20 20 69 66 28 20 65 72 72 43 6f 64 65 . if( errCode
31a0: 3d 3d 32 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 ==2 ){. fos
31b0: 73 69 6c 5f 77 61 72 6e 69 6e 67 28 22 66 69 6c sil_warning("fil
31c0: 65 20 6e 6f 74 20 69 6e 20 72 65 70 6f 73 69 74 e not in reposit
31d0: 6f 72 79 3a 20 25 73 22 2c 20 7a 46 69 6c 65 29 ory: %s", zFile)
31e0: 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 ;. }else{.
31f0: 20 20 20 75 6e 64 6f 5f 73 61 76 65 28 62 6c 6f undo_save(blo
3200: 62 5f 73 74 72 28 26 66 6e 61 6d 65 29 29 3b 0a b_str(&fname));.
3210: 20 20 20 20 20 20 62 6c 6f 62 5f 77 72 69 74 65 blob_write
3220: 5f 74 6f 5f 66 69 6c 65 28 26 72 65 63 6f 72 64 _to_file(&record
3230: 2c 20 7a 46 69 6c 65 29 3b 0a 20 20 20 20 20 20 , zFile);.
3240: 70 72 69 6e 74 66 28 22 25 73 20 72 65 76 65 72 printf("%s rever
3250: 74 65 64 5c 6e 22 2c 20 7a 46 69 6c 65 29 3b 0a ted\n", zFile);.
3260: 20 20 20 20 7d 0a 20 20 20 20 62 6c 6f 62 5f 72 }. blob_r
3270: 65 73 65 74 28 26 72 65 63 6f 72 64 29 3b 0a 20 eset(&record);.
3280: 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 66 blob_reset(&f
3290: 6e 61 6d 65 29 3b 0a 20 20 20 20 66 72 65 65 28 name);. free(
32a0: 7a 46 69 6c 65 29 3b 0a 20 20 7d 0a 20 20 64 62 zFile);. }. db
32b0: 5f 65 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e _end_transaction
32c0: 28 30 29 3b 0a 7d 0a (0);.}.