Hex Artifact Content
Not logged in

Artifact 62efa1b452526ee413b98ea1c335beeecd3e70b4:


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 53 69 6d 70 6c 69 66 69 65 64 20 42 53 44 20   Simplified BSD 
00a0: 4c 69 63 65 6e 73 65 20 28 61 6c 73 6f 0a 2a 2a  License (also.**
00b0: 20 6b 6e 6f 77 6e 20 61 73 20 74 68 65 20 22 32   known as the "2
00c0: 2d 43 6c 61 75 73 65 20 4c 69 63 65 6e 73 65 22  -Clause License"
00d0: 20 6f 72 20 22 46 72 65 65 42 53 44 20 4c 69 63   or "FreeBSD Lic
00e0: 65 6e 73 65 22 2e 29 0a 0a 2a 2a 20 54 68 69 73  ense".)..** This
00f0: 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73 74   program is dist
0100: 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20 68  ributed in the h
0110: 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c 6c  ope that it will
0120: 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20 62   be useful,.** b
0130: 75 74 20 77 69 74 68 6f 75 74 20 61 6e 79 20 77  ut without any w
0140: 61 72 72 61 6e 74 79 3b 20 77 69 74 68 6f 75 74  arranty; without
0150: 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69 65   even the implie
0160: 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a 2a  d warranty of.**
0170: 20 6d 65 72 63 68 61 6e 74 61 62 69 6c 69 74 79   merchantability
0180: 20 6f 72 20 66 69 74 6e 65 73 73 20 66 6f 72 20   or fitness for 
0190: 61 20 70 61 72 74 69 63 75 6c 61 72 20 70 75 72  a particular pur
01a0: 70 6f 73 65 2e 0a 2a 2a 0a 2a 2a 20 41 75 74 68  pose..**.** Auth
01b0: 6f 72 20 63 6f 6e 74 61 63 74 20 69 6e 66 6f 72  or contact infor
01c0: 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20 20 64 72 68  mation:.**   drh
01d0: 40 68 77 61 63 69 2e 63 6f 6d 0a 2a 2a 20 20 20  @hwaci.com.**   
01e0: 68 74 74 70 3a 2f 2f 77 77 77 2e 68 77 61 63 69  http://www.hwaci
01f0: 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a 0a 2a 2a 2a  .com/drh/.**.***
0200: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0210: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0220: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0230: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0240: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 2a 2a 0a  ************.**.
0250: 2a 2a 20 54 68 69 73 20 66 69 6c 65 20 63 6f 6e  ** This file con
0260: 74 61 69 6e 73 20 63 6f 64 65 20 75 73 65 64 20  tains code used 
0270: 74 6f 20 6d 65 72 67 65 20 74 68 65 20 63 68 61  to merge the cha
0280: 6e 67 65 73 20 69 6e 20 74 68 65 20 63 75 72 72  nges in the curr
0290: 65 6e 74 0a 2a 2a 20 63 68 65 63 6b 6f 75 74 20  ent.** checkout 
02a0: 69 6e 74 6f 20 61 20 64 69 66 66 65 72 65 6e 74  into a different
02b0: 20 76 65 72 73 69 6f 6e 20 61 6e 64 20 73 77 69   version and swi
02c0: 74 63 68 20 74 6f 20 74 68 61 74 20 76 65 72 73  tch to that vers
02d0: 69 6f 6e 2e 0a 2a 2f 0a 23 69 6e 63 6c 75 64 65  ion..*/.#include
02e0: 20 22 63 6f 6e 66 69 67 2e 68 22 0a 23 69 6e 63   "config.h".#inc
02f0: 6c 75 64 65 20 22 75 70 64 61 74 65 2e 68 22 0a  lude "update.h".
0300: 23 69 6e 63 6c 75 64 65 20 3c 61 73 73 65 72 74  #include <assert
0310: 2e 68 3e 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72  .h>../*.** Retur
0320: 6e 20 74 72 75 65 20 69 66 20 61 72 74 69 66 61  n true if artifa
0330: 63 74 20 72 69 64 20 69 73 20 61 20 76 65 72 73  ct rid is a vers
0340: 69 6f 6e 0a 2a 2f 0a 69 6e 74 20 69 73 5f 61 5f  ion.*/.int is_a_
0350: 76 65 72 73 69 6f 6e 28 69 6e 74 20 72 69 64 29  version(int rid)
0360: 7b 0a 20 20 72 65 74 75 72 6e 20 64 62 5f 65 78  {.  return db_ex
0370: 69 73 74 73 28 22 53 45 4c 45 43 54 20 31 20 46  ists("SELECT 1 F
0380: 52 4f 4d 20 65 76 65 6e 74 20 57 48 45 52 45 20  ROM event WHERE 
0390: 6f 62 6a 69 64 3d 25 64 20 41 4e 44 20 74 79 70  objid=%d AND typ
03a0: 65 3d 27 63 69 27 22 2c 20 72 69 64 29 3b 0a 7d  e='ci'", rid);.}
03b0: 0a 0a 2f 2a 20 54 68 69 73 20 76 61 72 69 61 62  ../* This variab
03c0: 6c 65 20 69 73 20 73 65 74 20 69 66 20 77 65 20  le is set if we 
03d0: 61 72 65 20 64 6f 69 6e 67 20 61 6e 20 69 6e 74  are doing an int
03e0: 65 72 6e 61 6c 20 75 70 64 61 74 65 2e 20 20 49  ernal update.  I
03f0: 74 20 69 73 20 63 6c 65 61 72 0a 2a 2a 20 77 68  t is clear.** wh
0400: 65 6e 20 72 75 6e 6e 69 6e 67 20 74 68 65 20 22  en running the "
0410: 75 70 64 61 74 65 22 20 63 6f 6d 6d 61 6e 64 2e  update" command.
0420: 0a 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 69  .*/.static int i
0430: 6e 74 65 72 6e 61 6c 55 70 64 61 74 65 20 3d 20  nternalUpdate = 
0440: 30 3b 0a 73 74 61 74 69 63 20 69 6e 74 20 69 6e  0;.static int in
0450: 74 65 72 6e 61 6c 43 6f 6e 66 6c 69 63 74 43 6e  ternalConflictCn
0460: 74 20 3d 20 30 3b 0a 0a 2f 2a 0a 2a 2a 20 44 6f  t = 0;../*.** Do
0470: 20 61 6e 20 75 70 64 61 74 65 20 74 6f 20 76 65   an update to ve
0480: 72 73 69 6f 6e 20 76 69 64 2e 20 20 0a 2a 2a 0a  rsion vid.  .**.
0490: 2a 2a 20 53 74 61 72 74 20 61 6e 20 75 6e 64 6f  ** Start an undo
04a0: 20 73 65 73 73 69 6f 6e 20 62 75 74 20 64 6f 20   session but do 
04b0: 6e 6f 74 20 74 65 72 6d 69 6e 61 74 65 20 69 74  not terminate it
04c0: 2e 20 20 44 6f 20 6e 6f 74 20 61 75 74 6f 73 79  .  Do not autosy
04d0: 6e 63 2e 0a 2a 2f 0a 69 6e 74 20 75 70 64 61 74  nc..*/.int updat
04e0: 65 5f 74 6f 28 69 6e 74 20 76 69 64 29 7b 0a 20  e_to(int vid){. 
04f0: 20 69 6e 74 20 73 61 76 65 64 41 72 67 63 3b 0a   int savedArgc;.
0500: 20 20 63 68 61 72 20 2a 2a 73 61 76 65 64 41 72    char **savedAr
0510: 67 76 3b 0a 20 20 63 68 61 72 20 2a 6e 65 77 41  gv;.  char *newA
0520: 72 67 76 5b 33 5d 3b 0a 20 20 6e 65 77 41 72 67  rgv[3];.  newArg
0530: 76 5b 30 5d 20 3d 20 67 2e 61 72 67 76 5b 30 5d  v[0] = g.argv[0]
0540: 3b 0a 20 20 6e 65 77 41 72 67 76 5b 31 5d 20 3d  ;.  newArgv[1] =
0550: 20 22 75 70 64 61 74 65 22 3b 0a 20 20 6e 65 77   "update";.  new
0560: 41 72 67 76 5b 32 5d 20 3d 20 30 3b 0a 20 20 73  Argv[2] = 0;.  s
0570: 61 76 65 64 41 72 67 76 20 3d 20 67 2e 61 72 67  avedArgv = g.arg
0580: 76 3b 0a 20 20 73 61 76 65 64 41 72 67 63 20 3d  v;.  savedArgc =
0590: 20 67 2e 61 72 67 63 3b 0a 20 20 67 2e 61 72 67   g.argc;.  g.arg
05a0: 63 20 3d 20 32 3b 0a 20 20 67 2e 61 72 67 76 20  c = 2;.  g.argv 
05b0: 3d 20 6e 65 77 41 72 67 76 3b 0a 20 20 69 6e 74  = newArgv;.  int
05c0: 65 72 6e 61 6c 55 70 64 61 74 65 20 3d 20 76 69  ernalUpdate = vi
05d0: 64 3b 0a 20 20 69 6e 74 65 72 6e 61 6c 43 6f 6e  d;.  internalCon
05e0: 66 6c 69 63 74 43 6e 74 20 3d 20 30 3b 0a 20 20  flictCnt = 0;.  
05f0: 75 70 64 61 74 65 5f 63 6d 64 28 29 3b 0a 20 20  update_cmd();.  
0600: 67 2e 61 72 67 63 20 3d 20 73 61 76 65 64 41 72  g.argc = savedAr
0610: 67 63 3b 0a 20 20 67 2e 61 72 67 76 20 3d 20 73  gc;.  g.argv = s
0620: 61 76 65 64 41 72 67 76 3b 0a 20 20 72 65 74 75  avedArgv;.  retu
0630: 72 6e 20 69 6e 74 65 72 6e 61 6c 43 6f 6e 66 6c  rn internalConfl
0640: 69 63 74 43 6e 74 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a  ictCnt;.}../*.**
0650: 20 43 4f 4d 4d 41 4e 44 3a 20 75 70 64 61 74 65   COMMAND: update
0660: 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66  .**.** Usage: %f
0670: 6f 73 73 69 6c 20 75 70 64 61 74 65 20 3f 4f 50  ossil update ?OP
0680: 54 49 4f 4e 53 3f 20 3f 56 45 52 53 49 4f 4e 3f  TIONS? ?VERSION?
0690: 20 3f 46 49 4c 45 53 2e 2e 2e 3f 0a 2a 2a 0a 2a   ?FILES...?.**.*
06a0: 2a 20 43 68 61 6e 67 65 20 74 68 65 20 76 65 72  * Change the ver
06b0: 73 69 6f 6e 20 6f 66 20 74 68 65 20 63 75 72 72  sion of the curr
06c0: 65 6e 74 20 63 68 65 63 6b 6f 75 74 20 74 6f 20  ent checkout to 
06d0: 56 45 52 53 49 4f 4e 2e 20 20 41 6e 79 20 75 6e  VERSION.  Any un
06e0: 63 6f 6d 6d 69 74 74 65 64 0a 2a 2a 20 63 68 61  committed.** cha
06f0: 6e 67 65 73 20 61 72 65 20 72 65 74 61 69 6e 65  nges are retaine
0700: 64 20 61 6e 64 20 61 70 70 6c 69 65 64 20 74 6f  d and applied to
0710: 20 74 68 65 20 6e 65 77 20 63 68 65 63 6b 6f 75   the new checkou
0720: 74 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 56 45 52  t..**.** The VER
0730: 53 49 4f 4e 20 61 72 67 75 6d 65 6e 74 20 63 61  SION argument ca
0740: 6e 20 62 65 20 61 20 73 70 65 63 69 66 69 63 20  n be a specific 
0750: 76 65 72 73 69 6f 6e 20 6f 72 20 74 61 67 20 6f  version or tag o
0760: 72 20 62 72 61 6e 63 68 20 6e 61 6d 65 2e 0a 2a  r branch name..*
0770: 2a 20 49 66 20 74 68 65 20 56 45 52 53 49 4f 4e  * If the VERSION
0780: 20 61 72 67 75 6d 65 6e 74 20 69 73 20 6f 6d 69   argument is omi
0790: 74 74 65 64 2c 20 74 68 65 6e 20 74 68 65 20 6c  tted, then the l
07a0: 65 61 66 20 6f 66 20 74 68 65 20 73 75 62 74 72  eaf of the subtr
07b0: 65 65 0a 2a 2a 20 74 68 61 74 20 62 65 67 69 6e  ee.** that begin
07c0: 73 20 61 74 20 74 68 65 20 63 75 72 72 65 6e 74  s at the current
07d0: 20 76 65 72 73 69 6f 6e 20 69 73 20 75 73 65 64   version is used
07e0: 2c 20 69 66 20 74 68 65 72 65 20 69 73 20 6f 6e  , if there is on
07f0: 6c 79 20 61 20 73 69 6e 67 6c 65 0a 2a 2a 20 6c  ly a single.** l
0800: 65 61 66 2e 20 20 56 45 52 53 49 4f 4e 20 63 61  eaf.  VERSION ca
0810: 6e 20 61 6c 73 6f 20 62 65 20 22 63 75 72 72 65  n also be "curre
0820: 6e 74 22 20 74 6f 20 73 65 6c 65 63 74 20 74 68  nt" to select th
0830: 65 20 6c 65 61 66 20 6f 66 20 74 68 65 20 63 75  e leaf of the cu
0840: 72 72 65 6e 74 0a 2a 2a 20 76 65 72 73 69 6f 6e  rrent.** version
0850: 20 6f 72 20 22 6c 61 74 65 73 74 22 20 74 6f 20   or "latest" to 
0860: 73 65 6c 65 63 74 20 74 68 65 20 6d 6f 73 74 20  select the most 
0870: 72 65 63 65 6e 74 20 63 68 65 63 6b 2d 69 6e 2e  recent check-in.
0880: 0a 2a 2a 0a 2a 2a 20 49 66 20 6f 6e 65 20 6f 72  .**.** If one or
0890: 20 6d 6f 72 65 20 46 49 4c 45 53 20 61 72 65 20   more FILES are 
08a0: 6c 69 73 74 65 64 20 61 66 74 65 72 20 74 68 65  listed after the
08b0: 20 56 45 52 53 49 4f 4e 20 74 68 65 6e 20 6f 6e   VERSION then on
08c0: 6c 79 20 74 68 65 0a 2a 2a 20 6e 61 6d 65 64 20  ly the.** named 
08d0: 66 69 6c 65 73 20 61 72 65 20 63 61 6e 64 69 64  files are candid
08e0: 61 74 65 73 20 74 6f 20 62 65 20 75 70 64 61 74  ates to be updat
08f0: 65 64 2e 20 20 49 66 20 46 49 4c 45 53 20 69 73  ed.  If FILES is
0900: 20 6f 6d 69 74 74 65 64 2c 20 61 6c 6c 0a 2a 2a   omitted, all.**
0910: 20 66 69 6c 65 73 20 69 6e 20 74 68 65 20 63 75   files in the cu
0920: 72 72 65 6e 74 20 63 68 65 63 6b 6f 75 74 20 61  rrent checkout a
0930: 72 65 20 73 75 62 6a 65 63 74 20 74 6f 20 62 65  re subject to be
0940: 20 75 70 64 61 74 65 64 2e 20 20 55 73 69 6e 67   updated.  Using
0950: 0a 2a 2a 20 61 20 64 69 72 65 63 74 6f 72 79 20  .** a directory 
0960: 6e 61 6d 65 20 66 6f 72 20 6f 6e 65 20 6f 66 20  name for one of 
0970: 74 68 65 20 46 49 4c 45 53 20 61 72 67 75 6d 65  the FILES argume
0980: 6e 74 73 20 69 73 20 74 68 65 20 73 61 6d 65 20  nts is the same 
0990: 61 73 0a 2a 2a 20 75 73 69 6e 67 20 65 76 65 72  as.** using ever
09a0: 79 20 73 75 62 64 69 72 65 63 74 6f 72 79 20 61  y subdirectory a
09b0: 6e 64 20 66 69 6c 65 20 62 65 6e 65 61 74 68 20  nd file beneath 
09c0: 74 68 61 74 20 64 69 72 65 63 74 6f 72 79 2e 0a  that directory..
09d0: 2a 2a 0a 2a 2a 20 54 68 65 20 2d 6e 20 6f 72 20  **.** The -n or 
09e0: 2d 2d 6e 6f 63 68 61 6e 67 65 20 6f 70 74 69 6f  --nochange optio
09f0: 6e 20 63 61 75 73 65 73 20 74 68 69 73 20 63 6f  n causes this co
0a00: 6d 6d 61 6e 64 20 74 6f 20 64 6f 20 61 20 22 64  mmand to do a "d
0a10: 72 79 20 72 75 6e 22 2e 20 20 49 74 0a 2a 2a 20  ry run".  It.** 
0a20: 70 72 69 6e 74 73 20 6f 75 74 20 77 68 61 74 20  prints out what 
0a30: 77 6f 75 6c 64 20 68 61 76 65 20 68 61 70 70 65  would have happe
0a40: 6e 65 64 20 62 75 74 20 64 6f 65 73 20 6e 6f 74  ned but does not
0a50: 20 61 63 74 75 61 6c 6c 79 20 6d 61 6b 65 20 61   actually make a
0a60: 6e 79 0a 2a 2a 20 63 68 61 6e 67 65 73 20 74 6f  ny.** changes to
0a70: 20 74 68 65 20 63 75 72 72 65 6e 74 20 63 68 65   the current che
0a80: 63 6b 6f 75 74 20 6f 72 20 74 68 65 20 72 65 70  ckout or the rep
0a90: 6f 73 69 74 6f 72 79 2e 0a 2a 2a 0a 2a 2a 20 54  ository..**.** T
0aa0: 68 65 20 2d 76 20 6f 72 20 2d 2d 76 65 72 62 6f  he -v or --verbo
0ab0: 73 65 20 6f 70 74 69 6f 6e 20 70 72 69 6e 74 73  se option prints
0ac0: 20 73 74 61 74 75 73 20 69 6e 66 6f 72 6d 61 74   status informat
0ad0: 69 6f 6e 20 61 62 6f 75 74 20 75 6e 63 68 61 6e  ion about unchan
0ae0: 67 65 64 0a 2a 2a 20 66 69 6c 65 73 20 69 6e 20  ged.** files in 
0af0: 61 64 64 69 74 69 6f 6e 20 74 6f 20 74 68 6f 73  addition to thos
0b00: 65 20 66 69 6c 65 20 74 68 61 74 20 61 63 74 75  e file that actu
0b10: 61 6c 6c 79 20 64 6f 20 63 68 61 6e 67 65 2e 0a  ally do change..
0b20: 2a 2a 0a 2a 2a 20 4f 70 74 69 6f 6e 73 3a 0a 2a  **.** Options:.*
0b30: 2a 20 20 20 2d 2d 64 65 62 75 67 20 20 20 20 20  *   --debug     
0b40: 20 20 20 20 20 70 72 69 6e 74 20 64 65 62 75 67       print debug
0b50: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 6f 6e 20   information on 
0b60: 73 74 64 6f 75 74 0a 2a 2a 20 20 20 2d 2d 6c 61  stdout.**   --la
0b70: 74 65 73 74 20 20 20 20 20 20 20 20 20 61 63 63  test         acc
0b80: 65 70 74 61 62 6c 65 20 69 6e 20 70 6c 61 63 65  eptable in place
0b90: 20 6f 66 20 56 45 52 53 49 4f 4e 2c 20 75 70 64   of VERSION, upd
0ba0: 61 74 65 20 74 6f 20 6c 61 74 65 73 74 20 76 65  ate to latest ve
0bb0: 72 73 69 6f 6e 0a 2a 2a 20 20 20 2d 6e 7c 2d 2d  rsion.**   -n|--
0bc0: 6e 6f 63 68 61 6e 67 65 20 20 20 20 64 6f 20 6e  nochange    do n
0bd0: 6f 74 20 70 65 72 66 6f 72 6d 20 63 68 61 6e 67  ot perform chang
0be0: 65 73 20 62 75 74 20 73 68 6f 77 20 77 68 61 74  es but show what
0bf0: 20 77 6f 75 6c 64 20 62 65 20 64 6f 6e 65 0a 2a   would be done.*
0c00: 2a 20 20 20 2d 76 7c 2d 2d 76 65 72 62 6f 73 65  *   -v|--verbose
0c10: 20 20 20 20 20 70 72 69 6e 74 20 73 74 61 74 75       print statu
0c20: 73 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62  s information ab
0c30: 6f 75 74 20 61 6c 6c 20 66 69 6c 65 73 0a 2a 2a  out all files.**
0c40: 0a 2a 2a 20 53 65 65 20 61 6c 73 6f 3a 20 72 65  .** See also: re
0c50: 76 65 72 74 0a 2a 2f 0a 76 6f 69 64 20 75 70 64  vert.*/.void upd
0c60: 61 74 65 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20  ate_cmd(void){. 
0c70: 20 69 6e 74 20 76 69 64 3b 20 20 20 20 20 20 20   int vid;       
0c80: 20 20 20 20 20 20 20 2f 2a 20 43 75 72 72 65 6e         /* Curren
0c90: 74 20 76 65 72 73 69 6f 6e 20 2a 2f 0a 20 20 69  t version */.  i
0ca0: 6e 74 20 74 69 64 3d 30 3b 20 20 20 20 20 20 20  nt tid=0;       
0cb0: 20 20 20 20 20 2f 2a 20 54 61 72 67 65 74 20 76       /* Target v
0cc0: 65 72 73 69 6f 6e 20 2d 20 76 65 72 73 69 6f 6e  ersion - version
0cd0: 20 77 65 20 61 72 65 20 63 68 61 6e 67 69 6e 67   we are changing
0ce0: 20 74 6f 20 2a 2f 0a 20 20 53 74 6d 74 20 71 3b   to */.  Stmt q;
0cf0: 0a 20 20 69 6e 74 20 6c 61 74 65 73 74 46 6c 61  .  int latestFla
0d00: 67 3b 20 20 20 20 20 20 20 2f 2a 20 2d 2d 6c 61  g;       /* --la
0d10: 74 65 73 74 2e 20 20 50 69 63 6b 20 74 68 65 20  test.  Pick the 
0d20: 6c 61 74 65 73 74 20 76 65 72 73 69 6f 6e 20 69  latest version i
0d30: 66 20 74 72 75 65 20 2a 2f 0a 20 20 69 6e 74 20  f true */.  int 
0d40: 6e 6f 63 68 61 6e 67 65 46 6c 61 67 3b 20 20 20  nochangeFlag;   
0d50: 20 20 2f 2a 20 2d 6e 20 6f 72 20 2d 2d 6e 6f 63    /* -n or --noc
0d60: 68 61 6e 67 65 2e 20 20 44 6f 20 61 20 64 72 79  hange.  Do a dry
0d70: 20 72 75 6e 20 2a 2f 0a 20 20 69 6e 74 20 76 65   run */.  int ve
0d80: 72 62 6f 73 65 46 6c 61 67 3b 20 20 20 20 20 20  rboseFlag;      
0d90: 2f 2a 20 2d 76 20 6f 72 20 2d 2d 76 65 72 62 6f  /* -v or --verbo
0da0: 73 65 2e 20 20 4f 75 74 70 75 74 20 65 78 74 72  se.  Output extr
0db0: 61 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 2a 2f  a information */
0dc0: 0a 20 20 69 6e 74 20 64 65 62 75 67 46 6c 61 67  .  int debugFlag
0dd0: 3b 20 20 20 20 20 20 20 20 2f 2a 20 2d 2d 64 65  ;        /* --de
0de0: 62 75 67 20 6f 70 74 69 6f 6e 20 2a 2f 0a 20 20  bug option */.  
0df0: 69 6e 74 20 73 65 74 6d 74 69 6d 65 46 6c 61 67  int setmtimeFlag
0e00: 3b 20 20 20 20 20 2f 2a 20 2d 2d 73 65 74 6d 74  ;     /* --setmt
0e10: 69 6d 65 2e 20 20 53 65 74 20 6d 74 69 6d 65 73  ime.  Set mtimes
0e20: 20 6f 6e 20 66 69 6c 65 73 20 2a 2f 0a 20 20 69   on files */.  i
0e30: 6e 74 20 6e 43 68 6e 67 3b 20 20 20 20 20 20 20  nt nChng;       
0e40: 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f       /* Number o
0e50: 66 20 66 69 6c 65 20 72 65 6e 61 6d 65 73 20 2a  f file renames *
0e60: 2f 0a 20 20 69 6e 74 20 2a 61 43 68 6e 67 3b 20  /.  int *aChng; 
0e70: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 72 72            /* Arr
0e80: 61 79 20 6f 66 20 66 69 6c 65 20 72 65 6e 61 6d  ay of file renam
0e90: 65 73 20 2a 2f 0a 20 20 69 6e 74 20 69 3b 20 20  es */.  int i;  
0ea0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a                /*
0eb0: 20 4c 6f 6f 70 20 63 6f 75 6e 74 65 72 20 2a 2f   Loop counter */
0ec0: 0a 20 20 69 6e 74 20 6e 43 6f 6e 66 6c 69 63 74  .  int nConflict
0ed0: 20 3d 20 30 3b 20 20 20 20 2f 2a 20 4e 75 6d 62   = 0;    /* Numb
0ee0: 65 72 20 6f 66 20 6d 65 72 67 65 20 63 6f 6e 66  er of merge conf
0ef0: 6c 69 63 74 73 20 2a 2f 0a 20 20 69 6e 74 20 6e  licts */.  int n
0f00: 4f 76 65 72 77 72 69 74 65 20 3d 20 30 3b 20 20  Overwrite = 0;  
0f10: 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 75 6e   /* Number of un
0f20: 6d 61 6e 61 67 65 64 20 66 69 6c 65 73 20 6f 76  managed files ov
0f30: 65 72 77 72 69 74 74 65 6e 20 2a 2f 0a 20 20 69  erwritten */.  i
0f40: 6e 74 20 6e 55 70 64 61 74 65 20 3d 20 30 3b 20  nt nUpdate = 0; 
0f50: 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f       /* Number o
0f60: 66 20 63 68 61 6e 67 65 73 20 6f 66 20 61 6e 79  f changes of any
0f70: 20 6b 69 6e 64 20 2a 2f 0a 20 20 53 74 6d 74 20   kind */.  Stmt 
0f80: 6d 74 69 6d 65 58 66 65 72 3b 20 20 20 20 20 20  mtimeXfer;      
0f90: 20 2f 2a 20 53 74 61 74 65 6d 65 6e 74 20 74 6f   /* Statement to
0fa0: 20 74 72 61 6e 73 66 65 72 20 6d 74 69 6d 65 73   transfer mtimes
0fb0: 20 2a 2f 0a 0a 20 20 69 66 28 20 21 69 6e 74 65   */..  if( !inte
0fc0: 72 6e 61 6c 55 70 64 61 74 65 20 29 7b 0a 20 20  rnalUpdate ){.  
0fd0: 20 20 75 6e 64 6f 5f 63 61 70 74 75 72 65 5f 63    undo_capture_c
0fe0: 6f 6d 6d 61 6e 64 5f 6c 69 6e 65 28 29 3b 0a 20  ommand_line();. 
0ff0: 20 20 20 75 72 6c 5f 70 72 6f 78 79 5f 6f 70 74     url_proxy_opt
1000: 69 6f 6e 73 28 29 3b 0a 20 20 7d 0a 20 20 6c 61  ions();.  }.  la
1010: 74 65 73 74 46 6c 61 67 20 3d 20 66 69 6e 64 5f  testFlag = find_
1020: 6f 70 74 69 6f 6e 28 22 6c 61 74 65 73 74 22 2c  option("latest",
1030: 30 2c 20 30 29 21 3d 30 3b 0a 20 20 6e 6f 63 68  0, 0)!=0;.  noch
1040: 61 6e 67 65 46 6c 61 67 20 3d 20 66 69 6e 64 5f  angeFlag = find_
1050: 6f 70 74 69 6f 6e 28 22 6e 6f 63 68 61 6e 67 65  option("nochange
1060: 22 2c 22 6e 22 2c 30 29 21 3d 30 3b 0a 20 20 76  ","n",0)!=0;.  v
1070: 65 72 62 6f 73 65 46 6c 61 67 20 3d 20 66 69 6e  erboseFlag = fin
1080: 64 5f 6f 70 74 69 6f 6e 28 22 76 65 72 62 6f 73  d_option("verbos
1090: 65 22 2c 22 76 22 2c 30 29 21 3d 30 3b 0a 20 20  e","v",0)!=0;.  
10a0: 64 65 62 75 67 46 6c 61 67 20 3d 20 66 69 6e 64  debugFlag = find
10b0: 5f 6f 70 74 69 6f 6e 28 22 64 65 62 75 67 22 2c  _option("debug",
10c0: 30 2c 30 29 21 3d 30 3b 0a 20 20 73 65 74 6d 74  0,0)!=0;.  setmt
10d0: 69 6d 65 46 6c 61 67 20 3d 20 66 69 6e 64 5f 6f  imeFlag = find_o
10e0: 70 74 69 6f 6e 28 22 73 65 74 6d 74 69 6d 65 22  ption("setmtime"
10f0: 2c 30 2c 30 29 21 3d 30 3b 0a 20 20 64 62 5f 6d  ,0,0)!=0;.  db_m
1100: 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72  ust_be_within_tr
1110: 65 65 28 29 3b 0a 20 20 76 69 64 20 3d 20 64 62  ee();.  vid = db
1120: 5f 6c 67 65 74 5f 69 6e 74 28 22 63 68 65 63 6b  _lget_int("check
1130: 6f 75 74 22 2c 20 30 29 3b 0a 20 20 69 66 28 20  out", 0);.  if( 
1140: 76 69 64 3d 3d 30 20 29 7b 0a 20 20 20 20 66 6f  vid==0 ){.    fo
1150: 73 73 69 6c 5f 66 61 74 61 6c 28 22 63 61 6e 6e  ssil_fatal("cann
1160: 6f 74 20 66 69 6e 64 20 63 75 72 72 65 6e 74 20  ot find current 
1170: 76 65 72 73 69 6f 6e 22 29 3b 0a 20 20 7d 0a 20  version");.  }. 
1180: 20 69 66 28 20 21 6e 6f 63 68 61 6e 67 65 46 6c   if( !nochangeFl
1190: 61 67 20 26 26 20 21 69 6e 74 65 72 6e 61 6c 55  ag && !internalU
11a0: 70 64 61 74 65 20 29 7b 0a 20 20 20 20 61 75 74  pdate ){.    aut
11b0: 6f 73 79 6e 63 28 53 59 4e 43 5f 50 55 4c 4c 20  osync(SYNC_PULL 
11c0: 2b 20 53 59 4e 43 5f 56 45 52 42 4f 53 45 2a 76  + SYNC_VERBOSE*v
11d0: 65 72 62 6f 73 65 46 6c 61 67 29 3b 0a 20 20 7d  erboseFlag);.  }
11e0: 0a 20 20 0a 20 20 2f 2a 20 43 72 65 61 74 65 20  .  .  /* Create 
11f0: 61 6e 79 20 65 6d 70 74 79 20 64 69 72 65 63 74  any empty direct
1200: 6f 72 69 65 73 20 6e 6f 77 2c 20 61 73 20 77 65  ories now, as we
1210: 6c 6c 20 61 73 20 61 66 74 65 72 20 74 68 65 20  ll as after the 
1220: 75 70 64 61 74 65 2c 0a 20 20 2a 2a 20 73 6f 20  update,.  ** so 
1230: 63 68 61 6e 67 65 73 20 69 6e 20 73 65 74 74 69  changes in setti
1240: 6e 67 73 20 61 72 65 20 72 65 66 6c 65 63 74 65  ngs are reflecte
1250: 64 20 6e 6f 77 20 2a 2f 0a 20 20 69 66 28 20 21  d now */.  if( !
1260: 6e 6f 63 68 61 6e 67 65 46 6c 61 67 20 29 20 65  nochangeFlag ) e
1270: 6e 73 75 72 65 5f 65 6d 70 74 79 5f 64 69 72 73  nsure_empty_dirs
1280: 5f 63 72 65 61 74 65 64 28 29 3b 0a 0a 20 20 69  _created();..  i
1290: 66 28 20 69 6e 74 65 72 6e 61 6c 55 70 64 61 74  f( internalUpdat
12a0: 65 20 29 7b 0a 20 20 20 20 74 69 64 20 3d 20 69  e ){.    tid = i
12b0: 6e 74 65 72 6e 61 6c 55 70 64 61 74 65 3b 0a 20  nternalUpdate;. 
12c0: 20 7d 65 6c 73 65 20 69 66 28 20 67 2e 61 72 67   }else if( g.arg
12d0: 63 3e 3d 33 20 29 7b 0a 20 20 20 20 69 66 28 20  c>=3 ){.    if( 
12e0: 66 6f 73 73 69 6c 5f 73 74 72 63 6d 70 28 67 2e  fossil_strcmp(g.
12f0: 61 72 67 76 5b 32 5d 2c 20 22 63 75 72 72 65 6e  argv[2], "curren
1300: 74 22 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20  t")==0 ){.      
1310: 2f 2a 20 49 66 20 56 45 52 53 49 4f 4e 20 69 73  /* If VERSION is
1320: 20 22 63 75 72 72 65 6e 74 22 2c 20 74 68 65 6e   "current", then
1330: 20 75 73 65 20 74 68 65 20 73 61 6d 65 20 61 6c   use the same al
1340: 67 6f 72 69 74 68 6d 20 74 6f 20 66 69 6e 64 20  gorithm to find 
1350: 74 68 65 0a 20 20 20 20 20 20 2a 2a 20 74 61 72  the.      ** tar
1360: 67 65 74 20 61 73 20 69 66 20 56 45 52 53 49 4f  get as if VERSIO
1370: 4e 20 77 65 72 65 20 6f 6d 69 74 74 65 64 2e 20  N were omitted. 
1380: 2a 2f 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28  */.    }else if(
1390: 20 66 6f 73 73 69 6c 5f 73 74 72 63 6d 70 28 67   fossil_strcmp(g
13a0: 2e 61 72 67 76 5b 32 5d 2c 20 22 6c 61 74 65 73  .argv[2], "lates
13b0: 74 22 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20  t")==0 ){.      
13c0: 2f 2a 20 49 66 20 56 45 52 53 49 4f 4e 20 69 73  /* If VERSION is
13d0: 20 22 6c 61 74 65 73 74 22 2c 20 74 68 65 6e 20   "latest", then 
13e0: 75 73 65 20 74 68 65 20 73 61 6d 65 20 61 6c 67  use the same alg
13f0: 6f 72 69 74 68 6d 20 74 6f 20 66 69 6e 64 20 74  orithm to find t
1400: 68 65 0a 20 20 20 20 20 20 2a 2a 20 74 61 72 67  he.      ** targ
1410: 65 74 20 61 73 20 69 66 20 56 45 52 53 49 4f 4e  et as if VERSION
1420: 20 77 65 72 65 20 6f 6d 69 74 74 65 64 20 61 6e   were omitted an
1430: 64 20 74 68 65 20 2d 2d 6c 61 74 65 73 74 20 66  d the --latest f
1440: 6c 61 67 20 69 73 20 70 72 65 73 65 6e 74 2e 0a  lag is present..
1450: 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 6c        */.      l
1460: 61 74 65 73 74 46 6c 61 67 20 3d 20 31 3b 0a 20  atestFlag = 1;. 
1470: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20     }else{.      
1480: 74 69 64 20 3d 20 6e 61 6d 65 5f 74 6f 5f 74 79  tid = name_to_ty
1490: 70 65 64 5f 72 69 64 28 67 2e 61 72 67 76 5b 32  ped_rid(g.argv[2
14a0: 5d 2c 22 63 69 22 29 3b 0a 20 20 20 20 20 20 69  ],"ci");.      i
14b0: 66 28 20 74 69 64 3d 3d 30 20 29 7b 0a 20 20 20  f( tid==0 ){.   
14c0: 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61       fossil_fata
14d0: 6c 28 22 6e 6f 20 73 75 63 68 20 76 65 72 73 69  l("no such versi
14e0: 6f 6e 3a 20 25 73 22 2c 20 67 2e 61 72 67 76 5b  on: %s", g.argv[
14f0: 32 5d 29 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65  2]);.      }else
1500: 20 69 66 28 20 21 69 73 5f 61 5f 76 65 72 73 69   if( !is_a_versi
1510: 6f 6e 28 74 69 64 29 20 29 7b 0a 20 20 20 20 20  on(tid) ){.     
1520: 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28     fossil_fatal(
1530: 22 6e 6f 20 73 75 63 68 20 76 65 72 73 69 6f 6e  "no such version
1540: 3a 20 25 73 22 2c 20 67 2e 61 72 67 76 5b 32 5d  : %s", g.argv[2]
1550: 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d  );.      }.    }
1560: 0a 20 20 7d 0a 20 20 0a 20 20 2f 2a 20 49 66 20  .  }.  .  /* If 
1570: 6e 6f 20 56 45 52 53 49 4f 4e 20 69 73 20 73 70  no VERSION is sp
1580: 65 63 69 66 69 65 64 20 6f 6e 20 74 68 65 20 63  ecified on the c
1590: 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 2c 20 74 68 65  ommand-line, the
15a0: 6e 20 6c 6f 6f 6b 20 66 6f 72 20 61 0a 20 20 2a  n look for a.  *
15b0: 2a 20 64 65 73 63 65 6e 64 65 6e 74 20 6f 66 20  * descendent of 
15c0: 74 68 65 20 63 75 72 72 65 6e 74 20 76 65 72 73  the current vers
15d0: 69 6f 6e 2e 20 20 49 66 20 74 68 65 72 65 20 61  ion.  If there a
15e0: 72 65 20 6d 75 6c 74 69 70 6c 65 20 64 65 73 63  re multiple desc
15f0: 65 6e 64 61 6e 74 73 2c 0a 20 20 2a 2a 20 6c 6f  endants,.  ** lo
1600: 6f 6b 20 66 6f 72 20 6f 6e 65 20 66 72 6f 6d 20  ok for one from 
1610: 74 68 65 20 73 61 6d 65 20 62 72 61 6e 63 68 20  the same branch 
1620: 61 73 20 74 68 65 20 63 75 72 72 65 6e 74 20 76  as the current v
1630: 65 72 73 69 6f 6e 2e 20 20 49 66 20 74 68 65 72  ersion.  If ther
1640: 65 0a 20 20 2a 2a 20 61 72 65 20 73 74 69 6c 6c  e.  ** are still
1650: 20 6d 75 6c 74 69 70 6c 65 20 64 65 73 63 65 6e   multiple descen
1660: 64 61 6e 74 73 2c 20 73 68 6f 77 20 74 68 65 6d  dants, show them
1670: 20 61 6c 6c 20 61 6e 64 20 72 65 66 75 73 65 20   all and refuse 
1680: 74 6f 20 75 70 64 61 74 65 0a 20 20 2a 2a 20 75  to update.  ** u
1690: 6e 74 69 6c 20 74 68 65 20 75 73 65 72 20 73 65  ntil the user se
16a0: 6c 65 63 74 73 20 6f 6e 65 2e 0a 20 20 2a 2f 0a  lects one..  */.
16b0: 20 20 69 66 28 20 74 69 64 3d 3d 30 20 29 7b 0a    if( tid==0 ){.
16c0: 20 20 20 20 69 6e 74 20 63 6c 6f 73 65 43 6f 64      int closeCod
16d0: 65 20 3d 20 31 3b 0a 20 20 20 20 63 6f 6d 70 75  e = 1;.    compu
16e0: 74 65 5f 6c 65 61 76 65 73 28 76 69 64 2c 20 63  te_leaves(vid, c
16f0: 6c 6f 73 65 43 6f 64 65 29 3b 0a 20 20 20 20 69  loseCode);.    i
1700: 66 28 20 21 64 62 5f 65 78 69 73 74 73 28 22 53  f( !db_exists("S
1710: 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 6c 65 61  ELECT 1 FROM lea
1720: 76 65 73 22 29 20 29 7b 0a 20 20 20 20 20 20 63  ves") ){.      c
1730: 6c 6f 73 65 43 6f 64 65 20 3d 20 30 3b 0a 20 20  loseCode = 0;.  
1740: 20 20 20 20 63 6f 6d 70 75 74 65 5f 6c 65 61 76      compute_leav
1750: 65 73 28 76 69 64 2c 20 63 6c 6f 73 65 43 6f 64  es(vid, closeCod
1760: 65 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66  e);.    }.    if
1770: 28 20 21 6c 61 74 65 73 74 46 6c 61 67 20 26 26  ( !latestFlag &&
1780: 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45   db_int(0, "SELE
1790: 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d  CT count(*) FROM
17a0: 20 6c 65 61 76 65 73 22 29 3e 31 20 29 7b 0a 20   leaves")>1 ){. 
17b0: 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78       db_multi_ex
17c0: 65 63 28 0a 20 20 20 20 20 20 20 20 22 44 45 4c  ec(.        "DEL
17d0: 45 54 45 20 46 52 4f 4d 20 6c 65 61 76 65 73 20  ETE FROM leaves 
17e0: 57 48 45 52 45 20 72 69 64 20 4e 4f 54 20 49 4e  WHERE rid NOT IN
17f0: 22 0a 20 20 20 20 20 20 20 20 22 20 20 20 28 53  ".        "   (S
1800: 45 4c 45 43 54 20 6c 65 61 76 65 73 2e 72 69 64  ELECT leaves.rid
1810: 20 46 52 4f 4d 20 6c 65 61 76 65 73 2c 20 74 61   FROM leaves, ta
1820: 67 78 72 65 66 22 0a 20 20 20 20 20 20 20 20 22  gxref".        "
1830: 20 20 20 20 20 57 48 45 52 45 20 6c 65 61 76 65       WHERE leave
1840: 73 2e 72 69 64 3d 74 61 67 78 72 65 66 2e 72 69  s.rid=tagxref.ri
1850: 64 20 41 4e 44 20 74 61 67 78 72 65 66 2e 74 61  d AND tagxref.ta
1860: 67 69 64 3d 25 64 22 0a 20 20 20 20 20 20 20 20  gid=%d".        
1870: 22 20 20 20 20 20 20 20 41 4e 44 20 74 61 67 78  "       AND tagx
1880: 72 65 66 2e 76 61 6c 75 65 3d 3d 28 53 45 4c 45  ref.value==(SELE
1890: 43 54 20 76 61 6c 75 65 20 46 52 4f 4d 20 74 61  CT value FROM ta
18a0: 67 78 72 65 66 22 0a 20 20 20 20 20 20 20 20 20  gxref".         
18b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
18c0: 20 20 20 20 20 20 20 20 20 20 22 20 57 48 45 52            " WHER
18d0: 45 20 74 61 67 69 64 3d 25 64 20 41 4e 44 20 72  E tagid=%d AND r
18e0: 69 64 3d 25 64 29 29 22 2c 0a 20 20 20 20 20 20  id=%d))",.      
18f0: 20 20 54 41 47 5f 42 52 41 4e 43 48 2c 20 54 41    TAG_BRANCH, TA
1900: 47 5f 42 52 41 4e 43 48 2c 20 76 69 64 0a 20 20  G_BRANCH, vid.  
1910: 20 20 20 20 29 3b 0a 20 20 20 20 20 20 69 66 28      );.      if(
1920: 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45   db_int(0, "SELE
1930: 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d  CT count(*) FROM
1940: 20 6c 65 61 76 65 73 22 29 3e 31 20 29 7b 0a 20   leaves")>1 ){. 
1950: 20 20 20 20 20 20 20 63 6f 6d 70 75 74 65 5f 6c         compute_l
1960: 65 61 76 65 73 28 76 69 64 2c 20 63 6c 6f 73 65  eaves(vid, close
1970: 43 6f 64 65 29 3b 0a 20 20 20 20 20 20 20 20 64  Code);.        d
1980: 62 5f 70 72 65 70 61 72 65 28 26 71 2c 20 0a 20  b_prepare(&q, . 
1990: 20 20 20 20 20 20 20 20 20 22 25 73 20 22 0a 20           "%s ". 
19a0: 20 20 20 20 20 20 20 20 20 22 20 20 20 41 4e 44           "   AND
19b0: 20 65 76 65 6e 74 2e 6f 62 6a 69 64 20 49 4e 20   event.objid IN 
19c0: 6c 65 61 76 65 73 22 0a 20 20 20 20 20 20 20 20  leaves".        
19d0: 20 20 22 20 4f 52 44 45 52 20 42 59 20 65 76 65    " ORDER BY eve
19e0: 6e 74 2e 6d 74 69 6d 65 20 44 45 53 43 22 2c 0a  nt.mtime DESC",.
19f0: 20 20 20 20 20 20 20 20 20 20 74 69 6d 65 6c 69            timeli
1a00: 6e 65 5f 71 75 65 72 79 5f 66 6f 72 5f 74 74 79  ne_query_for_tty
1a10: 28 29 0a 20 20 20 20 20 20 20 20 29 3b 0a 20 20  ().        );.  
1a20: 20 20 20 20 20 20 70 72 69 6e 74 5f 74 69 6d 65        print_time
1a30: 6c 69 6e 65 28 26 71 2c 20 31 30 30 2c 20 30 29  line(&q, 100, 0)
1a40: 3b 0a 20 20 20 20 20 20 20 20 64 62 5f 66 69 6e  ;.        db_fin
1a50: 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 20 20 20  alize(&q);.     
1a60: 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28     fossil_fatal(
1a70: 22 4d 75 6c 74 69 70 6c 65 20 64 65 73 63 65 6e  "Multiple descen
1a80: 64 61 6e 74 73 22 29 3b 0a 20 20 20 20 20 20 7d  dants");.      }
1a90: 0a 20 20 20 20 7d 0a 20 20 20 20 74 69 64 20 3d  .    }.    tid =
1aa0: 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45   db_int(0, "SELE
1ab0: 43 54 20 72 69 64 20 46 52 4f 4d 20 6c 65 61 76  CT rid FROM leav
1ac0: 65 73 2c 20 65 76 65 6e 74 22 0a 20 20 20 20 20  es, event".     
1ad0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22                 "
1ae0: 20 57 48 45 52 45 20 65 76 65 6e 74 2e 6f 62 6a   WHERE event.obj
1af0: 69 64 3d 6c 65 61 76 65 73 2e 72 69 64 22 0a 20  id=leaves.rid". 
1b00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1b10: 20 20 20 22 20 4f 52 44 45 52 20 42 59 20 65 76     " ORDER BY ev
1b20: 65 6e 74 2e 6d 74 69 6d 65 20 44 45 53 43 22 29  ent.mtime DESC")
1b30: 3b 20 0a 20 20 20 20 69 66 28 20 74 69 64 3d 3d  ; .    if( tid==
1b40: 30 20 29 20 74 69 64 20 3d 20 76 69 64 3b 0a 20  0 ) tid = vid;. 
1b50: 20 7d 0a 0a 20 20 69 66 28 20 74 69 64 3d 3d 30   }..  if( tid==0
1b60: 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70   ){.    fossil_p
1b70: 61 6e 69 63 28 22 49 6e 74 65 72 6e 61 6c 20 45  anic("Internal E
1b80: 72 72 6f 72 3a 20 75 6e 61 62 6c 65 20 74 6f 20  rror: unable to 
1b90: 66 69 6e 64 20 61 20 76 65 72 73 69 6f 6e 20 74  find a version t
1ba0: 6f 20 75 70 64 61 74 65 20 74 6f 2e 22 29 3b 0a  o update to.");.
1bb0: 20 20 7d 0a 0a 20 20 64 62 5f 62 65 67 69 6e 5f    }..  db_begin_
1bc0: 74 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a 20  transaction();. 
1bd0: 20 76 66 69 6c 65 5f 63 68 65 63 6b 5f 73 69 67   vfile_check_sig
1be0: 6e 61 74 75 72 65 28 76 69 64 2c 20 43 4b 53 49  nature(vid, CKSI
1bf0: 47 5f 45 4e 4f 54 46 49 4c 45 29 3b 0a 20 20 69  G_ENOTFILE);.  i
1c00: 66 28 20 21 6e 6f 63 68 61 6e 67 65 46 6c 61 67  f( !nochangeFlag
1c10: 20 26 26 20 21 69 6e 74 65 72 6e 61 6c 55 70 64   && !internalUpd
1c20: 61 74 65 20 29 20 75 6e 64 6f 5f 62 65 67 69 6e  ate ) undo_begin
1c30: 28 29 3b 0a 20 20 6c 6f 61 64 5f 76 66 69 6c 65  ();.  load_vfile
1c40: 5f 66 72 6f 6d 5f 72 69 64 28 74 69 64 29 3b 0a  _from_rid(tid);.
1c50: 0a 20 20 2f 2a 0a 20 20 2a 2a 20 54 68 65 20 72  .  /*.  ** The r
1c60: 65 63 6f 72 64 2e 66 6e 20 66 69 65 6c 64 20 69  ecord.fn field i
1c70: 73 20 75 73 65 64 20 74 6f 20 6d 61 74 63 68 20  s used to match 
1c80: 66 69 6c 65 73 20 61 67 61 69 6e 73 74 20 65 61  files against ea
1c90: 63 68 20 6f 74 68 65 72 2e 20 20 54 68 65 0a 20  ch other.  The. 
1ca0: 20 2a 2a 20 46 56 20 74 61 62 6c 65 20 63 6f 6e   ** FV table con
1cb0: 74 61 69 6e 73 20 6f 6e 65 20 72 6f 77 20 66 6f  tains one row fo
1cc0: 72 20 65 61 63 68 20 65 61 63 68 20 75 6e 69 71  r each each uniq
1cd0: 75 65 20 66 69 6c 65 6e 61 6d 65 20 69 6e 0a 20  ue filename in. 
1ce0: 20 2a 2a 20 69 6e 20 74 68 65 20 63 75 72 72 65   ** in the curre
1cf0: 6e 74 20 63 68 65 63 6b 6f 75 74 2c 20 74 68 65  nt checkout, the
1d00: 20 70 69 76 6f 74 2c 20 61 6e 64 20 74 68 65 20   pivot, and the 
1d10: 76 65 72 73 69 6f 6e 20 62 65 69 6e 67 20 6d 65  version being me
1d20: 72 67 65 64 2e 0a 20 20 2a 2f 0a 20 20 64 62 5f  rged..  */.  db_
1d30: 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20  multi_exec(.    
1d40: 22 44 52 4f 50 20 54 41 42 4c 45 20 49 46 20 45  "DROP TABLE IF E
1d50: 58 49 53 54 53 20 66 76 3b 22 0a 20 20 20 20 22  XISTS fv;".    "
1d60: 43 52 45 41 54 45 20 54 45 4d 50 20 54 41 42 4c  CREATE TEMP TABL
1d70: 45 20 66 76 28 22 0a 20 20 20 20 22 20 20 66 6e  E fv(".    "  fn
1d80: 20 54 45 58 54 20 50 52 49 4d 41 52 59 20 4b 45   TEXT PRIMARY KE
1d90: 59 2c 22 20 20 20 20 20 20 2f 2a 20 54 68 65 20  Y,"      /* The 
1da0: 66 69 6c 65 6e 61 6d 65 20 72 65 6c 61 74 69 76  filename relativ
1db0: 65 20 74 6f 20 72 6f 6f 74 20 2a 2f 0a 20 20 20  e to root */.   
1dc0: 20 22 20 20 69 64 76 20 49 4e 54 45 47 45 52 2c   "  idv INTEGER,
1dd0: 22 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f  "              /
1de0: 2a 20 56 46 49 4c 45 20 65 6e 74 72 79 20 66 6f  * VFILE entry fo
1df0: 72 20 63 75 72 72 65 6e 74 20 76 65 72 73 69 6f  r current versio
1e00: 6e 20 2a 2f 0a 20 20 20 20 22 20 20 69 64 74 20  n */.    "  idt 
1e10: 49 4e 54 45 47 45 52 2c 22 20 20 20 20 20 20 20  INTEGER,"       
1e20: 20 20 20 20 20 20 20 2f 2a 20 56 46 49 4c 45 20         /* VFILE 
1e30: 65 6e 74 72 79 20 66 6f 72 20 74 61 72 67 65 74  entry for target
1e40: 20 76 65 72 73 69 6f 6e 20 2a 2f 0a 20 20 20 20   version */.    
1e50: 22 20 20 63 68 6e 67 65 64 20 42 4f 4f 4c 45 41  "  chnged BOOLEA
1e60: 4e 2c 22 20 20 20 20 20 20 20 20 20 20 20 2f 2a  N,"           /*
1e70: 20 54 72 75 65 20 69 66 20 63 75 72 72 65 6e 74   True if current
1e80: 20 76 65 72 73 69 6f 6e 20 68 61 73 20 62 65 65   version has bee
1e90: 6e 20 65 64 69 74 65 64 20 2a 2f 0a 20 20 20 20  n edited */.    
1ea0: 22 20 20 69 73 6c 69 6e 6b 76 20 42 4f 4f 4c 45  "  islinkv BOOLE
1eb0: 41 4e 2c 22 20 20 20 20 20 20 20 20 20 20 2f 2a  AN,"          /*
1ec0: 20 54 72 75 65 20 69 66 20 63 75 72 72 65 6e 74   True if current
1ed0: 20 66 69 6c 65 20 69 73 20 61 20 6c 69 6e 6b 20   file is a link 
1ee0: 2a 2f 0a 20 20 20 20 22 20 20 69 73 6c 69 6e 6b  */.    "  islink
1ef0: 74 20 42 4f 4f 4c 45 41 4e 2c 22 20 20 20 20 20  t BOOLEAN,"     
1f00: 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20       /* True if 
1f10: 74 61 72 67 65 74 20 66 69 6c 65 20 69 73 20 61  target file is a
1f20: 20 6c 69 6e 6b 20 2a 2f 0a 20 20 20 20 22 20 20   link */.    "  
1f30: 72 69 64 76 20 49 4e 54 45 47 45 52 2c 22 20 20  ridv INTEGER,"  
1f40: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 52 65             /* Re
1f50: 63 6f 72 64 20 49 44 20 66 6f 72 20 63 75 72 72  cord ID for curr
1f60: 65 6e 74 20 76 65 72 73 69 6f 6e 20 2a 2f 0a 20  ent version */. 
1f70: 20 20 20 22 20 20 72 69 64 74 20 49 4e 54 45 47     "  ridt INTEG
1f80: 45 52 2c 22 20 20 20 20 20 20 20 20 20 20 20 20  ER,"            
1f90: 20 2f 2a 20 52 65 63 6f 72 64 20 49 44 20 66 6f   /* Record ID fo
1fa0: 72 20 74 61 72 67 65 74 20 2a 2f 0a 20 20 20 20  r target */.    
1fb0: 22 20 20 69 73 65 78 65 20 42 4f 4f 4c 45 41 4e  "  isexe BOOLEAN
1fc0: 2c 22 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a  ,"            /*
1fd0: 20 44 6f 65 73 20 74 61 72 67 65 74 20 68 61 76   Does target hav
1fe0: 65 20 65 78 65 63 75 74 65 20 70 65 72 6d 69 73  e execute permis
1ff0: 73 69 6f 6e 3f 20 2a 2f 0a 20 20 20 20 22 20 20  sion? */.    "  
2000: 64 65 6c 65 74 65 64 20 42 4f 4f 4c 45 41 4e 20  deleted BOOLEAN 
2010: 44 45 46 41 55 4c 54 20 30 2c 22 2f 2a 20 46 69  DEFAULT 0,"/* Fi
2020: 6c 65 20 6d 61 72 6b 65 20 62 79 20 22 72 6d 22  le marke by "rm"
2030: 20 74 6f 20 62 65 63 6f 6d 65 20 75 6e 6d 61 6e   to become unman
2040: 61 67 65 64 20 2a 2f 0a 20 20 20 20 22 20 20 66  aged */.    "  f
2050: 6e 74 20 54 45 58 54 22 20 20 20 20 20 20 20 20  nt TEXT"        
2060: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 69 6c            /* Fil
2070: 65 6e 61 6d 65 20 6f 66 20 73 61 6d 65 20 66 69  ename of same fi
2080: 6c 65 20 6f 6e 20 74 61 72 67 65 74 20 76 65 72  le on target ver
2090: 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 22 29 3b 22  sion */.    ");"
20a0: 0a 20 20 29 3b 0a 0a 20 20 2f 2a 20 41 64 64 20  .  );..  /* Add 
20b0: 66 69 6c 65 73 20 66 6f 75 6e 64 20 69 6e 20 74  files found in t
20c0: 68 65 20 63 75 72 72 65 6e 74 20 76 65 72 73 69  he current versi
20d0: 6f 6e 0a 20 20 2a 2f 0a 20 20 64 62 5f 6d 75 6c  on.  */.  db_mul
20e0: 74 69 5f 65 78 65 63 28 0a 20 20 20 20 22 49 4e  ti_exec(.    "IN
20f0: 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 45 20 49  SERT OR IGNORE I
2100: 4e 54 4f 20 66 76 28 66 6e 2c 66 6e 74 2c 69 64  NTO fv(fn,fnt,id
2110: 76 2c 69 64 74 2c 72 69 64 76 2c 72 69 64 74 2c  v,idt,ridv,ridt,
2120: 69 73 65 78 65 2c 63 68 6e 67 65 64 2c 64 65 6c  isexe,chnged,del
2130: 65 74 65 64 29 22 0a 20 20 20 20 22 20 53 45 4c  eted)".    " SEL
2140: 45 43 54 20 70 61 74 68 6e 61 6d 65 2c 20 70 61  ECT pathname, pa
2150: 74 68 6e 61 6d 65 2c 20 69 64 2c 20 30 2c 20 72  thname, id, 0, r
2160: 69 64 2c 20 30 2c 20 69 73 65 78 65 2c 20 63 68  id, 0, isexe, ch
2170: 6e 67 65 64 2c 20 64 65 6c 65 74 65 64 22 0a 20  nged, deleted". 
2180: 20 20 20 22 20 20 20 46 52 4f 4d 20 76 66 69 6c     "   FROM vfil
2190: 65 20 57 48 45 52 45 20 76 69 64 3d 25 64 22 2c  e WHERE vid=%d",
21a0: 0a 20 20 20 20 76 69 64 0a 20 20 29 3b 0a 0a 20  .    vid.  );.. 
21b0: 20 2f 2a 20 43 6f 6d 70 75 74 65 20 66 69 6c 65   /* Compute file
21c0: 20 6e 61 6d 65 20 63 68 61 6e 67 65 73 20 6f 6e   name changes on
21d0: 20 56 2d 3e 54 2e 20 20 52 65 63 6f 72 64 20 6e   V->T.  Record n
21e0: 61 6d 65 20 63 68 61 6e 67 65 73 20 69 6e 20 66  ame changes in f
21f0: 69 6c 65 73 20 74 68 61 74 0a 20 20 2a 2a 20 68  iles that.  ** h
2200: 61 76 65 20 63 68 61 6e 67 65 64 20 6c 6f 63 61  ave changed loca
2210: 6c 6c 79 2e 0a 20 20 2a 2f 0a 20 20 66 69 6e 64  lly..  */.  find
2220: 5f 66 69 6c 65 6e 61 6d 65 5f 63 68 61 6e 67 65  _filename_change
2230: 73 28 76 69 64 2c 20 74 69 64 2c 20 31 2c 20 26  s(vid, tid, 1, &
2240: 6e 43 68 6e 67 2c 20 26 61 43 68 6e 67 2c 20 64  nChng, &aChng, d
2250: 65 62 75 67 46 6c 61 67 20 3f 20 22 56 2d 3e 54  ebugFlag ? "V->T
2260: 22 3a 20 30 29 3b 0a 20 20 69 66 28 20 6e 43 68  ": 0);.  if( nCh
2270: 6e 67 20 29 7b 0a 20 20 20 20 66 6f 72 28 69 3d  ng ){.    for(i=
2280: 30 3b 20 69 3c 6e 43 68 6e 67 3b 20 69 2b 2b 29  0; i<nChng; i++)
2290: 7b 0a 20 20 20 20 20 20 64 62 5f 6d 75 6c 74 69  {.      db_multi
22a0: 5f 65 78 65 63 28 0a 20 20 20 20 20 20 20 20 22  _exec(.        "
22b0: 55 50 44 41 54 45 20 66 76 22 0a 20 20 20 20 20  UPDATE fv".     
22c0: 20 20 20 22 20 20 20 53 45 54 20 66 6e 74 3d 28     "   SET fnt=(
22d0: 53 45 4c 45 43 54 20 6e 61 6d 65 20 46 52 4f 4d  SELECT name FROM
22e0: 20 66 69 6c 65 6e 61 6d 65 20 57 48 45 52 45 20   filename WHERE 
22f0: 66 6e 69 64 3d 25 64 29 22 0a 20 20 20 20 20 20  fnid=%d)".      
2300: 20 20 22 20 57 48 45 52 45 20 66 6e 3d 28 53 45    " WHERE fn=(SE
2310: 4c 45 43 54 20 6e 61 6d 65 20 46 52 4f 4d 20 66  LECT name FROM f
2320: 69 6c 65 6e 61 6d 65 20 57 48 45 52 45 20 66 6e  ilename WHERE fn
2330: 69 64 3d 25 64 29 20 41 4e 44 20 63 68 6e 67 65  id=%d) AND chnge
2340: 64 22 2c 0a 20 20 20 20 20 20 20 20 61 43 68 6e  d",.        aChn
2350: 67 5b 69 2a 32 2b 31 5d 2c 20 61 43 68 6e 67 5b  g[i*2+1], aChng[
2360: 69 2a 32 5d 0a 20 20 20 20 20 20 29 3b 0a 20 20  i*2].      );.  
2370: 20 20 7d 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66    }.    fossil_f
2380: 72 65 65 28 61 43 68 6e 67 29 3b 0a 20 20 7d 0a  ree(aChng);.  }.
2390: 0a 20 20 2f 2a 20 41 64 64 20 66 69 6c 65 73 20  .  /* Add files 
23a0: 66 6f 75 6e 64 20 69 6e 20 74 68 65 20 74 61 72  found in the tar
23b0: 67 65 74 20 76 65 72 73 69 6f 6e 20 54 20 62 75  get version T bu
23c0: 74 20 6d 69 73 73 69 6e 67 20 66 72 6f 6d 20 74  t missing from t
23d0: 68 65 20 63 75 72 72 65 6e 74 0a 20 20 2a 2a 20  he current.  ** 
23e0: 76 65 72 73 69 6f 6e 20 56 2e 0a 20 20 2a 2f 0a  version V..  */.
23f0: 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28    db_multi_exec(
2400: 0a 20 20 20 20 22 49 4e 53 45 52 54 20 4f 52 20  .    "INSERT OR 
2410: 49 47 4e 4f 52 45 20 49 4e 54 4f 20 66 76 28 66  IGNORE INTO fv(f
2420: 6e 2c 66 6e 74 2c 69 64 76 2c 69 64 74 2c 72 69  n,fnt,idv,idt,ri
2430: 64 76 2c 72 69 64 74 2c 69 73 65 78 65 2c 63 68  dv,ridt,isexe,ch
2440: 6e 67 65 64 29 22 0a 20 20 20 20 22 20 53 45 4c  nged)".    " SEL
2450: 45 43 54 20 70 61 74 68 6e 61 6d 65 2c 20 70 61  ECT pathname, pa
2460: 74 68 6e 61 6d 65 2c 20 30 2c 20 30 2c 20 30 2c  thname, 0, 0, 0,
2470: 20 30 2c 20 69 73 65 78 65 2c 20 30 20 46 52 4f   0, isexe, 0 FRO
2480: 4d 20 76 66 69 6c 65 22 0a 20 20 20 20 22 20 20  M vfile".    "  
2490: 57 48 45 52 45 20 76 69 64 3d 25 64 22 0a 20 20  WHERE vid=%d".  
24a0: 20 20 22 20 20 20 20 41 4e 44 20 70 61 74 68 6e    "    AND pathn
24b0: 61 6d 65 20 4e 4f 54 20 49 4e 20 28 53 45 4c 45  ame NOT IN (SELE
24c0: 43 54 20 66 6e 74 20 46 52 4f 4d 20 66 76 29 22  CT fnt FROM fv)"
24d0: 2c 0a 20 20 20 20 74 69 64 0a 20 20 29 3b 0a 0a  ,.    tid.  );..
24e0: 20 20 2f 2a 0a 20 20 2a 2a 20 43 6f 6d 70 75 74    /*.  ** Comput
24f0: 65 20 74 68 65 20 66 69 6c 65 20 76 65 72 73 69  e the file versi
2500: 6f 6e 20 69 64 73 20 66 6f 72 20 54 0a 20 20 2a  on ids for T.  *
2510: 2f 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65  /.  db_multi_exe
2520: 63 28 0a 20 20 20 20 22 55 50 44 41 54 45 20 66  c(.    "UPDATE f
2530: 76 20 53 45 54 22 0a 20 20 20 20 22 20 69 64 74  v SET".    " idt
2540: 3d 63 6f 61 6c 65 73 63 65 28 28 53 45 4c 45 43  =coalesce((SELEC
2550: 54 20 69 64 20 46 52 4f 4d 20 76 66 69 6c 65 20  T id FROM vfile 
2560: 57 48 45 52 45 20 76 69 64 3d 25 64 20 41 4e 44  WHERE vid=%d AND
2570: 20 70 61 74 68 6e 61 6d 65 3d 66 6e 74 29 2c 30   pathname=fnt),0
2580: 29 2c 22 0a 20 20 20 20 22 20 72 69 64 74 3d 63  ),".    " ridt=c
2590: 6f 61 6c 65 73 63 65 28 28 53 45 4c 45 43 54 20  oalesce((SELECT 
25a0: 72 69 64 20 46 52 4f 4d 20 76 66 69 6c 65 20 57  rid FROM vfile W
25b0: 48 45 52 45 20 76 69 64 3d 25 64 20 41 4e 44 20  HERE vid=%d AND 
25c0: 70 61 74 68 6e 61 6d 65 3d 66 6e 74 29 2c 30 29  pathname=fnt),0)
25d0: 22 2c 0a 20 20 20 20 74 69 64 2c 20 74 69 64 0a  ",.    tid, tid.
25e0: 20 20 29 3b 0a 0a 20 20 2f 2a 0a 20 20 2a 2a 20    );..  /*.  ** 
25f0: 41 64 64 20 69 73 6c 69 6e 6b 20 69 6e 66 6f 72  Add islink infor
2600: 6d 61 74 69 6f 6e 0a 20 20 2a 2f 0a 20 20 64 62  mation.  */.  db
2610: 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20  _multi_exec(.   
2620: 20 22 55 50 44 41 54 45 20 66 76 20 53 45 54 22   "UPDATE fv SET"
2630: 0a 20 20 20 20 22 20 69 73 6c 69 6e 6b 76 3d 63  .    " islinkv=c
2640: 6f 61 6c 65 73 63 65 28 28 53 45 4c 45 43 54 20  oalesce((SELECT 
2650: 69 73 6c 69 6e 6b 20 46 52 4f 4d 20 76 66 69 6c  islink FROM vfil
2660: 65 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  e".             
2670: 20 20 20 20 20 20 20 20 20 20 22 20 57 48 45 52            " WHER
2680: 45 20 76 69 64 3d 25 64 20 41 4e 44 20 70 61 74  E vid=%d AND pat
2690: 68 6e 61 6d 65 3d 66 6e 74 29 2c 30 29 2c 22 0a  hname=fnt),0),".
26a0: 20 20 20 20 22 20 69 73 6c 69 6e 6b 74 3d 63 6f      " islinkt=co
26b0: 61 6c 65 73 63 65 28 28 53 45 4c 45 43 54 20 69  alesce((SELECT i
26c0: 73 6c 69 6e 6b 20 46 52 4f 4d 20 76 66 69 6c 65  slink FROM vfile
26d0: 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ".              
26e0: 20 20 20 20 20 20 20 20 20 22 20 57 48 45 52 45           " WHERE
26f0: 20 76 69 64 3d 25 64 20 41 4e 44 20 70 61 74 68   vid=%d AND path
2700: 6e 61 6d 65 3d 66 6e 74 29 2c 30 29 22 2c 0a 20  name=fnt),0)",. 
2710: 20 20 20 76 69 64 2c 20 74 69 64 0a 20 20 29 3b     vid, tid.  );
2720: 0a 0a 0a 20 20 69 66 28 20 64 65 62 75 67 46 6c  ...  if( debugFl
2730: 61 67 20 29 7b 0a 20 20 20 20 64 62 5f 70 72 65  ag ){.    db_pre
2740: 70 61 72 65 28 26 71 2c 0a 20 20 20 20 20 20 20  pare(&q,.       
2750: 22 53 45 4c 45 43 54 20 72 6f 77 69 64 2c 20 66  "SELECT rowid, f
2760: 6e 2c 20 66 6e 74 2c 20 63 68 6e 67 65 64 2c 20  n, fnt, chnged, 
2770: 72 69 64 76 2c 20 72 69 64 74 2c 20 69 73 65 78  ridv, ridt, isex
2780: 65 2c 22 0a 20 20 20 20 20 20 20 22 20 20 20 20  e,".       "    
2790: 20 20 20 69 73 6c 69 6e 6b 76 2c 20 69 73 6c 69     islinkv, isli
27a0: 6e 6b 74 20 46 52 4f 4d 20 66 76 22 0a 20 20 20  nkt FROM fv".   
27b0: 20 29 3b 0a 20 20 20 20 77 68 69 6c 65 28 20 64   );.    while( d
27c0: 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49  b_step(&q)==SQLI
27d0: 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 20 20  TE_ROW ){.      
27e0: 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 25   fossil_print("%
27f0: 33 64 3a 20 72 69 64 76 3d 25 2d 34 64 20 72 69  3d: ridv=%-4d ri
2800: 64 74 3d 25 2d 34 64 20 63 68 6e 67 65 64 3d 25  dt=%-4d chnged=%
2810: 64 20 69 73 65 78 65 3d 25 64 22 0a 20 20 20 20  d isexe=%d".    
2820: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2830: 22 20 69 73 6c 69 6e 6b 76 3d 25 64 20 20 69 73  " islinkv=%d  is
2840: 6c 69 6e 6b 74 3d 25 64 5c 6e 22 2c 0a 20 20 20  linkt=%d\n",.   
2850: 20 20 20 20 20 20 20 64 62 5f 63 6f 6c 75 6d 6e         db_column
2860: 5f 69 6e 74 28 26 71 2c 20 30 29 2c 0a 20 20 20  _int(&q, 0),.   
2870: 20 20 20 20 20 20 20 64 62 5f 63 6f 6c 75 6d 6e         db_column
2880: 5f 69 6e 74 28 26 71 2c 20 34 29 2c 0a 20 20 20  _int(&q, 4),.   
2890: 20 20 20 20 20 20 20 64 62 5f 63 6f 6c 75 6d 6e         db_column
28a0: 5f 69 6e 74 28 26 71 2c 20 35 29 2c 0a 20 20 20  _int(&q, 5),.   
28b0: 20 20 20 20 20 20 20 64 62 5f 63 6f 6c 75 6d 6e         db_column
28c0: 5f 69 6e 74 28 26 71 2c 20 33 29 2c 0a 20 20 20  _int(&q, 3),.   
28d0: 20 20 20 20 20 20 20 64 62 5f 63 6f 6c 75 6d 6e         db_column
28e0: 5f 69 6e 74 28 26 71 2c 20 36 29 2c 0a 20 20 20  _int(&q, 6),.   
28f0: 20 20 20 20 20 20 20 64 62 5f 63 6f 6c 75 6d 6e         db_column
2900: 5f 69 6e 74 28 26 71 2c 20 37 29 2c 0a 20 20 20  _int(&q, 7),.   
2910: 20 20 20 20 20 20 20 64 62 5f 63 6f 6c 75 6d 6e         db_column
2920: 5f 69 6e 74 28 26 71 2c 20 38 29 29 3b 0a 20 20  _int(&q, 8));.  
2930: 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e       fossil_prin
2940: 74 28 22 20 20 20 20 20 66 6e 76 20 3d 20 5b 25  t("     fnv = [%
2950: 73 5d 5c 6e 22 2c 20 64 62 5f 63 6f 6c 75 6d 6e  s]\n", db_column
2960: 5f 74 65 78 74 28 26 71 2c 20 31 29 29 3b 0a 20  _text(&q, 1));. 
2970: 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69        fossil_pri
2980: 6e 74 28 22 20 20 20 20 20 66 6e 74 20 3d 20 5b  nt("     fnt = [
2990: 25 73 5d 5c 6e 22 2c 20 64 62 5f 63 6f 6c 75 6d  %s]\n", db_colum
29a0: 6e 5f 74 65 78 74 28 26 71 2c 20 32 29 29 3b 0a  n_text(&q, 2));.
29b0: 20 20 20 20 7d 0a 20 20 20 20 64 62 5f 66 69 6e      }.    db_fin
29c0: 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 7d 0a 0a  alize(&q);.  }..
29d0: 20 20 2f 2a 20 49 66 20 46 49 4c 45 53 20 61 70    /* If FILES ap
29e0: 70 65 61 72 20 6f 6e 20 74 68 65 20 63 6f 6d 6d  pear on the comm
29f0: 61 6e 64 2d 6c 69 6e 65 2c 20 72 65 6d 6f 76 65  and-line, remove
2a00: 20 66 72 6f 6d 20 74 68 65 20 22 66 76 22 20 74   from the "fv" t
2a10: 61 62 6c 65 0a 20 20 2a 2a 20 65 76 65 72 79 20  able.  ** every 
2a20: 65 6e 74 72 79 20 74 68 61 74 20 69 73 20 6e 6f  entry that is no
2a30: 74 20 6e 61 6d 65 64 20 6f 6e 20 74 68 65 20 63  t named on the c
2a40: 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f 72 20 77  ommand-line or w
2a50: 68 69 63 68 20 69 73 20 6e 6f 74 0a 20 20 2a 2a  hich is not.  **
2a60: 20 69 6e 20 61 20 64 69 72 65 63 74 6f 72 79 20   in a directory 
2a70: 6e 61 6d 65 64 20 6f 6e 20 74 68 65 20 63 6f 6d  named on the com
2a80: 6d 61 6e 64 2d 6c 69 6e 65 2e 0a 20 20 2a 2f 0a  mand-line..  */.
2a90: 20 20 69 66 28 20 67 2e 61 72 67 63 3e 3d 34 20    if( g.argc>=4 
2aa0: 29 7b 0a 20 20 20 20 42 6c 6f 62 20 73 71 6c 3b  ){.    Blob sql;
2ab0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a                /*
2ac0: 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 20 74   SQL statement t
2ad0: 6f 20 70 75 72 67 65 20 75 6e 77 61 6e 74 65 64  o purge unwanted
2ae0: 20 65 6e 74 72 69 65 73 20 2a 2f 0a 20 20 20 20   entries */.    
2af0: 42 6c 6f 62 20 74 72 65 65 6e 61 6d 65 3b 20 20  Blob treename;  
2b00: 20 20 20 20 20 20 20 2f 2a 20 4e 6f 72 6d 61 6c         /* Normal
2b10: 69 7a 65 64 20 66 69 6c 65 6e 61 6d 65 20 2a 2f  ized filename */
2b20: 0a 20 20 20 20 69 6e 74 20 69 3b 20 20 20 20 20  .    int i;     
2b30: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c              /* L
2b40: 6f 6f 70 20 63 6f 75 6e 74 65 72 20 2a 2f 0a 20  oop counter */. 
2b50: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a     const char *z
2b60: 53 65 70 3b 20 20 20 20 20 20 2f 2a 20 54 65 72  Sep;      /* Ter
2b70: 6d 20 73 65 70 61 72 61 74 6f 72 20 2a 2f 0a 0a  m separator */..
2b80: 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 73      blob_zero(&s
2b90: 71 6c 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70  ql);.    blob_ap
2ba0: 70 65 6e 64 28 26 73 71 6c 2c 20 22 44 45 4c 45  pend(&sql, "DELE
2bb0: 54 45 20 46 52 4f 4d 20 66 76 20 57 48 45 52 45  TE FROM fv WHERE
2bc0: 20 22 2c 20 2d 31 29 3b 0a 20 20 20 20 7a 53 65   ", -1);.    zSe
2bd0: 70 20 3d 20 22 22 3b 0a 20 20 20 20 66 6f 72 28  p = "";.    for(
2be0: 69 3d 33 3b 20 69 3c 67 2e 61 72 67 63 3b 20 69  i=3; i<g.argc; i
2bf0: 2b 2b 29 7b 0a 20 20 20 20 20 20 66 69 6c 65 5f  ++){.      file_
2c00: 74 72 65 65 5f 6e 61 6d 65 28 67 2e 61 72 67 76  tree_name(g.argv
2c10: 5b 69 5d 2c 20 26 74 72 65 65 6e 61 6d 65 2c 20  [i], &treename, 
2c20: 31 29 3b 0a 20 20 20 20 20 20 69 66 28 20 66 69  1);.      if( fi
2c30: 6c 65 5f 77 64 5f 69 73 64 69 72 28 67 2e 61 72  le_wd_isdir(g.ar
2c40: 67 76 5b 69 5d 29 3d 3d 31 20 29 7b 0a 20 20 20  gv[i])==1 ){.   
2c50: 20 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 73 69       if( blob_si
2c60: 7a 65 28 26 74 72 65 65 6e 61 6d 65 29 20 21 3d  ze(&treename) !=
2c70: 20 31 20 7c 7c 20 62 6c 6f 62 5f 73 74 72 28 26   1 || blob_str(&
2c80: 74 72 65 65 6e 61 6d 65 29 5b 30 5d 20 21 3d 20  treename)[0] != 
2c90: 27 2e 27 20 29 7b 0a 20 20 20 20 20 20 20 20 20  '.' ){.         
2ca0: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 73   blob_appendf(&s
2cb0: 71 6c 2c 20 22 25 73 66 6e 20 4e 4f 54 20 47 4c  ql, "%sfn NOT GL
2cc0: 4f 42 20 27 25 62 2f 2a 27 20 22 2c 20 7a 53 65  OB '%b/*' ", zSe
2cd0: 70 2c 20 26 74 72 65 65 6e 61 6d 65 29 3b 0a 20  p, &treename);. 
2ce0: 20 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20         }else{.  
2cf0: 20 20 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73          blob_res
2d00: 65 74 28 26 73 71 6c 29 3b 0a 20 20 20 20 20 20  et(&sql);.      
2d10: 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20      break;.     
2d20: 20 20 20 7d 0a 20 20 20 20 20 20 7d 65 6c 73 65     }.      }else
2d30: 7b 0a 20 20 20 20 20 20 20 20 62 6c 6f 62 5f 61  {.        blob_a
2d40: 70 70 65 6e 64 66 28 26 73 71 6c 2c 20 22 25 73  ppendf(&sql, "%s
2d50: 66 6e 3c 3e 25 42 20 22 2c 20 7a 53 65 70 2c 20  fn<>%B ", zSep, 
2d60: 26 74 72 65 65 6e 61 6d 65 29 3b 0a 20 20 20 20  &treename);.    
2d70: 20 20 7d 0a 20 20 20 20 20 20 7a 53 65 70 20 3d    }.      zSep =
2d80: 20 22 41 4e 44 20 22 3b 0a 20 20 20 20 20 20 62   "AND ";.      b
2d90: 6c 6f 62 5f 72 65 73 65 74 28 26 74 72 65 65 6e  lob_reset(&treen
2da0: 61 6d 65 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20  ame);.    }.    
2db0: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 62 6c  db_multi_exec(bl
2dc0: 6f 62 5f 73 74 72 28 26 73 71 6c 29 29 3b 0a 20  ob_str(&sql));. 
2dd0: 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 73     blob_reset(&s
2de0: 71 6c 29 3b 0a 20 20 7d 0a 0a 20 20 2f 2a 0a 20  ql);.  }..  /*. 
2df0: 20 2a 2a 20 41 6c 74 65 72 20 74 68 65 20 63 6f   ** Alter the co
2e00: 6e 74 65 6e 74 20 6f 66 20 74 68 65 20 63 68 65  ntent of the che
2e10: 63 6b 6f 75 74 20 73 6f 20 74 68 61 74 20 69 74  ckout so that it
2e20: 20 63 6f 6e 66 6f 72 6d 73 20 77 69 74 68 20 74   conforms with t
2e30: 68 65 0a 20 20 2a 2a 20 74 61 72 67 65 74 0a 20  he.  ** target. 
2e40: 20 2a 2f 0a 20 20 64 62 5f 70 72 65 70 61 72 65   */.  db_prepare
2e50: 28 26 71 2c 20 0a 20 20 20 20 22 53 45 4c 45 43  (&q, .    "SELEC
2e60: 54 20 66 6e 2c 20 69 64 76 2c 20 72 69 64 76 2c  T fn, idv, ridv,
2e70: 20 69 64 74 2c 20 72 69 64 74 2c 20 63 68 6e 67   idt, ridt, chng
2e80: 65 64 2c 20 66 6e 74 2c 22 0a 20 20 20 20 22 20  ed, fnt,".    " 
2e90: 20 20 20 20 20 20 69 73 65 78 65 2c 20 69 73 6c        isexe, isl
2ea0: 69 6e 6b 76 2c 20 69 73 6c 69 6e 6b 74 2c 20 64  inkv, islinkt, d
2eb0: 65 6c 65 74 65 64 20 46 52 4f 4d 20 66 76 20 4f  eleted FROM fv O
2ec0: 52 44 45 52 20 42 59 20 31 22 0a 20 20 29 3b 0a  RDER BY 1".  );.
2ed0: 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 6d 74    db_prepare(&mt
2ee0: 69 6d 65 58 66 65 72 2c 0a 20 20 20 20 22 55 50  imeXfer,.    "UP
2ef0: 44 41 54 45 20 76 66 69 6c 65 20 53 45 54 20 6d  DATE vfile SET m
2f00: 74 69 6d 65 3d 28 53 45 4c 45 43 54 20 6d 74 69  time=(SELECT mti
2f10: 6d 65 20 46 52 4f 4d 20 76 66 69 6c 65 20 57 48  me FROM vfile WH
2f20: 45 52 45 20 69 64 3d 3a 69 64 76 29 22 0a 20 20  ERE id=:idv)".  
2f30: 20 20 22 20 57 48 45 52 45 20 69 64 3d 3a 69 64    " WHERE id=:id
2f40: 74 22 0a 20 20 29 3b 0a 20 20 61 73 73 65 72 74  t".  );.  assert
2f50: 28 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 21 3d  ( g.zLocalRoot!=
2f60: 30 20 29 3b 0a 20 20 61 73 73 65 72 74 28 20 73  0 );.  assert( s
2f70: 74 72 6c 65 6e 28 67 2e 7a 4c 6f 63 61 6c 52 6f  trlen(g.zLocalRo
2f80: 6f 74 29 3e 31 20 29 3b 0a 20 20 61 73 73 65 72  ot)>1 );.  asser
2f90: 74 28 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 5b  t( g.zLocalRoot[
2fa0: 73 74 72 6c 65 6e 28 67 2e 7a 4c 6f 63 61 6c 52  strlen(g.zLocalR
2fb0: 6f 6f 74 29 2d 31 5d 3d 3d 27 2f 27 20 29 3b 0a  oot)-1]=='/' );.
2fc0: 20 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70    while( db_step
2fd0: 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57  (&q)==SQLITE_ROW
2fe0: 20 29 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68   ){.    const ch
2ff0: 61 72 20 2a 7a 4e 61 6d 65 20 3d 20 64 62 5f 63  ar *zName = db_c
3000: 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30  olumn_text(&q, 0
3010: 29 3b 20 20 2f 2a 20 54 68 65 20 66 69 6c 65 6e  );  /* The filen
3020: 61 6d 65 20 66 72 6f 6d 20 72 6f 6f 74 20 2a 2f  ame from root */
3030: 0a 20 20 20 20 69 6e 74 20 69 64 76 20 3d 20 64  .    int idv = d
3040: 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c  b_column_int(&q,
3050: 20 31 29 3b 20 20 20 20 20 20 20 20 20 20 20 20   1);            
3060: 20 2f 2a 20 56 46 49 4c 45 20 65 6e 74 72 79 20   /* VFILE entry 
3070: 66 6f 72 20 63 75 72 72 65 6e 74 20 2a 2f 0a 20  for current */. 
3080: 20 20 20 69 6e 74 20 72 69 64 76 20 3d 20 64 62     int ridv = db
3090: 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20  _column_int(&q, 
30a0: 32 29 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f  2);            /
30b0: 2a 20 52 65 63 6f 72 64 49 44 20 66 6f 72 20 63  * RecordID for c
30c0: 75 72 72 65 6e 74 20 2a 2f 0a 20 20 20 20 69 6e  urrent */.    in
30d0: 74 20 69 64 74 20 3d 20 64 62 5f 63 6f 6c 75 6d  t idt = db_colum
30e0: 6e 5f 69 6e 74 28 26 71 2c 20 33 29 3b 20 20 20  n_int(&q, 3);   
30f0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 46 49            /* VFI
3100: 4c 45 20 65 6e 74 72 79 20 66 6f 72 20 74 61 72  LE entry for tar
3110: 67 65 74 20 2a 2f 0a 20 20 20 20 69 6e 74 20 72  get */.    int r
3120: 69 64 74 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f  idt = db_column_
3130: 69 6e 74 28 26 71 2c 20 34 29 3b 20 20 20 20 20  int(&q, 4);     
3140: 20 20 20 20 20 20 20 2f 2a 20 52 65 63 6f 72 64         /* Record
3150: 49 44 20 66 6f 72 20 74 61 72 67 65 74 20 2a 2f  ID for target */
3160: 0a 20 20 20 20 69 6e 74 20 63 68 6e 67 65 64 20  .    int chnged 
3170: 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28  = db_column_int(
3180: 26 71 2c 20 35 29 3b 20 20 20 20 20 20 20 20 20  &q, 5);         
3190: 20 2f 2a 20 43 75 72 72 65 6e 74 20 69 73 20 65   /* Current is e
31a0: 64 69 74 65 64 20 2a 2f 0a 20 20 20 20 63 6f 6e  dited */.    con
31b0: 73 74 20 63 68 61 72 20 2a 7a 4e 65 77 4e 61 6d  st char *zNewNam
31c0: 65 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65  e = db_column_te
31d0: 78 74 28 26 71 2c 36 29 3b 2f 2a 20 4e 65 77 20  xt(&q,6);/* New 
31e0: 66 69 6c 65 6e 61 6d 65 20 2a 2f 0a 20 20 20 20  filename */.    
31f0: 69 6e 74 20 69 73 65 78 65 20 3d 20 64 62 5f 63  int isexe = db_c
3200: 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 37 29  olumn_int(&q, 7)
3210: 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 45  ;           /* E
3220: 58 45 20 70 65 72 6d 20 66 6f 72 20 6e 65 77 20  XE perm for new 
3230: 66 69 6c 65 20 2a 2f 0a 20 20 20 20 69 6e 74 20  file */.    int 
3240: 69 73 6c 69 6e 6b 76 20 3d 20 64 62 5f 63 6f 6c  islinkv = db_col
3250: 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 38 29 3b 20  umn_int(&q, 8); 
3260: 20 20 20 20 20 20 20 20 2f 2a 20 49 73 20 63 75          /* Is cu
3270: 72 72 65 6e 74 20 66 69 6c 65 20 69 73 20 61 20  rrent file is a 
3280: 6c 69 6e 6b 20 2a 2f 0a 20 20 20 20 69 6e 74 20  link */.    int 
3290: 69 73 6c 69 6e 6b 74 20 3d 20 64 62 5f 63 6f 6c  islinkt = db_col
32a0: 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 39 29 3b 20  umn_int(&q, 9); 
32b0: 20 20 20 20 20 20 20 20 2f 2a 20 49 73 20 74 61          /* Is ta
32c0: 72 67 65 74 20 66 69 6c 65 20 69 73 20 61 20 6c  rget file is a l
32d0: 69 6e 6b 20 2a 2f 0a 20 20 20 20 69 6e 74 20 64  ink */.    int d
32e0: 65 6c 65 74 65 64 20 3d 20 64 62 5f 63 6f 6c 75  eleted = db_colu
32f0: 6d 6e 5f 69 6e 74 28 26 71 2c 20 31 30 29 3b 20  mn_int(&q, 10); 
3300: 20 20 20 20 20 20 20 2f 2a 20 4d 61 72 6b 65 64         /* Marked
3310: 20 66 6f 72 20 64 65 6c 65 74 69 6f 6e 20 2a 2f   for deletion */
3320: 0a 20 20 20 20 63 68 61 72 20 2a 7a 46 75 6c 6c  .    char *zFull
3330: 50 61 74 68 3b 20 20 20 20 20 20 20 20 20 20 20  Path;           
3340: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3350: 20 2f 2a 20 46 75 6c 6c 20 70 61 74 68 6e 61 6d   /* Full pathnam
3360: 65 20 6f 66 20 74 68 65 20 66 69 6c 65 20 2a 2f  e of the file */
3370: 0a 20 20 20 20 63 68 61 72 20 2a 7a 46 75 6c 6c  .    char *zFull
3380: 4e 65 77 50 61 74 68 3b 20 20 20 20 20 20 20 20  NewPath;        
3390: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
33a0: 20 2f 2a 20 46 75 6c 6c 20 70 61 74 68 6e 61 6d   /* Full pathnam
33b0: 65 20 6f 66 20 64 65 73 74 20 2a 2f 0a 20 20 20  e of dest */.   
33c0: 20 63 68 61 72 20 6e 61 6d 65 43 68 6e 67 3b 20   char nameChng; 
33d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
33e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20               /* 
33f0: 54 72 75 65 20 69 66 20 74 68 65 20 6e 61 6d 65  True if the name
3400: 20 63 68 61 6e 67 65 64 20 2a 2f 0a 0a 20 20 20   changed */..   
3410: 20 7a 46 75 6c 6c 50 61 74 68 20 3d 20 6d 70 72   zFullPath = mpr
3420: 69 6e 74 66 28 22 25 73 25 73 22 2c 20 67 2e 7a  intf("%s%s", g.z
3430: 4c 6f 63 61 6c 52 6f 6f 74 2c 20 7a 4e 61 6d 65  LocalRoot, zName
3440: 29 3b 0a 20 20 20 20 7a 46 75 6c 6c 4e 65 77 50  );.    zFullNewP
3450: 61 74 68 20 3d 20 6d 70 72 69 6e 74 66 28 22 25  ath = mprintf("%
3460: 73 25 73 22 2c 20 67 2e 7a 4c 6f 63 61 6c 52 6f  s%s", g.zLocalRo
3470: 6f 74 2c 20 7a 4e 65 77 4e 61 6d 65 29 3b 0a 20  ot, zNewName);. 
3480: 20 20 20 6e 61 6d 65 43 68 6e 67 20 3d 20 66 6f     nameChng = fo
3490: 73 73 69 6c 5f 73 74 72 63 6d 70 28 7a 4e 61 6d  ssil_strcmp(zNam
34a0: 65 2c 20 7a 4e 65 77 4e 61 6d 65 29 3b 0a 20 20  e, zNewName);.  
34b0: 20 20 6e 55 70 64 61 74 65 2b 2b 3b 0a 20 20 20    nUpdate++;.   
34c0: 20 69 66 28 20 64 65 6c 65 74 65 64 20 29 7b 0a   if( deleted ){.
34d0: 20 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65        db_multi_e
34e0: 78 65 63 28 22 55 50 44 41 54 45 20 76 66 69 6c  xec("UPDATE vfil
34f0: 65 20 53 45 54 20 64 65 6c 65 74 65 64 3d 31 20  e SET deleted=1 
3500: 57 48 45 52 45 20 69 64 3d 25 64 22 2c 20 69 64  WHERE id=%d", id
3510: 74 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66  t);.    }.    if
3520: 28 20 69 64 76 3e 30 20 26 26 20 72 69 64 76 3d  ( idv>0 && ridv=
3530: 3d 30 20 26 26 20 69 64 74 3e 30 20 26 26 20 72  =0 && idt>0 && r
3540: 69 64 74 3e 30 20 29 7b 0a 20 20 20 20 20 20 2f  idt>0 ){.      /
3550: 2a 20 43 6f 6e 66 6c 69 63 74 2e 20 20 54 68 69  * Conflict.  Thi
3560: 73 20 66 69 6c 65 20 68 61 73 20 62 65 65 6e 20  s file has been 
3570: 61 64 64 65 64 20 74 6f 20 74 68 65 20 63 75 72  added to the cur
3580: 72 65 6e 74 20 63 68 65 63 6b 6f 75 74 0a 20 20  rent checkout.  
3590: 20 20 20 20 2a 2a 20 62 75 74 20 61 6c 73 6f 20      ** but also 
35a0: 65 78 69 73 74 73 20 69 6e 20 74 68 65 20 74 61  exists in the ta
35b0: 72 67 65 74 20 63 68 65 63 6b 6f 75 74 2e 20 20  rget checkout.  
35c0: 55 73 65 20 74 68 65 20 63 75 72 72 65 6e 74 20  Use the current 
35d0: 76 65 72 73 69 6f 6e 2e 0a 20 20 20 20 20 20 2a  version..      *
35e0: 2f 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 70  /.      fossil_p
35f0: 72 69 6e 74 28 22 43 4f 4e 46 4c 49 43 54 20 25  rint("CONFLICT %
3600: 73 5c 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20  s\n", zName);.  
3610: 20 20 20 20 6e 43 6f 6e 66 6c 69 63 74 2b 2b 3b      nConflict++;
3620: 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 69  .    }else if( i
3630: 64 74 3e 30 20 26 26 20 69 64 76 3d 3d 30 20 29  dt>0 && idv==0 )
3640: 7b 0a 20 20 20 20 20 20 2f 2a 20 46 69 6c 65 20  {.      /* File 
3650: 61 64 64 65 64 20 69 6e 20 74 68 65 20 74 61 72  added in the tar
3660: 67 65 74 2e 20 2a 2f 0a 20 20 20 20 20 20 69 66  get. */.      if
3670: 28 20 66 69 6c 65 5f 77 64 5f 69 73 66 69 6c 65  ( file_wd_isfile
3680: 5f 6f 72 5f 6c 69 6e 6b 28 7a 46 75 6c 6c 50 61  _or_link(zFullPa
3690: 74 68 29 20 29 7b 0a 20 20 20 20 20 20 20 20 66  th) ){.        f
36a0: 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 41 44 44  ossil_print("ADD
36b0: 20 25 73 20 2d 20 6f 76 65 72 77 72 69 74 65 73   %s - overwrites
36c0: 20 61 6e 20 75 6e 6d 61 6e 61 67 65 64 20 66 69   an unmanaged fi
36d0: 6c 65 5c 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20  le\n", zName);. 
36e0: 20 20 20 20 20 20 20 6e 4f 76 65 72 77 72 69 74         nOverwrit
36f0: 65 2b 2b 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65  e++;.      }else
3700: 7b 0a 20 20 20 20 20 20 20 20 66 6f 73 73 69 6c  {.        fossil
3710: 5f 70 72 69 6e 74 28 22 41 44 44 20 25 73 5c 6e  _print("ADD %s\n
3720: 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20  ", zName);.     
3730: 20 7d 0a 20 20 20 20 20 20 75 6e 64 6f 5f 73 61   }.      undo_sa
3740: 76 65 28 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20  ve(zName);.     
3750: 20 69 66 28 20 21 6e 6f 63 68 61 6e 67 65 46 6c   if( !nochangeFl
3760: 61 67 20 29 20 76 66 69 6c 65 5f 74 6f 5f 64 69  ag ) vfile_to_di
3770: 73 6b 28 30 2c 20 69 64 74 2c 20 30 2c 20 30 29  sk(0, idt, 0, 0)
3780: 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20  ;.    }else if( 
3790: 69 64 74 3e 30 20 26 26 20 69 64 76 3e 30 20 26  idt>0 && idv>0 &
37a0: 26 20 72 69 64 74 21 3d 72 69 64 76 20 26 26 20  & ridt!=ridv && 
37b0: 28 63 68 6e 67 65 64 3d 3d 30 20 7c 7c 20 64 65  (chnged==0 || de
37c0: 6c 65 74 65 64 29 20 29 7b 0a 20 20 20 20 20 20  leted) ){.      
37d0: 2f 2a 20 54 68 65 20 66 69 6c 65 20 69 73 20 75  /* The file is u
37e0: 6e 65 64 69 74 65 64 2e 20 20 43 68 61 6e 67 65  nedited.  Change
37f0: 20 69 74 20 74 6f 20 74 68 65 20 74 61 72 67 65   it to the targe
3800: 74 20 76 65 72 73 69 6f 6e 20 2a 2f 0a 20 20 20  t version */.   
3810: 20 20 20 75 6e 64 6f 5f 73 61 76 65 28 7a 4e 61     undo_save(zNa
3820: 6d 65 29 3b 0a 20 20 20 20 20 20 69 66 28 20 64  me);.      if( d
3830: 65 6c 65 74 65 64 20 29 7b 0a 20 20 20 20 20 20  eleted ){.      
3840: 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22    fossil_print("
3850: 55 50 44 41 54 45 20 25 73 20 2d 20 63 68 61 6e  UPDATE %s - chan
3860: 67 65 20 74 6f 20 75 6e 6d 61 6e 67 65 64 20 66  ge to unmanged f
3870: 69 6c 65 5c 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a  ile\n", zName);.
3880: 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20        }else{.   
3890: 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e       fossil_prin
38a0: 74 28 22 55 50 44 41 54 45 20 25 73 5c 6e 22 2c  t("UPDATE %s\n",
38b0: 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 7d   zName);.      }
38c0: 0a 20 20 20 20 20 20 69 66 28 20 21 6e 6f 63 68  .      if( !noch
38d0: 61 6e 67 65 46 6c 61 67 20 29 20 76 66 69 6c 65  angeFlag ) vfile
38e0: 5f 74 6f 5f 64 69 73 6b 28 30 2c 20 69 64 74 2c  _to_disk(0, idt,
38f0: 20 30 2c 20 30 29 3b 0a 20 20 20 20 7d 65 6c 73   0, 0);.    }els
3900: 65 20 69 66 28 20 69 64 74 3e 30 20 26 26 20 69  e if( idt>0 && i
3910: 64 76 3e 30 20 26 26 20 66 69 6c 65 5f 77 64 5f  dv>0 && file_wd_
3920: 73 69 7a 65 28 7a 46 75 6c 6c 50 61 74 68 29 3c  size(zFullPath)<
3930: 30 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 54 68  0 ){.      /* Th
3940: 65 20 66 69 6c 65 20 6d 69 73 73 69 6e 67 20 66  e file missing f
3950: 72 6f 6d 20 74 68 65 20 6c 6f 63 61 6c 20 63 68  rom the local ch
3960: 65 63 6b 2d 6f 75 74 2e 20 52 65 73 74 6f 72 65  eck-out. Restore
3970: 20 69 74 20 74 6f 20 74 68 65 0a 20 20 20 20 20   it to the.     
3980: 20 2a 2a 20 76 65 72 73 69 6f 6e 20 74 68 61 74   ** version that
3990: 20 61 70 70 65 61 72 73 20 69 6e 20 74 68 65 20   appears in the 
39a0: 74 61 72 67 65 74 2e 20 2a 2f 0a 20 20 20 20 20  target. */.     
39b0: 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 55   fossil_print("U
39c0: 50 44 41 54 45 20 25 73 25 73 5c 6e 22 2c 20 7a  PDATE %s%s\n", z
39d0: 4e 61 6d 65 2c 0a 20 20 20 20 20 20 20 20 20 20  Name,.          
39e0: 20 20 20 20 20 20 20 20 20 20 64 65 6c 65 74 65            delete
39f0: 64 3f 22 20 2d 20 63 68 61 6e 67 65 20 74 6f 20  d?" - change to 
3a00: 75 6e 6d 61 6e 61 67 65 64 20 66 69 6c 65 22 3a  unmanaged file":
3a10: 22 22 29 3b 0a 20 20 20 20 20 20 75 6e 64 6f 5f  "");.      undo_
3a20: 73 61 76 65 28 7a 4e 61 6d 65 29 3b 0a 20 20 20  save(zName);.   
3a30: 20 20 20 69 66 28 20 21 6e 6f 63 68 61 6e 67 65     if( !nochange
3a40: 46 6c 61 67 20 29 20 76 66 69 6c 65 5f 74 6f 5f  Flag ) vfile_to_
3a50: 64 69 73 6b 28 30 2c 20 69 64 74 2c 20 30 2c 20  disk(0, idt, 0, 
3a60: 30 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69 66  0);.    }else if
3a70: 28 20 69 64 74 3d 3d 30 20 26 26 20 69 64 76 3e  ( idt==0 && idv>
3a80: 30 20 29 7b 0a 20 20 20 20 20 20 69 66 28 20 72  0 ){.      if( r
3a90: 69 64 76 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20  idv==0 ){.      
3aa0: 20 20 2f 2a 20 41 64 64 65 64 20 69 6e 20 63 75    /* Added in cu
3ab0: 72 72 65 6e 74 20 63 68 65 63 6b 6f 75 74 2e 20  rrent checkout. 
3ac0: 20 43 6f 6e 74 69 6e 75 65 20 74 6f 20 68 6f 6c   Continue to hol
3ad0: 64 20 74 68 65 20 66 69 6c 65 20 61 73 0a 20 20  d the file as.  
3ae0: 20 20 20 20 20 20 2a 2a 20 61 73 20 61 6e 20 61        ** as an a
3af0: 64 64 69 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 20  ddition */.     
3b00: 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63     db_multi_exec
3b10: 28 22 55 50 44 41 54 45 20 76 66 69 6c 65 20 53  ("UPDATE vfile S
3b20: 45 54 20 76 69 64 3d 25 64 20 57 48 45 52 45 20  ET vid=%d WHERE 
3b30: 69 64 3d 25 64 22 2c 20 74 69 64 2c 20 69 64 76  id=%d", tid, idv
3b40: 29 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 20 69  );.      }else i
3b50: 66 28 20 63 68 6e 67 65 64 20 29 7b 0a 20 20 20  f( chnged ){.   
3b60: 20 20 20 20 20 2f 2a 20 45 64 69 74 65 64 20 6c       /* Edited l
3b70: 6f 63 61 6c 6c 79 20 62 75 74 20 64 65 6c 65 74  ocally but delet
3b80: 65 64 20 66 72 6f 6d 20 74 68 65 20 74 61 72 67  ed from the targ
3b90: 65 74 2e 20 20 44 6f 20 6e 6f 74 20 74 72 61 63  et.  Do not trac
3ba0: 6b 20 74 68 65 0a 20 20 20 20 20 20 20 20 2a 2a  k the.        **
3bb0: 20 66 69 6c 65 20 62 75 74 20 6b 65 65 70 20 74   file but keep t
3bc0: 68 65 20 65 64 69 74 65 64 20 76 65 72 73 69 6f  he edited versio
3bd0: 6e 20 61 72 6f 75 6e 64 2e 20 2a 2f 0a 20 20 20  n around. */.   
3be0: 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e       fossil_prin
3bf0: 74 28 22 43 4f 4e 46 4c 49 43 54 20 25 73 20 2d  t("CONFLICT %s -
3c00: 20 65 64 69 74 65 64 20 6c 6f 63 61 6c 6c 79 20   edited locally 
3c10: 62 75 74 20 64 65 6c 65 74 65 64 20 62 79 20 75  but deleted by u
3c20: 70 64 61 74 65 5c 6e 22 2c 0a 20 20 20 20 20 20  pdate\n",.      
3c30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7a                 z
3c40: 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 20 20 6e  Name);.        n
3c50: 43 6f 6e 66 6c 69 63 74 2b 2b 3b 0a 20 20 20 20  Conflict++;.    
3c60: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20    }else{.       
3c70: 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 52   fossil_print("R
3c80: 45 4d 4f 56 45 20 25 73 5c 6e 22 2c 20 7a 4e 61  EMOVE %s\n", zNa
3c90: 6d 65 29 3b 0a 20 20 20 20 20 20 20 20 75 6e 64  me);.        und
3ca0: 6f 5f 73 61 76 65 28 7a 4e 61 6d 65 29 3b 0a 20  o_save(zName);. 
3cb0: 20 20 20 20 20 20 20 69 66 28 20 21 6e 6f 63 68         if( !noch
3cc0: 61 6e 67 65 46 6c 61 67 20 29 20 66 69 6c 65 5f  angeFlag ) file_
3cd0: 64 65 6c 65 74 65 28 7a 46 75 6c 6c 50 61 74 68  delete(zFullPath
3ce0: 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d  );.      }.    }
3cf0: 65 6c 73 65 20 69 66 28 20 69 64 74 3e 30 20 26  else if( idt>0 &
3d00: 26 20 69 64 76 3e 30 20 26 26 20 72 69 64 74 21  & idv>0 && ridt!
3d10: 3d 72 69 64 76 20 26 26 20 63 68 6e 67 65 64 20  =ridv && chnged 
3d20: 29 7b 0a 20 20 20 20 20 20 2f 2a 20 4d 65 72 67  ){.      /* Merg
3d30: 65 20 74 68 65 20 63 68 61 6e 67 65 73 20 69 6e  e the changes in
3d40: 20 74 68 65 20 63 75 72 72 65 6e 74 20 74 72 65   the current tre
3d50: 65 20 69 6e 74 6f 20 74 68 65 20 74 61 72 67 65  e into the targe
3d60: 74 20 76 65 72 73 69 6f 6e 20 2a 2f 0a 20 20 20  t version */.   
3d70: 20 20 20 42 6c 6f 62 20 72 2c 20 74 2c 20 76 3b     Blob r, t, v;
3d80: 0a 20 20 20 20 20 20 69 6e 74 20 72 63 3b 0a 20  .      int rc;. 
3d90: 20 20 20 20 20 69 66 28 20 6e 61 6d 65 43 68 6e       if( nameChn
3da0: 67 20 29 7b 0a 20 20 20 20 20 20 20 20 66 6f 73  g ){.        fos
3db0: 73 69 6c 5f 70 72 69 6e 74 28 22 4d 45 52 47 45  sil_print("MERGE
3dc0: 20 25 73 20 2d 3e 20 25 73 5c 6e 22 2c 20 7a 4e   %s -> %s\n", zN
3dd0: 61 6d 65 2c 20 7a 4e 65 77 4e 61 6d 65 29 3b 0a  ame, zNewName);.
3de0: 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20        }else{.   
3df0: 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e       fossil_prin
3e00: 74 28 22 4d 45 52 47 45 20 25 73 5c 6e 22 2c 20  t("MERGE %s\n", 
3e10: 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 7d 0a  zName);.      }.
3e20: 20 20 20 20 20 20 69 66 28 20 69 73 6c 69 6e 6b        if( islink
3e30: 76 20 7c 7c 20 69 73 6c 69 6e 6b 74 20 2f 2a 20  v || islinkt /* 
3e40: 7c 7c 20 66 69 6c 65 5f 77 64 5f 69 73 6c 69 6e  || file_wd_islin
3e50: 6b 28 7a 46 75 6c 6c 50 61 74 68 29 20 2a 2f 20  k(zFullPath) */ 
3e60: 29 7b 0a 20 20 20 20 20 20 20 20 66 6f 73 73 69  ){.        fossi
3e70: 6c 5f 70 72 69 6e 74 28 22 2a 2a 2a 2a 2a 20 43  l_print("***** C
3e80: 61 6e 6e 6f 74 20 6d 65 72 67 65 20 73 79 6d 6c  annot merge syml
3e90: 69 6e 6b 20 25 73 5c 6e 22 2c 20 7a 4e 65 77 4e  ink %s\n", zNewN
3ea0: 61 6d 65 29 3b 0a 20 20 20 20 20 20 20 20 6e 43  ame);.        nC
3eb0: 6f 6e 66 6c 69 63 74 2b 2b 3b 20 20 20 20 20 20  onflict++;      
3ec0: 20 20 0a 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a    .      }else{.
3ed0: 20 20 20 20 20 20 20 20 75 6e 73 69 67 6e 65 64          unsigned
3ee0: 20 6d 65 72 67 65 46 6c 61 67 73 20 3d 20 6e 6f   mergeFlags = no
3ef0: 63 68 61 6e 67 65 46 6c 61 67 20 3f 20 4d 45 52  changeFlag ? MER
3f00: 47 45 5f 44 52 59 52 55 4e 20 3a 20 30 3b 0a 20  GE_DRYRUN : 0;. 
3f10: 20 20 20 20 20 20 20 75 6e 64 6f 5f 73 61 76 65         undo_save
3f20: 28 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 20  (zName);.       
3f30: 20 63 6f 6e 74 65 6e 74 5f 67 65 74 28 72 69 64   content_get(rid
3f40: 74 2c 20 26 74 29 3b 0a 20 20 20 20 20 20 20 20  t, &t);.        
3f50: 63 6f 6e 74 65 6e 74 5f 67 65 74 28 72 69 64 76  content_get(ridv
3f60: 2c 20 26 76 29 3b 0a 20 20 20 20 20 20 20 20 72  , &v);.        r
3f70: 63 20 3d 20 6d 65 72 67 65 5f 33 77 61 79 28 26  c = merge_3way(&
3f80: 76 2c 20 7a 46 75 6c 6c 50 61 74 68 2c 20 26 74  v, zFullPath, &t
3f90: 2c 20 26 72 2c 20 6d 65 72 67 65 46 6c 61 67 73  , &r, mergeFlags
3fa0: 29 3b 0a 20 20 20 20 20 20 20 20 69 66 28 20 72  );.        if( r
3fb0: 63 3e 3d 30 20 29 7b 0a 20 20 20 20 20 20 20 20  c>=0 ){.        
3fc0: 20 20 69 66 28 20 21 6e 6f 63 68 61 6e 67 65 46    if( !nochangeF
3fd0: 6c 61 67 20 29 7b 0a 20 20 20 20 20 20 20 20 20  lag ){.         
3fe0: 20 20 20 62 6c 6f 62 5f 77 72 69 74 65 5f 74 6f     blob_write_to
3ff0: 5f 66 69 6c 65 28 26 72 2c 20 7a 46 75 6c 6c 4e  _file(&r, zFullN
4000: 65 77 50 61 74 68 29 3b 0a 20 20 20 20 20 20 20  ewPath);.       
4010: 20 20 20 20 20 66 69 6c 65 5f 77 64 5f 73 65 74       file_wd_set
4020: 65 78 65 28 7a 46 75 6c 6c 4e 65 77 50 61 74 68  exe(zFullNewPath
4030: 2c 20 69 73 65 78 65 29 3b 0a 20 20 20 20 20 20  , isexe);.      
4040: 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 20 20      }.          
4050: 69 66 28 20 72 63 3e 30 20 29 7b 0a 20 20 20 20  if( rc>0 ){.    
4060: 20 20 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 70          fossil_p
4070: 72 69 6e 74 28 22 2a 2a 2a 2a 2a 20 25 64 20 6d  rint("***** %d m
4080: 65 72 67 65 20 63 6f 6e 66 6c 69 63 74 73 20 69  erge conflicts i
4090: 6e 20 25 73 5c 6e 22 2c 20 72 63 2c 20 7a 4e 65  n %s\n", rc, zNe
40a0: 77 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 20 20  wName);.        
40b0: 20 20 20 20 6e 43 6f 6e 66 6c 69 63 74 2b 2b 3b      nConflict++;
40c0: 0a 20 20 20 20 20 20 20 20 20 20 7d 0a 20 20 20  .          }.   
40d0: 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20       }else{.    
40e0: 20 20 20 20 20 20 69 66 28 20 21 6e 6f 63 68 61        if( !nocha
40f0: 6e 67 65 46 6c 61 67 20 29 7b 0a 20 20 20 20 20  ngeFlag ){.     
4100: 20 20 20 20 20 20 20 62 6c 6f 62 5f 77 72 69 74         blob_writ
4110: 65 5f 74 6f 5f 66 69 6c 65 28 26 74 2c 20 7a 46  e_to_file(&t, zF
4120: 75 6c 6c 4e 65 77 50 61 74 68 29 3b 0a 20 20 20  ullNewPath);.   
4130: 20 20 20 20 20 20 20 20 20 66 69 6c 65 5f 77 64           file_wd
4140: 5f 73 65 74 65 78 65 28 7a 46 75 6c 6c 4e 65 77  _setexe(zFullNew
4150: 50 61 74 68 2c 20 69 73 65 78 65 29 3b 0a 20 20  Path, isexe);.  
4160: 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20          }.      
4170: 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74      fossil_print
4180: 28 22 2a 2a 2a 2a 2a 20 43 61 6e 6e 6f 74 20 6d  ("***** Cannot m
4190: 65 72 67 65 20 62 69 6e 61 72 79 20 66 69 6c 65  erge binary file
41a0: 20 25 73 5c 6e 22 2c 20 7a 4e 65 77 4e 61 6d 65   %s\n", zNewName
41b0: 29 3b 0a 20 20 20 20 20 20 20 20 20 20 6e 43 6f  );.          nCo
41c0: 6e 66 6c 69 63 74 2b 2b 3b 0a 20 20 20 20 20 20  nflict++;.      
41d0: 20 20 7d 0a 20 20 20 20 20 20 7d 0a 20 20 20 20    }.      }.    
41e0: 20 20 69 66 28 20 6e 61 6d 65 43 68 6e 67 20 26    if( nameChng &
41f0: 26 20 21 6e 6f 63 68 61 6e 67 65 46 6c 61 67 20  & !nochangeFlag 
4200: 29 20 66 69 6c 65 5f 64 65 6c 65 74 65 28 7a 46  ) file_delete(zF
4210: 75 6c 6c 50 61 74 68 29 3b 0a 20 20 20 20 20 20  ullPath);.      
4220: 62 6c 6f 62 5f 72 65 73 65 74 28 26 76 29 3b 0a  blob_reset(&v);.
4230: 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74        blob_reset
4240: 28 26 74 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62  (&t);.      blob
4250: 5f 72 65 73 65 74 28 26 72 29 3b 0a 20 20 20 20  _reset(&r);.    
4260: 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 6e 55 70  }else{.      nUp
4270: 64 61 74 65 2d 2d 3b 0a 20 20 20 20 20 20 69 66  date--;.      if
4280: 28 20 63 68 6e 67 65 64 20 29 7b 0a 20 20 20 20  ( chnged ){.    
4290: 20 20 20 20 69 66 28 20 76 65 72 62 6f 73 65 46      if( verboseF
42a0: 6c 61 67 20 29 20 66 6f 73 73 69 6c 5f 70 72 69  lag ) fossil_pri
42b0: 6e 74 28 22 45 44 49 54 45 44 20 25 73 5c 6e 22  nt("EDITED %s\n"
42c0: 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20  , zName);.      
42d0: 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20 20 64  }else{.        d
42e0: 62 5f 62 69 6e 64 5f 69 6e 74 28 26 6d 74 69 6d  b_bind_int(&mtim
42f0: 65 58 66 65 72 2c 20 22 3a 69 64 76 22 2c 20 69  eXfer, ":idv", i
4300: 64 76 29 3b 0a 20 20 20 20 20 20 20 20 64 62 5f  dv);.        db_
4310: 62 69 6e 64 5f 69 6e 74 28 26 6d 74 69 6d 65 58  bind_int(&mtimeX
4320: 66 65 72 2c 20 22 3a 69 64 74 22 2c 20 69 64 74  fer, ":idt", idt
4330: 29 3b 0a 20 20 20 20 20 20 20 20 64 62 5f 73 74  );.        db_st
4340: 65 70 28 26 6d 74 69 6d 65 58 66 65 72 29 3b 0a  ep(&mtimeXfer);.
4350: 20 20 20 20 20 20 20 20 64 62 5f 72 65 73 65 74          db_reset
4360: 28 26 6d 74 69 6d 65 58 66 65 72 29 3b 0a 20 20  (&mtimeXfer);.  
4370: 20 20 20 20 20 20 69 66 28 20 76 65 72 62 6f 73        if( verbos
4380: 65 46 6c 61 67 20 29 20 66 6f 73 73 69 6c 5f 70  eFlag ) fossil_p
4390: 72 69 6e 74 28 22 55 4e 43 48 41 4e 47 45 44 20  rint("UNCHANGED 
43a0: 25 73 5c 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20  %s\n", zName);. 
43b0: 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20       }.    }.   
43c0: 20 66 72 65 65 28 7a 46 75 6c 6c 50 61 74 68 29   free(zFullPath)
43d0: 3b 0a 20 20 20 20 66 72 65 65 28 7a 46 75 6c 6c  ;.    free(zFull
43e0: 4e 65 77 50 61 74 68 29 3b 0a 20 20 7d 0a 20 20  NewPath);.  }.  
43f0: 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b  db_finalize(&q);
4400: 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26  .  db_finalize(&
4410: 6d 74 69 6d 65 58 66 65 72 29 3b 0a 20 20 66 6f  mtimeXfer);.  fo
4420: 73 73 69 6c 5f 70 72 69 6e 74 28 22 25 2e 37 39  ssil_print("%.79
4430: 63 5c 6e 22 2c 27 2d 27 29 3b 0a 20 20 69 66 28  c\n",'-');.  if(
4440: 20 6e 55 70 64 61 74 65 3d 3d 30 20 29 7b 0a 20   nUpdate==0 ){. 
4450: 20 20 20 73 68 6f 77 5f 63 6f 6d 6d 6f 6e 5f 69     show_common_i
4460: 6e 66 6f 28 74 69 64 2c 20 22 63 68 65 63 6b 6f  nfo(tid, "checko
4470: 75 74 3a 22 2c 20 31 2c 20 30 29 3b 0a 20 20 20  ut:", 1, 0);.   
4480: 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28 22 25   fossil_print("%
4490: 2d 31 33 73 20 4e 6f 6e 65 2e 20 41 6c 72 65 61  -13s None. Alrea
44a0: 64 79 20 75 70 2d 74 6f 2d 64 61 74 65 5c 6e 22  dy up-to-date\n"
44b0: 2c 20 22 63 68 61 6e 67 65 73 3a 22 29 3b 0a 20  , "changes:");. 
44c0: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 73 68 6f 77   }else{.    show
44d0: 5f 63 6f 6d 6d 6f 6e 5f 69 6e 66 6f 28 74 69 64  _common_info(tid
44e0: 2c 20 22 75 70 64 61 74 65 64 2d 74 6f 3a 22 2c  , "updated-to:",
44f0: 20 31 2c 20 30 29 3b 0a 20 20 20 20 66 6f 73 73   1, 0);.    foss
4500: 69 6c 5f 70 72 69 6e 74 28 22 25 2d 31 33 73 20  il_print("%-13s 
4510: 25 64 20 66 69 6c 65 25 73 20 6d 6f 64 69 66 69  %d file%s modifi
4520: 65 64 2e 5c 6e 22 2c 20 22 63 68 61 6e 67 65 73  ed.\n", "changes
4530: 3a 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20  :",.            
4540: 20 20 20 20 20 6e 55 70 64 61 74 65 2c 20 6e 55       nUpdate, nU
4550: 70 64 61 74 65 3e 31 20 3f 20 22 73 22 20 3a 20  pdate>1 ? "s" : 
4560: 22 22 29 3b 0a 20 20 7d 0a 0a 20 20 2f 2a 20 52  "");.  }..  /* R
4570: 65 70 6f 72 74 20 6f 6e 20 63 6f 6e 66 6c 69 63  eport on conflic
4580: 74 73 0a 20 20 2a 2f 0a 20 20 69 66 28 20 21 6e  ts.  */.  if( !n
4590: 6f 63 68 61 6e 67 65 46 6c 61 67 20 29 7b 0a 20  ochangeFlag ){. 
45a0: 20 20 20 53 74 6d 74 20 71 3b 0a 20 20 20 20 69     Stmt q;.    i
45b0: 6e 74 20 6e 4d 65 72 67 65 20 3d 20 30 3b 0a 20  nt nMerge = 0;. 
45c0: 20 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71     db_prepare(&q
45d0: 2c 20 22 53 45 4c 45 43 54 20 75 75 69 64 2c 20  , "SELECT uuid, 
45e0: 69 64 20 46 52 4f 4d 20 76 6d 65 72 67 65 20 4a  id FROM vmerge J
45f0: 4f 49 4e 20 62 6c 6f 62 20 4f 4e 20 6d 65 72 67  OIN blob ON merg
4600: 65 3d 72 69 64 22 0a 20 20 20 20 20 20 20 20 20  e=rid".         
4610: 20 20 20 20 20 20 20 20 20 20 22 20 57 48 45 52            " WHER
4620: 45 20 69 64 3c 3d 30 22 29 3b 0a 20 20 20 20 77  E id<=0");.    w
4630: 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71  hile( db_step(&q
4640: 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b  )==SQLITE_ROW ){
4650: 0a 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61  .      const cha
4660: 72 20 2a 7a 4c 61 62 65 6c 20 3d 20 22 6d 65 72  r *zLabel = "mer
4670: 67 65 22 3b 0a 20 20 20 20 20 20 73 77 69 74 63  ge";.      switc
4680: 68 28 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74  h( db_column_int
4690: 28 26 71 2c 20 31 29 20 29 7b 0a 20 20 20 20 20  (&q, 1) ){.     
46a0: 20 20 20 63 61 73 65 20 2d 31 3a 20 20 7a 4c 61     case -1:  zLa
46b0: 62 65 6c 20 3d 20 22 63 68 65 72 72 79 70 69 63  bel = "cherrypic
46c0: 6b 20 6d 65 72 67 65 22 3b 20 62 72 65 61 6b 3b  k merge"; break;
46d0: 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 2d 32  .        case -2
46e0: 3a 20 20 7a 4c 61 62 65 6c 20 3d 20 22 62 61 63  :  zLabel = "bac
46f0: 6b 6f 75 74 20 6d 65 72 67 65 22 3b 20 20 20 20  kout merge";    
4700: 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 7d 0a 20  break;.      }. 
4710: 20 20 20 20 20 66 6f 73 73 69 6c 5f 77 61 72 6e       fossil_warn
4720: 69 6e 67 28 22 75 6e 63 6f 6d 6d 69 74 74 65 64  ing("uncommitted
4730: 20 25 73 20 61 67 61 69 6e 73 74 20 25 53 2e 22   %s against %S."
4740: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ,.              
4750: 20 20 20 20 20 20 20 7a 4c 61 62 65 6c 2c 20 64         zLabel, d
4760: 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71  b_column_text(&q
4770: 2c 20 30 29 29 3b 0a 20 20 20 20 20 20 6e 4d 65  , 0));.      nMe
4780: 72 67 65 2b 2b 3b 0a 20 20 20 20 7d 0a 20 20 20  rge++;.    }.   
4790: 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29   db_finalize(&q)
47a0: 3b 0a 20 20 20 20 0a 20 20 20 20 69 66 28 20 6e  ;.    .    if( n
47b0: 43 6f 6e 66 6c 69 63 74 20 29 7b 0a 20 20 20 20  Conflict ){.    
47c0: 20 20 69 66 28 20 69 6e 74 65 72 6e 61 6c 55 70    if( internalUp
47d0: 64 61 74 65 20 29 7b 0a 20 20 20 20 20 20 20 20  date ){.        
47e0: 69 6e 74 65 72 6e 61 6c 43 6f 6e 66 6c 69 63 74  internalConflict
47f0: 43 6e 74 20 3d 20 6e 43 6f 6e 66 6c 69 63 74 3b  Cnt = nConflict;
4800: 0a 20 20 20 20 20 20 20 20 6e 43 6f 6e 66 6c 69  .        nConfli
4810: 63 74 20 3d 20 30 3b 0a 20 20 20 20 20 20 7d 65  ct = 0;.      }e
4820: 6c 73 65 7b 0a 20 20 20 20 20 20 20 20 66 6f 73  lse{.        fos
4830: 73 69 6c 5f 77 61 72 6e 69 6e 67 28 22 57 41 52  sil_warning("WAR
4840: 4e 49 4e 47 3a 20 25 64 20 6d 65 72 67 65 20 63  NING: %d merge c
4850: 6f 6e 66 6c 69 63 74 73 22 2c 20 6e 43 6f 6e 66  onflicts", nConf
4860: 6c 69 63 74 29 3b 0a 20 20 20 20 20 20 7d 0a 20  lict);.      }. 
4870: 20 20 20 7d 0a 20 20 20 20 69 66 28 20 6e 4f 76     }.    if( nOv
4880: 65 72 77 72 69 74 65 20 29 7b 0a 20 20 20 20 20  erwrite ){.     
4890: 20 66 6f 73 73 69 6c 5f 77 61 72 6e 69 6e 67 28   fossil_warning(
48a0: 22 57 41 52 4e 49 4e 47 3a 20 25 64 20 75 6e 6d  "WARNING: %d unm
48b0: 61 6e 61 67 65 64 20 66 69 6c 65 73 20 77 65 72  anaged files wer
48c0: 65 20 6f 76 65 72 77 72 69 74 74 65 6e 22 2c 0a  e overwritten",.
48d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
48e0: 20 20 20 20 20 6e 4f 76 65 72 77 72 69 74 65 29       nOverwrite)
48f0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20  ;.    }.    if( 
4900: 6e 4d 65 72 67 65 20 29 7b 0a 20 20 20 20 20 20  nMerge ){.      
4910: 66 6f 73 73 69 6c 5f 77 61 72 6e 69 6e 67 28 22  fossil_warning("
4920: 57 41 52 4e 49 4e 47 3a 20 25 64 20 75 6e 63 6f  WARNING: %d unco
4930: 6d 6d 69 74 74 65 64 20 70 72 69 6f 72 20 6d 65  mmitted prior me
4940: 72 67 65 73 22 2c 20 6e 4d 65 72 67 65 29 3b 0a  rges", nMerge);.
4950: 20 20 20 20 7d 0a 20 20 7d 0a 20 20 0a 20 20 2f      }.  }.  .  /
4960: 2a 0a 20 20 2a 2a 20 43 6c 65 61 6e 20 75 70 20  *.  ** Clean up 
4970: 74 68 65 20 6d 69 64 20 61 6e 64 20 70 69 64 20  the mid and pid 
4980: 56 46 49 4c 45 20 65 6e 74 72 69 65 73 2e 20 20  VFILE entries.  
4990: 54 68 65 6e 20 63 6f 6d 6d 69 74 20 74 68 65 20  Then commit the 
49a0: 63 68 61 6e 67 65 73 2e 0a 20 20 2a 2f 0a 20 20  changes..  */.  
49b0: 69 66 28 20 6e 6f 63 68 61 6e 67 65 46 6c 61 67  if( nochangeFlag
49c0: 20 29 7b 0a 20 20 20 20 64 62 5f 65 6e 64 5f 74   ){.    db_end_t
49d0: 72 61 6e 73 61 63 74 69 6f 6e 28 31 29 3b 20 20  ransaction(1);  
49e0: 2f 2a 20 57 69 74 68 20 2d 2d 6e 6f 63 68 61 6e  /* With --nochan
49f0: 67 65 2c 20 72 6f 6c 6c 62 61 63 6b 20 63 68 61  ge, rollback cha
4a00: 6e 67 65 73 20 2a 2f 0a 20 20 7d 65 6c 73 65 7b  nges */.  }else{
4a10: 0a 20 20 20 20 65 6e 73 75 72 65 5f 65 6d 70 74  .    ensure_empt
4a20: 79 5f 64 69 72 73 5f 63 72 65 61 74 65 64 28 29  y_dirs_created()
4a30: 3b 0a 20 20 20 20 69 66 28 20 67 2e 61 72 67 63  ;.    if( g.argc
4a40: 3c 3d 33 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20  <=3 ){.      /* 
4a50: 41 6c 6c 20 66 69 6c 65 73 20 75 70 64 61 74 65  All files update
4a60: 64 2e 20 20 53 68 69 66 74 20 74 68 65 20 63 75  d.  Shift the cu
4a70: 72 72 65 6e 74 20 63 68 65 63 6b 6f 75 74 20 74  rrent checkout t
4a80: 6f 20 74 68 65 20 74 61 72 67 65 74 2e 20 2a 2f  o the target. */
4a90: 0a 20 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f  .      db_multi_
4aa0: 65 78 65 63 28 22 44 45 4c 45 54 45 20 46 52 4f  exec("DELETE FRO
4ab0: 4d 20 76 66 69 6c 65 20 57 48 45 52 45 20 76 69  M vfile WHERE vi
4ac0: 64 21 3d 25 64 22 2c 20 74 69 64 29 3b 0a 20 20  d!=%d", tid);.  
4ad0: 20 20 20 20 63 68 65 63 6b 6f 75 74 5f 73 65 74      checkout_set
4ae0: 5f 61 6c 6c 5f 65 78 65 28 74 69 64 29 3b 0a 20  _all_exe(tid);. 
4af0: 20 20 20 20 20 6d 61 6e 69 66 65 73 74 5f 74 6f       manifest_to
4b00: 5f 64 69 73 6b 28 74 69 64 29 3b 0a 20 20 20 20  _disk(tid);.    
4b10: 20 20 64 62 5f 6c 73 65 74 5f 69 6e 74 28 22 63    db_lset_int("c
4b20: 68 65 63 6b 6f 75 74 22 2c 20 74 69 64 29 3b 0a  heckout", tid);.
4b30: 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20      }else{.     
4b40: 20 2f 2a 20 41 20 73 75 62 73 65 74 20 6f 66 20   /* A subset of 
4b50: 66 69 6c 65 73 20 68 61 76 65 20 62 65 65 6e 20  files have been 
4b60: 63 68 65 63 6b 65 64 20 6f 75 74 2e 20 20 4b 65  checked out.  Ke
4b70: 65 70 20 74 68 65 20 63 75 72 72 65 6e 74 0a 20  ep the current. 
4b80: 20 20 20 20 20 2a 2a 20 63 68 65 63 6b 6f 75 74       ** checkout
4b90: 20 75 6e 63 68 61 6e 67 65 64 2e 20 2a 2f 0a 20   unchanged. */. 
4ba0: 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78       db_multi_ex
4bb0: 65 63 28 22 44 45 4c 45 54 45 20 46 52 4f 4d 20  ec("DELETE FROM 
4bc0: 76 66 69 6c 65 20 57 48 45 52 45 20 76 69 64 21  vfile WHERE vid!
4bd0: 3d 25 64 22 2c 20 76 69 64 29 3b 0a 20 20 20 20  =%d", vid);.    
4be0: 7d 0a 20 20 20 20 69 66 28 20 21 69 6e 74 65 72  }.    if( !inter
4bf0: 6e 61 6c 55 70 64 61 74 65 20 29 20 75 6e 64 6f  nalUpdate ) undo
4c00: 5f 66 69 6e 69 73 68 28 29 3b 0a 20 20 20 20 69  _finish();.    i
4c10: 66 28 20 73 65 74 6d 74 69 6d 65 46 6c 61 67 20  f( setmtimeFlag 
4c20: 29 20 76 66 69 6c 65 5f 63 68 65 63 6b 5f 73 69  ) vfile_check_si
4c30: 67 6e 61 74 75 72 65 28 74 69 64 2c 20 43 4b 53  gnature(tid, CKS
4c40: 49 47 5f 53 45 54 4d 54 49 4d 45 29 3b 0a 20 20  IG_SETMTIME);.  
4c50: 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63    db_end_transac
4c60: 74 69 6f 6e 28 30 29 3b 0a 20 20 7d 0a 7d 0a 0a  tion(0);.  }.}..
4c70: 2f 2a 0a 2a 2a 20 4d 61 6b 65 20 73 75 72 65 20  /*.** Make sure 
4c80: 65 6d 70 74 79 20 64 69 72 65 63 74 6f 72 69 65  empty directorie
4c90: 73 20 61 72 65 20 63 72 65 61 74 65 64 0a 2a 2f  s are created.*/
4ca0: 0a 76 6f 69 64 20 65 6e 73 75 72 65 5f 65 6d 70  .void ensure_emp
4cb0: 74 79 5f 64 69 72 73 5f 63 72 65 61 74 65 64 28  ty_dirs_created(
4cc0: 76 6f 69 64 29 7b 0a 20 20 2f 2a 20 4d 61 6b 65  void){.  /* Make
4cd0: 20 65 6d 70 74 79 20 64 69 72 65 63 74 6f 72 69   empty directori
4ce0: 65 73 3f 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a  es? */.  char *z
4cf0: 45 6d 70 74 79 44 69 72 73 20 3d 20 64 62 5f 67  EmptyDirs = db_g
4d00: 65 74 28 22 65 6d 70 74 79 2d 64 69 72 73 22 2c  et("empty-dirs",
4d10: 20 30 29 3b 0a 20 20 69 66 28 20 7a 45 6d 70 74   0);.  if( zEmpt
4d20: 79 44 69 72 73 21 3d 30 20 29 7b 0a 20 20 20 20  yDirs!=0 ){.    
4d30: 63 68 61 72 20 2a 62 63 3b 0a 20 20 20 20 42 6c  char *bc;.    Bl
4d40: 6f 62 20 64 69 72 4e 61 6d 65 3b 0a 20 20 20 20  ob dirName;.    
4d50: 42 6c 6f 62 20 64 69 72 73 4c 69 73 74 3b 0a 0a  Blob dirsList;..
4d60: 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 64      blob_zero(&d
4d70: 69 72 73 4c 69 73 74 29 3b 0a 20 20 20 20 62 6c  irsList);.    bl
4d80: 6f 62 5f 69 6e 69 74 28 26 64 69 72 73 4c 69 73  ob_init(&dirsLis
4d90: 74 2c 20 7a 45 6d 70 74 79 44 69 72 73 2c 20 73  t, zEmptyDirs, s
4da0: 74 72 6c 65 6e 28 7a 45 6d 70 74 79 44 69 72 73  trlen(zEmptyDirs
4db0: 29 29 3b 0a 20 20 20 20 2f 2a 20 52 65 70 6c 61  ));.    /* Repla
4dc0: 63 65 20 63 6f 6d 6d 61 73 20 62 79 20 73 70 61  ce commas by spa
4dd0: 63 65 73 20 2a 2f 0a 20 20 20 20 62 63 20 3d 20  ces */.    bc = 
4de0: 62 6c 6f 62 5f 73 74 72 28 26 64 69 72 73 4c 69  blob_str(&dirsLi
4df0: 73 74 29 3b 0a 20 20 20 20 77 68 69 6c 65 28 20  st);.    while( 
4e00: 28 2a 62 63 29 21 3d 27 5c 30 27 20 29 7b 0a 20  (*bc)!='\0' ){. 
4e10: 20 20 20 20 20 69 66 28 20 28 2a 62 63 29 3d 3d       if( (*bc)==
4e20: 27 2c 27 20 29 20 7b 20 2a 62 63 20 3d 20 27 20  ',' ) { *bc = ' 
4e30: 27 3b 20 7d 0a 20 20 20 20 20 20 2b 2b 62 63 3b  '; }.      ++bc;
4e40: 0a 20 20 20 20 7d 0a 20 20 20 20 2f 2a 20 4d 61  .    }.    /* Ma
4e50: 6b 65 20 64 69 72 65 63 74 6f 72 69 65 73 20 2a  ke directories *
4e60: 2f 0a 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28  /.    blob_zero(
4e70: 26 64 69 72 4e 61 6d 65 29 3b 0a 20 20 20 20 77  &dirName);.    w
4e80: 68 69 6c 65 28 20 62 6c 6f 62 5f 74 6f 6b 65 6e  hile( blob_token
4e90: 28 26 64 69 72 73 4c 69 73 74 2c 20 26 64 69 72  (&dirsList, &dir
4ea0: 4e 61 6d 65 29 20 29 7b 0a 20 20 20 20 20 20 63  Name) ){.      c
4eb0: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 69 72 20  onst char *zDir 
4ec0: 3d 20 62 6c 6f 62 5f 73 74 72 28 26 64 69 72 4e  = blob_str(&dirN
4ed0: 61 6d 65 29 3b 0a 20 20 20 20 20 20 2f 2a 20 4d  ame);.      /* M
4ee0: 61 6b 65 20 66 75 6c 6c 20 70 61 74 68 6e 61 6d  ake full pathnam
4ef0: 65 20 6f 66 20 74 68 65 20 64 69 72 65 63 74 6f  e of the directo
4f00: 72 79 20 2a 2f 0a 20 20 20 20 20 20 42 6c 6f 62  ry */.      Blob
4f10: 20 70 61 74 68 3b 0a 20 20 20 20 20 20 63 6f 6e   path;.      con
4f20: 73 74 20 63 68 61 72 20 2a 7a 50 61 74 68 3b 0a  st char *zPath;.
4f30: 0a 20 20 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f  .      blob_zero
4f40: 28 26 70 61 74 68 29 3b 0a 20 20 20 20 20 20 62  (&path);.      b
4f50: 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 70 61 74  lob_appendf(&pat
4f60: 68 2c 20 22 25 73 2f 25 73 22 2c 20 67 2e 7a 4c  h, "%s/%s", g.zL
4f70: 6f 63 61 6c 52 6f 6f 74 2c 20 7a 44 69 72 29 3b  ocalRoot, zDir);
4f80: 0a 20 20 20 20 20 20 7a 50 61 74 68 20 3d 20 62  .      zPath = b
4f90: 6c 6f 62 5f 73 74 72 28 26 70 61 74 68 29 3b 20  lob_str(&path); 
4fa0: 20 20 20 20 20 0a 20 20 20 20 20 20 2f 2a 20 48       .      /* H
4fb0: 61 6e 64 6c 65 20 76 61 72 69 6f 75 73 20 63 61  andle various ca
4fc0: 73 65 73 20 6f 66 20 65 78 69 73 74 65 6e 63 65  ses of existence
4fd0: 20 6f 66 20 74 68 65 20 64 69 72 65 63 74 6f 72   of the director
4fe0: 79 20 2a 2f 0a 20 20 20 20 20 20 73 77 69 74 63  y */.      switc
4ff0: 68 28 20 66 69 6c 65 5f 77 64 5f 69 73 64 69 72  h( file_wd_isdir
5000: 28 7a 50 61 74 68 29 20 29 7b 0a 20 20 20 20 20  (zPath) ){.     
5010: 20 20 20 63 61 73 65 20 30 3a 20 7b 20 2f 2a 20     case 0: { /* 
5020: 64 6f 65 73 6e 27 74 20 65 78 69 73 74 20 2a 2f  doesn't exist */
5030: 0a 20 20 20 20 20 20 20 20 20 20 69 66 28 20 66  .          if( f
5040: 69 6c 65 5f 6d 6b 64 69 72 28 7a 50 61 74 68 2c  ile_mkdir(zPath,
5050: 20 30 29 21 3d 30 20 29 20 7b 0a 20 20 20 20 20   0)!=0 ) {.     
5060: 20 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 77 61         fossil_wa
5070: 72 6e 69 6e 67 28 22 63 6f 75 6c 64 6e 27 74 20  rning("couldn't 
5080: 63 72 65 61 74 65 20 64 69 72 65 63 74 6f 72 79  create directory
5090: 20 25 73 20 61 73 20 22 0a 20 20 20 20 20 20 20   %s as ".       
50a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
50b0: 20 20 20 20 22 72 65 71 75 69 72 65 64 20 62 79      "required by
50c0: 20 65 6d 70 74 79 2d 64 69 72 73 20 73 65 74 74   empty-dirs sett
50d0: 69 6e 67 22 2c 20 7a 44 69 72 29 3b 0a 20 20 20  ing", zDir);.   
50e0: 20 20 20 20 20 20 20 7d 20 20 20 20 20 20 20 20         }        
50f0: 20 20 0a 20 20 20 20 20 20 20 20 20 20 62 72 65    .          bre
5100: 61 6b 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20  ak;.        }.  
5110: 20 20 20 20 20 20 63 61 73 65 20 31 3a 20 7b 20        case 1: { 
5120: 2f 2a 20 65 78 69 73 74 73 2c 20 61 6e 64 20 69  /* exists, and i
5130: 73 20 61 20 64 69 72 65 63 74 6f 72 79 20 2a 2f  s a directory */
5140: 0a 20 20 20 20 20 20 20 20 20 20 2f 2a 20 64 6f  .          /* do
5150: 20 6e 6f 74 68 69 6e 67 20 2d 20 72 65 71 75 69   nothing - requi
5160: 72 65 64 20 64 69 72 65 63 74 6f 72 79 20 65 78  red directory ex
5170: 69 73 74 73 20 61 6c 72 65 61 64 79 20 2a 2f 0a  ists already */.
5180: 20 20 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b            break;
5190: 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20  .        }.     
51a0: 20 20 20 63 61 73 65 20 32 3a 20 7b 20 2f 2a 20     case 2: { /* 
51b0: 65 78 69 73 74 73 2c 20 62 75 74 20 69 73 6e 27  exists, but isn'
51c0: 74 20 61 20 64 69 72 65 63 74 6f 72 79 20 2a 2f  t a directory */
51d0: 0a 20 20 20 20 20 20 20 20 20 20 66 6f 73 73 69  .          fossi
51e0: 6c 5f 77 61 72 6e 69 6e 67 28 22 66 69 6c 65 20  l_warning("file 
51f0: 25 73 20 66 6f 75 6e 64 2c 20 62 75 74 20 61 20  %s found, but a 
5200: 64 69 72 65 63 74 6f 72 79 20 69 73 20 72 65 71  directory is req
5210: 75 69 72 65 64 20 22 0a 20 20 20 20 20 20 20 20  uired ".        
5220: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
5230: 20 22 62 79 20 65 6d 70 74 79 2d 64 69 72 73 20   "by empty-dirs 
5240: 73 65 74 74 69 6e 67 22 2c 20 7a 44 69 72 29 3b  setting", zDir);
5250: 20 20 20 20 20 20 20 20 20 20 0a 20 20 20 20 20            .     
5260: 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a 20 20 20     }.      }.   
5270: 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 70     blob_reset(&p
5280: 61 74 68 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a  ath);.    }.  }.
5290: 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 47 65 74 20 74 68  }.../*.** Get th
52a0: 65 20 63 6f 6e 74 65 6e 74 73 20 6f 66 20 61 20  e contents of a 
52b0: 66 69 6c 65 20 77 69 74 68 69 6e 20 74 68 65 20  file within the 
52c0: 63 68 65 63 6b 69 6e 67 20 22 72 65 76 69 73 69  checking "revisi
52d0: 6f 6e 22 2e 20 20 49 66 0a 2a 2a 20 72 65 76 69  on".  If.** revi
52e0: 73 69 6f 6e 3d 3d 4e 55 4c 4c 20 74 68 65 6e 20  sion==NULL then 
52f0: 67 65 74 20 74 68 65 20 66 69 6c 65 20 63 6f 6e  get the file con
5300: 74 65 6e 74 20 66 6f 72 20 74 68 65 20 63 75 72  tent for the cur
5310: 72 65 6e 74 20 63 68 65 63 6b 6f 75 74 2e 0a 2a  rent checkout..*
5320: 2f 0a 69 6e 74 20 68 69 73 74 6f 72 69 63 61 6c  /.int historical
5330: 5f 76 65 72 73 69 6f 6e 5f 6f 66 5f 66 69 6c 65  _version_of_file
5340: 28 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  (.  const char *
5350: 72 65 76 69 73 69 6f 6e 2c 20 20 20 20 2f 2a 20  revision,    /* 
5360: 54 68 65 20 63 68 65 63 6b 69 6e 20 63 6f 6e 74  The checkin cont
5370: 61 69 6e 69 6e 67 20 74 68 65 20 66 69 6c 65 20  aining the file 
5380: 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  */.  const char 
5390: 2a 66 69 6c 65 2c 20 20 20 20 20 20 20 20 2f 2a  *file,        /*
53a0: 20 46 75 6c 6c 20 74 72 65 65 6e 61 6d 65 20 6f   Full treename o
53b0: 66 20 74 68 65 20 66 69 6c 65 20 2a 2f 0a 20 20  f the file */.  
53c0: 42 6c 6f 62 20 2a 63 6f 6e 74 65 6e 74 2c 20 20  Blob *content,  
53d0: 20 20 20 20 20 20 20 20 20 2f 2a 20 50 75 74 20           /* Put 
53e0: 74 68 65 20 63 6f 6e 74 65 6e 74 20 68 65 72 65  the content here
53f0: 20 2a 2f 0a 20 20 69 6e 74 20 2a 70 49 73 4c 69   */.  int *pIsLi
5400: 6e 6b 2c 20 20 20 20 20 20 20 20 20 20 20 20 2f  nk,            /
5410: 2a 20 53 65 74 20 74 6f 20 74 72 75 65 20 69 66  * Set to true if
5420: 20 66 69 6c 65 20 69 73 20 6c 69 6e 6b 2e 20 2a   file is link. *
5430: 2f 0a 20 20 69 6e 74 20 2a 70 49 73 45 78 65 2c  /.  int *pIsExe,
5440: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20               /* 
5450: 53 65 74 20 74 6f 20 74 72 75 65 20 69 66 20 66  Set to true if f
5460: 69 6c 65 20 69 73 20 65 78 65 63 75 74 61 62 6c  ile is executabl
5470: 65 20 2a 2f 0a 20 20 69 6e 74 20 2a 70 49 73 42  e */.  int *pIsB
5480: 69 6e 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  in,             
5490: 2f 2a 20 53 65 74 20 74 6f 20 74 72 75 65 20 69  /* Set to true i
54a0: 66 20 66 69 6c 65 20 69 73 20 62 69 6e 61 72 79  f file is binary
54b0: 20 2a 2f 0a 20 20 69 6e 74 20 65 72 72 43 6f 64   */.  int errCod
54c0: 65 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f  e              /
54d0: 2a 20 45 72 72 6f 72 20 63 6f 64 65 20 69 66 20  * Error code if 
54e0: 66 69 6c 65 20 6e 6f 74 20 66 6f 75 6e 64 2e 20  file not found. 
54f0: 20 50 61 6e 69 63 20 69 66 20 30 2e 20 2a 2f 0a   Panic if 0. */.
5500: 29 7b 0a 20 20 4d 61 6e 69 66 65 73 74 20 2a 70  ){.  Manifest *p
5510: 4d 61 6e 69 66 65 73 74 3b 0a 20 20 4d 61 6e 69  Manifest;.  Mani
5520: 66 65 73 74 46 69 6c 65 20 2a 70 46 69 6c 65 3b  festFile *pFile;
5530: 0a 20 20 69 6e 74 20 72 69 64 3d 30 3b 0a 20 20  .  int rid=0;.  
5540: 0a 20 20 69 66 28 20 72 65 76 69 73 69 6f 6e 20  .  if( revision 
5550: 29 7b 0a 20 20 20 20 72 69 64 20 3d 20 6e 61 6d  ){.    rid = nam
5560: 65 5f 74 6f 5f 74 79 70 65 64 5f 72 69 64 28 72  e_to_typed_rid(r
5570: 65 76 69 73 69 6f 6e 2c 22 63 69 22 29 3b 0a 20  evision,"ci");. 
5580: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 72 69 64 20   }else{.    rid 
5590: 3d 20 64 62 5f 6c 67 65 74 5f 69 6e 74 28 22 63  = db_lget_int("c
55a0: 68 65 63 6b 6f 75 74 22 2c 20 30 29 3b 0a 20 20  heckout", 0);.  
55b0: 7d 0a 20 20 69 66 28 20 21 69 73 5f 61 5f 76 65  }.  if( !is_a_ve
55c0: 72 73 69 6f 6e 28 72 69 64 29 20 29 7b 0a 20 20  rsion(rid) ){.  
55d0: 20 20 69 66 28 20 65 72 72 43 6f 64 65 3e 30 20    if( errCode>0 
55e0: 29 20 72 65 74 75 72 6e 20 65 72 72 43 6f 64 65  ) return errCode
55f0: 3b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74  ;.    fossil_fat
5600: 61 6c 28 22 6e 6f 20 73 75 63 68 20 63 68 65 63  al("no such chec
5610: 6b 69 6e 3a 20 25 73 22 2c 20 72 65 76 69 73 69  kin: %s", revisi
5620: 6f 6e 29 3b 0a 20 20 7d 0a 20 20 70 4d 61 6e 69  on);.  }.  pMani
5630: 66 65 73 74 20 3d 20 6d 61 6e 69 66 65 73 74 5f  fest = manifest_
5640: 67 65 74 28 72 69 64 2c 20 43 46 54 59 50 45 5f  get(rid, CFTYPE_
5650: 4d 41 4e 49 46 45 53 54 29 3b 0a 20 20 0a 20 20  MANIFEST);.  .  
5660: 69 66 28 20 70 4d 61 6e 69 66 65 73 74 20 29 7b  if( pManifest ){
5670: 0a 20 20 20 20 70 46 69 6c 65 20 3d 20 6d 61 6e  .    pFile = man
5680: 69 66 65 73 74 5f 66 69 6c 65 5f 66 69 6e 64 28  ifest_file_find(
5690: 70 4d 61 6e 69 66 65 73 74 2c 20 66 69 6c 65 29  pManifest, file)
56a0: 3b 0a 20 20 20 20 69 66 28 20 70 46 69 6c 65 20  ;.    if( pFile 
56b0: 29 7b 0a 20 20 20 20 20 20 69 6e 74 20 72 63 3b  ){.      int rc;
56c0: 0a 20 20 20 20 20 20 72 69 64 20 3d 20 75 75 69  .      rid = uui
56d0: 64 5f 74 6f 5f 72 69 64 28 70 46 69 6c 65 2d 3e  d_to_rid(pFile->
56e0: 7a 55 75 69 64 2c 20 30 29 3b 0a 20 20 20 20 20  zUuid, 0);.     
56f0: 20 69 66 28 20 70 49 73 45 78 65 20 29 20 2a 70   if( pIsExe ) *p
5700: 49 73 45 78 65 20 3d 20 28 20 6d 61 6e 69 66 65  IsExe = ( manife
5710: 73 74 5f 66 69 6c 65 5f 6d 70 65 72 6d 28 70 46  st_file_mperm(pF
5720: 69 6c 65 29 3d 3d 50 45 52 4d 5f 45 58 45 20 29  ile)==PERM_EXE )
5730: 3b 0a 20 20 20 20 20 20 69 66 28 20 70 49 73 4c  ;.      if( pIsL
5740: 69 6e 6b 20 29 20 2a 70 49 73 4c 69 6e 6b 20 3d  ink ) *pIsLink =
5750: 20 28 20 6d 61 6e 69 66 65 73 74 5f 66 69 6c 65   ( manifest_file
5760: 5f 6d 70 65 72 6d 28 70 46 69 6c 65 29 3d 3d 50  _mperm(pFile)==P
5770: 45 52 4d 5f 4c 4e 4b 20 29 3b 0a 20 20 20 20 20  ERM_LNK );.     
5780: 20 6d 61 6e 69 66 65 73 74 5f 64 65 73 74 72 6f   manifest_destro
5790: 79 28 70 4d 61 6e 69 66 65 73 74 29 3b 0a 20 20  y(pManifest);.  
57a0: 20 20 20 20 72 63 20 3d 20 63 6f 6e 74 65 6e 74      rc = content
57b0: 5f 67 65 74 28 72 69 64 2c 20 63 6f 6e 74 65 6e  _get(rid, conten
57c0: 74 29 3b 0a 20 20 20 20 20 20 69 66 28 20 72 63  t);.      if( rc
57d0: 20 26 26 20 70 49 73 42 69 6e 20 29 7b 0a 20 20   && pIsBin ){.  
57e0: 20 20 20 20 20 20 2a 70 49 73 42 69 6e 20 3d 20        *pIsBin = 
57f0: 6c 6f 6f 6b 73 5f 6c 69 6b 65 5f 62 69 6e 61 72  looks_like_binar
5800: 79 28 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 20 20  y(content);.    
5810: 20 20 7d 0a 20 20 20 20 20 20 72 65 74 75 72 6e    }.      return
5820: 20 72 63 3b 0a 20 20 20 20 7d 0a 20 20 20 20 6d   rc;.    }.    m
5830: 61 6e 69 66 65 73 74 5f 64 65 73 74 72 6f 79 28  anifest_destroy(
5840: 70 4d 61 6e 69 66 65 73 74 29 3b 0a 20 20 20 20  pManifest);.    
5850: 69 66 28 20 65 72 72 43 6f 64 65 3c 3d 30 20 29  if( errCode<=0 )
5860: 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66  {.      fossil_f
5870: 61 74 61 6c 28 22 66 69 6c 65 20 25 73 20 64 6f  atal("file %s do
5880: 65 73 20 6e 6f 74 20 65 78 69 73 74 20 69 6e 20  es not exist in 
5890: 63 68 65 63 6b 69 6e 3a 20 25 73 22 2c 20 66 69  checkin: %s", fi
58a0: 6c 65 2c 20 72 65 76 69 73 69 6f 6e 29 3b 0a 20  le, revision);. 
58b0: 20 20 20 7d 0a 20 20 7d 65 6c 73 65 20 69 66 28     }.  }else if(
58c0: 20 65 72 72 43 6f 64 65 3c 3d 30 20 29 7b 0a 20   errCode<=0 ){. 
58d0: 20 20 20 69 66 28 20 72 65 76 69 73 69 6f 6e 3d     if( revision=
58e0: 3d 30 20 29 7b 0a 20 20 20 20 20 20 72 65 76 69  =0 ){.      revi
58f0: 73 69 6f 6e 20 3d 20 64 62 5f 74 65 78 74 28 22  sion = db_text("
5900: 63 75 72 72 65 6e 74 22 2c 20 22 53 45 4c 45 43  current", "SELEC
5910: 54 20 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62  T uuid FROM blob
5920: 20 57 48 45 52 45 20 72 69 64 3d 25 64 22 2c 20   WHERE rid=%d", 
5930: 72 69 64 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20  rid);.    }.    
5940: 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 63 6f  fossil_panic("co
5950: 75 6c 64 20 6e 6f 74 20 70 61 72 73 65 20 6d 61  uld not parse ma
5960: 6e 69 66 65 73 74 20 66 6f 72 20 63 68 65 63 6b  nifest for check
5970: 69 6e 3a 20 25 73 22 2c 20 72 65 76 69 73 69 6f  in: %s", revisio
5980: 6e 29 3b 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e  n);.  }.  return
5990: 20 65 72 72 43 6f 64 65 3b 0a 7d 0a 0a 0a 2f 2a   errCode;.}.../*
59a0: 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 72 65 76  .** COMMAND: rev
59b0: 65 72 74 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a  ert.**.** Usage:
59c0: 20 25 66 6f 73 73 69 6c 20 72 65 76 65 72 74 20   %fossil revert 
59d0: 3f 2d 72 20 52 45 56 49 53 49 4f 4e 3f 20 3f 46  ?-r REVISION? ?F
59e0: 49 4c 45 20 2e 2e 2e 3f 0a 2a 2a 0a 2a 2a 20 52  ILE ...?.**.** R
59f0: 65 76 65 72 74 20 74 6f 20 74 68 65 20 63 75 72  evert to the cur
5a00: 72 65 6e 74 20 72 65 70 6f 73 69 74 6f 72 79 20  rent repository 
5a10: 76 65 72 73 69 6f 6e 20 6f 66 20 46 49 4c 45 2c  version of FILE,
5a20: 20 6f 72 20 74 6f 0a 2a 2a 20 74 68 65 20 76 65   or to.** the ve
5a30: 72 73 69 6f 6e 20 61 73 73 6f 63 69 61 74 65 64  rsion associated
5a40: 20 77 69 74 68 20 62 61 73 65 6c 69 6e 65 20 52   with baseline R
5a50: 45 56 49 53 49 4f 4e 20 69 66 20 74 68 65 20 2d  EVISION if the -
5a60: 72 20 66 6c 61 67 0a 2a 2a 20 61 70 70 65 61 72  r flag.** appear
5a70: 73 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 46 49 4c 45  s..**.** If FILE
5a80: 20 77 61 73 20 70 61 72 74 20 6f 66 20 61 20 72   was part of a r
5a90: 65 6e 61 6d 65 20 6f 70 65 72 61 74 69 6f 6e 2c  ename operation,
5aa0: 20 62 6f 74 68 20 74 68 65 20 6f 72 69 67 69 6e   both the origin
5ab0: 61 6c 20 66 69 6c 65 0a 2a 2a 20 61 6e 64 20 74  al file.** and t
5ac0: 68 65 20 72 65 6e 61 6d 65 64 20 66 69 6c 65 20  he renamed file 
5ad0: 61 72 65 20 72 65 76 65 72 74 65 64 2e 0a 2a 2a  are reverted..**
5ae0: 0a 2a 2a 20 52 65 76 65 72 74 20 61 6c 6c 20 66  .** Revert all f
5af0: 69 6c 65 73 20 69 66 20 6e 6f 20 66 69 6c 65 20  iles if no file 
5b00: 6e 61 6d 65 20 69 73 20 70 72 6f 76 69 64 65 64  name is provided
5b10: 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 61 20 66 69 6c  ..**.** If a fil
5b20: 65 20 69 73 20 72 65 76 65 72 74 65 64 20 61 63  e is reverted ac
5b30: 63 69 64 65 6e 74 6c 79 2c 20 69 74 20 63 61 6e  cidently, it can
5b40: 20 62 65 20 72 65 73 74 6f 72 65 64 20 75 73 69   be restored usi
5b50: 6e 67 0a 2a 2a 20 74 68 65 20 22 66 6f 73 73 69  ng.** the "fossi
5b60: 6c 20 75 6e 64 6f 22 20 63 6f 6d 6d 61 6e 64 2e  l undo" command.
5b70: 0a 2a 2a 0a 2a 2a 20 4f 70 74 69 6f 6e 73 3a 0a  .**.** Options:.
5b80: 2a 2a 20 20 20 2d 72 20 52 45 56 49 53 49 4f 4e  **   -r REVISION
5b90: 20 20 20 20 72 65 76 65 72 74 20 67 69 76 65 6e      revert given
5ba0: 20 46 49 4c 45 28 73 29 20 62 61 63 6b 20 74 6f   FILE(s) back to
5bb0: 20 67 69 76 65 6e 20 52 45 56 49 53 49 4f 4e 0a   given REVISION.
5bc0: 2a 2a 0a 2a 2a 20 53 65 65 20 61 6c 73 6f 3a 20  **.** See also: 
5bd0: 72 65 64 6f 2c 20 75 6e 64 6f 2c 20 75 70 64 61  redo, undo, upda
5be0: 74 65 0a 2a 2f 0a 76 6f 69 64 20 72 65 76 65 72  te.*/.void rever
5bf0: 74 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 63  t_cmd(void){.  c
5c00: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 46 69 6c 65  onst char *zFile
5c10: 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  ;.  const char *
5c20: 7a 52 65 76 69 73 69 6f 6e 3b 0a 20 20 42 6c 6f  zRevision;.  Blo
5c30: 62 20 72 65 63 6f 72 64 3b 0a 20 20 69 6e 74 20  b record;.  int 
5c40: 69 3b 0a 20 20 69 6e 74 20 65 72 72 43 6f 64 65  i;.  int errCode
5c50: 3b 0a 20 20 53 74 6d 74 20 71 3b 0a 0a 20 20 75  ;.  Stmt q;..  u
5c60: 6e 64 6f 5f 63 61 70 74 75 72 65 5f 63 6f 6d 6d  ndo_capture_comm
5c70: 61 6e 64 5f 6c 69 6e 65 28 29 3b 20 20 0a 20 20  and_line();  .  
5c80: 7a 52 65 76 69 73 69 6f 6e 20 3d 20 66 69 6e 64  zRevision = find
5c90: 5f 6f 70 74 69 6f 6e 28 22 72 65 76 69 73 69 6f  _option("revisio
5ca0: 6e 22 2c 20 22 72 22 2c 20 31 29 3b 0a 20 20 76  n", "r", 1);.  v
5cb0: 65 72 69 66 79 5f 61 6c 6c 5f 6f 70 74 69 6f 6e  erify_all_option
5cc0: 73 28 29 3b 0a 20 20 0a 20 20 69 66 28 20 67 2e  s();.  .  if( g.
5cd0: 61 72 67 63 3c 32 20 29 7b 0a 20 20 20 20 75 73  argc<2 ){.    us
5ce0: 61 67 65 28 22 3f 4f 50 54 49 4f 4e 53 3f 20 5b  age("?OPTIONS? [
5cf0: 46 49 4c 45 5d 20 2e 2e 2e 22 29 3b 0a 20 20 7d  FILE] ...");.  }
5d00: 0a 20 20 69 66 28 20 7a 52 65 76 69 73 69 6f 6e  .  if( zRevision
5d10: 20 26 26 20 67 2e 61 72 67 63 3c 33 20 29 7b 0a   && g.argc<3 ){.
5d20: 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c      fossil_fatal
5d30: 28 22 74 68 65 20 2d 2d 72 65 76 69 73 69 6f 6e  ("the --revision
5d40: 20 6f 70 74 69 6f 6e 20 64 6f 65 73 20 6e 6f 74   option does not
5d50: 20 77 6f 72 6b 20 66 6f 72 20 74 68 65 20 65 6e   work for the en
5d60: 74 69 72 65 20 74 72 65 65 22 29 3b 0a 20 20 7d  tire tree");.  }
5d70: 0a 20 20 64 62 5f 6d 75 73 74 5f 62 65 5f 77 69  .  db_must_be_wi
5d80: 74 68 69 6e 5f 74 72 65 65 28 29 3b 0a 20 20 64  thin_tree();.  d
5d90: 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61 63 74  b_begin_transact
5da0: 69 6f 6e 28 29 3b 0a 20 20 75 6e 64 6f 5f 62 65  ion();.  undo_be
5db0: 67 69 6e 28 29 3b 0a 20 20 64 62 5f 6d 75 6c 74  gin();.  db_mult
5dc0: 69 5f 65 78 65 63 28 22 43 52 45 41 54 45 20 54  i_exec("CREATE T
5dd0: 45 4d 50 20 54 41 42 4c 45 20 74 6f 72 65 76 65  EMP TABLE toreve
5de0: 72 74 28 6e 61 6d 65 20 55 4e 49 51 55 45 29 3b  rt(name UNIQUE);
5df0: 22 29 3b 0a 0a 20 20 69 66 28 20 67 2e 61 72 67  ");..  if( g.arg
5e00: 63 3e 32 20 29 7b 0a 20 20 20 20 66 6f 72 28 69  c>2 ){.    for(i
5e10: 3d 32 3b 20 69 3c 67 2e 61 72 67 63 3b 20 69 2b  =2; i<g.argc; i+
5e20: 2b 29 7b 0a 20 20 20 20 20 20 42 6c 6f 62 20 66  +){.      Blob f
5e30: 6e 61 6d 65 3b 0a 20 20 20 20 20 20 7a 46 69 6c  name;.      zFil
5e40: 65 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 2f 22  e = mprintf("%/"
5e50: 2c 20 67 2e 61 72 67 76 5b 69 5d 29 3b 0a 20 20  , g.argv[i]);.  
5e60: 20 20 20 20 66 69 6c 65 5f 74 72 65 65 5f 6e 61      file_tree_na
5e70: 6d 65 28 7a 46 69 6c 65 2c 20 26 66 6e 61 6d 65  me(zFile, &fname
5e80: 2c 20 31 29 3b 0a 20 20 20 20 20 20 64 62 5f 6d  , 1);.      db_m
5e90: 75 6c 74 69 5f 65 78 65 63 28 0a 20 20 20 20 20  ulti_exec(.     
5ea0: 20 20 20 22 52 45 50 4c 41 43 45 20 49 4e 54 4f     "REPLACE INTO
5eb0: 20 74 6f 72 65 76 65 72 74 20 56 41 4c 55 45 53   torevert VALUES
5ec0: 28 25 42 29 3b 22 0a 20 20 20 20 20 20 20 20 22  (%B);".        "
5ed0: 49 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 45  INSERT OR IGNORE
5ee0: 20 49 4e 54 4f 20 74 6f 72 65 76 65 72 74 22 0a   INTO torevert".
5ef0: 20 20 20 20 20 20 20 20 22 20 53 45 4c 45 43 54          " SELECT
5f00: 20 70 61 74 68 6e 61 6d 65 22 0a 20 20 20 20 20   pathname".     
5f10: 20 20 20 22 20 20 20 46 52 4f 4d 20 76 66 69 6c     "   FROM vfil
5f20: 65 22 0a 20 20 20 20 20 20 20 20 22 20 20 57 48  e".        "  WH
5f30: 45 52 45 20 6f 72 69 67 6e 61 6d 65 20 49 4e 28  ERE origname IN(
5f40: 25 42 29 22 0a 20 20 20 20 20 20 20 20 22 20 55  %B)".        " U
5f50: 4e 49 4f 4e 20 41 4c 4c 22 0a 20 20 20 20 20 20  NION ALL".      
5f60: 20 20 22 20 53 45 4c 45 43 54 20 6f 72 69 67 6e    " SELECT orign
5f70: 61 6d 65 22 0a 20 20 20 20 20 20 20 20 22 20 20  ame".        "  
5f80: 20 46 52 4f 4d 20 76 66 69 6c 65 22 0a 20 20 20   FROM vfile".   
5f90: 20 20 20 20 20 22 20 20 57 48 45 52 45 20 70 61       "  WHERE pa
5fa0: 74 68 6e 61 6d 65 20 49 4e 28 25 42 29 20 41 4e  thname IN(%B) AN
5fb0: 44 20 6f 72 69 67 6e 61 6d 65 20 49 53 20 4e 4f  D origname IS NO
5fc0: 54 20 4e 55 4c 4c 3b 22 2c 0a 20 20 20 20 20 20  T NULL;",.      
5fd0: 20 20 26 66 6e 61 6d 65 2c 20 26 66 6e 61 6d 65    &fname, &fname
5fe0: 2c 20 26 66 6e 61 6d 65 0a 20 20 20 20 20 20 29  , &fname.      )
5ff0: 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73  ;.      blob_res
6000: 65 74 28 26 66 6e 61 6d 65 29 3b 0a 20 20 20 20  et(&fname);.    
6010: 7d 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 69  }.  }else{.    i
6020: 6e 74 20 76 69 64 3b 0a 20 20 20 20 76 69 64 20  nt vid;.    vid 
6030: 3d 20 64 62 5f 6c 67 65 74 5f 69 6e 74 28 22 63  = db_lget_int("c
6040: 68 65 63 6b 6f 75 74 22 2c 20 30 29 3b 0a 20 20  heckout", 0);.  
6050: 20 20 76 66 69 6c 65 5f 63 68 65 63 6b 5f 73 69    vfile_check_si
6060: 67 6e 61 74 75 72 65 28 76 69 64 2c 20 30 29 3b  gnature(vid, 0);
6070: 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78  .    db_multi_ex
6080: 65 63 28 0a 20 20 20 20 20 20 22 44 45 4c 45 54  ec(.      "DELET
6090: 45 20 46 52 4f 4d 20 76 6d 65 72 67 65 3b 22 0a  E FROM vmerge;".
60a0: 20 20 20 20 20 20 22 49 4e 53 45 52 54 20 4f 52        "INSERT OR
60b0: 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 74 6f 72   IGNORE INTO tor
60c0: 65 76 65 72 74 20 22 0a 20 20 20 20 20 20 22 20  evert ".      " 
60d0: 53 45 4c 45 43 54 20 70 61 74 68 6e 61 6d 65 22  SELECT pathname"
60e0: 0a 20 20 20 20 20 20 22 20 20 20 46 52 4f 4d 20  .      "   FROM 
60f0: 76 66 69 6c 65 20 22 0a 20 20 20 20 20 20 22 20  vfile ".      " 
6100: 20 57 48 45 52 45 20 63 68 6e 67 65 64 20 4f 52   WHERE chnged OR
6110: 20 64 65 6c 65 74 65 64 20 4f 52 20 72 69 64 3d   deleted OR rid=
6120: 30 20 4f 52 20 70 61 74 68 6e 61 6d 65 21 3d 6f  0 OR pathname!=o
6130: 72 69 67 6e 61 6d 65 20 22 0a 20 20 20 20 20 20  rigname ".      
6140: 22 20 55 4e 49 4f 4e 20 41 4c 4c 20 22 0a 20 20  " UNION ALL ".  
6150: 20 20 20 20 22 20 53 45 4c 45 43 54 20 6f 72 69      " SELECT ori
6160: 67 6e 61 6d 65 22 0a 20 20 20 20 20 20 22 20 20  gname".      "  
6170: 20 46 52 4f 4d 20 76 66 69 6c 65 22 0a 20 20 20   FROM vfile".   
6180: 20 20 20 22 20 20 57 48 45 52 45 20 6f 72 69 67     "  WHERE orig
6190: 6e 61 6d 65 21 3d 70 61 74 68 6e 61 6d 65 3b 22  name!=pathname;"
61a0: 0a 20 20 20 20 29 3b 0a 20 20 7d 0a 20 20 62 6c  .    );.  }.  bl
61b0: 6f 62 5f 7a 65 72 6f 28 26 72 65 63 6f 72 64 29  ob_zero(&record)
61c0: 3b 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26  ;.  db_prepare(&
61d0: 71 2c 20 22 53 45 4c 45 43 54 20 6e 61 6d 65 20  q, "SELECT name 
61e0: 46 52 4f 4d 20 74 6f 72 65 76 65 72 74 22 29 3b  FROM torevert");
61f0: 0a 20 20 69 66 28 20 7a 52 65 76 69 73 69 6f 6e  .  if( zRevision
6200: 3d 3d 30 20 29 7b 0a 20 20 20 20 69 6e 74 20 76  ==0 ){.    int v
6210: 69 64 20 3d 20 64 62 5f 6c 67 65 74 5f 69 6e 74  id = db_lget_int
6220: 28 22 63 68 65 63 6b 6f 75 74 22 2c 20 30 29 3b  ("checkout", 0);
6230: 0a 20 20 20 20 7a 52 65 76 69 73 69 6f 6e 20 3d  .    zRevision =
6240: 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 45 4c   db_text(0, "SEL
6250: 45 43 54 20 75 75 69 64 20 46 52 4f 4d 20 62 6c  ECT uuid FROM bl
6260: 6f 62 20 57 48 45 52 45 20 72 69 64 3d 25 64 22  ob WHERE rid=%d"
6270: 2c 20 76 69 64 29 3b 0a 20 20 7d 0a 20 20 77 68  , vid);.  }.  wh
6280: 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 29  ile( db_step(&q)
6290: 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a  ==SQLITE_ROW ){.
62a0: 20 20 20 20 69 6e 74 20 69 73 45 78 65 20 3d 20      int isExe = 
62b0: 30 3b 0a 20 20 20 20 69 6e 74 20 69 73 4c 69 6e  0;.    int isLin
62c0: 6b 20 3d 20 30 3b 0a 20 20 20 20 63 68 61 72 20  k = 0;.    char 
62d0: 2a 7a 46 75 6c 6c 3b 0a 20 20 20 20 7a 46 69 6c  *zFull;.    zFil
62e0: 65 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65  e = db_column_te
62f0: 78 74 28 26 71 2c 20 30 29 3b 0a 20 20 20 20 7a  xt(&q, 0);.    z
6300: 46 75 6c 6c 20 3d 20 6d 70 72 69 6e 74 66 28 22  Full = mprintf("
6310: 25 2f 25 2f 22 2c 20 67 2e 7a 4c 6f 63 61 6c 52  %/%/", g.zLocalR
6320: 6f 6f 74 2c 20 7a 46 69 6c 65 29 3b 0a 20 20 20  oot, zFile);.   
6330: 20 65 72 72 43 6f 64 65 20 3d 20 68 69 73 74 6f   errCode = histo
6340: 72 69 63 61 6c 5f 76 65 72 73 69 6f 6e 5f 6f 66  rical_version_of
6350: 5f 66 69 6c 65 28 7a 52 65 76 69 73 69 6f 6e 2c  _file(zRevision,
6360: 20 7a 46 69 6c 65 2c 20 26 72 65 63 6f 72 64 2c   zFile, &record,
6370: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
6380: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
6390: 20 20 20 20 20 20 20 20 20 20 26 69 73 4c 69 6e            &isLin
63a0: 6b 2c 20 26 69 73 45 78 65 2c 20 30 2c 20 32 29  k, &isExe, 0, 2)
63b0: 3b 0a 20 20 20 20 69 66 28 20 65 72 72 43 6f 64  ;.    if( errCod
63c0: 65 3d 3d 32 20 29 7b 0a 20 20 20 20 20 20 69 66  e==2 ){.      if
63d0: 28 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c  ( db_int(0, "SEL
63e0: 45 43 54 20 72 69 64 20 46 52 4f 4d 20 76 66 69  ECT rid FROM vfi
63f0: 6c 65 20 57 48 45 52 45 20 70 61 74 68 6e 61 6d  le WHERE pathnam
6400: 65 3d 25 51 20 4f 52 20 6f 72 69 67 6e 61 6d 65  e=%Q OR origname
6410: 3d 25 51 22 2c 0a 20 20 20 20 20 20 20 20 20 20  =%Q",.          
6420: 20 20 20 20 20 20 20 7a 46 69 6c 65 2c 20 7a 46         zFile, zF
6430: 69 6c 65 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20  ile)==0 ){.     
6440: 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e 74 28     fossil_print(
6450: 22 55 4e 4d 41 4e 41 47 45 3a 20 25 73 5c 6e 22  "UNMANAGE: %s\n"
6460: 2c 20 7a 46 69 6c 65 29 3b 0a 20 20 20 20 20 20  , zFile);.      
6470: 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20 20 75  }else{.        u
6480: 6e 64 6f 5f 73 61 76 65 28 7a 46 69 6c 65 29 3b  ndo_save(zFile);
6490: 0a 20 20 20 20 20 20 20 20 66 69 6c 65 5f 64 65  .        file_de
64a0: 6c 65 74 65 28 7a 46 75 6c 6c 29 3b 0a 20 20 20  lete(zFull);.   
64b0: 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 72 69 6e       fossil_prin
64c0: 74 28 22 44 45 4c 45 54 45 3a 20 25 73 5c 6e 22  t("DELETE: %s\n"
64d0: 2c 20 7a 46 69 6c 65 29 3b 0a 20 20 20 20 20 20  , zFile);.      
64e0: 7d 0a 20 20 20 20 20 20 64 62 5f 6d 75 6c 74 69  }.      db_multi
64f0: 5f 65 78 65 63 28 0a 20 20 20 20 20 20 20 20 22  _exec(.        "
6500: 55 50 44 41 54 45 20 76 66 69 6c 65 22 0a 20 20  UPDATE vfile".  
6510: 20 20 20 20 20 20 22 20 20 20 53 45 54 20 70 61        "   SET pa
6520: 74 68 6e 61 6d 65 3d 6f 72 69 67 6e 61 6d 65 2c  thname=origname,
6530: 20 6f 72 69 67 6e 61 6d 65 3d 4e 55 4c 4c 22 0a   origname=NULL".
6540: 20 20 20 20 20 20 20 20 22 20 57 48 45 52 45 20          " WHERE 
6550: 70 61 74 68 6e 61 6d 65 3d 25 51 20 41 4e 44 20  pathname=%Q AND 
6560: 6f 72 69 67 6e 61 6d 65 21 3d 70 61 74 68 6e 61  origname!=pathna
6570: 6d 65 20 41 4e 44 20 6f 72 69 67 6e 61 6d 65 20  me AND origname 
6580: 49 53 20 4e 4f 54 20 4e 55 4c 4c 3b 22 0a 20 20  IS NOT NULL;".  
6590: 20 20 20 20 20 20 22 44 45 4c 45 54 45 20 46 52        "DELETE FR
65a0: 4f 4d 20 76 66 69 6c 65 20 57 48 45 52 45 20 70  OM vfile WHERE p
65b0: 61 74 68 6e 61 6d 65 3d 25 51 22 2c 0a 20 20 20  athname=%Q",.   
65c0: 20 20 20 20 20 7a 46 69 6c 65 2c 20 7a 46 69 6c       zFile, zFil
65d0: 65 0a 20 20 20 20 20 20 29 3b 0a 20 20 20 20 7d  e.      );.    }
65e0: 65 6c 73 65 7b 0a 20 20 20 20 20 20 73 71 6c 69  else{.      sqli
65f0: 74 65 33 5f 69 6e 74 36 34 20 6d 74 69 6d 65 3b  te3_int64 mtime;
6600: 0a 20 20 20 20 20 20 75 6e 64 6f 5f 73 61 76 65  .      undo_save
6610: 28 7a 46 69 6c 65 29 3b 0a 20 20 20 20 20 20 69  (zFile);.      i
6620: 66 28 20 66 69 6c 65 5f 77 64 5f 73 69 7a 65 28  f( file_wd_size(
6630: 7a 46 75 6c 6c 29 3e 3d 30 20 26 26 20 28 69 73  zFull)>=0 && (is
6640: 4c 69 6e 6b 20 7c 7c 20 66 69 6c 65 5f 77 64 5f  Link || file_wd_
6650: 69 73 6c 69 6e 6b 28 7a 46 75 6c 6c 29 29 20 29  islink(zFull)) )
6660: 7b 0a 20 20 20 20 20 20 20 20 66 69 6c 65 5f 64  {.        file_d
6670: 65 6c 65 74 65 28 7a 46 75 6c 6c 29 3b 0a 20 20  elete(zFull);.  
6680: 20 20 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20      }.      if( 
6690: 69 73 4c 69 6e 6b 20 29 7b 0a 20 20 20 20 20 20  isLink ){.      
66a0: 20 20 73 79 6d 6c 69 6e 6b 5f 63 72 65 61 74 65    symlink_create
66b0: 28 62 6c 6f 62 5f 73 74 72 28 26 72 65 63 6f 72  (blob_str(&recor
66c0: 64 29 2c 20 7a 46 75 6c 6c 29 3b 0a 20 20 20 20  d), zFull);.    
66d0: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20    }else{.       
66e0: 20 62 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f 66   blob_write_to_f
66f0: 69 6c 65 28 26 72 65 63 6f 72 64 2c 20 7a 46 75  ile(&record, zFu
6700: 6c 6c 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20  ll);.      }.   
6710: 20 20 20 66 69 6c 65 5f 77 64 5f 73 65 74 65 78     file_wd_setex
6720: 65 28 7a 46 75 6c 6c 2c 20 69 73 45 78 65 29 3b  e(zFull, isExe);
6730: 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 70 72  .      fossil_pr
6740: 69 6e 74 28 22 52 45 56 45 52 54 45 44 3a 20 25  int("REVERTED: %
6750: 73 5c 6e 22 2c 20 7a 46 69 6c 65 29 3b 0a 20 20  s\n", zFile);.  
6760: 20 20 20 20 6d 74 69 6d 65 20 3d 20 66 69 6c 65      mtime = file
6770: 5f 77 64 5f 6d 74 69 6d 65 28 7a 46 75 6c 6c 29  _wd_mtime(zFull)
6780: 3b 0a 20 20 20 20 20 20 64 62 5f 6d 75 6c 74 69  ;.      db_multi
6790: 5f 65 78 65 63 28 0a 20 20 20 20 20 20 20 20 20  _exec(.         
67a0: 22 55 50 44 41 54 45 20 76 66 69 6c 65 22 0a 20  "UPDATE vfile". 
67b0: 20 20 20 20 20 20 20 20 22 20 20 20 53 45 54 20          "   SET 
67c0: 6d 74 69 6d 65 3d 25 6c 6c 64 2c 20 63 68 6e 67  mtime=%lld, chng
67d0: 65 64 3d 30 2c 20 64 65 6c 65 74 65 64 3d 30 2c  ed=0, deleted=0,
67e0: 20 69 73 65 78 65 3d 25 64 2c 20 69 73 6c 69 6e   isexe=%d, islin
67f0: 6b 3d 25 64 2c 6d 72 69 64 3d 72 69 64 22 0a 20  k=%d,mrid=rid". 
6800: 20 20 20 20 20 20 20 20 22 20 57 48 45 52 45 20          " WHERE 
6810: 70 61 74 68 6e 61 6d 65 3d 25 51 20 4f 52 20 6f  pathname=%Q OR o
6820: 72 69 67 6e 61 6d 65 3d 25 51 22 2c 0a 20 20 20  rigname=%Q",.   
6830: 20 20 20 20 20 20 6d 74 69 6d 65 2c 20 69 73 45        mtime, isE
6840: 78 65 2c 20 69 73 4c 69 6e 6b 2c 20 7a 46 69 6c  xe, isLink, zFil
6850: 65 2c 20 7a 46 69 6c 65 0a 20 20 20 20 20 20 29  e, zFile.      )
6860: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 62 6c 6f 62  ;.    }.    blob
6870: 5f 72 65 73 65 74 28 26 72 65 63 6f 72 64 29 3b  _reset(&record);
6880: 0a 20 20 20 20 66 72 65 65 28 7a 46 75 6c 6c 29  .    free(zFull)
6890: 3b 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c  ;.  }.  db_final
68a0: 69 7a 65 28 26 71 29 3b 0a 20 20 75 6e 64 6f 5f  ize(&q);.  undo_
68b0: 66 69 6e 69 73 68 28 29 3b 0a 20 20 64 62 5f 65  finish();.  db_e
68c0: 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30  nd_transaction(0
68d0: 29 3b 0a 7d 0a                                   );.}.