Hex Artifact Content
Not logged in

Artifact ca0677b5f765ebf58f0e307f3b9998ce554fac4e:

File src/update.c part of check-in [41561125cd] - Added safemerge option to commit, update and settings by jnc on 2007-09-26 04:17:37.

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 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6f 70 74 69  ?.**.** The opti
0500: 6f 6e 61 6c 20 61 72 67 75 6d 65 6e 74 20 69 73  onal argument is
0510: 20 61 20 76 65 72 73 69 6f 6e 20 74 68 61 74 20   a version that 
0520: 73 68 6f 75 6c 64 20 62 65 63 6f 6d 65 20 74 68  should become th
0530: 65 20 63 75 72 72 65 6e 74 0a 2a 2a 20 76 65 72  e current.** ver
0540: 73 69 6f 6e 2e 20 20 49 66 20 74 68 65 20 61 72  sion.  If the ar
0550: 67 75 6d 65 6e 74 20 69 73 20 6f 6d 69 74 74 65  gument is omitte
0560: 64 2c 20 74 68 65 6e 20 75 73 65 20 74 68 65 20  d, then use the 
0570: 6c 65 61 66 20 6f 66 20 74 68 65 0a 2a 2a 20 74  leaf of the.** t
0580: 72 65 65 20 74 68 61 74 20 62 65 67 69 6e 73 20  ree that begins 
0590: 77 69 74 68 20 74 68 65 20 63 75 72 72 65 6e 74  with the current
05a0: 20 76 65 72 73 69 6f 6e 2c 20 69 66 20 74 68 65   version, if the
05b0: 72 65 20 69 73 20 6f 6e 6c 79 20 61 20 0a 2a 2a  re is only a .**
05c0: 20 73 69 6e 67 6c 65 20 6c 65 61 66 2e 20 20 0a   single leaf.  .
05d0: 2a 2a 0a 2a 2a 20 54 68 69 73 20 63 6f 6d 6d 61  **.** This comma
05e0: 6e 64 20 69 73 20 64 69 66 66 65 72 65 6e 74 20  nd is different 
05f0: 66 72 6f 6d 20 74 68 65 20 22 63 68 65 63 6b 6f  from the "checko
0600: 75 74 22 20 69 6e 20 74 68 61 74 20 65 64 69 74  ut" in that edit
0610: 73 20 61 72 65 0a 2a 2a 20 6e 6f 74 20 6f 76 65  s are.** not ove
0620: 72 77 72 69 74 74 65 6e 2e 20 20 45 64 69 74 73  rwritten.  Edits
0630: 20 61 72 65 20 6d 65 72 67 65 64 20 69 6e 74 6f   are merged into
0640: 20 74 68 65 20 6e 65 77 20 76 65 72 73 69 6f 6e   the new version
0650: 2e 0a 2a 2a 0a 2a 2f 0a 76 6f 69 64 20 75 70 64  ..**.*/.void upd
0660: 61 74 65 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20  ate_cmd(void){. 
0670: 20 69 6e 74 20 76 69 64 3b 20 20 20 20 20 20 20   int vid;       
0680: 20 20 20 20 20 20 20 2f 2a 20 43 75 72 72 65 6e         /* Curren
0690: 74 20 76 65 72 73 69 6f 6e 20 2a 2f 0a 20 20 69  t version */.  i
06a0: 6e 74 20 74 69 64 3d 30 3b 20 20 20 20 20 20 20  nt tid=0;       
06b0: 20 20 20 20 20 2f 2a 20 54 61 72 67 65 74 20 76       /* Target v
06c0: 65 72 73 69 6f 6e 20 2d 20 76 65 72 73 69 6f 6e  ersion - version
06d0: 20 77 65 20 61 72 65 20 63 68 61 6e 67 69 6e 67   we are changing
06e0: 20 74 6f 20 2a 2f 0a 20 20 53 74 6d 74 20 71 3b   to */.  Stmt q;
06f0: 0a 20 20 69 6e 74 20 6c 61 74 65 73 74 46 6c 61  .  int latestFla
0700: 67 3b 20 20 20 20 20 20 20 2f 2a 20 50 69 63 6b  g;       /* Pick
0710: 20 74 68 65 20 6c 61 74 65 73 74 20 76 65 72 73   the latest vers
0720: 69 6f 6e 20 69 66 20 74 72 75 65 20 2a 2f 0a 0a  ion if true */..
0730: 20 20 6c 61 74 65 73 74 46 6c 61 67 20 3d 20 66    latestFlag = f
0740: 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 6c 61 74 65  ind_option("late
0750: 73 74 22 2c 30 2c 20 30 29 21 3d 30 3b 0a 20 20  st",0, 0)!=0;.  
0760: 69 66 28 20 67 2e 61 72 67 63 21 3d 33 20 26 26  if( g.argc!=3 &&
0770: 20 67 2e 61 72 67 63 21 3d 32 20 29 7b 0a 20 20   g.argc!=2 ){.  
0780: 20 20 75 73 61 67 65 28 22 3f 56 45 52 53 49 4f    usage("?VERSIO
0790: 4e 3f 22 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 6d  N?");.  }.  db_m
07a0: 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72  ust_be_within_tr
07b0: 65 65 28 29 3b 0a 20 20 76 69 64 20 3d 20 64 62  ee();.  vid = db
07c0: 5f 6c 67 65 74 5f 69 6e 74 28 22 63 68 65 63 6b  _lget_int("check
07d0: 6f 75 74 22 2c 20 30 29 3b 0a 20 20 69 66 28 20  out", 0);.  if( 
07e0: 76 69 64 3d 3d 30 20 29 7b 0a 20 20 20 20 66 6f  vid==0 ){.    fo
07f0: 73 73 69 6c 5f 66 61 74 61 6c 28 22 63 61 6e 6e  ssil_fatal("cann
0800: 6f 74 20 66 69 6e 64 20 63 75 72 72 65 6e 74 20  ot find current 
0810: 76 65 72 73 69 6f 6e 22 29 3b 0a 20 20 7d 0a 20  version");.  }. 
0820: 20 69 66 28 20 64 62 5f 65 78 69 73 74 73 28 22   if( db_exists("
0830: 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 76 6d  SELECT 1 FROM vm
0840: 65 72 67 65 22 29 20 29 7b 0a 20 20 20 20 66 6f  erge") ){.    fo
0850: 73 73 69 6c 5f 66 61 74 61 6c 28 22 63 61 6e 6e  ssil_fatal("cann
0860: 6f 74 20 75 70 64 61 74 65 20 61 6e 20 75 6e 63  ot update an unc
0870: 6f 6d 6d 69 74 74 65 64 20 6d 65 72 67 65 22 29  ommitted merge")
0880: 3b 0a 20 20 7d 0a 20 20 69 66 28 20 75 6e 73 61  ;.  }.  if( unsa
0890: 76 65 64 5f 63 68 61 6e 67 65 73 28 29 20 26 26  ved_changes() &&
08a0: 20 64 62 5f 67 65 74 5f 69 6e 74 28 22 73 61 66   db_get_int("saf
08b0: 65 6d 65 72 67 65 22 2c 20 30 29 20 29 7b 0a 20  emerge", 0) ){. 
08c0: 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28     fossil_fatal(
08d0: 22 79 6f 75 20 68 61 76 65 20 75 6e 63 6f 6d 6d  "you have uncomm
08e0: 69 74 74 65 64 20 63 68 61 6e 67 65 73 20 61 6e  itted changes an
08f0: 64 20 73 61 66 65 6d 65 72 67 65 20 69 73 20 65  d safemerge is e
0900: 6e 61 62 6c 65 64 22 29 3b 0a 20 20 7d 0a 20 20  nabled");.  }.  
0910: 20 20 20 20 0a 20 20 69 66 28 20 67 2e 61 72 67      .  if( g.arg
0920: 63 3d 3d 33 20 29 7b 0a 20 20 20 20 74 69 64 20  c==3 ){.    tid 
0930: 3d 20 6e 61 6d 65 5f 74 6f 5f 72 69 64 28 67 2e  = name_to_rid(g.
0940: 61 72 67 76 5b 32 5d 29 3b 0a 20 20 20 20 69 66  argv[2]);.    if
0950: 28 20 74 69 64 3d 3d 30 20 29 7b 0a 20 20 20 20  ( tid==0 ){.    
0960: 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22    fossil_fatal("
0970: 6e 6f 74 20 61 20 76 65 72 73 69 6f 6e 3a 20 25  not a version: %
0980: 73 22 2c 20 67 2e 61 72 67 76 5b 32 5d 29 3b 0a  s", g.argv[2]);.
0990: 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 21 69      }.    if( !i
09a0: 73 5f 61 5f 76 65 72 73 69 6f 6e 28 74 69 64 29  s_a_version(tid)
09b0: 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c   ){.      fossil
09c0: 5f 66 61 74 61 6c 28 22 6e 6f 74 20 61 20 76 65  _fatal("not a ve
09d0: 72 73 69 6f 6e 3a 20 25 73 22 2c 20 67 2e 61 72  rsion: %s", g.ar
09e0: 67 76 5b 32 5d 29 3b 0a 20 20 20 20 7d 0a 20 20  gv[2]);.    }.  
09f0: 7d 0a 0a 20 20 69 66 28 20 74 69 64 3d 3d 30 20  }..  if( tid==0 
0a00: 29 7b 0a 20 20 20 20 2f 2a 20 0a 20 20 20 20 2a  ){.    /* .    *
0a10: 2a 20 44 6f 20 61 6e 20 61 75 74 6f 73 79 6e 63  * Do an autosync
0a20: 20 70 75 6c 6c 20 70 72 69 6f 72 20 74 6f 20 74   pull prior to t
0a30: 68 65 20 75 70 64 61 74 65 2c 20 69 66 20 61 75  he update, if au
0a40: 74 6f 73 79 6e 63 20 69 73 20 6f 6e 20 61 6e 64  tosync is on and
0a50: 20 74 68 65 79 0a 20 20 20 20 2a 2a 20 64 69 64   they.    ** did
0a60: 20 6e 6f 74 20 77 61 6e 74 20 61 20 73 70 65 63   not want a spec
0a70: 69 66 69 63 20 76 65 72 73 69 6f 6e 20 28 69 2e  ific version (i.
0a80: 65 2e 20 61 6e 6f 74 68 65 72 20 62 72 61 6e 63  e. another branc
0a90: 68 2c 20 61 20 70 61 73 74 20 72 65 76 69 73 69  h, a past revisi
0aa0: 6f 6e 29 2e 0a 20 20 20 20 2a 2a 20 42 79 20 6e  on)..    ** By n
0ab0: 6f 74 20 67 69 76 69 6e 67 20 61 20 73 70 65 63  ot giving a spec
0ac0: 69 66 69 63 20 76 65 72 73 69 6f 6e 2c 20 74 68  ific version, th
0ad0: 65 79 20 61 72 65 20 61 73 6b 69 6e 67 20 66 6f  ey are asking fo
0ae0: 72 20 74 68 65 20 6c 61 74 65 73 74 2c 20 74 68  r the latest, th
0af0: 75 73 0a 20 20 20 20 2a 2a 20 70 75 6c 6c 20 74  us.    ** pull t
0b00: 6f 20 67 65 74 20 74 68 65 20 6c 61 74 65 73 74  o get the latest
0b10: 2c 20 74 68 65 6e 20 75 70 64 61 74 65 2e 0a 20  , then update.. 
0b20: 20 20 20 2a 2f 0a 20 20 20 20 61 75 74 6f 73 79     */.    autosy
0b30: 6e 63 28 31 29 3b 0a 20 20 7d 0a 20 20 0a 20 20  nc(1);.  }.  .  
0b40: 69 66 28 20 74 69 64 3d 3d 30 20 29 7b 0a 20 20  if( tid==0 ){.  
0b50: 20 20 63 6f 6d 70 75 74 65 5f 6c 65 61 76 65 73    compute_leaves
0b60: 28 76 69 64 29 3b 0a 20 20 20 20 69 66 28 20 21  (vid);.    if( !
0b70: 6c 61 74 65 73 74 46 6c 61 67 20 26 26 20 64 62  latestFlag && db
0b80: 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 20  _int(0, "SELECT 
0b90: 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 6c 65  count(*) FROM le
0ba0: 61 76 65 73 22 29 3e 31 20 29 7b 0a 20 20 20 20  aves")>1 ){.    
0bb0: 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c    db_prepare(&q,
0bc0: 20 0a 20 20 20 20 20 20 20 20 22 25 73 20 22 0a   .        "%s ".
0bd0: 20 20 20 20 20 20 20 20 22 20 20 20 41 4e 44 20          "   AND 
0be0: 65 76 65 6e 74 2e 6f 62 6a 69 64 20 49 4e 20 6c  event.objid IN l
0bf0: 65 61 76 65 73 22 0a 20 20 20 20 20 20 20 20 22  eaves".        "
0c00: 20 4f 52 44 45 52 20 42 59 20 65 76 65 6e 74 2e   ORDER BY event.
0c10: 6d 74 69 6d 65 20 44 45 53 43 22 2c 0a 20 20 20  mtime DESC",.   
0c20: 20 20 20 20 20 74 69 6d 65 6c 69 6e 65 5f 71 75       timeline_qu
0c30: 65 72 79 5f 66 6f 72 5f 74 74 79 28 29 0a 20 20  ery_for_tty().  
0c40: 20 20 20 20 29 3b 0a 20 20 20 20 20 20 70 72 69      );.      pri
0c50: 6e 74 5f 74 69 6d 65 6c 69 6e 65 28 26 71 2c 20  nt_timeline(&q, 
0c60: 31 30 30 29 3b 0a 20 20 20 20 20 20 64 62 5f 66  100);.      db_f
0c70: 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 20  inalize(&q);.   
0c80: 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28     fossil_fatal(
0c90: 22 4d 75 6c 74 69 70 6c 65 20 64 65 73 63 65 6e  "Multiple descen
0ca0: 64 65 6e 74 73 22 29 3b 0a 20 20 20 20 7d 0a 20  dents");.    }. 
0cb0: 20 20 20 74 69 64 20 3d 20 64 62 5f 69 6e 74 28     tid = db_int(
0cc0: 30 2c 20 22 53 45 4c 45 43 54 20 72 69 64 20 46  0, "SELECT rid F
0cd0: 52 4f 4d 20 6c 65 61 76 65 73 2c 20 65 76 65 6e  ROM leaves, even
0ce0: 74 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  t".             
0cf0: 20 20 20 20 20 20 20 22 20 57 48 45 52 45 20 65         " WHERE e
0d00: 76 65 6e 74 2e 6f 62 6a 69 64 3d 6c 65 61 76 65  vent.objid=leave
0d10: 73 2e 72 69 64 22 0a 20 20 20 20 20 20 20 20 20  s.rid".         
0d20: 20 20 20 20 20 20 20 20 20 20 20 22 20 4f 52 44             " ORD
0d30: 45 52 20 42 59 20 65 76 65 6e 74 2e 6d 74 69 6d  ER BY event.mtim
0d40: 65 20 44 45 53 43 22 29 3b 20 0a 20 20 7d 0a 0a  e DESC"); .  }..
0d50: 20 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73    db_begin_trans
0d60: 61 63 74 69 6f 6e 28 29 3b 0a 20 20 76 66 69 6c  action();.  vfil
0d70: 65 5f 63 68 65 63 6b 5f 73 69 67 6e 61 74 75 72  e_check_signatur
0d80: 65 28 76 69 64 29 3b 0a 20 20 75 6e 64 6f 5f 62  e(vid);.  undo_b
0d90: 65 67 69 6e 28 29 3b 0a 20 20 6c 6f 61 64 5f 76  egin();.  load_v
0da0: 66 69 6c 65 5f 66 72 6f 6d 5f 72 69 64 28 74 69  file_from_rid(ti
0db0: 64 29 3b 0a 0a 20 20 2f 2a 0a 20 20 2a 2a 20 54  d);..  /*.  ** T
0dc0: 68 65 20 72 65 63 6f 72 64 2e 66 6e 20 66 69 65  he record.fn fie
0dd0: 6c 64 20 69 73 20 75 73 65 64 20 74 6f 20 6d 61  ld is used to ma
0de0: 74 63 68 20 66 69 6c 65 73 20 61 67 61 69 6e 73  tch files agains
0df0: 74 20 65 61 63 68 20 6f 74 68 65 72 2e 20 20 54  t each other.  T
0e00: 68 65 0a 20 20 2a 2a 20 46 56 20 74 61 62 6c 65  he.  ** FV table
0e10: 20 63 6f 6e 74 61 69 6e 73 20 6f 6e 65 20 72 6f   contains one ro
0e20: 77 20 66 6f 72 20 65 61 63 68 20 65 61 63 68 20  w for each each 
0e30: 75 6e 69 71 75 65 20 66 69 6c 65 6e 61 6d 65 20  unique filename 
0e40: 69 6e 0a 20 20 2a 2a 20 69 6e 20 74 68 65 20 63  in.  ** in the c
0e50: 75 72 72 65 6e 74 20 63 68 65 63 6b 6f 75 74 2c  urrent checkout,
0e60: 20 74 68 65 20 70 69 76 6f 74 2c 20 61 6e 64 20   the pivot, and 
0e70: 74 68 65 20 76 65 72 73 69 6f 6e 20 62 65 69 6e  the version bein
0e80: 67 20 6d 65 72 67 65 64 2e 0a 20 20 2a 2f 0a 20  g merged..  */. 
0e90: 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 0a   db_multi_exec(.
0ea0: 20 20 20 20 22 44 52 4f 50 20 54 41 42 4c 45 20      "DROP TABLE 
0eb0: 49 46 20 45 58 49 53 54 53 20 66 76 3b 22 0a 20  IF EXISTS fv;". 
0ec0: 20 20 20 22 43 52 45 41 54 45 20 54 45 4d 50 20     "CREATE TEMP 
0ed0: 54 41 42 4c 45 20 66 76 28 22 0a 20 20 20 20 22  TABLE fv(".    "
0ee0: 20 20 66 6e 20 54 45 58 54 20 50 52 49 4d 41 52    fn TEXT PRIMAR
0ef0: 59 20 4b 45 59 2c 22 20 20 20 20 20 20 2f 2a 20  Y KEY,"      /* 
0f00: 54 68 65 20 66 69 6c 65 6e 61 6d 65 20 2a 2f 0a  The filename */.
0f10: 20 20 20 20 22 20 20 69 64 76 20 49 4e 54 45 47      "  idv INTEG
0f20: 45 52 2c 22 20 20 20 20 20 20 20 20 20 20 20 20  ER,"            
0f30: 20 20 2f 2a 20 56 46 49 4c 45 20 65 6e 74 72 79    /* VFILE entry
0f40: 20 66 6f 72 20 63 75 72 72 65 6e 74 20 76 65 72   for current ver
0f50: 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 22 20 20 69  sion */.    "  i
0f60: 64 74 20 49 4e 54 45 47 45 52 2c 22 20 20 20 20  dt INTEGER,"    
0f70: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 46 49            /* VFI
0f80: 4c 45 20 65 6e 74 72 79 20 66 6f 72 20 74 61 72  LE entry for tar
0f90: 67 65 74 20 76 65 72 73 69 6f 6e 20 2a 2f 0a 20  get version */. 
0fa0: 20 20 20 22 20 20 63 68 6e 67 65 64 20 42 4f 4f     "  chnged BOO
0fb0: 4c 45 41 4e 2c 22 20 20 20 20 20 20 20 20 20 20  LEAN,"          
0fc0: 20 2f 2a 20 54 72 75 65 20 69 66 20 63 75 72 72   /* True if curr
0fd0: 65 6e 74 20 76 65 72 73 69 6f 6e 20 68 61 73 20  ent version has 
0fe0: 62 65 65 6e 20 65 64 69 74 65 64 20 2a 2f 0a 20  been edited */. 
0ff0: 20 20 20 22 20 20 72 69 64 76 20 49 4e 54 45 47     "  ridv INTEG
1000: 45 52 2c 22 20 20 20 20 20 20 20 20 20 20 20 20  ER,"            
1010: 20 2f 2a 20 52 65 63 6f 72 64 20 49 44 20 66 6f   /* Record ID fo
1020: 72 20 63 75 72 72 65 6e 74 20 76 65 72 73 69 6f  r current versio
1030: 6e 20 2a 2f 0a 20 20 20 20 22 20 20 72 69 64 74  n */.    "  ridt
1040: 20 49 4e 54 45 47 45 52 20 22 20 20 20 20 20 20   INTEGER "      
1050: 20 20 20 20 20 20 20 2f 2a 20 52 65 63 6f 72 64         /* Record
1060: 20 49 44 20 66 6f 72 20 74 61 72 67 65 74 20 2a   ID for target *
1070: 2f 0a 20 20 20 20 22 29 3b 22 0a 20 20 20 20 22  /.    ");".    "
1080: 49 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 45  INSERT OR IGNORE
1090: 20 49 4e 54 4f 20 66 76 22 0a 20 20 20 20 22 20   INTO fv".    " 
10a0: 53 45 4c 45 43 54 20 70 61 74 68 6e 61 6d 65 2c  SELECT pathname,
10b0: 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 20 46   0, 0, 0, 0, 0 F
10c0: 52 4f 4d 20 76 66 69 6c 65 22 0a 20 20 29 3b 0a  ROM vfile".  );.
10d0: 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c    db_prepare(&q,
10e0: 0a 20 20 20 20 22 53 45 4c 45 43 54 20 69 64 2c  .    "SELECT id,
10f0: 20 70 61 74 68 6e 61 6d 65 2c 20 72 69 64 20 46   pathname, rid F
1100: 52 4f 4d 20 76 66 69 6c 65 22 0a 20 20 20 20 22  ROM vfile".    "
1110: 20 57 48 45 52 45 20 76 69 64 3d 25 64 22 2c 20   WHERE vid=%d", 
1120: 74 69 64 0a 20 20 29 3b 0a 20 20 77 68 69 6c 65  tid.  );.  while
1130: 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53  ( db_step(&q)==S
1140: 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20  QLITE_ROW ){.   
1150: 20 69 6e 74 20 69 64 20 3d 20 64 62 5f 63 6f 6c   int id = db_col
1160: 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 30 29 3b 0a  umn_int(&q, 0);.
1170: 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a      const char *
1180: 66 6e 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74  fn = db_column_t
1190: 65 78 74 28 26 71 2c 20 31 29 3b 0a 20 20 20 20  ext(&q, 1);.    
11a0: 69 6e 74 20 72 69 64 20 3d 20 64 62 5f 63 6f 6c  int rid = db_col
11b0: 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 32 29 3b 0a  umn_int(&q, 2);.
11c0: 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65      db_multi_exe
11d0: 63 28 0a 20 20 20 20 20 20 22 55 50 44 41 54 45  c(.      "UPDATE
11e0: 20 66 76 20 53 45 54 20 69 64 74 3d 25 64 2c 20   fv SET idt=%d, 
11f0: 72 69 64 74 3d 25 64 20 57 48 45 52 45 20 66 6e  ridt=%d WHERE fn
1200: 3d 25 51 22 2c 0a 20 20 20 20 20 20 69 64 2c 20  =%Q",.      id, 
1210: 72 69 64 2c 20 66 6e 0a 20 20 20 20 29 3b 0a 20  rid, fn.    );. 
1220: 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65   }.  db_finalize
1230: 28 26 71 29 3b 0a 20 20 64 62 5f 70 72 65 70 61  (&q);.  db_prepa
1240: 72 65 28 26 71 2c 0a 20 20 20 20 22 53 45 4c 45  re(&q,.    "SELE
1250: 43 54 20 69 64 2c 20 70 61 74 68 6e 61 6d 65 2c  CT id, pathname,
1260: 20 72 69 64 2c 20 63 68 6e 67 65 64 20 46 52 4f   rid, chnged FRO
1270: 4d 20 76 66 69 6c 65 22 0a 20 20 20 20 22 20 57  M vfile".    " W
1280: 48 45 52 45 20 76 69 64 3d 25 64 22 2c 20 76 69  HERE vid=%d", vi
1290: 64 0a 20 20 29 3b 0a 20 20 77 68 69 6c 65 28 20  d.  );.  while( 
12a0: 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c  db_step(&q)==SQL
12b0: 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 69  ITE_ROW ){.    i
12c0: 6e 74 20 69 64 20 3d 20 64 62 5f 63 6f 6c 75 6d  nt id = db_colum
12d0: 6e 5f 69 6e 74 28 26 71 2c 20 30 29 3b 0a 20 20  n_int(&q, 0);.  
12e0: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 6e    const char *fn
12f0: 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78   = db_column_tex
1300: 74 28 26 71 2c 20 31 29 3b 0a 20 20 20 20 69 6e  t(&q, 1);.    in
1310: 74 20 72 69 64 20 3d 20 64 62 5f 63 6f 6c 75 6d  t rid = db_colum
1320: 6e 5f 69 6e 74 28 26 71 2c 20 32 29 3b 0a 20 20  n_int(&q, 2);.  
1330: 20 20 69 6e 74 20 63 68 6e 67 65 64 20 3d 20 64    int chnged = d
1340: 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c  b_column_int(&q,
1350: 20 33 29 3b 0a 20 20 20 20 64 62 5f 6d 75 6c 74   3);.    db_mult
1360: 69 5f 65 78 65 63 28 0a 20 20 20 20 20 20 22 55  i_exec(.      "U
1370: 50 44 41 54 45 20 66 76 20 53 45 54 20 69 64 76  PDATE fv SET idv
1380: 3d 25 64 2c 20 72 69 64 76 3d 25 64 2c 20 63 68  =%d, ridv=%d, ch
1390: 6e 67 65 64 3d 25 64 20 57 48 45 52 45 20 66 6e  nged=%d WHERE fn
13a0: 3d 25 51 22 2c 0a 20 20 20 20 20 20 69 64 2c 20  =%Q",.      id, 
13b0: 72 69 64 2c 20 63 68 6e 67 65 64 2c 20 66 6e 0a  rid, chnged, fn.
13c0: 20 20 20 20 29 3b 0a 20 20 7d 0a 20 20 64 62 5f      );.  }.  db_
13d0: 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 0a 20  finalize(&q);.. 
13e0: 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c 20   db_prepare(&q, 
13f0: 0a 20 20 20 20 22 53 45 4c 45 43 54 20 66 6e 2c  .    "SELECT fn,
1400: 20 69 64 76 2c 20 72 69 64 76 2c 20 69 64 74 2c   idv, ridv, idt,
1410: 20 72 69 64 74 2c 20 63 68 6e 67 65 64 20 46 52   ridt, chnged FR
1420: 4f 4d 20 66 76 20 4f 52 44 45 52 20 42 59 20 31  OM fv ORDER BY 1
1430: 22 0a 20 20 29 3b 0a 20 20 77 68 69 6c 65 28 20  ".  );.  while( 
1440: 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c  db_step(&q)==SQL
1450: 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 63  ITE_ROW ){.    c
1460: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65  onst char *zName
1470: 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78   = db_column_tex
1480: 74 28 26 71 2c 20 30 29 3b 0a 20 20 20 20 69 6e  t(&q, 0);.    in
1490: 74 20 69 64 76 20 3d 20 64 62 5f 63 6f 6c 75 6d  t idv = db_colum
14a0: 6e 5f 69 6e 74 28 26 71 2c 20 31 29 3b 0a 20 20  n_int(&q, 1);.  
14b0: 20 20 69 6e 74 20 72 69 64 76 20 3d 20 64 62 5f    int ridv = db_
14c0: 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 32  column_int(&q, 2
14d0: 29 3b 0a 20 20 20 20 69 6e 74 20 69 64 74 20 3d  );.    int idt =
14e0: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26   db_column_int(&
14f0: 71 2c 20 33 29 3b 0a 20 20 20 20 69 6e 74 20 72  q, 3);.    int r
1500: 69 64 74 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f  idt = db_column_
1510: 69 6e 74 28 26 71 2c 20 34 29 3b 0a 20 20 20 20  int(&q, 4);.    
1520: 69 6e 74 20 63 68 6e 67 65 64 20 3d 20 64 62 5f  int chnged = db_
1530: 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 35  column_int(&q, 5
1540: 29 3b 0a 0a 20 20 20 20 69 66 28 20 69 64 76 3e  );..    if( idv>
1550: 30 20 26 26 20 72 69 64 76 3d 3d 30 20 26 26 20  0 && ridv==0 && 
1560: 69 64 74 3e 30 20 29 7b 0a 20 20 20 20 20 20 2f  idt>0 ){.      /
1570: 2a 20 43 6f 6e 66 6c 69 63 74 2e 20 20 54 68 69  * Conflict.  Thi
1580: 73 20 66 69 6c 65 20 68 61 73 20 62 65 65 6e 20  s file has been 
1590: 61 64 64 65 64 20 74 6f 20 74 68 65 20 63 75 72  added to the cur
15a0: 72 65 6e 74 20 63 68 65 63 6b 6f 75 74 0a 20 20  rent checkout.  
15b0: 20 20 20 20 2a 2a 20 62 75 74 20 61 6c 73 6f 20      ** but also 
15c0: 65 78 69 73 74 73 20 69 6e 20 74 68 65 20 74 61  exists in the ta
15d0: 72 67 65 74 20 63 68 65 63 6b 6f 75 74 2e 20 20  rget checkout.  
15e0: 55 73 65 20 74 68 65 20 63 75 72 72 65 6e 74 20  Use the current 
15f0: 76 65 72 73 69 6f 6e 2e 0a 20 20 20 20 20 20 2a  version..      *
1600: 2f 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28 22  /.      printf("
1610: 43 4f 4e 46 4c 49 43 54 20 25 73 5c 6e 22 2c 20  CONFLICT %s\n", 
1620: 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 7d 65 6c 73  zName);.    }els
1630: 65 20 69 66 28 20 69 64 74 3e 30 20 26 26 20 69  e if( idt>0 && i
1640: 64 76 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 2f  dv==0 ){.      /
1650: 2a 20 46 69 6c 65 20 61 64 64 65 64 20 69 6e 20  * File added in 
1660: 74 68 65 20 74 61 72 67 65 74 2e 20 2a 2f 0a 20  the target. */. 
1670: 20 20 20 20 20 70 72 69 6e 74 66 28 22 41 44 44       printf("ADD
1680: 20 25 73 5c 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a   %s\n", zName);.
1690: 20 20 20 20 20 20 75 6e 64 6f 5f 73 61 76 65 28        undo_save(
16a0: 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 76 66  zName);.      vf
16b0: 69 6c 65 5f 74 6f 5f 64 69 73 6b 28 30 2c 20 69  ile_to_disk(0, i
16c0: 64 74 2c 20 30 29 3b 0a 20 20 20 20 7d 65 6c 73  dt, 0);.    }els
16d0: 65 20 69 66 28 20 69 64 74 3e 30 20 26 26 20 69  e if( idt>0 && i
16e0: 64 76 3e 30 20 26 26 20 72 69 64 74 21 3d 72 69  dv>0 && ridt!=ri
16f0: 64 76 20 26 26 20 63 68 6e 67 65 64 3d 3d 30 20  dv && chnged==0 
1700: 29 7b 0a 20 20 20 20 20 20 2f 2a 20 54 68 65 20  ){.      /* The 
1710: 66 69 6c 65 20 69 73 20 75 6e 65 64 69 74 65 64  file is unedited
1720: 2e 20 20 43 68 61 6e 67 65 20 69 74 20 74 6f 20  .  Change it to 
1730: 74 68 65 20 74 61 72 67 65 74 20 76 65 72 73 69  the target versi
1740: 6f 6e 20 2a 2f 0a 20 20 20 20 20 20 70 72 69 6e  on */.      prin
1750: 74 66 28 22 55 50 44 41 54 45 20 25 73 5c 6e 22  tf("UPDATE %s\n"
1760: 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20  , zName);.      
1770: 75 6e 64 6f 5f 73 61 76 65 28 7a 4e 61 6d 65 29  undo_save(zName)
1780: 3b 0a 20 20 20 20 20 20 76 66 69 6c 65 5f 74 6f  ;.      vfile_to
1790: 5f 64 69 73 6b 28 30 2c 20 69 64 74 2c 20 30 29  _disk(0, idt, 0)
17a0: 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20  ;.    }else if( 
17b0: 69 64 74 3d 3d 30 20 26 26 20 69 64 76 3e 30 20  idt==0 && idv>0 
17c0: 29 7b 0a 20 20 20 20 20 20 69 66 28 20 63 68 6e  ){.      if( chn
17d0: 67 65 64 20 29 7b 0a 20 20 20 20 20 20 20 20 70  ged ){.        p
17e0: 72 69 6e 74 66 28 22 43 4f 4e 46 4c 49 43 54 20  rintf("CONFLICT 
17f0: 25 73 5c 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20  %s\n", zName);. 
1800: 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20       }else{.    
1810: 20 20 20 20 63 68 61 72 20 2a 7a 46 75 6c 6c 50      char *zFullP
1820: 61 74 68 3b 0a 20 20 20 20 20 20 20 20 70 72 69  ath;.        pri
1830: 6e 74 66 28 22 52 45 4d 4f 56 45 20 25 73 5c 6e  ntf("REMOVE %s\n
1840: 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20  ", zName);.     
1850: 20 20 20 75 6e 64 6f 5f 73 61 76 65 28 7a 4e 61     undo_save(zNa
1860: 6d 65 29 3b 0a 20 20 20 20 20 20 20 20 7a 46 75  me);.        zFu
1870: 6c 6c 50 61 74 68 20 3d 20 6d 70 72 69 6e 74 66  llPath = mprintf
1880: 28 22 25 73 2f 25 73 22 2c 20 67 2e 7a 4c 6f 63  ("%s/%s", g.zLoc
1890: 61 6c 52 6f 6f 74 2c 20 7a 4e 61 6d 65 29 3b 0a  alRoot, zName);.
18a0: 20 20 20 20 20 20 20 20 75 6e 6c 69 6e 6b 28 7a          unlink(z
18b0: 46 75 6c 6c 50 61 74 68 29 3b 0a 20 20 20 20 20  FullPath);.     
18c0: 20 20 20 66 72 65 65 28 7a 46 75 6c 6c 50 61 74     free(zFullPat
18d0: 68 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20  h);.      }.    
18e0: 7d 65 6c 73 65 20 69 66 28 20 69 64 74 3e 30 20  }else if( idt>0 
18f0: 26 26 20 69 64 76 3e 30 20 26 26 20 72 69 64 74  && idv>0 && ridt
1900: 21 3d 72 69 64 76 20 26 26 20 63 68 6e 67 65 64  !=ridv && chnged
1910: 20 29 7b 0a 20 20 20 20 20 20 2f 2a 20 4d 65 72   ){.      /* Mer
1920: 67 65 20 74 68 65 20 63 68 61 6e 67 65 73 20 69  ge the changes i
1930: 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20 74 72  n the current tr
1940: 65 65 20 69 6e 74 6f 20 74 68 65 20 74 61 72 67  ee into the targ
1950: 65 74 20 76 65 72 73 69 6f 6e 20 2a 2f 0a 20 20  et version */.  
1960: 20 20 20 20 42 6c 6f 62 20 65 2c 20 72 2c 20 74      Blob e, r, t
1970: 2c 20 76 3b 0a 20 20 20 20 20 20 63 68 61 72 20  , v;.      char 
1980: 2a 7a 46 75 6c 6c 50 61 74 68 3b 0a 20 20 20 20  *zFullPath;.    
1990: 20 20 70 72 69 6e 74 66 28 22 4d 45 52 47 45 20    printf("MERGE 
19a0: 25 73 5c 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20  %s\n", zName);. 
19b0: 20 20 20 20 20 75 6e 64 6f 5f 73 61 76 65 28 7a       undo_save(z
19c0: 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 7a 46 75  Name);.      zFu
19d0: 6c 6c 50 61 74 68 20 3d 20 6d 70 72 69 6e 74 66  llPath = mprintf
19e0: 28 22 25 73 2f 25 73 22 2c 20 67 2e 7a 4c 6f 63  ("%s/%s", g.zLoc
19f0: 61 6c 52 6f 6f 74 2c 20 7a 4e 61 6d 65 29 3b 0a  alRoot, zName);.
1a00: 20 20 20 20 20 20 63 6f 6e 74 65 6e 74 5f 67 65        content_ge
1a10: 74 28 72 69 64 74 2c 20 26 74 29 3b 0a 20 20 20  t(ridt, &t);.   
1a20: 20 20 20 63 6f 6e 74 65 6e 74 5f 67 65 74 28 72     content_get(r
1a30: 69 64 76 2c 20 26 76 29 3b 0a 20 20 20 20 20 20  idv, &v);.      
1a40: 62 6c 6f 62 5f 7a 65 72 6f 28 26 65 29 3b 0a 20  blob_zero(&e);. 
1a50: 20 20 20 20 20 62 6c 6f 62 5f 72 65 61 64 5f 66       blob_read_f
1a60: 72 6f 6d 5f 66 69 6c 65 28 26 65 2c 20 7a 46 75  rom_file(&e, zFu
1a70: 6c 6c 50 61 74 68 29 3b 0a 20 20 20 20 20 20 62  llPath);.      b
1a80: 6c 6f 62 5f 6d 65 72 67 65 28 26 76 2c 20 26 65  lob_merge(&v, &e
1a90: 2c 20 26 74 2c 20 26 72 29 3b 0a 20 20 20 20 20  , &t, &r);.     
1aa0: 20 62 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f 66   blob_write_to_f
1ab0: 69 6c 65 28 26 72 2c 20 7a 46 75 6c 6c 50 61 74  ile(&r, zFullPat
1ac0: 68 29 3b 0a 20 20 20 20 20 20 66 72 65 65 28 7a  h);.      free(z
1ad0: 46 75 6c 6c 50 61 74 68 29 3b 0a 20 20 20 20 20  FullPath);.     
1ae0: 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 76 29 3b   blob_reset(&v);
1af0: 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 65  .      blob_rese
1b00: 74 28 26 65 29 3b 0a 20 20 20 20 20 20 62 6c 6f  t(&e);.      blo
1b10: 62 5f 72 65 73 65 74 28 26 74 29 3b 0a 20 20 20  b_reset(&t);.   
1b20: 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 72     blob_reset(&r
1b30: 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 64  );.    }.  }.  d
1b40: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a  b_finalize(&q);.
1b50: 20 20 0a 20 20 2f 2a 0a 20 20 2a 2a 20 43 6c 65    .  /*.  ** Cle
1b60: 61 6e 20 75 70 20 74 68 65 20 6d 69 64 20 61 6e  an up the mid an
1b70: 64 20 70 69 64 20 56 46 49 4c 45 20 65 6e 74 72  d pid VFILE entr
1b80: 69 65 73 2e 20 20 54 68 65 6e 20 63 6f 6d 6d 69  ies.  Then commi
1b90: 74 20 74 68 65 20 63 68 61 6e 67 65 73 2e 0a 20  t the changes.. 
1ba0: 20 2a 2f 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65   */.  db_multi_e
1bb0: 78 65 63 28 22 44 45 4c 45 54 45 20 46 52 4f 4d  xec("DELETE FROM
1bc0: 20 76 66 69 6c 65 20 57 48 45 52 45 20 76 69 64   vfile WHERE vid
1bd0: 21 3d 25 64 22 2c 20 74 69 64 29 3b 0a 20 20 6d  !=%d", tid);.  m
1be0: 61 6e 69 66 65 73 74 5f 74 6f 5f 64 69 73 6b 28  anifest_to_disk(
1bf0: 74 69 64 29 3b 0a 20 20 64 62 5f 6c 73 65 74 5f  tid);.  db_lset_
1c00: 69 6e 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 20  int("checkout", 
1c10: 74 69 64 29 3b 0a 20 20 64 62 5f 65 6e 64 5f 74  tid);.  db_end_t
1c20: 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 3b 0a 7d  ransaction(0);.}
1c30: 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a  ../*.** COMMAND:
1c40: 20 72 65 76 65 72 74 0a 2a 2a 0a 2a 2a 20 55 73   revert.**.** Us
1c50: 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 72 65 76  age: %fossil rev
1c60: 65 72 74 20 3f 2d 79 65 73 20 3f 2d 72 20 52 45  ert ?-yes ?-r RE
1c70: 56 49 53 49 4f 4e 20 46 49 4c 45 0a 2a 2a 0a 2a  VISION FILE.**.*
1c80: 2a 20 52 65 76 65 72 74 20 74 6f 20 74 68 65 20  * Revert to the 
1c90: 63 75 72 72 65 6e 74 20 72 65 70 6f 73 69 74 6f  current reposito
1ca0: 72 79 20 76 65 72 73 69 6f 6e 20 6f 66 20 46 49  ry version of FI
1cb0: 4c 45 2e 20 54 68 69 73 0a 2a 2a 20 63 6f 6d 6d  LE. This.** comm
1cc0: 61 6e 64 20 77 69 6c 6c 20 63 6f 6e 66 69 72 6d  and will confirm
1cd0: 20 79 6f 75 72 20 6f 70 65 72 61 74 69 6f 6e 2c   your operation,
1ce0: 20 75 6e 6c 65 73 73 20 79 6f 75 20 64 6f 20 73   unless you do s
1cf0: 6f 0a 2a 2a 20 61 74 20 74 68 65 20 63 6f 6d 6d  o.** at the comm
1d00: 61 6e 64 20 6c 69 6e 65 20 76 69 61 20 74 68 65  and line via the
1d10: 20 2d 79 65 73 20 6f 70 74 69 6f 6e 2e 0a 2a 2a   -yes option..**
1d20: 2f 0a 76 6f 69 64 20 72 65 76 65 72 74 5f 63 6d  /.void revert_cm
1d30: 64 28 76 6f 69 64 29 7b 0a 20 20 63 6f 6e 73 74  d(void){.  const
1d40: 20 63 68 61 72 20 2a 7a 46 69 6c 65 3b 0a 20 20   char *zFile;.  
1d50: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 52 65 76  const char *zRev
1d60: 69 73 69 6f 6e 3b 0a 20 20 42 6c 6f 62 20 66 6e  ision;.  Blob fn
1d70: 61 6d 65 3b 0a 20 20 42 6c 6f 62 20 72 65 63 6f  ame;.  Blob reco
1d80: 72 64 3b 0a 20 20 42 6c 6f 62 20 61 6e 73 3b 0a  rd;.  Blob ans;.
1d90: 20 20 69 6e 74 20 72 69 64 20 3d 20 30 2c 20 79    int rid = 0, y
1da0: 65 73 52 65 76 65 72 74 3b 0a 20 20 0a 20 20 79  esRevert;.  .  y
1db0: 65 73 52 65 76 65 72 74 20 3d 20 66 69 6e 64 5f  esRevert = find_
1dc0: 6f 70 74 69 6f 6e 28 22 79 65 73 22 2c 20 22 79  option("yes", "y
1dd0: 22 2c 20 30 29 21 3d 30 3b 0a 20 20 7a 52 65 76  ", 0)!=0;.  zRev
1de0: 69 73 69 6f 6e 20 3d 20 66 69 6e 64 5f 6f 70 74  ision = find_opt
1df0: 69 6f 6e 28 22 72 65 76 69 73 69 6f 6e 22 2c 20  ion("revision", 
1e00: 22 72 22 2c 20 31 29 3b 0a 20 20 76 65 72 69 66  "r", 1);.  verif
1e10: 79 5f 61 6c 6c 5f 6f 70 74 69 6f 6e 73 28 29 3b  y_all_options();
1e20: 0a 20 20 0a 20 20 69 66 28 20 67 2e 61 72 67 63  .  .  if( g.argc
1e30: 3c 33 20 29 7b 0a 20 20 20 20 75 73 61 67 65 28  <3 ){.    usage(
1e40: 22 3f 4f 50 54 49 4f 4e 53 20 46 49 4c 45 22 29  "?OPTIONS FILE")
1e50: 3b 0a 20 20 7d 0a 20 20 64 62 5f 6d 75 73 74 5f  ;.  }.  db_must_
1e60: 62 65 5f 77 69 74 68 69 6e 5f 74 72 65 65 28 29  be_within_tree()
1e70: 3b 0a 20 20 0a 20 20 7a 46 69 6c 65 20 3d 20 67  ;.  .  zFile = g
1e80: 2e 61 72 67 76 5b 67 2e 61 72 67 63 2d 31 5d 3b  .argv[g.argc-1];
1e90: 0a 0a 20 20 69 66 28 20 21 66 69 6c 65 5f 74 72  ..  if( !file_tr
1ea0: 65 65 5f 6e 61 6d 65 28 7a 46 69 6c 65 2c 20 26  ee_name(zFile, &
1eb0: 66 6e 61 6d 65 29 20 29 7b 0a 20 20 20 20 66 6f  fname) ){.    fo
1ec0: 73 73 69 6c 5f 70 61 6e 69 63 28 22 75 6e 6b 6e  ssil_panic("unkn
1ed0: 6f 77 6e 20 66 69 6c 65 3a 20 25 73 22 2c 20 7a  own file: %s", z
1ee0: 46 69 6c 65 29 3b 0a 20 20 7d 0a 20 20 0a 20 20  File);.  }.  .  
1ef0: 69 66 28 20 79 65 73 52 65 76 65 72 74 3d 3d 30  if( yesRevert==0
1f00: 20 29 7b 0a 20 20 20 20 63 68 61 72 20 2a 70 72   ){.    char *pr
1f10: 6f 6d 70 74 20 3d 20 6d 70 72 69 6e 74 66 28 22  ompt = mprintf("
1f20: 72 65 76 65 72 74 20 66 69 6c 65 20 25 42 3f 20  revert file %B? 
1f30: 74 68 69 73 20 77 69 6c 6c 20 64 65 73 74 72 6f  this will destro
1f40: 79 20 6c 6f 63 61 6c 20 63 68 61 6e 67 65 73 20  y local changes 
1f50: 5b 79 2f 4e 5d 3f 20 22 2c 0a 20 20 20 20 20 20  [y/N]? ",.      
1f60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1f70: 20 20 20 20 20 26 66 6e 61 6d 65 29 3b 0a 20 20       &fname);.  
1f80: 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 61 6e 73    blob_zero(&ans
1f90: 29 3b 0a 20 20 20 20 70 72 6f 6d 70 74 5f 75 73  );.    prompt_us
1fa0: 65 72 28 70 72 6f 6d 70 74 2c 20 26 61 6e 73 29  er(prompt, &ans)
1fb0: 3b 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 73  ;.    if( blob_s
1fc0: 74 72 28 26 61 6e 73 29 5b 30 5d 3d 3d 27 79 27  tr(&ans)[0]=='y'
1fd0: 20 29 7b 0a 20 20 20 20 20 20 79 65 73 52 65 76   ){.      yesRev
1fe0: 65 72 74 20 3d 20 31 3b 0a 20 20 20 20 7d 0a 20  ert = 1;.    }. 
1ff0: 20 7d 0a 0a 20 20 69 66 28 20 79 65 73 52 65 76   }..  if( yesRev
2000: 65 72 74 3d 3d 31 20 26 26 20 7a 52 65 76 69 73  ert==1 && zRevis
2010: 69 6f 6e 21 3d 30 20 29 7b 0a 20 20 20 20 63 6f  ion!=0 ){.    co
2020: 6e 74 65 6e 74 5f 67 65 74 5f 68 69 73 74 6f 72  ntent_get_histor
2030: 69 63 61 6c 5f 66 69 6c 65 28 7a 52 65 76 69 73  ical_file(zRevis
2040: 69 6f 6e 2c 20 7a 46 69 6c 65 2c 20 26 72 65 63  ion, zFile, &rec
2050: 6f 72 64 29 3b 0a 20 20 7d 65 6c 73 65 20 69 66  ord);.  }else if
2060: 28 20 79 65 73 52 65 76 65 72 74 3d 3d 31 20 29  ( yesRevert==1 )
2070: 7b 0a 20 20 20 20 72 69 64 20 3d 20 64 62 5f 69  {.    rid = db_i
2080: 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 20 72 69  nt(0, "SELECT ri
2090: 64 20 46 52 4f 4d 20 76 66 69 6c 65 20 57 48 45  d FROM vfile WHE
20a0: 52 45 20 70 61 74 68 6e 61 6d 65 3d 25 42 22 2c  RE pathname=%B",
20b0: 20 26 66 6e 61 6d 65 29 3b 0a 20 20 20 20 69 66   &fname);.    if
20c0: 28 20 72 69 64 3d 3d 30 20 29 7b 0a 20 20 20 20  ( rid==0 ){.    
20d0: 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22    fossil_panic("
20e0: 6e 6f 20 68 69 73 74 6f 72 79 20 66 6f 72 20 66  no history for f
20f0: 69 6c 65 3a 20 25 62 22 2c 20 26 66 6e 61 6d 65  ile: %b", &fname
2100: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63 6f 6e  );.    }.    con
2110: 74 65 6e 74 5f 67 65 74 28 72 69 64 2c 20 26 72  tent_get(rid, &r
2120: 65 63 6f 72 64 29 3b 0a 20 20 7d 0a 20 20 0a 20  ecord);.  }.  . 
2130: 20 69 66 28 20 79 65 73 52 65 76 65 72 74 3d 3d   if( yesRevert==
2140: 31 20 29 7b 0a 20 20 20 20 62 6c 6f 62 5f 77 72  1 ){.    blob_wr
2150: 69 74 65 5f 74 6f 5f 66 69 6c 65 28 26 72 65 63  ite_to_file(&rec
2160: 6f 72 64 2c 20 62 6c 6f 62 5f 73 74 72 28 26 66  ord, blob_str(&f
2170: 6e 61 6d 65 29 29 3b 0a 20 20 20 20 70 72 69 6e  name));.    prin
2180: 74 66 28 22 25 73 20 72 65 76 65 72 74 65 64 5c  tf("%s reverted\
2190: 6e 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 66 6e  n", blob_str(&fn
21a0: 61 6d 65 29 29 3b 0a 20 20 20 20 62 6c 6f 62 5f  ame));.    blob_
21b0: 72 65 73 65 74 28 26 72 65 63 6f 72 64 29 3b 0a  reset(&record);.
21c0: 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26      blob_reset(&
21d0: 66 6e 61 6d 65 29 3b 0a 20 20 7d 65 6c 73 65 7b  fname);.  }else{
21e0: 0a 20 20 20 20 70 72 69 6e 74 66 28 22 72 65 76  .    printf("rev
21f0: 65 72 74 20 63 61 6e 63 65 6c 65 64 5c 6e 22 29  ert canceled\n")
2200: 3b 0a 20 20 7d 0a 7d 0a                          ;.  }.}.