Hex Artifact Content
Not logged in

Artifact abfa21b27a1cc1cf3c508533550ac5d9529bc308:

File src/update.c part of check-in [7eecb079ed] - Cleanup of the safemerge flag on update. Override available using the --force option. by drh on 2007-09-26 16:20:41.

0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20  /*.** Copyright 
0010: 28 63 29 20 32 30 30 37 20 44 2e 20 52 69 63 68  (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54  ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66  his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f  ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75  u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20  te it and/or.** 
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20  modify it under 
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65  the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76  lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c  ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65  ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69  ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73  s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20  tributed in the 
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c  hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20  l be useful,.** 
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20  but WITHOUT ANY 
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75  WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69  t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a  ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54  * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52  Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55   A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20  RPOSE.  See the 
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50  GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f  ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a  r more details..
01e0: 2a 2a 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c  ** .** You shoul
01f0: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20  d have received 
0200: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e  a copy of the GN
0210: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63  U General Public
0220: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e  .** License alon
0230: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72  g with this libr
0240: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69  ary; if not, wri
0250: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65  te to the.** Fre
0260: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
0270: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20  ation, Inc., 59 
0280: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53  Temple Place - S
0290: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73  uite 330,.** Bos
02a0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31  ton, MA  02111-1
02b0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20  307, USA..**.** 
02c0: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69  Author contact i
02d0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20  nformation:.**  
02e0: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a   drh@hwaci.com.*
02f0: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68  *   http://www.h
0300: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a  waci.com/drh/.**
0310: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  .***************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0360: 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 66 69 6c 65  .**.** This file
0370: 20 63 6f 6e 74 61 69 6e 73 20 63 6f 64 65 20 75   contains code u
0380: 73 65 64 20 74 6f 20 6d 65 72 67 65 20 74 68 65  sed to merge the
0390: 20 63 68 61 6e 67 65 73 20 69 6e 20 74 68 65 20   changes in the 
03a0: 63 75 72 72 65 6e 74 0a 2a 2a 20 63 68 65 63 6b  current.** check
03b0: 6f 75 74 20 69 6e 74 6f 20 61 20 64 69 66 66 65  out into a diffe
03c0: 72 65 6e 74 20 76 65 72 73 69 6f 6e 20 61 6e 64  rent version and
03d0: 20 73 77 69 74 63 68 20 74 6f 20 74 68 61 74 20   switch to that 
03e0: 76 65 72 73 69 6f 6e 2e 0a 2a 2f 0a 23 69 6e 63  version..*/.#inc
03f0: 6c 75 64 65 20 22 63 6f 6e 66 69 67 2e 68 22 0a  lude "config.h".
0400: 23 69 6e 63 6c 75 64 65 20 22 75 70 64 61 74 65  #include "update
0410: 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 3c 61 73  .h".#include <as
0420: 73 65 72 74 2e 68 3e 0a 0a 2f 2a 0a 2a 2a 20 52  sert.h>../*.** R
0430: 65 74 75 72 6e 20 74 72 75 65 20 69 66 20 61 72  eturn true if ar
0440: 74 69 66 61 63 74 20 72 69 64 20 69 73 20 61 20  tifact rid is a 
0450: 76 65 72 73 69 6f 6e 0a 2a 2f 0a 69 6e 74 20 69  version.*/.int i
0460: 73 5f 61 5f 76 65 72 73 69 6f 6e 28 69 6e 74 20  s_a_version(int 
0470: 72 69 64 29 7b 0a 20 20 72 65 74 75 72 6e 20 64  rid){.  return d
0480: 62 5f 65 78 69 73 74 73 28 22 53 45 4c 45 43 54  b_exists("SELECT
0490: 20 31 20 46 52 4f 4d 20 70 6c 69 6e 6b 20 57 48   1 FROM plink WH
04a0: 45 52 45 20 63 69 64 3d 25 64 22 2c 20 72 69 64  ERE cid=%d", rid
04b0: 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d  );.}../*.** COMM
04c0: 41 4e 44 3a 20 75 70 64 61 74 65 0a 2a 2a 0a 2a  AND: update.**.*
04d0: 2a 20 55 73 61 67 65 3a 20 25 66 6f 73 73 69 6c  * Usage: %fossil
04e0: 20 75 70 64 61 74 65 20 3f 56 45 52 53 49 4f 4e   update ?VERSION
04f0: 3f 20 3f 2d 2d 66 6f 72 63 65 3f 20 3f 2d 2d 6c  ? ?--force? ?--l
0500: 61 74 65 73 74 3f 0a 2a 2a 0a 2a 2a 20 54 68 65  atest?.**.** The
0510: 20 6f 70 74 69 6f 6e 61 6c 20 61 72 67 75 6d 65   optional argume
0520: 6e 74 20 69 73 20 61 20 76 65 72 73 69 6f 6e 20  nt is a version 
0530: 74 68 61 74 20 73 68 6f 75 6c 64 20 62 65 63 6f  that should beco
0540: 6d 65 20 74 68 65 20 63 75 72 72 65 6e 74 0a 2a  me the current.*
0550: 2a 20 76 65 72 73 69 6f 6e 2e 20 20 49 66 20 74  * version.  If t
0560: 68 65 20 61 72 67 75 6d 65 6e 74 20 69 73 20 6f  he argument is o
0570: 6d 69 74 74 65 64 2c 20 74 68 65 6e 20 75 73 65  mitted, then use
0580: 20 74 68 65 20 6c 65 61 66 20 6f 66 20 74 68 65   the leaf of the
0590: 0a 2a 2a 20 74 72 65 65 20 74 68 61 74 20 62 65  .** tree that be
05a0: 67 69 6e 73 20 77 69 74 68 20 74 68 65 20 63 75  gins with the cu
05b0: 72 72 65 6e 74 20 76 65 72 73 69 6f 6e 2c 20 69  rrent version, i
05c0: 66 20 74 68 65 72 65 20 69 73 20 6f 6e 6c 79 20  f there is only 
05d0: 61 20 0a 2a 2a 20 73 69 6e 67 6c 65 20 6c 65 61  a .** single lea
05e0: 66 2e 20 20 49 66 20 74 68 65 72 65 20 61 72 65  f.  If there are
05f0: 20 61 20 6d 75 6c 74 69 70 6c 65 20 6c 65 61 76   a multiple leav
0600: 65 73 2c 20 74 68 65 20 6c 61 74 65 73 74 20 69  es, the latest i
0610: 73 20 75 73 65 64 0a 2a 2a 20 69 66 20 74 68 65  s used.** if the
0620: 20 2d 2d 6c 61 74 65 73 74 20 66 6c 61 67 20 69   --latest flag i
0630: 73 20 70 72 65 73 65 6e 74 2e 0a 2a 2a 0a 2a 2a  s present..**.**
0640: 20 54 68 69 73 20 63 6f 6d 6d 61 6e 64 20 69 73   This command is
0650: 20 64 69 66 66 65 72 65 6e 74 20 66 72 6f 6d 20   different from 
0660: 74 68 65 20 22 63 68 65 63 6b 6f 75 74 22 20 69  the "checkout" i
0670: 6e 20 74 68 61 74 20 65 64 69 74 73 20 61 72 65  n that edits are
0680: 0a 2a 2a 20 6e 6f 74 20 6f 76 65 72 77 72 69 74  .** not overwrit
0690: 74 65 6e 2e 20 20 45 64 69 74 73 20 61 72 65 20  ten.  Edits are 
06a0: 6d 65 72 67 65 64 20 69 6e 74 6f 20 74 68 65 20  merged into the 
06b0: 6e 65 77 20 76 65 72 73 69 6f 6e 2e 0a 2a 2a 0a  new version..**.
06c0: 2a 2a 20 49 66 20 74 68 65 72 65 20 61 72 65 20  ** If there are 
06d0: 75 6e 63 6f 6d 6d 69 74 74 65 64 20 65 64 69 74  uncommitted edit
06e0: 73 20 61 6e 64 20 74 68 65 20 73 61 66 65 6d 65  s and the safeme
06f0: 72 67 65 20 6f 70 74 69 6f 6e 20 69 73 0a 2a 2a  rge option is.**
0700: 20 65 6e 61 62 6c 65 64 20 74 68 65 6e 20 6e 6f   enabled then no
0710: 20 75 70 64 61 74 65 20 77 69 6c 6c 20 6f 63 63   update will occ
0720: 75 72 20 75 6e 6c 65 73 73 20 79 6f 75 20 70 72  ur unless you pr
0730: 6f 76 69 64 65 20 74 68 65 20 0a 2a 2a 20 2d 2d  ovide the .** --
0740: 66 6f 72 63 65 20 66 6c 61 67 2e 0a 2a 2f 0a 76  force flag..*/.v
0750: 6f 69 64 20 75 70 64 61 74 65 5f 63 6d 64 28 76  oid update_cmd(v
0760: 6f 69 64 29 7b 0a 20 20 69 6e 74 20 76 69 64 3b  oid){.  int vid;
0770: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a                /*
0780: 20 43 75 72 72 65 6e 74 20 76 65 72 73 69 6f 6e   Current version
0790: 20 2a 2f 0a 20 20 69 6e 74 20 74 69 64 3d 30 3b   */.  int tid=0;
07a0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54              /* T
07b0: 61 72 67 65 74 20 76 65 72 73 69 6f 6e 20 2d 20  arget version - 
07c0: 76 65 72 73 69 6f 6e 20 77 65 20 61 72 65 20 63  version we are c
07d0: 68 61 6e 67 69 6e 67 20 74 6f 20 2a 2f 0a 20 20  hanging to */.  
07e0: 53 74 6d 74 20 71 3b 0a 20 20 69 6e 74 20 6c 61  Stmt q;.  int la
07f0: 74 65 73 74 46 6c 61 67 3b 20 20 20 20 20 20 20  testFlag;       
0800: 2f 2a 20 50 69 63 6b 20 74 68 65 20 6c 61 74 65  /* Pick the late
0810: 73 74 20 76 65 72 73 69 6f 6e 20 69 66 20 74 72  st version if tr
0820: 75 65 20 2a 2f 0a 20 20 69 6e 74 20 66 6f 72 63  ue */.  int forc
0830: 65 46 6c 61 67 3b 20 20 20 20 20 20 20 20 2f 2a  eFlag;        /*
0840: 20 54 72 75 65 20 66 6f 72 63 65 20 74 68 65 20   True force the 
0850: 75 70 64 61 74 65 20 2a 2f 0a 0a 20 20 6c 61 74  update */..  lat
0860: 65 73 74 46 6c 61 67 20 3d 20 66 69 6e 64 5f 6f  estFlag = find_o
0870: 70 74 69 6f 6e 28 22 6c 61 74 65 73 74 22 2c 30  ption("latest",0
0880: 2c 20 30 29 21 3d 30 3b 0a 20 20 66 6f 72 63 65  , 0)!=0;.  force
0890: 46 6c 61 67 20 3d 20 66 69 6e 64 5f 6f 70 74 69  Flag = find_opti
08a0: 6f 6e 28 22 66 6f 72 63 65 22 2c 22 66 22 2c 30  on("force","f",0
08b0: 29 21 3d 30 3b 0a 20 20 69 66 28 20 67 2e 61 72  )!=0;.  if( g.ar
08c0: 67 63 21 3d 33 20 26 26 20 67 2e 61 72 67 63 21  gc!=3 && g.argc!
08d0: 3d 32 20 29 7b 0a 20 20 20 20 75 73 61 67 65 28  =2 ){.    usage(
08e0: 22 3f 56 45 52 53 49 4f 4e 3f 22 29 3b 0a 20 20  "?VERSION?");.  
08f0: 7d 0a 20 20 64 62 5f 6d 75 73 74 5f 62 65 5f 77  }.  db_must_be_w
0900: 69 74 68 69 6e 5f 74 72 65 65 28 29 3b 0a 20 20  ithin_tree();.  
0910: 76 69 64 20 3d 20 64 62 5f 6c 67 65 74 5f 69 6e  vid = db_lget_in
0920: 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 20 30 29  t("checkout", 0)
0930: 3b 0a 20 20 69 66 28 20 76 69 64 3d 3d 30 20 29  ;.  if( vid==0 )
0940: 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74  {.    fossil_fat
0950: 61 6c 28 22 63 61 6e 6e 6f 74 20 66 69 6e 64 20  al("cannot find 
0960: 63 75 72 72 65 6e 74 20 76 65 72 73 69 6f 6e 22  current version"
0970: 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 64 62 5f  );.  }.  if( db_
0980: 65 78 69 73 74 73 28 22 53 45 4c 45 43 54 20 31  exists("SELECT 1
0990: 20 46 52 4f 4d 20 76 6d 65 72 67 65 22 29 20 29   FROM vmerge") )
09a0: 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74  {.    fossil_fat
09b0: 61 6c 28 22 63 61 6e 6e 6f 74 20 75 70 64 61 74  al("cannot updat
09c0: 65 20 61 6e 20 75 6e 63 6f 6d 6d 69 74 74 65 64  e an uncommitted
09d0: 20 6d 65 72 67 65 22 29 3b 0a 20 20 7d 0a 20 20   merge");.  }.  
09e0: 69 66 28 20 21 66 6f 72 63 65 46 6c 61 67 20 26  if( !forceFlag &
09f0: 26 20 64 62 5f 67 65 74 5f 69 6e 74 28 22 73 61  & db_get_int("sa
0a00: 66 65 6d 65 72 67 65 22 2c 20 30 29 20 26 26 20  femerge", 0) && 
0a10: 75 6e 73 61 76 65 64 5f 63 68 61 6e 67 65 73 28  unsaved_changes(
0a20: 29 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f  ) ){.    fossil_
0a30: 66 61 74 61 6c 28 22 74 68 65 72 65 20 61 72 65  fatal("there are
0a40: 20 75 6e 63 6f 6d 6d 69 74 74 65 64 20 63 68 61   uncommitted cha
0a50: 6e 67 65 73 20 61 6e 64 20 73 61 66 65 6d 65 72  nges and safemer
0a60: 67 65 20 69 73 20 65 6e 61 62 6c 65 64 22 29 3b  ge is enabled");
0a70: 0a 20 20 7d 0a 0a 20 20 69 66 28 20 67 2e 61 72  .  }..  if( g.ar
0a80: 67 63 3d 3d 33 20 29 7b 0a 20 20 20 20 74 69 64  gc==3 ){.    tid
0a90: 20 3d 20 6e 61 6d 65 5f 74 6f 5f 72 69 64 28 67   = name_to_rid(g
0aa0: 2e 61 72 67 76 5b 32 5d 29 3b 0a 20 20 20 20 69  .argv[2]);.    i
0ab0: 66 28 20 74 69 64 3d 3d 30 20 29 7b 0a 20 20 20  f( tid==0 ){.   
0ac0: 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28     fossil_fatal(
0ad0: 22 6e 6f 74 20 61 20 76 65 72 73 69 6f 6e 3a 20  "not a version: 
0ae0: 25 73 22 2c 20 67 2e 61 72 67 76 5b 32 5d 29 3b  %s", g.argv[2]);
0af0: 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 21  .    }.    if( !
0b00: 69 73 5f 61 5f 76 65 72 73 69 6f 6e 28 74 69 64  is_a_version(tid
0b10: 29 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69  ) ){.      fossi
0b20: 6c 5f 66 61 74 61 6c 28 22 6e 6f 74 20 61 20 76  l_fatal("not a v
0b30: 65 72 73 69 6f 6e 3a 20 25 73 22 2c 20 67 2e 61  ersion: %s", g.a
0b40: 72 67 76 5b 32 5d 29 3b 0a 20 20 20 20 7d 0a 20  rgv[2]);.    }. 
0b50: 20 7d 0a 0a 20 20 69 66 28 20 74 69 64 3d 3d 30   }..  if( tid==0
0b60: 20 29 7b 0a 20 20 20 20 2f 2a 20 0a 20 20 20 20   ){.    /* .    
0b70: 2a 2a 20 44 6f 20 61 6e 20 61 75 74 6f 73 79 6e  ** Do an autosyn
0b80: 63 20 70 75 6c 6c 20 70 72 69 6f 72 20 74 6f 20  c pull prior to 
0b90: 74 68 65 20 75 70 64 61 74 65 2c 20 69 66 20 61  the update, if a
0ba0: 75 74 6f 73 79 6e 63 20 69 73 20 6f 6e 20 61 6e  utosync is on an
0bb0: 64 20 74 68 65 79 0a 20 20 20 20 2a 2a 20 64 69  d they.    ** di
0bc0: 64 20 6e 6f 74 20 77 61 6e 74 20 61 20 73 70 65  d not want a spe
0bd0: 63 69 66 69 63 20 76 65 72 73 69 6f 6e 20 28 69  cific version (i
0be0: 2e 65 2e 20 61 6e 6f 74 68 65 72 20 62 72 61 6e  .e. another bran
0bf0: 63 68 2c 20 61 20 70 61 73 74 20 72 65 76 69 73  ch, a past revis
0c00: 69 6f 6e 29 2e 0a 20 20 20 20 2a 2a 20 42 79 20  ion)..    ** By 
0c10: 6e 6f 74 20 67 69 76 69 6e 67 20 61 20 73 70 65  not giving a spe
0c20: 63 69 66 69 63 20 76 65 72 73 69 6f 6e 2c 20 74  cific version, t
0c30: 68 65 79 20 61 72 65 20 61 73 6b 69 6e 67 20 66  hey are asking f
0c40: 6f 72 20 74 68 65 20 6c 61 74 65 73 74 2c 20 74  or the latest, t
0c50: 68 75 73 0a 20 20 20 20 2a 2a 20 70 75 6c 6c 20  hus.    ** pull 
0c60: 74 6f 20 67 65 74 20 74 68 65 20 6c 61 74 65 73  to get the lates
0c70: 74 2c 20 74 68 65 6e 20 75 70 64 61 74 65 2e 0a  t, then update..
0c80: 20 20 20 20 2a 2f 0a 20 20 20 20 61 75 74 6f 73      */.    autos
0c90: 79 6e 63 28 31 29 3b 0a 20 20 7d 0a 20 20 0a 20  ync(1);.  }.  . 
0ca0: 20 69 66 28 20 74 69 64 3d 3d 30 20 29 7b 0a 20   if( tid==0 ){. 
0cb0: 20 20 20 63 6f 6d 70 75 74 65 5f 6c 65 61 76 65     compute_leave
0cc0: 73 28 76 69 64 29 3b 0a 20 20 20 20 69 66 28 20  s(vid);.    if( 
0cd0: 21 6c 61 74 65 73 74 46 6c 61 67 20 26 26 20 64  !latestFlag && d
0ce0: 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54  b_int(0, "SELECT
0cf0: 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 6c   count(*) FROM l
0d00: 65 61 76 65 73 22 29 3e 31 20 29 7b 0a 20 20 20  eaves")>1 ){.   
0d10: 20 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71     db_prepare(&q
0d20: 2c 20 0a 20 20 20 20 20 20 20 20 22 25 73 20 22  , .        "%s "
0d30: 0a 20 20 20 20 20 20 20 20 22 20 20 20 41 4e 44  .        "   AND
0d40: 20 65 76 65 6e 74 2e 6f 62 6a 69 64 20 49 4e 20   event.objid IN 
0d50: 6c 65 61 76 65 73 22 0a 20 20 20 20 20 20 20 20  leaves".        
0d60: 22 20 4f 52 44 45 52 20 42 59 20 65 76 65 6e 74  " ORDER BY event
0d70: 2e 6d 74 69 6d 65 20 44 45 53 43 22 2c 0a 20 20  .mtime DESC",.  
0d80: 20 20 20 20 20 20 74 69 6d 65 6c 69 6e 65 5f 71        timeline_q
0d90: 75 65 72 79 5f 66 6f 72 5f 74 74 79 28 29 0a 20  uery_for_tty(). 
0da0: 20 20 20 20 20 29 3b 0a 20 20 20 20 20 20 70 72       );.      pr
0db0: 69 6e 74 5f 74 69 6d 65 6c 69 6e 65 28 26 71 2c  int_timeline(&q,
0dc0: 20 31 30 30 29 3b 0a 20 20 20 20 20 20 64 62 5f   100);.      db_
0dd0: 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20  finalize(&q);.  
0de0: 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c      fossil_fatal
0df0: 28 22 4d 75 6c 74 69 70 6c 65 20 64 65 73 63 65  ("Multiple desce
0e00: 6e 64 65 6e 74 73 22 29 3b 0a 20 20 20 20 7d 0a  ndents");.    }.
0e10: 20 20 20 20 74 69 64 20 3d 20 64 62 5f 69 6e 74      tid = db_int
0e20: 28 30 2c 20 22 53 45 4c 45 43 54 20 72 69 64 20  (0, "SELECT rid 
0e30: 46 52 4f 4d 20 6c 65 61 76 65 73 2c 20 65 76 65  FROM leaves, eve
0e40: 6e 74 22 0a 20 20 20 20 20 20 20 20 20 20 20 20  nt".            
0e50: 20 20 20 20 20 20 20 20 22 20 57 48 45 52 45 20          " WHERE 
0e60: 65 76 65 6e 74 2e 6f 62 6a 69 64 3d 6c 65 61 76  event.objid=leav
0e70: 65 73 2e 72 69 64 22 0a 20 20 20 20 20 20 20 20  es.rid".        
0e80: 20 20 20 20 20 20 20 20 20 20 20 20 22 20 4f 52              " OR
0e90: 44 45 52 20 42 59 20 65 76 65 6e 74 2e 6d 74 69  DER BY event.mti
0ea0: 6d 65 20 44 45 53 43 22 29 3b 20 0a 20 20 7d 0a  me DESC"); .  }.
0eb0: 0a 20 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e  .  db_begin_tran
0ec0: 73 61 63 74 69 6f 6e 28 29 3b 0a 20 20 76 66 69  saction();.  vfi
0ed0: 6c 65 5f 63 68 65 63 6b 5f 73 69 67 6e 61 74 75  le_check_signatu
0ee0: 72 65 28 76 69 64 29 3b 0a 20 20 75 6e 64 6f 5f  re(vid);.  undo_
0ef0: 62 65 67 69 6e 28 29 3b 0a 20 20 6c 6f 61 64 5f  begin();.  load_
0f00: 76 66 69 6c 65 5f 66 72 6f 6d 5f 72 69 64 28 74  vfile_from_rid(t
0f10: 69 64 29 3b 0a 0a 20 20 2f 2a 0a 20 20 2a 2a 20  id);..  /*.  ** 
0f20: 54 68 65 20 72 65 63 6f 72 64 2e 66 6e 20 66 69  The record.fn fi
0f30: 65 6c 64 20 69 73 20 75 73 65 64 20 74 6f 20 6d  eld is used to m
0f40: 61 74 63 68 20 66 69 6c 65 73 20 61 67 61 69 6e  atch files again
0f50: 73 74 20 65 61 63 68 20 6f 74 68 65 72 2e 20 20  st each other.  
0f60: 54 68 65 0a 20 20 2a 2a 20 46 56 20 74 61 62 6c  The.  ** FV tabl
0f70: 65 20 63 6f 6e 74 61 69 6e 73 20 6f 6e 65 20 72  e contains one r
0f80: 6f 77 20 66 6f 72 20 65 61 63 68 20 65 61 63 68  ow for each each
0f90: 20 75 6e 69 71 75 65 20 66 69 6c 65 6e 61 6d 65   unique filename
0fa0: 20 69 6e 0a 20 20 2a 2a 20 69 6e 20 74 68 65 20   in.  ** in the 
0fb0: 63 75 72 72 65 6e 74 20 63 68 65 63 6b 6f 75 74  current checkout
0fc0: 2c 20 74 68 65 20 70 69 76 6f 74 2c 20 61 6e 64  , the pivot, and
0fd0: 20 74 68 65 20 76 65 72 73 69 6f 6e 20 62 65 69   the version bei
0fe0: 6e 67 20 6d 65 72 67 65 64 2e 0a 20 20 2a 2f 0a  ng merged..  */.
0ff0: 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28    db_multi_exec(
1000: 0a 20 20 20 20 22 44 52 4f 50 20 54 41 42 4c 45  .    "DROP TABLE
1010: 20 49 46 20 45 58 49 53 54 53 20 66 76 3b 22 0a   IF EXISTS fv;".
1020: 20 20 20 20 22 43 52 45 41 54 45 20 54 45 4d 50      "CREATE TEMP
1030: 20 54 41 42 4c 45 20 66 76 28 22 0a 20 20 20 20   TABLE fv(".    
1040: 22 20 20 66 6e 20 54 45 58 54 20 50 52 49 4d 41  "  fn TEXT PRIMA
1050: 52 59 20 4b 45 59 2c 22 20 20 20 20 20 20 2f 2a  RY KEY,"      /*
1060: 20 54 68 65 20 66 69 6c 65 6e 61 6d 65 20 2a 2f   The filename */
1070: 0a 20 20 20 20 22 20 20 69 64 76 20 49 4e 54 45  .    "  idv INTE
1080: 47 45 52 2c 22 20 20 20 20 20 20 20 20 20 20 20  GER,"           
1090: 20 20 20 2f 2a 20 56 46 49 4c 45 20 65 6e 74 72     /* VFILE entr
10a0: 79 20 66 6f 72 20 63 75 72 72 65 6e 74 20 76 65  y for current ve
10b0: 72 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 22 20 20  rsion */.    "  
10c0: 69 64 74 20 49 4e 54 45 47 45 52 2c 22 20 20 20  idt INTEGER,"   
10d0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 46             /* VF
10e0: 49 4c 45 20 65 6e 74 72 79 20 66 6f 72 20 74 61  ILE entry for ta
10f0: 72 67 65 74 20 76 65 72 73 69 6f 6e 20 2a 2f 0a  rget version */.
1100: 20 20 20 20 22 20 20 63 68 6e 67 65 64 20 42 4f      "  chnged BO
1110: 4f 4c 45 41 4e 2c 22 20 20 20 20 20 20 20 20 20  OLEAN,"         
1120: 20 20 2f 2a 20 54 72 75 65 20 69 66 20 63 75 72    /* True if cur
1130: 72 65 6e 74 20 76 65 72 73 69 6f 6e 20 68 61 73  rent version has
1140: 20 62 65 65 6e 20 65 64 69 74 65 64 20 2a 2f 0a   been edited */.
1150: 20 20 20 20 22 20 20 72 69 64 76 20 49 4e 54 45      "  ridv INTE
1160: 47 45 52 2c 22 20 20 20 20 20 20 20 20 20 20 20  GER,"           
1170: 20 20 2f 2a 20 52 65 63 6f 72 64 20 49 44 20 66    /* Record ID f
1180: 6f 72 20 63 75 72 72 65 6e 74 20 76 65 72 73 69  or current versi
1190: 6f 6e 20 2a 2f 0a 20 20 20 20 22 20 20 72 69 64  on */.    "  rid
11a0: 74 20 49 4e 54 45 47 45 52 20 22 20 20 20 20 20  t INTEGER "     
11b0: 20 20 20 20 20 20 20 20 2f 2a 20 52 65 63 6f 72          /* Recor
11c0: 64 20 49 44 20 66 6f 72 20 74 61 72 67 65 74 20  d ID for target 
11d0: 2a 2f 0a 20 20 20 20 22 29 3b 22 0a 20 20 20 20  */.    ");".    
11e0: 22 49 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f 52  "INSERT OR IGNOR
11f0: 45 20 49 4e 54 4f 20 66 76 22 0a 20 20 20 20 22  E INTO fv".    "
1200: 20 53 45 4c 45 43 54 20 70 61 74 68 6e 61 6d 65   SELECT pathname
1210: 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 20  , 0, 0, 0, 0, 0 
1220: 46 52 4f 4d 20 76 66 69 6c 65 22 0a 20 20 29 3b  FROM vfile".  );
1230: 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71  .  db_prepare(&q
1240: 2c 0a 20 20 20 20 22 53 45 4c 45 43 54 20 69 64  ,.    "SELECT id
1250: 2c 20 70 61 74 68 6e 61 6d 65 2c 20 72 69 64 20  , pathname, rid 
1260: 46 52 4f 4d 20 76 66 69 6c 65 22 0a 20 20 20 20  FROM vfile".    
1270: 22 20 57 48 45 52 45 20 76 69 64 3d 25 64 22 2c  " WHERE vid=%d",
1280: 20 74 69 64 0a 20 20 29 3b 0a 20 20 77 68 69 6c   tid.  );.  whil
1290: 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d  e( db_step(&q)==
12a0: 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20  SQLITE_ROW ){.  
12b0: 20 20 69 6e 74 20 69 64 20 3d 20 64 62 5f 63 6f    int id = db_co
12c0: 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 30 29 3b  lumn_int(&q, 0);
12d0: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20  .    const char 
12e0: 2a 66 6e 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f  *fn = db_column_
12f0: 74 65 78 74 28 26 71 2c 20 31 29 3b 0a 20 20 20  text(&q, 1);.   
1300: 20 69 6e 74 20 72 69 64 20 3d 20 64 62 5f 63 6f   int rid = db_co
1310: 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 32 29 3b  lumn_int(&q, 2);
1320: 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78  .    db_multi_ex
1330: 65 63 28 0a 20 20 20 20 20 20 22 55 50 44 41 54  ec(.      "UPDAT
1340: 45 20 66 76 20 53 45 54 20 69 64 74 3d 25 64 2c  E fv SET idt=%d,
1350: 20 72 69 64 74 3d 25 64 20 57 48 45 52 45 20 66   ridt=%d WHERE f
1360: 6e 3d 25 51 22 2c 0a 20 20 20 20 20 20 69 64 2c  n=%Q",.      id,
1370: 20 72 69 64 2c 20 66 6e 0a 20 20 20 20 29 3b 0a   rid, fn.    );.
1380: 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a    }.  db_finaliz
1390: 65 28 26 71 29 3b 0a 20 20 64 62 5f 70 72 65 70  e(&q);.  db_prep
13a0: 61 72 65 28 26 71 2c 0a 20 20 20 20 22 53 45 4c  are(&q,.    "SEL
13b0: 45 43 54 20 69 64 2c 20 70 61 74 68 6e 61 6d 65  ECT id, pathname
13c0: 2c 20 72 69 64 2c 20 63 68 6e 67 65 64 20 46 52  , rid, chnged FR
13d0: 4f 4d 20 76 66 69 6c 65 22 0a 20 20 20 20 22 20  OM vfile".    " 
13e0: 57 48 45 52 45 20 76 69 64 3d 25 64 22 2c 20 76  WHERE vid=%d", v
13f0: 69 64 0a 20 20 29 3b 0a 20 20 77 68 69 6c 65 28  id.  );.  while(
1400: 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51   db_step(&q)==SQ
1410: 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20  LITE_ROW ){.    
1420: 69 6e 74 20 69 64 20 3d 20 64 62 5f 63 6f 6c 75  int id = db_colu
1430: 6d 6e 5f 69 6e 74 28 26 71 2c 20 30 29 3b 0a 20  mn_int(&q, 0);. 
1440: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66     const char *f
1450: 6e 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65  n = db_column_te
1460: 78 74 28 26 71 2c 20 31 29 3b 0a 20 20 20 20 69  xt(&q, 1);.    i
1470: 6e 74 20 72 69 64 20 3d 20 64 62 5f 63 6f 6c 75  nt rid = db_colu
1480: 6d 6e 5f 69 6e 74 28 26 71 2c 20 32 29 3b 0a 20  mn_int(&q, 2);. 
1490: 20 20 20 69 6e 74 20 63 68 6e 67 65 64 20 3d 20     int chnged = 
14a0: 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71  db_column_int(&q
14b0: 2c 20 33 29 3b 0a 20 20 20 20 64 62 5f 6d 75 6c  , 3);.    db_mul
14c0: 74 69 5f 65 78 65 63 28 0a 20 20 20 20 20 20 22  ti_exec(.      "
14d0: 55 50 44 41 54 45 20 66 76 20 53 45 54 20 69 64  UPDATE fv SET id
14e0: 76 3d 25 64 2c 20 72 69 64 76 3d 25 64 2c 20 63  v=%d, ridv=%d, c
14f0: 68 6e 67 65 64 3d 25 64 20 57 48 45 52 45 20 66  hnged=%d WHERE f
1500: 6e 3d 25 51 22 2c 0a 20 20 20 20 20 20 69 64 2c  n=%Q",.      id,
1510: 20 72 69 64 2c 20 63 68 6e 67 65 64 2c 20 66 6e   rid, chnged, fn
1520: 0a 20 20 20 20 29 3b 0a 20 20 7d 0a 20 20 64 62  .    );.  }.  db
1530: 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 0a  _finalize(&q);..
1540: 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c    db_prepare(&q,
1550: 20 0a 20 20 20 20 22 53 45 4c 45 43 54 20 66 6e   .    "SELECT fn
1560: 2c 20 69 64 76 2c 20 72 69 64 76 2c 20 69 64 74  , idv, ridv, idt
1570: 2c 20 72 69 64 74 2c 20 63 68 6e 67 65 64 20 46  , ridt, chnged F
1580: 52 4f 4d 20 66 76 20 4f 52 44 45 52 20 42 59 20  ROM fv ORDER BY 
1590: 31 22 0a 20 20 29 3b 0a 20 20 77 68 69 6c 65 28  1".  );.  while(
15a0: 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51   db_step(&q)==SQ
15b0: 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20  LITE_ROW ){.    
15c0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d  const char *zNam
15d0: 65 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65  e = db_column_te
15e0: 78 74 28 26 71 2c 20 30 29 3b 0a 20 20 20 20 69  xt(&q, 0);.    i
15f0: 6e 74 20 69 64 76 20 3d 20 64 62 5f 63 6f 6c 75  nt idv = db_colu
1600: 6d 6e 5f 69 6e 74 28 26 71 2c 20 31 29 3b 0a 20  mn_int(&q, 1);. 
1610: 20 20 20 69 6e 74 20 72 69 64 76 20 3d 20 64 62     int ridv = db
1620: 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20  _column_int(&q, 
1630: 32 29 3b 0a 20 20 20 20 69 6e 74 20 69 64 74 20  2);.    int idt 
1640: 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28  = db_column_int(
1650: 26 71 2c 20 33 29 3b 0a 20 20 20 20 69 6e 74 20  &q, 3);.    int 
1660: 72 69 64 74 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e  ridt = db_column
1670: 5f 69 6e 74 28 26 71 2c 20 34 29 3b 0a 20 20 20  _int(&q, 4);.   
1680: 20 69 6e 74 20 63 68 6e 67 65 64 20 3d 20 64 62   int chnged = db
1690: 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20  _column_int(&q, 
16a0: 35 29 3b 0a 0a 20 20 20 20 69 66 28 20 69 64 76  5);..    if( idv
16b0: 3e 30 20 26 26 20 72 69 64 76 3d 3d 30 20 26 26  >0 && ridv==0 &&
16c0: 20 69 64 74 3e 30 20 29 7b 0a 20 20 20 20 20 20   idt>0 ){.      
16d0: 2f 2a 20 43 6f 6e 66 6c 69 63 74 2e 20 20 54 68  /* Conflict.  Th
16e0: 69 73 20 66 69 6c 65 20 68 61 73 20 62 65 65 6e  is file has been
16f0: 20 61 64 64 65 64 20 74 6f 20 74 68 65 20 63 75   added to the cu
1700: 72 72 65 6e 74 20 63 68 65 63 6b 6f 75 74 0a 20  rrent checkout. 
1710: 20 20 20 20 20 2a 2a 20 62 75 74 20 61 6c 73 6f       ** but also
1720: 20 65 78 69 73 74 73 20 69 6e 20 74 68 65 20 74   exists in the t
1730: 61 72 67 65 74 20 63 68 65 63 6b 6f 75 74 2e 20  arget checkout. 
1740: 20 55 73 65 20 74 68 65 20 63 75 72 72 65 6e 74   Use the current
1750: 20 76 65 72 73 69 6f 6e 2e 0a 20 20 20 20 20 20   version..      
1760: 2a 2f 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28  */.      printf(
1770: 22 43 4f 4e 46 4c 49 43 54 20 25 73 5c 6e 22 2c  "CONFLICT %s\n",
1780: 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 7d 65 6c   zName);.    }el
1790: 73 65 20 69 66 28 20 69 64 74 3e 30 20 26 26 20  se if( idt>0 && 
17a0: 69 64 76 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20  idv==0 ){.      
17b0: 2f 2a 20 46 69 6c 65 20 61 64 64 65 64 20 69 6e  /* File added in
17c0: 20 74 68 65 20 74 61 72 67 65 74 2e 20 2a 2f 0a   the target. */.
17d0: 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 41 44        printf("AD
17e0: 44 20 25 73 5c 6e 22 2c 20 7a 4e 61 6d 65 29 3b  D %s\n", zName);
17f0: 0a 20 20 20 20 20 20 75 6e 64 6f 5f 73 61 76 65  .      undo_save
1800: 28 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 76  (zName);.      v
1810: 66 69 6c 65 5f 74 6f 5f 64 69 73 6b 28 30 2c 20  file_to_disk(0, 
1820: 69 64 74 2c 20 30 29 3b 0a 20 20 20 20 7d 65 6c  idt, 0);.    }el
1830: 73 65 20 69 66 28 20 69 64 74 3e 30 20 26 26 20  se if( idt>0 && 
1840: 69 64 76 3e 30 20 26 26 20 72 69 64 74 21 3d 72  idv>0 && ridt!=r
1850: 69 64 76 20 26 26 20 63 68 6e 67 65 64 3d 3d 30  idv && chnged==0
1860: 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 54 68 65   ){.      /* The
1870: 20 66 69 6c 65 20 69 73 20 75 6e 65 64 69 74 65   file is unedite
1880: 64 2e 20 20 43 68 61 6e 67 65 20 69 74 20 74 6f  d.  Change it to
1890: 20 74 68 65 20 74 61 72 67 65 74 20 76 65 72 73   the target vers
18a0: 69 6f 6e 20 2a 2f 0a 20 20 20 20 20 20 70 72 69  ion */.      pri
18b0: 6e 74 66 28 22 55 50 44 41 54 45 20 25 73 5c 6e  ntf("UPDATE %s\n
18c0: 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20  ", zName);.     
18d0: 20 75 6e 64 6f 5f 73 61 76 65 28 7a 4e 61 6d 65   undo_save(zName
18e0: 29 3b 0a 20 20 20 20 20 20 76 66 69 6c 65 5f 74  );.      vfile_t
18f0: 6f 5f 64 69 73 6b 28 30 2c 20 69 64 74 2c 20 30  o_disk(0, idt, 0
1900: 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28  );.    }else if(
1910: 20 69 64 74 3d 3d 30 20 26 26 20 69 64 76 3e 30   idt==0 && idv>0
1920: 20 29 7b 0a 20 20 20 20 20 20 69 66 28 20 63 68   ){.      if( ch
1930: 6e 67 65 64 20 29 7b 0a 20 20 20 20 20 20 20 20  nged ){.        
1940: 70 72 69 6e 74 66 28 22 43 4f 4e 46 4c 49 43 54  printf("CONFLICT
1950: 20 25 73 5c 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a   %s\n", zName);.
1960: 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20        }else{.   
1970: 20 20 20 20 20 63 68 61 72 20 2a 7a 46 75 6c 6c       char *zFull
1980: 50 61 74 68 3b 0a 20 20 20 20 20 20 20 20 70 72  Path;.        pr
1990: 69 6e 74 66 28 22 52 45 4d 4f 56 45 20 25 73 5c  intf("REMOVE %s\
19a0: 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20  n", zName);.    
19b0: 20 20 20 20 75 6e 64 6f 5f 73 61 76 65 28 7a 4e      undo_save(zN
19c0: 61 6d 65 29 3b 0a 20 20 20 20 20 20 20 20 7a 46  ame);.        zF
19d0: 75 6c 6c 50 61 74 68 20 3d 20 6d 70 72 69 6e 74  ullPath = mprint
19e0: 66 28 22 25 73 2f 25 73 22 2c 20 67 2e 7a 4c 6f  f("%s/%s", g.zLo
19f0: 63 61 6c 52 6f 6f 74 2c 20 7a 4e 61 6d 65 29 3b  calRoot, zName);
1a00: 0a 20 20 20 20 20 20 20 20 75 6e 6c 69 6e 6b 28  .        unlink(
1a10: 7a 46 75 6c 6c 50 61 74 68 29 3b 0a 20 20 20 20  zFullPath);.    
1a20: 20 20 20 20 66 72 65 65 28 7a 46 75 6c 6c 50 61      free(zFullPa
1a30: 74 68 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20  th);.      }.   
1a40: 20 7d 65 6c 73 65 20 69 66 28 20 69 64 74 3e 30   }else if( idt>0
1a50: 20 26 26 20 69 64 76 3e 30 20 26 26 20 72 69 64   && idv>0 && rid
1a60: 74 21 3d 72 69 64 76 20 26 26 20 63 68 6e 67 65  t!=ridv && chnge
1a70: 64 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 4d 65  d ){.      /* Me
1a80: 72 67 65 20 74 68 65 20 63 68 61 6e 67 65 73 20  rge the changes 
1a90: 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20 74  in the current t
1aa0: 72 65 65 20 69 6e 74 6f 20 74 68 65 20 74 61 72  ree into the tar
1ab0: 67 65 74 20 76 65 72 73 69 6f 6e 20 2a 2f 0a 20  get version */. 
1ac0: 20 20 20 20 20 42 6c 6f 62 20 65 2c 20 72 2c 20       Blob e, r, 
1ad0: 74 2c 20 76 3b 0a 20 20 20 20 20 20 63 68 61 72  t, v;.      char
1ae0: 20 2a 7a 46 75 6c 6c 50 61 74 68 3b 0a 20 20 20   *zFullPath;.   
1af0: 20 20 20 70 72 69 6e 74 66 28 22 4d 45 52 47 45     printf("MERGE
1b00: 20 25 73 5c 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a   %s\n", zName);.
1b10: 20 20 20 20 20 20 75 6e 64 6f 5f 73 61 76 65 28        undo_save(
1b20: 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 7a 46  zName);.      zF
1b30: 75 6c 6c 50 61 74 68 20 3d 20 6d 70 72 69 6e 74  ullPath = mprint
1b40: 66 28 22 25 73 2f 25 73 22 2c 20 67 2e 7a 4c 6f  f("%s/%s", g.zLo
1b50: 63 61 6c 52 6f 6f 74 2c 20 7a 4e 61 6d 65 29 3b  calRoot, zName);
1b60: 0a 20 20 20 20 20 20 63 6f 6e 74 65 6e 74 5f 67  .      content_g
1b70: 65 74 28 72 69 64 74 2c 20 26 74 29 3b 0a 20 20  et(ridt, &t);.  
1b80: 20 20 20 20 63 6f 6e 74 65 6e 74 5f 67 65 74 28      content_get(
1b90: 72 69 64 76 2c 20 26 76 29 3b 0a 20 20 20 20 20  ridv, &v);.     
1ba0: 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 65 29 3b 0a   blob_zero(&e);.
1bb0: 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 61 64 5f        blob_read_
1bc0: 66 72 6f 6d 5f 66 69 6c 65 28 26 65 2c 20 7a 46  from_file(&e, zF
1bd0: 75 6c 6c 50 61 74 68 29 3b 0a 20 20 20 20 20 20  ullPath);.      
1be0: 62 6c 6f 62 5f 6d 65 72 67 65 28 26 76 2c 20 26  blob_merge(&v, &
1bf0: 65 2c 20 26 74 2c 20 26 72 29 3b 0a 20 20 20 20  e, &t, &r);.    
1c00: 20 20 62 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f    blob_write_to_
1c10: 66 69 6c 65 28 26 72 2c 20 7a 46 75 6c 6c 50 61  file(&r, zFullPa
1c20: 74 68 29 3b 0a 20 20 20 20 20 20 66 72 65 65 28  th);.      free(
1c30: 7a 46 75 6c 6c 50 61 74 68 29 3b 0a 20 20 20 20  zFullPath);.    
1c40: 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 76 29    blob_reset(&v)
1c50: 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73  ;.      blob_res
1c60: 65 74 28 26 65 29 3b 0a 20 20 20 20 20 20 62 6c  et(&e);.      bl
1c70: 6f 62 5f 72 65 73 65 74 28 26 74 29 3b 0a 20 20  ob_reset(&t);.  
1c80: 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26      blob_reset(&
1c90: 72 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20  r);.    }.  }.  
1ca0: 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b  db_finalize(&q);
1cb0: 0a 20 20 0a 20 20 2f 2a 0a 20 20 2a 2a 20 43 6c  .  .  /*.  ** Cl
1cc0: 65 61 6e 20 75 70 20 74 68 65 20 6d 69 64 20 61  ean up the mid a
1cd0: 6e 64 20 70 69 64 20 56 46 49 4c 45 20 65 6e 74  nd pid VFILE ent
1ce0: 72 69 65 73 2e 20 20 54 68 65 6e 20 63 6f 6d 6d  ries.  Then comm
1cf0: 69 74 20 74 68 65 20 63 68 61 6e 67 65 73 2e 0a  it the changes..
1d00: 20 20 2a 2f 0a 20 20 64 62 5f 6d 75 6c 74 69 5f    */.  db_multi_
1d10: 65 78 65 63 28 22 44 45 4c 45 54 45 20 46 52 4f  exec("DELETE FRO
1d20: 4d 20 76 66 69 6c 65 20 57 48 45 52 45 20 76 69  M vfile WHERE vi
1d30: 64 21 3d 25 64 22 2c 20 74 69 64 29 3b 0a 20 20  d!=%d", tid);.  
1d40: 6d 61 6e 69 66 65 73 74 5f 74 6f 5f 64 69 73 6b  manifest_to_disk
1d50: 28 74 69 64 29 3b 0a 20 20 64 62 5f 6c 73 65 74  (tid);.  db_lset
1d60: 5f 69 6e 74 28 22 63 68 65 63 6b 6f 75 74 22 2c  _int("checkout",
1d70: 20 74 69 64 29 3b 0a 20 20 64 62 5f 65 6e 64 5f   tid);.  db_end_
1d80: 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 3b 0a  transaction(0);.
1d90: 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44  }../*.** COMMAND
1da0: 3a 20 72 65 76 65 72 74 0a 2a 2a 0a 2a 2a 20 55  : revert.**.** U
1db0: 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 72 65  sage: %fossil re
1dc0: 76 65 72 74 20 3f 2d 2d 79 65 73 3f 20 3f 2d 72  vert ?--yes? ?-r
1dd0: 20 52 45 56 49 53 49 4f 4e 3f 20 46 49 4c 45 0a   REVISION? FILE.
1de0: 2a 2a 0a 2a 2a 20 52 65 76 65 72 74 20 74 6f 20  **.** Revert to 
1df0: 74 68 65 20 63 75 72 72 65 6e 74 20 72 65 70 6f  the current repo
1e00: 73 69 74 6f 72 79 20 76 65 72 73 69 6f 6e 20 6f  sitory version o
1e10: 66 20 46 49 4c 45 2e 20 54 68 69 73 0a 2a 2a 20  f FILE. This.** 
1e20: 63 6f 6d 6d 61 6e 64 20 77 69 6c 6c 20 63 6f 6e  command will con
1e30: 66 69 72 6d 20 79 6f 75 72 20 6f 70 65 72 61 74  firm your operat
1e40: 69 6f 6e 2c 20 75 6e 6c 65 73 73 20 79 6f 75 20  ion, unless you 
1e50: 64 6f 20 73 6f 0a 2a 2a 20 61 74 20 74 68 65 20  do so.** at the 
1e60: 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65 20 76 69 61  command line via
1e70: 20 74 68 65 20 2d 79 65 73 20 6f 70 74 69 6f 6e   the -yes option
1e80: 2e 0a 2a 2a 2f 0a 76 6f 69 64 20 72 65 76 65 72  ..**/.void rever
1e90: 74 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 63  t_cmd(void){.  c
1ea0: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 46 69 6c 65  onst char *zFile
1eb0: 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  ;.  const char *
1ec0: 7a 52 65 76 69 73 69 6f 6e 3b 0a 20 20 42 6c 6f  zRevision;.  Blo
1ed0: 62 20 66 6e 61 6d 65 3b 0a 20 20 42 6c 6f 62 20  b fname;.  Blob 
1ee0: 72 65 63 6f 72 64 3b 0a 20 20 42 6c 6f 62 20 61  record;.  Blob a
1ef0: 6e 73 3b 0a 20 20 69 6e 74 20 72 69 64 20 3d 20  ns;.  int rid = 
1f00: 30 2c 20 79 65 73 52 65 76 65 72 74 3b 0a 20 20  0, yesRevert;.  
1f10: 0a 20 20 79 65 73 52 65 76 65 72 74 20 3d 20 66  .  yesRevert = f
1f20: 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 79 65 73 22  ind_option("yes"
1f30: 2c 20 22 79 22 2c 20 30 29 21 3d 30 3b 0a 20 20  , "y", 0)!=0;.  
1f40: 7a 52 65 76 69 73 69 6f 6e 20 3d 20 66 69 6e 64  zRevision = find
1f50: 5f 6f 70 74 69 6f 6e 28 22 72 65 76 69 73 69 6f  _option("revisio
1f60: 6e 22 2c 20 22 72 22 2c 20 31 29 3b 0a 20 20 76  n", "r", 1);.  v
1f70: 65 72 69 66 79 5f 61 6c 6c 5f 6f 70 74 69 6f 6e  erify_all_option
1f80: 73 28 29 3b 0a 20 20 0a 20 20 69 66 28 20 67 2e  s();.  .  if( g.
1f90: 61 72 67 63 3c 33 20 29 7b 0a 20 20 20 20 75 73  argc<3 ){.    us
1fa0: 61 67 65 28 22 3f 4f 50 54 49 4f 4e 53 20 46 49  age("?OPTIONS FI
1fb0: 4c 45 22 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 6d  LE");.  }.  db_m
1fc0: 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72  ust_be_within_tr
1fd0: 65 65 28 29 3b 0a 20 20 0a 20 20 7a 46 69 6c 65  ee();.  .  zFile
1fe0: 20 3d 20 67 2e 61 72 67 76 5b 67 2e 61 72 67 63   = g.argv[g.argc
1ff0: 2d 31 5d 3b 0a 0a 20 20 69 66 28 20 21 66 69 6c  -1];..  if( !fil
2000: 65 5f 74 72 65 65 5f 6e 61 6d 65 28 7a 46 69 6c  e_tree_name(zFil
2010: 65 2c 20 26 66 6e 61 6d 65 29 20 29 7b 0a 20 20  e, &fname) ){.  
2020: 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22    fossil_panic("
2030: 75 6e 6b 6e 6f 77 6e 20 66 69 6c 65 3a 20 25 73  unknown file: %s
2040: 22 2c 20 7a 46 69 6c 65 29 3b 0a 20 20 7d 0a 20  ", zFile);.  }. 
2050: 20 0a 20 20 69 66 28 20 79 65 73 52 65 76 65 72   .  if( yesRever
2060: 74 3d 3d 30 20 29 7b 0a 20 20 20 20 63 68 61 72  t==0 ){.    char
2070: 20 2a 70 72 6f 6d 70 74 20 3d 20 6d 70 72 69 6e   *prompt = mprin
2080: 74 66 28 22 72 65 76 65 72 74 20 66 69 6c 65 20  tf("revert file 
2090: 25 42 3f 20 74 68 69 73 20 77 69 6c 6c 22 0a 20  %B? this will". 
20a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
20b0: 20 20 20 20 20 20 20 20 20 20 22 20 64 65 73 74            " dest
20c0: 72 6f 79 20 6c 6f 63 61 6c 20 63 68 61 6e 67 65  roy local change
20d0: 73 20 5b 79 2f 4e 5d 3f 20 22 2c 0a 20 20 20 20  s [y/N]? ",.    
20e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
20f0: 20 20 20 20 20 20 20 26 66 6e 61 6d 65 29 3b 0a         &fname);.
2100: 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 61      blob_zero(&a
2110: 6e 73 29 3b 0a 20 20 20 20 70 72 6f 6d 70 74 5f  ns);.    prompt_
2120: 75 73 65 72 28 70 72 6f 6d 70 74 2c 20 26 61 6e  user(prompt, &an
2130: 73 29 3b 0a 20 20 20 20 69 66 28 20 62 6c 6f 62  s);.    if( blob
2140: 5f 73 74 72 28 26 61 6e 73 29 5b 30 5d 3d 3d 27  _str(&ans)[0]=='
2150: 79 27 20 29 7b 0a 20 20 20 20 20 20 79 65 73 52  y' ){.      yesR
2160: 65 76 65 72 74 20 3d 20 31 3b 0a 20 20 20 20 7d  evert = 1;.    }
2170: 0a 20 20 7d 0a 0a 20 20 69 66 28 20 79 65 73 52  .  }..  if( yesR
2180: 65 76 65 72 74 3d 3d 31 20 26 26 20 7a 52 65 76  evert==1 && zRev
2190: 69 73 69 6f 6e 21 3d 30 20 29 7b 0a 20 20 20 20  ision!=0 ){.    
21a0: 63 6f 6e 74 65 6e 74 5f 67 65 74 5f 68 69 73 74  content_get_hist
21b0: 6f 72 69 63 61 6c 5f 66 69 6c 65 28 7a 52 65 76  orical_file(zRev
21c0: 69 73 69 6f 6e 2c 20 7a 46 69 6c 65 2c 20 26 72  ision, zFile, &r
21d0: 65 63 6f 72 64 29 3b 0a 20 20 7d 65 6c 73 65 20  ecord);.  }else 
21e0: 69 66 28 20 79 65 73 52 65 76 65 72 74 3d 3d 31  if( yesRevert==1
21f0: 20 29 7b 0a 20 20 20 20 72 69 64 20 3d 20 64 62   ){.    rid = db
2200: 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 20  _int(0, "SELECT 
2210: 72 69 64 20 46 52 4f 4d 20 76 66 69 6c 65 20 57  rid FROM vfile W
2220: 48 45 52 45 20 70 61 74 68 6e 61 6d 65 3d 25 42  HERE pathname=%B
2230: 22 2c 20 26 66 6e 61 6d 65 29 3b 0a 20 20 20 20  ", &fname);.    
2240: 69 66 28 20 72 69 64 3d 3d 30 20 29 7b 0a 20 20  if( rid==0 ){.  
2250: 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63      fossil_panic
2260: 28 22 6e 6f 20 68 69 73 74 6f 72 79 20 66 6f 72  ("no history for
2270: 20 66 69 6c 65 3a 20 25 62 22 2c 20 26 66 6e 61   file: %b", &fna
2280: 6d 65 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63  me);.    }.    c
2290: 6f 6e 74 65 6e 74 5f 67 65 74 28 72 69 64 2c 20  ontent_get(rid, 
22a0: 26 72 65 63 6f 72 64 29 3b 0a 20 20 7d 0a 20 20  &record);.  }.  
22b0: 0a 20 20 69 66 28 20 79 65 73 52 65 76 65 72 74  .  if( yesRevert
22c0: 3d 3d 31 20 29 7b 0a 20 20 20 20 62 6c 6f 62 5f  ==1 ){.    blob_
22d0: 77 72 69 74 65 5f 74 6f 5f 66 69 6c 65 28 26 72  write_to_file(&r
22e0: 65 63 6f 72 64 2c 20 62 6c 6f 62 5f 73 74 72 28  ecord, blob_str(
22f0: 26 66 6e 61 6d 65 29 29 3b 0a 20 20 20 20 70 72  &fname));.    pr
2300: 69 6e 74 66 28 22 25 73 20 72 65 76 65 72 74 65  intf("%s reverte
2310: 64 5c 6e 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26  d\n", blob_str(&
2320: 66 6e 61 6d 65 29 29 3b 0a 20 20 20 20 62 6c 6f  fname));.    blo
2330: 62 5f 72 65 73 65 74 28 26 72 65 63 6f 72 64 29  b_reset(&record)
2340: 3b 0a 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74  ;.    blob_reset
2350: 28 26 66 6e 61 6d 65 29 3b 0a 20 20 7d 65 6c 73  (&fname);.  }els
2360: 65 7b 0a 20 20 20 20 70 72 69 6e 74 66 28 22 72  e{.    printf("r
2370: 65 76 65 72 74 20 63 61 6e 63 65 6c 65 64 5c 6e  evert canceled\n
2380: 22 29 3b 0a 20 20 7d 0a 7d 0a                    ");.  }.}.