Hex Artifact Content
Not logged in

Artifact 676d19419e60b2c5516d86436ad58d06c5c8b2a9:

File src/update.c part of check-in [371dd6574c] - Fix the revert command so that it works from subdirectories. Other minor comment and help-text changes. by drh on 2007-12-04 01:26:21. Also file src/update.c part of check-in [d0305b305a] - Merged mainline into my branch to get the newest application. by aku on 2007-12-05 08:07:46.

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 69 6e 74 20  t, v;.      int 
1ae0: 72 63 3b 0a 20 20 20 20 20 20 63 68 61 72 20 2a  rc;.      char *
1af0: 7a 46 75 6c 6c 50 61 74 68 3b 0a 20 20 20 20 20  zFullPath;.     
1b00: 20 70 72 69 6e 74 66 28 22 4d 45 52 47 45 20 25   printf("MERGE %
1b10: 73 5c 6e 22 2c 20 7a 4e 61 6d 65 29 3b 0a 20 20  s\n", zName);.  
1b20: 20 20 20 20 75 6e 64 6f 5f 73 61 76 65 28 7a 4e      undo_save(zN
1b30: 61 6d 65 29 3b 0a 20 20 20 20 20 20 7a 46 75 6c  ame);.      zFul
1b40: 6c 50 61 74 68 20 3d 20 6d 70 72 69 6e 74 66 28  lPath = mprintf(
1b50: 22 25 73 2f 25 73 22 2c 20 67 2e 7a 4c 6f 63 61  "%s/%s", g.zLoca
1b60: 6c 52 6f 6f 74 2c 20 7a 4e 61 6d 65 29 3b 0a 20  lRoot, zName);. 
1b70: 20 20 20 20 20 63 6f 6e 74 65 6e 74 5f 67 65 74       content_get
1b80: 28 72 69 64 74 2c 20 26 74 29 3b 0a 20 20 20 20  (ridt, &t);.    
1b90: 20 20 63 6f 6e 74 65 6e 74 5f 67 65 74 28 72 69    content_get(ri
1ba0: 64 76 2c 20 26 76 29 3b 0a 20 20 20 20 20 20 62  dv, &v);.      b
1bb0: 6c 6f 62 5f 7a 65 72 6f 28 26 65 29 3b 0a 20 20  lob_zero(&e);.  
1bc0: 20 20 20 20 62 6c 6f 62 5f 72 65 61 64 5f 66 72      blob_read_fr
1bd0: 6f 6d 5f 66 69 6c 65 28 26 65 2c 20 7a 46 75 6c  om_file(&e, zFul
1be0: 6c 50 61 74 68 29 3b 0a 20 20 20 20 20 20 72 63  lPath);.      rc
1bf0: 20 3d 20 62 6c 6f 62 5f 6d 65 72 67 65 28 26 76   = blob_merge(&v
1c00: 2c 20 26 65 2c 20 26 74 2c 20 26 72 29 3b 0a 20  , &e, &t, &r);. 
1c10: 20 20 20 20 20 69 66 28 20 72 63 3e 3d 30 20 29       if( rc>=0 )
1c20: 7b 0a 20 20 20 20 20 20 20 20 62 6c 6f 62 5f 77  {.        blob_w
1c30: 72 69 74 65 5f 74 6f 5f 66 69 6c 65 28 26 72 2c  rite_to_file(&r,
1c40: 20 7a 46 75 6c 6c 50 61 74 68 29 3b 0a 20 20 20   zFullPath);.   
1c50: 20 20 20 20 20 69 66 28 20 72 63 3e 30 20 29 7b       if( rc>0 ){
1c60: 0a 20 20 20 20 20 20 20 20 20 20 70 72 69 6e 74  .          print
1c70: 66 28 22 2a 2a 2a 2a 2a 20 25 64 20 6d 65 72 67  f("***** %d merg
1c80: 65 20 63 6f 6e 66 6c 69 63 74 73 20 69 6e 20 25  e conflicts in %
1c90: 73 5c 6e 22 2c 20 72 63 2c 20 7a 4e 61 6d 65 29  s\n", rc, zName)
1ca0: 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20  ;.        }.    
1cb0: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20    }else{.       
1cc0: 20 70 72 69 6e 74 66 28 22 2a 2a 2a 2a 2a 20 43   printf("***** C
1cd0: 61 6e 6e 6f 74 20 6d 65 72 67 65 20 62 69 6e 61  annot merge bina
1ce0: 72 79 20 66 69 6c 65 20 25 73 5c 6e 22 2c 20 7a  ry file %s\n", z
1cf0: 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 7d 0a 20  Name);.      }. 
1d00: 20 20 20 20 20 66 72 65 65 28 7a 46 75 6c 6c 50       free(zFullP
1d10: 61 74 68 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62  ath);.      blob
1d20: 5f 72 65 73 65 74 28 26 76 29 3b 0a 20 20 20 20  _reset(&v);.    
1d30: 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 65 29    blob_reset(&e)
1d40: 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73  ;.      blob_res
1d50: 65 74 28 26 74 29 3b 0a 20 20 20 20 20 20 62 6c  et(&t);.      bl
1d60: 6f 62 5f 72 65 73 65 74 28 26 72 29 3b 0a 20 20  ob_reset(&r);.  
1d70: 20 20 20 20 0a 20 20 20 20 7d 0a 20 20 7d 0a 20      .    }.  }. 
1d80: 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29   db_finalize(&q)
1d90: 3b 0a 20 20 0a 20 20 2f 2a 0a 20 20 2a 2a 20 43  ;.  .  /*.  ** C
1da0: 6c 65 61 6e 20 75 70 20 74 68 65 20 6d 69 64 20  lean up the mid 
1db0: 61 6e 64 20 70 69 64 20 56 46 49 4c 45 20 65 6e  and pid VFILE en
1dc0: 74 72 69 65 73 2e 20 20 54 68 65 6e 20 63 6f 6d  tries.  Then com
1dd0: 6d 69 74 20 74 68 65 20 63 68 61 6e 67 65 73 2e  mit the changes.
1de0: 0a 20 20 2a 2f 0a 20 20 64 62 5f 6d 75 6c 74 69  .  */.  db_multi
1df0: 5f 65 78 65 63 28 22 44 45 4c 45 54 45 20 46 52  _exec("DELETE FR
1e00: 4f 4d 20 76 66 69 6c 65 20 57 48 45 52 45 20 76  OM vfile WHERE v
1e10: 69 64 21 3d 25 64 22 2c 20 74 69 64 29 3b 0a 20  id!=%d", tid);. 
1e20: 20 6d 61 6e 69 66 65 73 74 5f 74 6f 5f 64 69 73   manifest_to_dis
1e30: 6b 28 74 69 64 29 3b 0a 20 20 64 62 5f 6c 73 65  k(tid);.  db_lse
1e40: 74 5f 69 6e 74 28 22 63 68 65 63 6b 6f 75 74 22  t_int("checkout"
1e50: 2c 20 74 69 64 29 3b 0a 20 20 64 62 5f 65 6e 64  , tid);.  db_end
1e60: 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 3b  _transaction(0);
1e70: 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 47 65 74 20 74  .}.../*.** Get t
1e80: 68 65 20 63 6f 6e 74 65 6e 74 73 20 6f 66 20 61  he contents of a
1e90: 20 66 69 6c 65 20 77 69 74 68 69 6e 20 61 20 67   file within a g
1ea0: 69 76 65 6e 20 72 65 76 69 73 69 6f 6e 2e 0a 2a  iven revision..*
1eb0: 2f 0a 69 6e 74 20 68 69 73 74 6f 72 69 63 61 6c  /.int historical
1ec0: 5f 76 65 72 73 69 6f 6e 5f 6f 66 5f 66 69 6c 65  _version_of_file
1ed0: 28 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  (.  const char *
1ee0: 72 65 76 69 73 69 6f 6e 2c 20 20 20 20 2f 2a 20  revision,    /* 
1ef0: 54 68 65 20 62 61 73 65 6c 69 6e 65 20 6e 61 6d  The baseline nam
1f00: 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65  e containing the
1f10: 20 66 69 6c 65 20 2a 2f 0a 20 20 63 6f 6e 73 74   file */.  const
1f20: 20 63 68 61 72 20 2a 66 69 6c 65 2c 20 20 20 20   char *file,    
1f30: 20 20 20 20 2f 2a 20 46 75 6c 6c 20 74 72 65 65      /* Full tree
1f40: 6e 61 6d 65 20 6f 66 20 74 68 65 20 66 69 6c 65  name of the file
1f50: 20 2a 2f 0a 20 20 42 6c 6f 62 20 2a 63 6f 6e 74   */.  Blob *cont
1f60: 65 6e 74 20 20 20 20 20 20 20 20 20 20 20 20 2f  ent            /
1f70: 2a 20 50 75 74 20 74 68 65 20 63 6f 6e 74 65 6e  * Put the conten
1f80: 74 20 68 65 72 65 20 2a 2f 0a 29 7b 0a 20 20 42  t here */.){.  B
1f90: 6c 6f 62 20 6d 66 69 6c 65 3b 0a 20 20 4d 61 6e  lob mfile;.  Man
1fa0: 69 66 65 73 74 20 6d 3b 0a 20 20 69 6e 74 20 69  ifest m;.  int i
1fb0: 2c 20 72 69 64 3d 30 3b 0a 20 20 0a 20 20 72 69  , rid=0;.  .  ri
1fc0: 64 20 3d 20 6e 61 6d 65 5f 74 6f 5f 72 69 64 28  d = name_to_rid(
1fd0: 72 65 76 69 73 69 6f 6e 29 3b 0a 20 20 63 6f 6e  revision);.  con
1fe0: 74 65 6e 74 5f 67 65 74 28 72 69 64 2c 20 26 6d  tent_get(rid, &m
1ff0: 66 69 6c 65 29 3b 0a 20 20 0a 20 20 69 66 28 20  file);.  .  if( 
2000: 6d 61 6e 69 66 65 73 74 5f 70 61 72 73 65 28 26  manifest_parse(&
2010: 6d 2c 20 26 6d 66 69 6c 65 29 20 29 7b 0a 20 20  m, &mfile) ){.  
2020: 20 20 66 6f 72 28 69 3d 30 3b 20 69 3c 6d 2e 6e    for(i=0; i<m.n
2030: 46 69 6c 65 3b 20 69 2b 2b 29 7b 0a 20 20 20 20  File; i++){.    
2040: 20 20 69 66 28 20 73 74 72 63 6d 70 28 6d 2e 61    if( strcmp(m.a
2050: 46 69 6c 65 5b 69 5d 2e 7a 4e 61 6d 65 2c 20 66  File[i].zName, f
2060: 69 6c 65 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20  ile)==0 ){.     
2070: 20 20 20 72 69 64 20 3d 20 75 75 69 64 5f 74 6f     rid = uuid_to
2080: 5f 72 69 64 28 6d 2e 61 46 69 6c 65 5b 69 5d 2e  _rid(m.aFile[i].
2090: 7a 55 75 69 64 2c 20 30 29 3b 0a 20 20 20 20 20  zUuid, 0);.     
20a0: 20 20 20 72 65 74 75 72 6e 20 63 6f 6e 74 65 6e     return conten
20b0: 74 5f 67 65 74 28 72 69 64 2c 20 63 6f 6e 74 65  t_get(rid, conte
20c0: 6e 74 29 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20  nt);.      }.   
20d0: 20 7d 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 61   }.    fossil_fa
20e0: 74 61 6c 28 22 66 69 6c 65 20 25 73 20 64 6f 65  tal("file %s doe
20f0: 73 20 6e 6f 74 20 65 78 69 73 74 20 69 6e 20 62  s not exist in b
2100: 61 73 65 6c 69 6e 65 3a 20 25 73 22 2c 20 66 69  aseline: %s", fi
2110: 6c 65 2c 20 72 65 76 69 73 69 6f 6e 29 3b 0a 20  le, revision);. 
2120: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 66 6f 73 73   }else{.    foss
2130: 69 6c 5f 70 61 6e 69 63 28 22 63 6f 75 6c 64 20  il_panic("could 
2140: 6e 6f 74 20 70 61 72 73 65 20 6d 61 6e 69 66 65  not parse manife
2150: 73 74 20 66 6f 72 20 62 61 73 65 6c 69 6e 65 3a  st for baseline:
2160: 20 25 73 22 2c 20 72 65 76 69 73 69 6f 6e 29 3b   %s", revision);
2170: 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 30 3b  .  }.  return 0;
2180: 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41  .}.../*.** COMMA
2190: 4e 44 3a 20 72 65 76 65 72 74 0a 2a 2a 0a 2a 2a  ND: revert.**.**
21a0: 20 55 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20   Usage: %fossil 
21b0: 72 65 76 65 72 74 20 3f 2d 2d 79 65 73 3f 20 3f  revert ?--yes? ?
21c0: 2d 72 20 52 45 56 49 53 49 4f 4e 3f 20 46 49 4c  -r REVISION? FIL
21d0: 45 0a 2a 2a 0a 2a 2a 20 52 65 76 65 72 74 20 74  E.**.** Revert t
21e0: 6f 20 74 68 65 20 63 75 72 72 65 6e 74 20 72 65  o the current re
21f0: 70 6f 73 69 74 6f 72 79 20 76 65 72 73 69 6f 6e  pository version
2200: 20 6f 66 20 46 49 4c 45 2c 20 6f 72 20 74 6f 0a   of FILE, or to.
2210: 2a 2a 20 74 68 65 20 76 65 72 73 69 6f 6e 20 61  ** the version a
2220: 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 62  ssociated with b
2230: 61 73 65 6c 69 6e 65 20 52 45 56 49 53 49 4f 4e  aseline REVISION
2240: 20 69 66 20 74 68 65 20 2d 72 20 66 6c 61 67 0a   if the -r flag.
2250: 2a 2a 20 61 70 70 65 61 72 73 2e 20 20 54 68 69  ** appears.  Thi
2260: 73 20 63 6f 6d 6d 61 6e 64 20 77 69 6c 6c 20 63  s command will c
2270: 6f 6e 66 69 72 6d 20 79 6f 75 72 20 6f 70 65 72  onfirm your oper
2280: 61 74 69 6f 6e 20 75 6e 6c 65 73 73 20 74 68 65  ation unless the
2290: 0a 2a 2a 20 66 69 6c 65 20 69 73 20 6d 69 73 73  .** file is miss
22a0: 69 6e 67 20 6f 72 20 74 68 65 20 2d 2d 79 65 73  ing or the --yes
22b0: 20 6f 70 74 69 6f 6e 20 69 73 20 75 73 65 64 2e   option is used.
22c0: 0a 2a 2a 2f 0a 76 6f 69 64 20 72 65 76 65 72 74  .**/.void revert
22d0: 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 63 6f  _cmd(void){.  co
22e0: 6e 73 74 20 63 68 61 72 20 2a 7a 46 69 6c 65 3b  nst char *zFile;
22f0: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  .  const char *z
2300: 52 65 76 69 73 69 6f 6e 3b 0a 20 20 42 6c 6f 62  Revision;.  Blob
2310: 20 66 6e 61 6d 65 3b 0a 20 20 42 6c 6f 62 20 72   fname;.  Blob r
2320: 65 63 6f 72 64 3b 0a 20 20 42 6c 6f 62 20 61 6e  ecord;.  Blob an
2330: 73 3b 0a 20 20 69 6e 74 20 72 69 64 20 3d 20 30  s;.  int rid = 0
2340: 2c 20 79 65 73 52 65 76 65 72 74 3b 0a 20 20 0a  , yesRevert;.  .
2350: 20 20 79 65 73 52 65 76 65 72 74 20 3d 20 66 69    yesRevert = fi
2360: 6e 64 5f 6f 70 74 69 6f 6e 28 22 79 65 73 22 2c  nd_option("yes",
2370: 20 22 79 22 2c 20 30 29 21 3d 30 3b 0a 20 20 7a   "y", 0)!=0;.  z
2380: 52 65 76 69 73 69 6f 6e 20 3d 20 66 69 6e 64 5f  Revision = find_
2390: 6f 70 74 69 6f 6e 28 22 72 65 76 69 73 69 6f 6e  option("revision
23a0: 22 2c 20 22 72 22 2c 20 31 29 3b 0a 20 20 76 65  ", "r", 1);.  ve
23b0: 72 69 66 79 5f 61 6c 6c 5f 6f 70 74 69 6f 6e 73  rify_all_options
23c0: 28 29 3b 0a 20 20 0a 20 20 69 66 28 20 67 2e 61  ();.  .  if( g.a
23d0: 72 67 63 3c 33 20 29 7b 0a 20 20 20 20 75 73 61  rgc<3 ){.    usa
23e0: 67 65 28 22 3f 4f 50 54 49 4f 4e 53 20 46 49 4c  ge("?OPTIONS FIL
23f0: 45 22 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 6d 75  E");.  }.  db_mu
2400: 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72 65  st_be_within_tre
2410: 65 28 29 3b 0a 20 20 0a 20 20 7a 46 69 6c 65 20  e();.  .  zFile 
2420: 3d 20 6d 70 72 69 6e 74 66 28 22 25 2f 22 2c 20  = mprintf("%/", 
2430: 67 2e 61 72 67 76 5b 67 2e 61 72 67 63 2d 31 5d  g.argv[g.argc-1]
2440: 29 3b 0a 0a 20 20 69 66 28 20 21 66 69 6c 65 5f  );..  if( !file_
2450: 74 72 65 65 5f 6e 61 6d 65 28 7a 46 69 6c 65 2c  tree_name(zFile,
2460: 20 26 66 6e 61 6d 65 29 20 29 7b 0a 20 20 20 20   &fname) ){.    
2470: 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 75 6e  fossil_panic("un
2480: 6b 6e 6f 77 6e 20 66 69 6c 65 3a 20 25 73 22 2c  known file: %s",
2490: 20 7a 46 69 6c 65 29 3b 0a 20 20 7d 0a 0a 20 20   zFile);.  }..  
24a0: 69 66 28 20 61 63 63 65 73 73 28 7a 46 69 6c 65  if( access(zFile
24b0: 2c 20 30 29 20 29 20 79 65 73 52 65 76 65 72 74  , 0) ) yesRevert
24c0: 20 3d 20 31 3b 20 20 0a 20 20 69 66 28 20 79 65   = 1;  .  if( ye
24d0: 73 52 65 76 65 72 74 3d 3d 30 20 29 7b 0a 20 20  sRevert==0 ){.  
24e0: 20 20 63 68 61 72 20 2a 70 72 6f 6d 70 74 20 3d    char *prompt =
24f0: 20 6d 70 72 69 6e 74 66 28 22 72 65 76 65 72 74   mprintf("revert
2500: 20 66 69 6c 65 20 25 42 3f 20 74 68 69 73 20 77   file %B? this w
2510: 69 6c 6c 22 0a 20 20 20 20 20 20 20 20 20 20 20  ill".           
2520: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2530: 22 20 64 65 73 74 72 6f 79 20 6c 6f 63 61 6c 20  " destroy local 
2540: 63 68 61 6e 67 65 73 20 5b 79 2f 4e 5d 3f 20 22  changes [y/N]? "
2550: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ,.              
2560: 20 20 20 20 20 20 20 20 20 20 20 20 20 26 66 6e               &fn
2570: 61 6d 65 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 7a  ame);.    blob_z
2580: 65 72 6f 28 26 61 6e 73 29 3b 0a 20 20 20 20 70  ero(&ans);.    p
2590: 72 6f 6d 70 74 5f 75 73 65 72 28 70 72 6f 6d 70  rompt_user(promp
25a0: 74 2c 20 26 61 6e 73 29 3b 0a 20 20 20 20 69 66  t, &ans);.    if
25b0: 28 20 62 6c 6f 62 5f 73 74 72 28 26 61 6e 73 29  ( blob_str(&ans)
25c0: 5b 30 5d 3d 3d 27 79 27 20 29 7b 0a 20 20 20 20  [0]=='y' ){.    
25d0: 20 20 79 65 73 52 65 76 65 72 74 20 3d 20 31 3b    yesRevert = 1;
25e0: 0a 20 20 20 20 7d 0a 20 20 7d 0a 0a 20 20 69 66  .    }.  }..  if
25f0: 28 20 79 65 73 52 65 76 65 72 74 3d 3d 31 20 26  ( yesRevert==1 &
2600: 26 20 7a 52 65 76 69 73 69 6f 6e 21 3d 30 20 29  & zRevision!=0 )
2610: 7b 0a 20 20 20 20 68 69 73 74 6f 72 69 63 61 6c  {.    historical
2620: 5f 76 65 72 73 69 6f 6e 5f 6f 66 5f 66 69 6c 65  _version_of_file
2630: 28 7a 52 65 76 69 73 69 6f 6e 2c 20 7a 46 69 6c  (zRevision, zFil
2640: 65 2c 20 26 72 65 63 6f 72 64 29 3b 0a 20 20 7d  e, &record);.  }
2650: 65 6c 73 65 20 69 66 28 20 79 65 73 52 65 76 65  else if( yesReve
2660: 72 74 3d 3d 31 20 29 7b 0a 20 20 20 20 72 69 64  rt==1 ){.    rid
2670: 20 3d 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45   = db_int(0, "SE
2680: 4c 45 43 54 20 72 69 64 20 46 52 4f 4d 20 76 66  LECT rid FROM vf
2690: 69 6c 65 20 57 48 45 52 45 20 70 61 74 68 6e 61  ile WHERE pathna
26a0: 6d 65 3d 25 42 22 2c 20 26 66 6e 61 6d 65 29 3b  me=%B", &fname);
26b0: 0a 20 20 20 20 69 66 28 20 72 69 64 3d 3d 30 20  .    if( rid==0 
26c0: 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f  ){.      fossil_
26d0: 70 61 6e 69 63 28 22 6e 6f 20 68 69 73 74 6f 72  panic("no histor
26e0: 79 20 66 6f 72 20 66 69 6c 65 3a 20 25 62 22 2c  y for file: %b",
26f0: 20 26 66 6e 61 6d 65 29 3b 0a 20 20 20 20 7d 0a   &fname);.    }.
2700: 20 20 20 20 63 6f 6e 74 65 6e 74 5f 67 65 74 28      content_get(
2710: 72 69 64 2c 20 26 72 65 63 6f 72 64 29 3b 0a 20  rid, &record);. 
2720: 20 7d 0a 20 20 0a 20 20 69 66 28 20 79 65 73 52   }.  .  if( yesR
2730: 65 76 65 72 74 3d 3d 31 20 29 7b 0a 20 20 20 20  evert==1 ){.    
2740: 62 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f 66 69  blob_write_to_fi
2750: 6c 65 28 26 72 65 63 6f 72 64 2c 20 7a 46 69 6c  le(&record, zFil
2760: 65 29 3b 0a 20 20 20 20 70 72 69 6e 74 66 28 22  e);.    printf("
2770: 25 73 20 72 65 76 65 72 74 65 64 5c 6e 22 2c 20  %s reverted\n", 
2780: 7a 46 69 6c 65 29 3b 0a 20 20 20 20 62 6c 6f 62  zFile);.    blob
2790: 5f 72 65 73 65 74 28 26 72 65 63 6f 72 64 29 3b  _reset(&record);
27a0: 0a 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28  .    blob_reset(
27b0: 26 66 6e 61 6d 65 29 3b 0a 20 20 7d 65 6c 73 65  &fname);.  }else
27c0: 7b 0a 20 20 20 20 70 72 69 6e 74 66 28 22 72 65  {.    printf("re
27d0: 76 65 72 74 20 63 61 6e 63 65 6c 65 64 5c 6e 22  vert canceled\n"
27e0: 29 3b 0a 20 20 7d 0a 7d 0a                       );.  }.}.