Hex Artifact Content
Not logged in

Artifact 93e8f5c3cb11bac6476ec5deff05e0247958d05d:

File src/checkout.c part of check-in [76f169fca6] - Detect when the check-out contains missing files and filesystem objects that ought to be files but are not. Issue reasonable warnings. by drh on 2009-12-18 00:29:51. Also file src/checkout.c part of check-in [76bc05d739] - merge with trunk by btheado on 2009-12-30 20:33:59.

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 63 68 65 63 6b 2d 6f 75 74  sed to check-out
0390: 20 76 65 72 73 69 6f 6e 73 20 6f 66 20 74 68 65   versions of the
03a0: 20 70 72 6f 6a 65 63 74 0a 2a 2a 20 66 72 6f 6d   project.** from
03b0: 20 74 68 65 20 6c 6f 63 61 6c 20 72 65 70 6f 73   the local repos
03c0: 69 74 6f 72 79 2e 0a 2a 2f 0a 23 69 6e 63 6c 75  itory..*/.#inclu
03d0: 64 65 20 22 63 6f 6e 66 69 67 2e 68 22 0a 23 69  de "config.h".#i
03e0: 6e 63 6c 75 64 65 20 22 63 68 65 63 6b 6f 75 74  nclude "checkout
03f0: 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 3c 61 73  .h".#include <as
0400: 73 65 72 74 2e 68 3e 0a 0a 2f 2a 0a 2a 2a 20 43  sert.h>../*.** C
0410: 68 65 63 6b 20 74 6f 20 73 65 65 20 69 66 20 74  heck to see if t
0420: 68 65 72 65 20 69 73 20 61 6e 20 65 78 69 73 74  here is an exist
0430: 69 6e 67 20 63 68 65 63 6b 6f 75 74 20 74 68 61  ing checkout tha
0440: 74 20 68 61 73 20 62 65 65 6e 0a 2a 2a 20 6d 6f  t has been.** mo
0450: 64 69 66 69 65 64 2e 20 20 52 65 74 75 72 6e 20  dified.  Return 
0460: 76 61 6c 75 65 73 3a 0a 2a 2a 0a 2a 2a 20 20 20  values:.**.**   
0470: 20 20 30 3a 20 20 20 54 68 65 72 65 20 69 73 20    0:   There is 
0480: 61 6e 20 65 78 69 73 74 69 6e 67 20 63 68 65 63  an existing chec
0490: 6b 6f 75 74 20 62 75 74 20 69 74 20 69 73 20 75  kout but it is u
04a0: 6e 6d 6f 64 69 66 69 65 64 0a 2a 2a 20 20 20 20  nmodified.**    
04b0: 20 31 3a 20 20 20 54 68 65 72 65 20 69 73 20 61   1:   There is a
04c0: 20 6d 6f 64 69 66 69 65 64 20 63 68 65 63 6b 6f   modified checko
04d0: 75 74 20 2d 20 74 68 65 72 65 20 61 72 65 20 75  ut - there are u
04e0: 6e 73 61 76 65 64 20 63 68 61 6e 67 65 73 0a 2a  nsaved changes.*
04f0: 2a 20 20 20 20 20 32 3a 20 20 20 54 68 65 72 65  *     2:   There
0500: 20 69 73 20 6e 6f 20 65 78 69 73 74 69 6e 67 20   is no existing 
0510: 63 68 65 63 6b 6f 75 74 0a 2a 2f 0a 69 6e 74 20  checkout.*/.int 
0520: 75 6e 73 61 76 65 64 5f 63 68 61 6e 67 65 73 28  unsaved_changes(
0530: 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 76 69 64  void){.  int vid
0540: 3b 0a 20 20 64 62 5f 6d 75 73 74 5f 62 65 5f 77  ;.  db_must_be_w
0550: 69 74 68 69 6e 5f 74 72 65 65 28 29 3b 0a 20 20  ithin_tree();.  
0560: 76 69 64 20 3d 20 64 62 5f 6c 67 65 74 5f 69 6e  vid = db_lget_in
0570: 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 30 29 3b  t("checkout",0);
0580: 0a 20 20 69 66 28 20 76 69 64 3d 3d 30 20 29 20  .  if( vid==0 ) 
0590: 72 65 74 75 72 6e 20 32 3b 0a 20 20 76 66 69 6c  return 2;.  vfil
05a0: 65 5f 63 68 65 63 6b 5f 73 69 67 6e 61 74 75 72  e_check_signatur
05b0: 65 28 76 69 64 2c 20 31 29 3b 0a 20 20 72 65 74  e(vid, 1);.  ret
05c0: 75 72 6e 20 64 62 5f 65 78 69 73 74 73 28 22 53  urn db_exists("S
05d0: 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 76 66 69  ELECT 1 FROM vfi
05e0: 6c 65 20 57 48 45 52 45 20 63 68 6e 67 65 64 22  le WHERE chnged"
05f0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
0600: 20 20 20 20 22 20 4f 52 20 63 6f 61 6c 65 73 63      " OR coalesc
0610: 65 28 6f 72 69 67 6e 61 6d 65 21 3d 70 61 74 68  e(origname!=path
0620: 6e 61 6d 65 2c 30 29 22 29 3b 0a 7d 0a 0a 2f 2a  name,0)");.}../*
0630: 0a 2a 2a 20 55 6e 64 6f 20 74 68 65 20 63 75 72  .** Undo the cur
0640: 72 65 6e 74 20 63 68 65 63 6b 2d 6f 75 74 2e 20  rent check-out. 
0650: 20 55 6e 6c 69 6e 6b 20 61 6c 6c 20 66 69 6c 65   Unlink all file
0660: 73 20 66 72 6f 6d 20 74 68 65 20 64 69 73 6b 2e  s from the disk.
0670: 0a 2a 2a 20 43 6c 65 61 72 20 74 68 65 20 56 46  .** Clear the VF
0680: 49 4c 45 20 74 61 62 6c 65 2e 0a 2a 2f 0a 76 6f  ILE table..*/.vo
0690: 69 64 20 75 6e 63 68 65 63 6b 6f 75 74 28 69 6e  id uncheckout(in
06a0: 74 20 76 69 64 29 7b 0a 20 20 69 66 28 20 76 69  t vid){.  if( vi
06b0: 64 3d 3d 30 20 29 20 72 65 74 75 72 6e 3b 0a 20  d==0 ) return;. 
06c0: 20 76 66 69 6c 65 5f 75 6e 6c 69 6e 6b 28 76 69   vfile_unlink(vi
06d0: 64 29 3b 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65  d);.  db_multi_e
06e0: 78 65 63 28 22 44 45 4c 45 54 45 20 46 52 4f 4d  xec("DELETE FROM
06f0: 20 76 66 69 6c 65 20 57 48 45 52 45 20 76 69 64   vfile WHERE vid
0700: 3d 25 64 22 2c 20 76 69 64 29 3b 0a 7d 0a 0a 0a  =%d", vid);.}...
0710: 2f 2a 0a 2a 2a 20 47 69 76 65 6e 20 74 68 65 20  /*.** Given the 
0720: 61 62 62 72 65 76 69 61 74 65 64 20 55 55 49 44  abbreviated UUID
0730: 20 6e 61 6d 65 20 6f 66 20 61 20 76 65 72 73 69   name of a versi
0740: 6f 6e 2c 20 6c 6f 61 64 20 74 68 65 20 63 6f 6e  on, load the con
0750: 74 65 6e 74 20 6f 66 20 74 68 61 74 0a 2a 2a 20  tent of that.** 
0760: 76 65 72 73 69 6f 6e 20 69 6e 20 74 68 65 20 56  version in the V
0770: 46 49 4c 45 20 74 61 62 6c 65 2e 20 20 52 65 74  FILE table.  Ret
0780: 75 72 6e 20 74 68 65 20 56 49 44 20 66 6f 72 20  urn the VID for 
0790: 74 68 65 20 76 65 72 73 69 6f 6e 2e 0a 2a 2a 0a  the version..**.
07a0: 2a 2a 20 49 66 20 61 6e 79 74 68 69 6e 67 20 67  ** If anything g
07b0: 6f 65 73 20 77 72 6f 6e 67 2c 20 70 61 6e 69 63  oes wrong, panic
07c0: 2e 0a 2a 2f 0a 69 6e 74 20 6c 6f 61 64 5f 76 66  ..*/.int load_vf
07d0: 69 6c 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a  ile(const char *
07e0: 7a 4e 61 6d 65 29 7b 0a 20 20 42 6c 6f 62 20 75  zName){.  Blob u
07f0: 75 69 64 3b 0a 20 20 69 6e 74 20 76 69 64 3b 0a  uid;.  int vid;.
0800: 0a 20 20 62 6c 6f 62 5f 69 6e 69 74 28 26 75 75  .  blob_init(&uu
0810: 69 64 2c 20 7a 4e 61 6d 65 2c 20 2d 31 29 3b 0a  id, zName, -1);.
0820: 20 20 69 66 28 20 6e 61 6d 65 5f 74 6f 5f 75 75    if( name_to_uu
0830: 69 64 28 26 75 75 69 64 2c 20 31 29 20 29 7b 0a  id(&uuid, 1) ){.
0840: 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63      fossil_panic
0850: 28 67 2e 7a 45 72 72 4d 73 67 29 3b 0a 20 20 7d  (g.zErrMsg);.  }
0860: 0a 20 20 76 69 64 20 3d 20 64 62 5f 69 6e 74 28  .  vid = db_int(
0870: 30 2c 20 22 53 45 4c 45 43 54 20 72 69 64 20 46  0, "SELECT rid F
0880: 52 4f 4d 20 62 6c 6f 62 20 57 48 45 52 45 20 75  ROM blob WHERE u
0890: 75 69 64 3d 25 42 22 2c 20 26 75 75 69 64 29 3b  uid=%B", &uuid);
08a0: 0a 20 20 69 66 28 20 76 69 64 3d 3d 30 20 29 7b  .  if( vid==0 ){
08b0: 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61  .    fossil_fata
08c0: 6c 28 22 6e 6f 20 73 75 63 68 20 63 68 65 63 6b  l("no such check
08d0: 2d 69 6e 3a 20 25 73 22 2c 20 67 2e 61 72 67 76  -in: %s", g.argv
08e0: 5b 32 5d 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20  [2]);.  }.  if( 
08f0: 21 69 73 5f 61 5f 76 65 72 73 69 6f 6e 28 76 69  !is_a_version(vi
0900: 64 29 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c  d) ){.    fossil
0910: 5f 66 61 74 61 6c 28 22 6f 62 6a 65 63 74 20 5b  _fatal("object [
0920: 25 2e 31 30 73 5d 20 69 73 20 6e 6f 74 20 61 20  %.10s] is not a 
0930: 63 68 65 63 6b 2d 69 6e 22 2c 20 62 6c 6f 62 5f  check-in", blob_
0940: 73 74 72 28 26 75 75 69 64 29 29 3b 0a 20 20 7d  str(&uuid));.  }
0950: 0a 20 20 6c 6f 61 64 5f 76 66 69 6c 65 5f 66 72  .  load_vfile_fr
0960: 6f 6d 5f 72 69 64 28 76 69 64 29 3b 0a 20 20 72  om_rid(vid);.  r
0970: 65 74 75 72 6e 20 76 69 64 3b 0a 7d 0a 0a 2f 2a  eturn vid;.}../*
0980: 0a 2a 2a 20 4c 6f 61 64 20 61 20 76 66 69 6c 65  .** Load a vfile
0990: 20 66 72 6f 6d 20 61 20 72 65 63 6f 72 64 20 49   from a record I
09a0: 44 2e 0a 2a 2f 0a 76 6f 69 64 20 6c 6f 61 64 5f  D..*/.void load_
09b0: 76 66 69 6c 65 5f 66 72 6f 6d 5f 72 69 64 28 69  vfile_from_rid(i
09c0: 6e 74 20 76 69 64 29 7b 0a 20 20 42 6c 6f 62 20  nt vid){.  Blob 
09d0: 6d 61 6e 69 66 65 73 74 3b 0a 0a 20 20 69 66 28  manifest;..  if(
09e0: 20 64 62 5f 65 78 69 73 74 73 28 22 53 45 4c 45   db_exists("SELE
09f0: 43 54 20 31 20 46 52 4f 4d 20 76 66 69 6c 65 20  CT 1 FROM vfile 
0a00: 57 48 45 52 45 20 76 69 64 3d 25 64 22 2c 20 76  WHERE vid=%d", v
0a10: 69 64 29 20 29 7b 0a 20 20 20 20 72 65 74 75 72  id) ){.    retur
0a20: 6e 3b 0a 20 20 7d 0a 20 20 63 6f 6e 74 65 6e 74  n;.  }.  content
0a30: 5f 67 65 74 28 76 69 64 2c 20 26 6d 61 6e 69 66  _get(vid, &manif
0a40: 65 73 74 29 3b 0a 20 20 76 66 69 6c 65 5f 62 75  est);.  vfile_bu
0a50: 69 6c 64 28 76 69 64 2c 20 26 6d 61 6e 69 66 65  ild(vid, &manife
0a60: 73 74 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65  st);.  blob_rese
0a70: 74 28 26 6d 61 6e 69 66 65 73 74 29 3b 0a 7d 0a  t(&manifest);.}.
0a80: 0a 2f 2a 0a 2a 2a 20 52 65 61 64 20 74 68 65 20  ./*.** Read the 
0a90: 6d 61 6e 69 66 65 73 74 20 66 69 6c 65 20 67 69  manifest file gi
0aa0: 76 65 6e 20 62 79 20 76 69 64 20 6f 75 74 20 6f  ven by vid out o
0ab0: 66 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79  f the repository
0ac0: 0a 2a 2a 20 61 6e 64 20 73 74 6f 72 65 20 69 74  .** and store it
0ad0: 20 69 6e 20 74 68 65 20 72 6f 6f 74 20 6f 66 20   in the root of 
0ae0: 74 68 65 20 6c 6f 63 61 6c 20 63 68 65 63 6b 2d  the local check-
0af0: 6f 75 74 2e 0a 2a 2f 0a 76 6f 69 64 20 6d 61 6e  out..*/.void man
0b00: 69 66 65 73 74 5f 74 6f 5f 64 69 73 6b 28 69 6e  ifest_to_disk(in
0b10: 74 20 76 69 64 29 7b 0a 20 20 63 68 61 72 20 2a  t vid){.  char *
0b20: 7a 4d 61 6e 46 69 6c 65 3b 0a 20 20 42 6c 6f 62  zManFile;.  Blob
0b30: 20 6d 61 6e 69 66 65 73 74 3b 0a 20 20 42 6c 6f   manifest;.  Blo
0b40: 62 20 68 61 73 68 3b 0a 20 20 42 6c 6f 62 20 66  b hash;.  Blob f
0b50: 69 6c 65 6e 61 6d 65 3b 0a 20 20 69 6e 74 20 62  ilename;.  int b
0b60: 61 73 65 4c 65 6e 3b 0a 20 20 69 6e 74 20 69 3b  aseLen;.  int i;
0b70: 0a 20 20 4d 61 6e 69 66 65 73 74 20 6d 3b 0a 0a  .  Manifest m;..
0b80: 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 6d 61 6e    blob_zero(&man
0b90: 69 66 65 73 74 29 3b 0a 20 20 7a 4d 61 6e 46 69  ifest);.  zManFi
0ba0: 6c 65 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73  le = mprintf("%s
0bb0: 6d 61 6e 69 66 65 73 74 22 2c 20 67 2e 7a 4c 6f  manifest", g.zLo
0bc0: 63 61 6c 52 6f 6f 74 29 3b 0a 20 20 63 6f 6e 74  calRoot);.  cont
0bd0: 65 6e 74 5f 67 65 74 28 76 69 64 2c 20 26 6d 61  ent_get(vid, &ma
0be0: 6e 69 66 65 73 74 29 3b 0a 20 20 62 6c 6f 62 5f  nifest);.  blob_
0bf0: 77 72 69 74 65 5f 74 6f 5f 66 69 6c 65 28 26 6d  write_to_file(&m
0c00: 61 6e 69 66 65 73 74 2c 20 7a 4d 61 6e 46 69 6c  anifest, zManFil
0c10: 65 29 3b 0a 20 20 66 72 65 65 28 7a 4d 61 6e 46  e);.  free(zManF
0c20: 69 6c 65 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72  ile);.  blob_zer
0c30: 6f 28 26 68 61 73 68 29 3b 0a 20 20 73 68 61 31  o(&hash);.  sha1
0c40: 73 75 6d 5f 62 6c 6f 62 28 26 6d 61 6e 69 66 65  sum_blob(&manife
0c50: 73 74 2c 20 26 68 61 73 68 29 3b 0a 20 20 7a 4d  st, &hash);.  zM
0c60: 61 6e 46 69 6c 65 20 3d 20 6d 70 72 69 6e 74 66  anFile = mprintf
0c70: 28 22 25 73 6d 61 6e 69 66 65 73 74 2e 75 75 69  ("%smanifest.uui
0c80: 64 22 2c 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74  d", g.zLocalRoot
0c90: 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64  );.  blob_append
0ca0: 28 26 68 61 73 68 2c 20 22 5c 6e 22 2c 20 31 29  (&hash, "\n", 1)
0cb0: 3b 0a 20 20 62 6c 6f 62 5f 77 72 69 74 65 5f 74  ;.  blob_write_t
0cc0: 6f 5f 66 69 6c 65 28 26 68 61 73 68 2c 20 7a 4d  o_file(&hash, zM
0cd0: 61 6e 46 69 6c 65 29 3b 0a 20 20 66 72 65 65 28  anFile);.  free(
0ce0: 7a 4d 61 6e 46 69 6c 65 29 3b 0a 20 20 62 6c 6f  zManFile);.  blo
0cf0: 62 5f 72 65 73 65 74 28 26 68 61 73 68 29 3b 0a  b_reset(&hash);.
0d00: 20 20 6d 61 6e 69 66 65 73 74 5f 70 61 72 73 65    manifest_parse
0d10: 28 26 6d 2c 20 26 6d 61 6e 69 66 65 73 74 29 3b  (&m, &manifest);
0d20: 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 66 69  .  blob_zero(&fi
0d30: 6c 65 6e 61 6d 65 29 3b 0a 20 20 62 6c 6f 62 5f  lename);.  blob_
0d40: 61 70 70 65 6e 64 66 28 26 66 69 6c 65 6e 61 6d  appendf(&filenam
0d50: 65 2c 20 22 25 73 2f 22 2c 20 67 2e 7a 4c 6f 63  e, "%s/", g.zLoc
0d60: 61 6c 52 6f 6f 74 29 3b 0a 20 20 62 61 73 65 4c  alRoot);.  baseL
0d70: 65 6e 20 3d 20 62 6c 6f 62 5f 73 69 7a 65 28 26  en = blob_size(&
0d80: 66 69 6c 65 6e 61 6d 65 29 3b 0a 20 20 66 6f 72  filename);.  for
0d90: 28 69 3d 30 3b 20 69 3c 6d 2e 6e 46 69 6c 65 3b  (i=0; i<m.nFile;
0da0: 20 69 2b 2b 29 7b 20 0a 20 20 20 20 69 6e 74 20   i++){ .    int 
0db0: 69 73 45 78 65 3b 0a 20 20 20 20 62 6c 6f 62 5f  isExe;.    blob_
0dc0: 61 70 70 65 6e 64 28 26 66 69 6c 65 6e 61 6d 65  append(&filename
0dd0: 2c 20 6d 2e 61 46 69 6c 65 5b 69 5d 2e 7a 4e 61  , m.aFile[i].zNa
0de0: 6d 65 2c 20 2d 31 29 3b 0a 20 20 20 20 69 73 45  me, -1);.    isE
0df0: 78 65 20 3d 20 6d 2e 61 46 69 6c 65 5b 69 5d 2e  xe = m.aFile[i].
0e00: 7a 50 65 72 6d 20 26 26 20 73 74 72 73 74 72 28  zPerm && strstr(
0e10: 6d 2e 61 46 69 6c 65 5b 69 5d 2e 7a 50 65 72 6d  m.aFile[i].zPerm
0e20: 2c 20 22 78 22 29 3b 0a 20 20 20 20 66 69 6c 65  , "x");.    file
0e30: 5f 73 65 74 65 78 65 28 62 6c 6f 62 5f 73 74 72  _setexe(blob_str
0e40: 28 26 66 69 6c 65 6e 61 6d 65 29 2c 20 69 73 45  (&filename), isE
0e50: 78 65 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 72 65  xe);.    blob_re
0e60: 73 69 7a 65 28 26 66 69 6c 65 6e 61 6d 65 2c 20  size(&filename, 
0e70: 62 61 73 65 4c 65 6e 29 3b 0a 20 20 7d 0a 20 20  baseLen);.  }.  
0e80: 62 6c 6f 62 5f 72 65 73 65 74 28 26 66 69 6c 65  blob_reset(&file
0e90: 6e 61 6d 65 29 3b 0a 20 20 6d 61 6e 69 66 65 73  name);.  manifes
0ea0: 74 5f 63 6c 65 61 72 28 26 6d 29 3b 0a 7d 0a 0a  t_clear(&m);.}..
0eb0: 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 63  /*.** COMMAND: c
0ec0: 68 65 63 6b 6f 75 74 0a 2a 2a 20 43 4f 4d 4d 41  heckout.** COMMA
0ed0: 4e 44 3a 20 63 6f 0a 2a 2a 0a 2a 2a 20 55 73 61  ND: co.**.** Usa
0ee0: 67 65 3a 20 25 66 6f 73 73 69 6c 20 63 68 65 63  ge: %fossil chec
0ef0: 6b 6f 75 74 20 56 45 52 53 49 4f 4e 20 3f 2d 66  kout VERSION ?-f
0f00: 7c 2d 2d 66 6f 72 63 65 3f 20 3f 2d 2d 6b 65 65  |--force? ?--kee
0f10: 70 3f 0a 2a 2a 0a 2a 2a 20 43 68 65 63 6b 20 6f  p?.**.** Check o
0f20: 75 74 20 61 20 76 65 72 73 69 6f 6e 20 73 70 65  ut a version spe
0f30: 63 69 66 69 65 64 20 6f 6e 20 74 68 65 20 63 6f  cified on the co
0f40: 6d 6d 61 6e 64 2d 6c 69 6e 65 2e 20 20 54 68 69  mmand-line.  Thi
0f50: 73 20 63 6f 6d 6d 61 6e 64 0a 2a 2a 20 77 69 6c  s command.** wil
0f60: 6c 20 61 62 6f 72 74 20 69 66 20 74 68 65 72 65  l abort if there
0f70: 20 61 72 65 20 65 64 69 74 65 64 20 66 69 6c 65   are edited file
0f80: 73 20 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74  s in the current
0f90: 20 63 68 65 63 6b 6f 75 74 20 75 6e 6c 65 73 73   checkout unless
0fa0: 0a 2a 2a 20 74 68 65 20 2d 2d 66 6f 72 63 65 20  .** the --force 
0fb0: 6f 70 74 69 6f 6e 20 61 70 70 65 61 72 73 20 6f  option appears o
0fc0: 6e 20 74 68 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69  n the command-li
0fd0: 6e 65 2e 20 20 54 68 65 20 2d 2d 6b 65 65 70 20  ne.  The --keep 
0fe0: 6f 70 74 69 6f 6e 0a 2a 2a 20 6c 65 61 76 65 73  option.** leaves
0ff0: 20 66 69 6c 65 73 20 6f 6e 20 64 69 73 6b 20 75   files on disk u
1000: 6e 63 68 61 6e 67 65 64 2c 20 65 78 63 65 70 74  nchanged, except
1010: 20 74 68 65 20 6d 61 6e 69 66 65 73 74 20 61 6e   the manifest an
1020: 64 20 6d 61 6e 69 66 65 73 74 2e 75 75 69 64 0a  d manifest.uuid.
1030: 2a 2a 20 66 69 6c 65 73 2e 0a 2a 2a 0a 2a 2a 20  ** files..**.** 
1040: 54 68 65 20 2d 2d 6c 61 74 65 73 74 20 66 6c 61  The --latest fla
1050: 67 20 63 61 6e 20 62 65 20 75 73 65 64 20 69 6e  g can be used in
1060: 20 70 6c 61 63 65 20 6f 66 20 56 45 52 53 49 4f   place of VERSIO
1070: 4e 20 74 6f 20 63 68 65 63 6b 6f 75 74 20 74 68  N to checkout th
1080: 65 0a 2a 2a 20 6c 61 74 65 73 74 20 76 65 72 73  e.** latest vers
1090: 69 6f 6e 20 69 6e 20 74 68 65 20 72 65 70 6f 73  ion in the repos
10a0: 69 74 6f 72 79 2e 0a 2a 2a 0a 2a 2a 20 53 65 65  itory..**.** See
10b0: 20 61 6c 73 6f 20 74 68 65 20 22 75 70 64 61 74   also the "updat
10c0: 65 22 20 63 6f 6d 6d 61 6e 64 2e 0a 2a 2f 0a 76  e" command..*/.v
10d0: 6f 69 64 20 63 68 65 63 6b 6f 75 74 5f 63 6d 64  oid checkout_cmd
10e0: 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 66 6f  (void){.  int fo
10f0: 72 63 65 46 6c 61 67 3b 20 20 20 20 20 20 20 20  rceFlag;        
1100: 20 20 20 20 20 20 20 20 20 2f 2a 20 46 6f 72 63           /* Forc
1110: 65 20 63 68 65 63 6b 6f 75 74 20 65 76 65 6e 20  e checkout even 
1120: 69 66 20 65 64 69 74 73 20 65 78 69 73 74 20 2a  if edits exist *
1130: 2f 0a 20 20 69 6e 74 20 6b 65 65 70 46 6c 61 67  /.  int keepFlag
1140: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ;               
1150: 20 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 63 68 61     /* Do not cha
1160: 6e 67 65 20 61 6e 79 20 66 69 6c 65 73 20 6f 6e  nge any files on
1170: 20 64 69 73 6b 20 2a 2f 0a 20 20 69 6e 74 20 6c   disk */.  int l
1180: 61 74 65 73 74 46 6c 61 67 3b 20 20 20 20 20 20  atestFlag;      
1190: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 68 65            /* Che
11a0: 63 6b 6f 75 74 20 74 68 65 20 6c 61 74 65 73 74  ckout the latest
11b0: 20 76 65 72 73 69 6f 6e 20 2a 2f 0a 20 20 63 68   version */.  ch
11c0: 61 72 20 2a 7a 56 65 72 73 3b 20 20 20 20 20 20  ar *zVers;      
11d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20               /* 
11e0: 56 65 72 73 69 6f 6e 20 74 6f 20 63 68 65 63 6b  Version to check
11f0: 6f 75 74 20 2a 2f 0a 20 20 69 6e 74 20 76 69 64  out */.  int vid
1200: 2c 20 70 72 69 6f 72 3b 0a 20 20 42 6c 6f 62 20  , prior;.  Blob 
1210: 63 6b 73 75 6d 31 2c 20 63 6b 73 75 6d 31 62 2c  cksum1, cksum1b,
1220: 20 63 6b 73 75 6d 32 3b 0a 20 20 0a 20 20 64 62   cksum2;.  .  db
1230: 5f 6d 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f  _must_be_within_
1240: 74 72 65 65 28 29 3b 0a 20 20 64 62 5f 62 65 67  tree();.  db_beg
1250: 69 6e 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 29  in_transaction()
1260: 3b 0a 20 20 66 6f 72 63 65 46 6c 61 67 20 3d 20  ;.  forceFlag = 
1270: 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 66 6f 72  find_option("for
1280: 63 65 22 2c 22 66 22 2c 30 29 21 3d 30 3b 0a 20  ce","f",0)!=0;. 
1290: 20 6b 65 65 70 46 6c 61 67 20 3d 20 66 69 6e 64   keepFlag = find
12a0: 5f 6f 70 74 69 6f 6e 28 22 6b 65 65 70 22 2c 30  _option("keep",0
12b0: 2c 30 29 21 3d 30 3b 0a 20 20 6c 61 74 65 73 74  ,0)!=0;.  latest
12c0: 46 6c 61 67 20 3d 20 66 69 6e 64 5f 6f 70 74 69  Flag = find_opti
12d0: 6f 6e 28 22 6c 61 74 65 73 74 22 2c 30 2c 30 29  on("latest",0,0)
12e0: 21 3d 30 3b 0a 20 20 69 66 28 20 28 6c 61 74 65  !=0;.  if( (late
12f0: 73 74 46 6c 61 67 21 3d 30 20 26 26 20 67 2e 61  stFlag!=0 && g.a
1300: 72 67 63 21 3d 32 29 20 7c 7c 20 28 6c 61 74 65  rgc!=2) || (late
1310: 73 74 46 6c 61 67 3d 3d 30 20 26 26 20 67 2e 61  stFlag==0 && g.a
1320: 72 67 63 21 3d 33 29 20 29 7b 0a 20 20 20 20 20  rgc!=3) ){.     
1330: 75 73 61 67 65 28 22 56 45 52 53 49 4f 4e 7c 2d  usage("VERSION|-
1340: 2d 6c 61 74 65 73 74 20 3f 2d 2d 66 6f 72 63 65  -latest ?--force
1350: 3f 20 3f 2d 2d 6b 65 65 70 3f 22 29 3b 0a 20 20  ? ?--keep?");.  
1360: 7d 0a 20 20 69 66 28 20 21 66 6f 72 63 65 46 6c  }.  if( !forceFl
1370: 61 67 20 26 26 20 75 6e 73 61 76 65 64 5f 63 68  ag && unsaved_ch
1380: 61 6e 67 65 73 28 29 3d 3d 31 20 29 7b 0a 20 20  anges()==1 ){.  
1390: 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22    fossil_fatal("
13a0: 74 68 65 72 65 20 61 72 65 20 75 6e 73 61 76 65  there are unsave
13b0: 64 20 63 68 61 6e 67 65 73 20 69 6e 20 74 68 65  d changes in the
13c0: 20 63 75 72 72 65 6e 74 20 63 68 65 63 6b 6f 75   current checkou
13d0: 74 22 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 66  t");.  }.  if( f
13e0: 6f 72 63 65 46 6c 61 67 20 29 7b 0a 20 20 20 20  orceFlag ){.    
13f0: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 44  db_multi_exec("D
1400: 45 4c 45 54 45 20 46 52 4f 4d 20 76 66 69 6c 65  ELETE FROM vfile
1410: 22 29 3b 0a 20 20 20 20 70 72 69 6f 72 20 3d 20  ");.    prior = 
1420: 30 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20  0;.  }else{.    
1430: 70 72 69 6f 72 20 3d 20 64 62 5f 6c 67 65 74 5f  prior = db_lget_
1440: 69 6e 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 30  int("checkout",0
1450: 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 6c 61 74  );.  }.  if( lat
1460: 65 73 74 46 6c 61 67 20 29 7b 0a 20 20 20 20 63  estFlag ){.    c
1470: 6f 6d 70 75 74 65 5f 6c 65 61 76 65 73 28 64 62  ompute_leaves(db
1480: 5f 6c 67 65 74 5f 69 6e 74 28 22 63 68 65 63 6b  _lget_int("check
1490: 6f 75 74 22 2c 30 29 2c 20 31 29 3b 0a 20 20 20  out",0), 1);.   
14a0: 20 7a 56 65 72 73 20 3d 20 64 62 5f 74 65 78 74   zVers = db_text
14b0: 28 30 2c 20 22 53 45 4c 45 43 54 20 75 75 69 64  (0, "SELECT uuid
14c0: 20 46 52 4f 4d 20 6c 65 61 76 65 73 2c 20 65 76   FROM leaves, ev
14d0: 65 6e 74 2c 20 62 6c 6f 62 22 0a 20 20 20 20 20  ent, blob".     
14e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
14f0: 20 20 22 20 57 48 45 52 45 20 65 76 65 6e 74 2e    " WHERE event.
1500: 6f 62 6a 69 64 3d 6c 65 61 76 65 73 2e 72 69 64  objid=leaves.rid
1510: 20 41 4e 44 20 62 6c 6f 62 2e 72 69 64 3d 6c 65   AND blob.rid=le
1520: 61 76 65 73 2e 72 69 64 22 0a 20 20 20 20 20 20  aves.rid".      
1530: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1540: 20 22 20 4f 52 44 45 52 20 42 59 20 65 76 65 6e   " ORDER BY even
1550: 74 2e 6d 74 69 6d 65 20 44 45 53 43 22 29 3b 0a  t.mtime DESC");.
1560: 20 20 20 20 69 66 28 20 7a 56 65 72 73 3d 3d 30      if( zVers==0
1570: 20 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c   ){.      fossil
1580: 5f 66 61 74 61 6c 28 22 63 61 6e 6e 6f 74 20 6c  _fatal("cannot l
1590: 6f 63 61 74 65 20 5c 22 6c 61 74 65 73 74 5c 22  ocate \"latest\"
15a0: 20 63 68 65 63 6b 6f 75 74 22 29 3b 0a 20 20 20   checkout");.   
15b0: 20 7d 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20   }.  }else{.    
15c0: 7a 56 65 72 73 20 3d 20 67 2e 61 72 67 76 5b 32  zVers = g.argv[2
15d0: 5d 3b 0a 20 20 7d 0a 20 20 76 69 64 20 3d 20 6c  ];.  }.  vid = l
15e0: 6f 61 64 5f 76 66 69 6c 65 28 7a 56 65 72 73 29  oad_vfile(zVers)
15f0: 3b 0a 20 20 69 66 28 20 70 72 69 6f 72 3d 3d 76  ;.  if( prior==v
1600: 69 64 20 29 7b 0a 20 20 20 20 72 65 74 75 72 6e  id ){.    return
1610: 3b 0a 20 20 7d 0a 20 20 69 66 28 20 21 6b 65 65  ;.  }.  if( !kee
1620: 70 46 6c 61 67 20 29 7b 0a 20 20 20 20 75 6e 63  pFlag ){.    unc
1630: 68 65 63 6b 6f 75 74 28 70 72 69 6f 72 29 3b 0a  heckout(prior);.
1640: 20 20 7d 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65    }.  db_multi_e
1650: 78 65 63 28 22 44 45 4c 45 54 45 20 46 52 4f 4d  xec("DELETE FROM
1660: 20 76 66 69 6c 65 20 57 48 45 52 45 20 76 69 64   vfile WHERE vid
1670: 21 3d 25 64 22 2c 20 76 69 64 29 3b 0a 20 20 69  !=%d", vid);.  i
1680: 66 28 20 21 6b 65 65 70 46 6c 61 67 20 29 7b 0a  f( !keepFlag ){.
1690: 20 20 20 20 76 66 69 6c 65 5f 74 6f 5f 64 69 73      vfile_to_dis
16a0: 6b 28 76 69 64 2c 20 30 2c 20 31 29 3b 0a 20 20  k(vid, 0, 1);.  
16b0: 7d 0a 20 20 6d 61 6e 69 66 65 73 74 5f 74 6f 5f  }.  manifest_to_
16c0: 64 69 73 6b 28 76 69 64 29 3b 0a 20 20 64 62 5f  disk(vid);.  db_
16d0: 6c 73 65 74 5f 69 6e 74 28 22 63 68 65 63 6b 6f  lset_int("checko
16e0: 75 74 22 2c 20 76 69 64 29 3b 0a 20 20 75 6e 64  ut", vid);.  und
16f0: 6f 5f 72 65 73 65 74 28 29 3b 0a 20 20 64 62 5f  o_reset();.  db_
1700: 6d 75 6c 74 69 5f 65 78 65 63 28 22 44 45 4c 45  multi_exec("DELE
1710: 54 45 20 46 52 4f 4d 20 76 6d 65 72 67 65 22 29  TE FROM vmerge")
1720: 3b 0a 20 20 69 66 28 20 21 6b 65 65 70 46 6c 61  ;.  if( !keepFla
1730: 67 20 29 7b 0a 20 20 20 20 76 66 69 6c 65 5f 61  g ){.    vfile_a
1740: 67 67 72 65 67 61 74 65 5f 63 68 65 63 6b 73 75  ggregate_checksu
1750: 6d 5f 6d 61 6e 69 66 65 73 74 28 76 69 64 2c 20  m_manifest(vid, 
1760: 26 63 6b 73 75 6d 31 2c 20 26 63 6b 73 75 6d 31  &cksum1, &cksum1
1770: 62 29 3b 0a 20 20 20 20 76 66 69 6c 65 5f 61 67  b);.    vfile_ag
1780: 67 72 65 67 61 74 65 5f 63 68 65 63 6b 73 75 6d  gregate_checksum
1790: 5f 64 69 73 6b 28 76 69 64 2c 20 26 63 6b 73 75  _disk(vid, &cksu
17a0: 6d 32 29 3b 0a 20 20 20 20 69 66 28 20 62 6c 6f  m2);.    if( blo
17b0: 62 5f 63 6f 6d 70 61 72 65 28 26 63 6b 73 75 6d  b_compare(&cksum
17c0: 31 2c 20 26 63 6b 73 75 6d 32 29 20 29 7b 0a 20  1, &cksum2) ){. 
17d0: 20 20 20 20 20 70 72 69 6e 74 66 28 22 57 41 52       printf("WAR
17e0: 4e 49 4e 47 3a 20 6d 61 6e 69 66 65 73 74 20 63  NING: manifest c
17f0: 68 65 63 6b 73 75 6d 20 64 6f 65 73 20 6e 6f 74  hecksum does not
1800: 20 61 67 72 65 65 20 77 69 74 68 20 64 69 73 6b   agree with disk
1810: 5c 6e 22 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20  \n");.    }.    
1820: 69 66 28 20 62 6c 6f 62 5f 63 6f 6d 70 61 72 65  if( blob_compare
1830: 28 26 63 6b 73 75 6d 31 2c 20 26 63 6b 73 75 6d  (&cksum1, &cksum
1840: 31 62 29 20 29 7b 0a 20 20 20 20 20 20 70 72 69  1b) ){.      pri
1850: 6e 74 66 28 22 57 41 52 4e 49 4e 47 3a 20 6d 61  ntf("WARNING: ma
1860: 6e 69 66 65 73 74 20 63 68 65 63 6b 73 75 6d 20  nifest checksum 
1870: 64 6f 65 73 20 6e 6f 74 20 61 67 72 65 65 20 77  does not agree w
1880: 69 74 68 20 6d 61 6e 69 66 65 73 74 5c 6e 22 29  ith manifest\n")
1890: 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 64 62  ;.    }.  }.  db
18a0: 5f 65 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e  _end_transaction
18b0: 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 55 6e  (0);.}../*.** Un
18c0: 6c 69 6e 6b 20 74 68 65 20 6c 6f 63 61 6c 20 64  link the local d
18d0: 61 74 61 62 61 73 65 20 66 69 6c 65 0a 2a 2f 0a  atabase file.*/.
18e0: 76 6f 69 64 20 75 6e 6c 69 6e 6b 5f 6c 6f 63 61  void unlink_loca
18f0: 6c 5f 64 61 74 61 62 61 73 65 28 76 6f 69 64 29  l_database(void)
1900: 7b 0a 20 20 73 74 61 74 69 63 20 63 6f 6e 73 74  {.  static const
1910: 20 63 68 61 72 20 2a 61 7a 46 69 6c 65 5b 5d 20   char *azFile[] 
1920: 3d 20 7b 0a 20 20 20 20 20 22 25 73 5f 46 4f 53  = {.     "%s_FOS
1930: 53 49 4c 5f 22 2c 0a 20 20 20 20 20 22 25 73 5f  SIL_",.     "%s_
1940: 46 4f 53 53 49 4c 5f 2d 6a 6f 75 72 6e 61 6c 22  FOSSIL_-journal"
1950: 2c 0a 20 20 20 20 20 22 25 73 2e 66 6f 73 22 2c  ,.     "%s.fos",
1960: 0a 20 20 20 20 20 22 25 73 2e 66 6f 73 2d 6a 6f  .     "%s.fos-jo
1970: 75 72 6e 61 6c 22 2c 0a 20 20 7d 3b 0a 20 20 69  urnal",.  };.  i
1980: 6e 74 20 69 3b 0a 20 20 66 6f 72 28 69 3d 30 3b  nt i;.  for(i=0;
1990: 20 69 3c 73 69 7a 65 6f 66 28 61 7a 46 69 6c 65   i<sizeof(azFile
19a0: 29 2f 73 69 7a 65 6f 66 28 61 7a 46 69 6c 65 5b  )/sizeof(azFile[
19b0: 30 5d 29 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 63  0]); i++){.    c
19c0: 68 61 72 20 2a 7a 20 3d 20 6d 70 72 69 6e 74 66  har *z = mprintf
19d0: 28 61 7a 46 69 6c 65 5b 69 5d 2c 20 67 2e 7a 4c  (azFile[i], g.zL
19e0: 6f 63 61 6c 52 6f 6f 74 29 3b 0a 20 20 20 20 75  ocalRoot);.    u
19f0: 6e 6c 69 6e 6b 28 7a 29 3b 0a 20 20 20 20 66 72  nlink(z);.    fr
1a00: 65 65 28 7a 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a  ee(z);.  }.}../*
1a10: 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 63 6c 6f  .** COMMAND: clo
1a20: 73 65 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20  se.**.** Usage: 
1a30: 25 66 6f 73 73 69 6c 20 63 6c 6f 73 65 20 3f 2d  %fossil close ?-
1a40: 66 7c 2d 2d 66 6f 72 63 65 3f 0a 2a 2a 0a 2a 2a  f|--force?.**.**
1a50: 20 54 68 65 20 6f 70 70 6f 73 69 74 65 20 6f 66   The opposite of
1a60: 20 22 6f 70 65 6e 22 2e 20 20 43 6c 6f 73 65 20   "open".  Close 
1a70: 74 68 65 20 63 75 72 72 65 6e 74 20 64 61 74 61  the current data
1a80: 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e  base connection.
1a90: 0a 2a 2a 20 52 65 71 75 69 72 65 20 61 20 2d 66  .** Require a -f
1aa0: 20 6f 72 20 2d 2d 66 6f 72 63 65 20 66 6c 61 67   or --force flag
1ab0: 20 69 66 20 74 68 65 72 65 20 61 72 65 20 75 6e   if there are un
1ac0: 73 61 76 65 64 20 63 68 61 6e 67 65 64 20 69 6e  saved changed in
1ad0: 20 74 68 65 0a 2a 2a 20 63 75 72 72 65 6e 74 20   the.** current 
1ae0: 63 68 65 63 6b 2d 6f 75 74 2e 0a 2a 2f 0a 76 6f  check-out..*/.vo
1af0: 69 64 20 63 6c 6f 73 65 5f 63 6d 64 28 76 6f 69  id close_cmd(voi
1b00: 64 29 7b 0a 20 20 69 6e 74 20 66 6f 72 63 65 46  d){.  int forceF
1b10: 6c 61 67 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f  lag = find_optio
1b20: 6e 28 22 66 6f 72 63 65 22 2c 22 66 22 2c 30 29  n("force","f",0)
1b30: 21 3d 30 3b 0a 20 20 64 62 5f 6d 75 73 74 5f 62  !=0;.  db_must_b
1b40: 65 5f 77 69 74 68 69 6e 5f 74 72 65 65 28 29 3b  e_within_tree();
1b50: 0a 20 20 69 66 28 20 21 66 6f 72 63 65 46 6c 61  .  if( !forceFla
1b60: 67 20 26 26 20 75 6e 73 61 76 65 64 5f 63 68 61  g && unsaved_cha
1b70: 6e 67 65 73 28 29 3d 3d 31 20 29 7b 0a 20 20 20  nges()==1 ){.   
1b80: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 74   fossil_fatal("t
1b90: 68 65 72 65 20 61 72 65 20 75 6e 73 61 76 65 64  here are unsaved
1ba0: 20 63 68 61 6e 67 65 73 20 69 6e 20 74 68 65 20   changes in the 
1bb0: 63 75 72 72 65 6e 74 20 63 68 65 63 6b 6f 75 74  current checkout
1bc0: 22 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 63 6c 6f  ");.  }.  db_clo
1bd0: 73 65 28 29 3b 0a 20 20 75 6e 6c 69 6e 6b 5f 6c  se();.  unlink_l
1be0: 6f 63 61 6c 5f 64 61 74 61 62 61 73 65 28 29 3b  ocal_database();
1bf0: 0a 7d 0a                                         .}.