Hex Artifact Content
Not logged in

Artifact e9bf03b43280cadde374a765efdcd8390ae13145:

File src/checkout.c part of check-in [695b1c7563] - test recycling "is_ticket()" from wikiformat.c as a way to avoid trying to checkout a ticket by bch on 2009-04-29 03:51:02.

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 29 3b 0a 20 20 72 65 74 75 72 6e  e(vid);.  return
05c0: 20 64 62 5f 65 78 69 73 74 73 28 22 53 45 4c 45   db_exists("SELE
05d0: 43 54 20 31 20 46 52 4f 4d 20 76 66 69 6c 65 20  CT 1 FROM vfile 
05e0: 57 48 45 52 45 20 63 68 6e 67 65 64 22 0a 20 20  WHERE chnged".  
05f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0600: 20 22 20 4f 52 20 63 6f 61 6c 65 73 63 65 28 6f   " OR coalesce(o
0610: 72 69 67 6e 61 6d 65 21 3d 70 61 74 68 6e 61 6d  rigname!=pathnam
0620: 65 2c 30 29 22 29 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a  e,0)");.}.../*.*
0630: 2a 20 7a 54 61 72 67 65 74 20 69 73 20 67 75 61  * zTarget is gua
0640: 72 61 6e 74 65 65 64 20 74 6f 20 62 65 20 61 20  ranteed to be a 
0650: 55 55 49 44 2e 20 20 49 74 20 6d 69 67 68 74 20  UUID.  It might 
0660: 62 65 20 74 68 65 20 55 55 49 44 20 6f 66 20 61  be the UUID of a
0670: 20 74 69 63 6b 65 74 2e 0a 2a 2a 20 49 66 20 69   ticket..** If i
0680: 74 20 69 73 2c 20 73 74 6f 72 65 20 69 6e 20 2a  t is, store in *
0690: 70 43 6c 6f 73 65 64 20 61 20 74 72 75 65 20 6f  pClosed a true o
06a0: 72 20 66 61 6c 73 65 20 64 65 70 65 6e 64 69 6e  r false dependin
06b0: 67 20 6f 6e 20 77 68 65 74 68 65 72 20 6f 72 20  g on whether or 
06c0: 6e 6f 74 0a 2a 2a 20 74 68 65 20 74 69 63 6b 65  not.** the ticke
06d0: 74 20 69 73 20 63 6c 6f 73 65 64 20 61 6e 64 20  t is closed and 
06e0: 72 65 74 75 72 6e 20 74 72 75 65 2e 20 49 66 20  return true. If 
06f0: 7a 54 61 72 67 65 74 0a 2a 2a 20 69 73 20 6e 6f  zTarget.** is no
0700: 74 20 74 68 65 20 55 55 49 44 20 6f 66 20 61 20  t the UUID of a 
0710: 74 69 63 6b 65 74 2c 20 72 65 74 75 72 6e 20 66  ticket, return f
0720: 61 6c 73 65 2e 0a 2a 2f 0a 73 74 61 74 69 63 20  alse..*/.static 
0730: 69 6e 74 20 69 73 5f 74 69 63 6b 65 74 28 0a 20  int is_ticket(. 
0740: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 54 61   const char *zTa
0750: 72 67 65 74 2c 20 20 20 20 2f 2a 20 54 69 63 6b  rget,    /* Tick
0760: 65 74 20 55 55 49 44 20 2a 2f 0a 20 20 69 6e 74  et UUID */.  int
0770: 20 2a 70 43 6c 6f 73 65 64 20 20 20 20 20 20 20   *pClosed       
0780: 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20       /* True if 
0790: 74 68 65 20 74 69 63 6b 65 74 20 69 73 20 63 6c  the ticket is cl
07a0: 6f 73 65 64 20 2a 2f 0a 29 7b 0a 20 20 73 74 61  osed */.){.  sta
07b0: 74 69 63 20 53 74 6d 74 20 71 3b 0a 20 20 73 74  tic Stmt q;.  st
07c0: 61 74 69 63 20 69 6e 74 20 6f 6e 63 65 20 3d 20  atic int once = 
07d0: 31 3b 0a 20 20 69 6e 74 20 6e 3b 0a 20 20 69 6e  1;.  int n;.  in
07e0: 74 20 72 63 3b 0a 20 20 63 68 61 72 20 7a 4c 6f  t rc;.  char zLo
07f0: 77 65 72 5b 55 55 49 44 5f 53 49 5a 45 2b 31 5d  wer[UUID_SIZE+1]
0800: 3b 0a 20 20 63 68 61 72 20 7a 55 70 70 65 72 5b  ;.  char zUpper[
0810: 55 55 49 44 5f 53 49 5a 45 2b 31 5d 3b 0a 20 20  UUID_SIZE+1];.  
0820: 6e 20 3d 20 73 74 72 6c 65 6e 28 7a 54 61 72 67  n = strlen(zTarg
0830: 65 74 29 3b 0a 20 20 6d 65 6d 63 70 79 28 7a 4c  et);.  memcpy(zL
0840: 6f 77 65 72 2c 20 7a 54 61 72 67 65 74 2c 20 6e  ower, zTarget, n
0850: 2b 31 29 3b 0a 20 20 63 61 6e 6f 6e 69 63 61 6c  +1);.  canonical
0860: 31 36 28 7a 4c 6f 77 65 72 2c 20 6e 2b 31 29 3b  16(zLower, n+1);
0870: 0a 20 20 6d 65 6d 63 70 79 28 7a 55 70 70 65 72  .  memcpy(zUpper
0880: 2c 20 7a 4c 6f 77 65 72 2c 20 6e 2b 31 29 3b 0a  , zLower, n+1);.
0890: 20 20 7a 55 70 70 65 72 5b 6e 2d 31 5d 2b 2b 3b    zUpper[n-1]++;
08a0: 0a 20 20 69 66 28 20 6f 6e 63 65 20 29 7b 0a 20  .  if( once ){. 
08b0: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a     const char *z
08c0: 43 6c 6f 73 65 64 45 78 70 72 20 3d 20 64 62 5f  ClosedExpr = db_
08d0: 67 65 74 28 22 74 69 63 6b 65 74 2d 63 6c 6f 73  get("ticket-clos
08e0: 65 64 2d 65 78 70 72 22 2c 20 22 73 74 61 74 75  ed-expr", "statu
08f0: 73 3d 27 43 6c 6f 73 65 64 27 22 29 3b 0a 20 20  s='Closed'");.  
0900: 20 20 64 62 5f 73 74 61 74 69 63 5f 70 72 65 70    db_static_prep
0910: 61 72 65 28 26 71 2c 20 0a 20 20 20 20 20 20 22  are(&q, .      "
0920: 53 45 4c 45 43 54 20 25 73 20 46 52 4f 4d 20 74  SELECT %s FROM t
0930: 69 63 6b 65 74 20 22 0a 20 20 20 20 20 20 22 20  icket ".      " 
0940: 57 48 45 52 45 20 74 6b 74 5f 75 75 69 64 3e 3d  WHERE tkt_uuid>=
0950: 3a 6c 77 72 20 41 4e 44 20 74 6b 74 5f 75 75 69  :lwr AND tkt_uui
0960: 64 3c 3a 75 70 72 22 2c 0a 20 20 20 20 20 20 7a  d<:upr",.      z
0970: 43 6c 6f 73 65 64 45 78 70 72 0a 20 20 20 20 29  ClosedExpr.    )
0980: 3b 0a 20 20 20 20 6f 6e 63 65 20 3d 20 30 3b 0a  ;.    once = 0;.
0990: 20 20 7d 0a 20 20 64 62 5f 62 69 6e 64 5f 74 65    }.  db_bind_te
09a0: 78 74 28 26 71 2c 20 22 3a 6c 77 72 22 2c 20 7a  xt(&q, ":lwr", z
09b0: 4c 6f 77 65 72 29 3b 0a 20 20 64 62 5f 62 69 6e  Lower);.  db_bin
09c0: 64 5f 74 65 78 74 28 26 71 2c 20 22 3a 75 70 72  d_text(&q, ":upr
09d0: 22 2c 20 7a 55 70 70 65 72 29 3b 0a 20 20 69 66  ", zUpper);.  if
09e0: 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53  ( db_step(&q)==S
09f0: 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20  QLITE_ROW ){.   
0a00: 20 72 63 20 3d 20 31 3b 0a 20 20 20 20 2a 70 43   rc = 1;.    *pC
0a10: 6c 6f 73 65 64 20 3d 20 64 62 5f 63 6f 6c 75 6d  losed = db_colum
0a20: 6e 5f 69 6e 74 28 26 71 2c 20 30 29 3b 0a 20 20  n_int(&q, 0);.  
0a30: 7d 65 6c 73 65 7b 0a 20 20 20 20 72 63 20 3d 20  }else{.    rc = 
0a40: 30 3b 0a 20 20 7d 0a 20 20 64 62 5f 72 65 73 65  0;.  }.  db_rese
0a50: 74 28 26 71 29 3b 0a 20 20 72 65 74 75 72 6e 20  t(&q);.  return 
0a60: 72 63 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 68 65  rc;.}../*.** Che
0a70: 63 6b 20 74 6f 20 73 65 65 20 69 66 20 74 68 65  ck to see if the
0a80: 20 72 65 71 75 65 73 74 65 64 20 63 6f 20 69 73   requested co is
0a90: 20 69 6e 20 66 61 63 74 20 22 63 68 65 63 6b 6f   in fact "checko
0aa0: 75 74 2d 61 62 6c 65 22 0a 2a 2a 20 52 65 74 75  ut-able".** Retu
0ab0: 72 6e 20 76 61 6c 75 65 73 3a 0a 2a 2a 20 20 20  rn values:.**   
0ac0: 30 3a 20 4e 6f 74 20 63 68 65 63 6b 6f 75 74 2d  0: Not checkout-
0ad0: 61 62 6c 65 20 28 64 6f 65 73 20 6e 6f 74 20 65  able (does not e
0ae0: 78 69 73 74 2c 20 6f 72 20 69 73 20 6e 6f 74 20  xist, or is not 
0af0: 61 6e 20 6f 6e 2d 64 69 73 6b 20 61 72 74 69 66  an on-disk artif
0b00: 61 63 74 29 0a 2a 2a 20 20 20 31 3a 20 49 73 20  act).**   1: Is 
0b10: 63 68 65 63 6b 6f 75 74 2d 61 62 6c 65 2e 0a 2a  checkout-able..*
0b20: 2f 0a 69 6e 74 20 63 68 65 63 6b 6f 75 74 61 62  /.int checkoutab
0b30: 6c 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  le(const char *z
0b40: 4e 61 6d 65 29 7b 0a 20 20 69 6e 74 20 72 63 3b  Name){.  int rc;
0b50: 20 2f 2a 20 72 65 74 75 72 6e 20 63 6f 64 65 20   /* return code 
0b60: 2a 2f 0a 20 20 69 6e 74 20 74 68 72 6f 77 61 77  */.  int throwaw
0b70: 61 79 3b 0a 0a 20 20 72 63 20 3d 20 21 69 73 5f  ay;..  rc = !is_
0b80: 74 69 63 6b 65 74 28 7a 4e 61 6d 65 2c 20 26 74  ticket(zName, &t
0b90: 68 72 6f 77 61 77 61 79 29 3b 0a 20 20 72 65 74  hrowaway);.  ret
0ba0: 75 72 6e 28 72 63 29 3b 0a 0a 20 20 42 6c 6f 62  urn(rc);..  Blob
0bb0: 20 75 75 69 64 3b 0a 20 20 63 6f 6e 73 74 20 63   uuid;.  const c
0bc0: 68 61 72 20 2a 72 69 64 3d 28 63 68 61 72 20 2a  har *rid=(char *
0bd0: 29 4e 55 4c 4c 3b 0a 20 20 53 74 6d 74 20 71 3b  )NULL;.  Stmt q;
0be0: 20 2f 2f 20 64 62 20 71 75 65 72 79 0a 20 20 63   // db query.  c
0bf0: 68 61 72 20 2a 7a 53 51 4c 3b 20 2f 2f 62 75 69  har *zSQL; //bui
0c00: 6c 64 2d 75 70 20 73 71 6c 0a 0a 20 20 2f 2f 20  ld-up sql..  // 
0c10: 20 7a 53 51 4c 20 3d 20 6d 70 72 69 6e 74 66 28   zSQL = mprintf(
0c20: 29 3b 0a 0a 20 20 2f 2f 20 5b 63 72 65 61 74 65  );..  // [create
0c30: 20 73 71 6c 20 73 74 61 74 65 6d 65 6e 74 5d 0a   sql statement].
0c40: 20 20 2f 2f 20 64 62 5f 70 72 65 70 61 72 65 28    // db_prepare(
0c50: 26 71 2c 73 71 6c 73 74 6d 74 29 3b 0a 0a 20 20  &q,sqlstmt);..  
0c60: 62 6c 6f 62 5f 69 6e 69 74 28 26 75 75 69 64 2c  blob_init(&uuid,
0c70: 20 7a 4e 61 6d 65 2c 20 2d 31 29 3b 0a 20 20 69   zName, -1);.  i
0c80: 66 28 20 6e 61 6d 65 5f 74 6f 5f 75 75 69 64 28  f( name_to_uuid(
0c90: 26 75 75 69 64 2c 20 31 29 20 29 7b 0a 20 20 20  &uuid, 1) ){.   
0ca0: 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 67 2e   fossil_panic(g.
0cb0: 7a 45 72 72 4d 73 67 29 3b 0a 20 20 7d 0a 0a 20  zErrMsg);.  }.. 
0cc0: 20 2f 2a 20 20 6e 50 61 72 65 6e 74 3d 64 62 5f   /*  nParent=db_
0cd0: 74 65 78 74 28 30 2c 22 73 65 6c 65 63 74 20 72  text(0,"select r
0ce0: 69 64 20 66 72 6f 6d 20 62 6c 6f 62 20 77 68 65  id from blob whe
0cf0: 72 65 20 75 75 69 64 3d 25 73 22 2c 75 75 69 64  re uuid=%s",uuid
0d00: 2e 6e 61 6d 65 6f 66 6f 62 6a 29 3b 20 2a 2f 0a  .nameofobj); */.
0d10: 0a 20 20 2f 2a 20 20 69 6e 74 20 6e 50 61 72 65  .  /*  int nPare
0d20: 6e 74 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69  nt = db_column_i
0d30: 6e 74 28 71 2c 20 73 6f 6d 65 6e 75 6d 29 3b 20  nt(q, somenum); 
0d40: 2a 2f 0a 20 20 72 65 74 75 72 6e 20 72 63 3b 0a  */.  return rc;.
0d50: 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 55 6e 64 6f 20 74  }.../*.** Undo t
0d60: 68 65 20 63 75 72 72 65 6e 74 20 63 68 65 63 6b  he current check
0d70: 2d 6f 75 74 2e 20 20 55 6e 6c 69 6e 6b 20 61 6c  -out.  Unlink al
0d80: 6c 20 66 69 6c 65 73 20 66 72 6f 6d 20 74 68 65  l files from the
0d90: 20 64 69 73 6b 2e 0a 2a 2a 20 43 6c 65 61 72 20   disk..** Clear 
0da0: 74 68 65 20 56 46 49 4c 45 20 74 61 62 6c 65 2e  the VFILE table.
0db0: 0a 2a 2f 0a 76 6f 69 64 20 75 6e 63 68 65 63 6b  .*/.void uncheck
0dc0: 6f 75 74 28 69 6e 74 20 76 69 64 29 7b 0a 20 20  out(int vid){.  
0dd0: 69 66 28 20 76 69 64 3d 3d 30 20 29 20 72 65 74  if( vid==0 ) ret
0de0: 75 72 6e 3b 0a 20 20 76 66 69 6c 65 5f 75 6e 6c  urn;.  vfile_unl
0df0: 69 6e 6b 28 76 69 64 29 3b 0a 20 20 64 62 5f 6d  ink(vid);.  db_m
0e00: 75 6c 74 69 5f 65 78 65 63 28 22 44 45 4c 45 54  ulti_exec("DELET
0e10: 45 20 46 52 4f 4d 20 76 66 69 6c 65 20 57 48 45  E FROM vfile WHE
0e20: 52 45 20 76 69 64 3d 25 64 22 2c 20 76 69 64 29  RE vid=%d", vid)
0e30: 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 47 69 76 65  ;.}.../*.** Give
0e40: 6e 20 74 68 65 20 61 62 62 72 65 76 69 61 74 65  n the abbreviate
0e50: 64 20 55 55 49 44 20 6e 61 6d 65 20 6f 66 20 61  d UUID name of a
0e60: 20 76 65 72 73 69 6f 6e 2c 20 6c 6f 61 64 20 74   version, load t
0e70: 68 65 20 63 6f 6e 74 65 6e 74 20 6f 66 20 74 68  he content of th
0e80: 61 74 0a 2a 2a 20 76 65 72 73 69 6f 6e 20 69 6e  at.** version in
0e90: 20 74 68 65 20 56 46 49 4c 45 20 74 61 62 6c 65   the VFILE table
0ea0: 2e 20 20 52 65 74 75 72 6e 20 74 68 65 20 56 49  .  Return the VI
0eb0: 44 20 66 6f 72 20 74 68 65 20 76 65 72 73 69 6f  D for the versio
0ec0: 6e 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 61 6e 79 74  n..**.** If anyt
0ed0: 68 69 6e 67 20 67 6f 65 73 20 77 72 6f 6e 67 2c  hing goes wrong,
0ee0: 20 70 61 6e 69 63 2e 0a 2a 2f 0a 69 6e 74 20 6c   panic..*/.int l
0ef0: 6f 61 64 5f 76 66 69 6c 65 28 63 6f 6e 73 74 20  oad_vfile(const 
0f00: 63 68 61 72 20 2a 7a 4e 61 6d 65 29 7b 0a 20 20  char *zName){.  
0f10: 42 6c 6f 62 20 75 75 69 64 3b 0a 20 20 69 6e 74  Blob uuid;.  int
0f20: 20 76 69 64 3b 0a 0a 20 20 62 6c 6f 62 5f 69 6e   vid;..  blob_in
0f30: 69 74 28 26 75 75 69 64 2c 20 7a 4e 61 6d 65 2c  it(&uuid, zName,
0f40: 20 2d 31 29 3b 0a 20 20 69 66 28 20 6e 61 6d 65   -1);.  if( name
0f50: 5f 74 6f 5f 75 75 69 64 28 26 75 75 69 64 2c 20  _to_uuid(&uuid, 
0f60: 31 29 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c  1) ){.    fossil
0f70: 5f 70 61 6e 69 63 28 67 2e 7a 45 72 72 4d 73 67  _panic(g.zErrMsg
0f80: 29 3b 0a 20 20 7d 0a 20 20 76 69 64 20 3d 20 64  );.  }.  vid = d
0f90: 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54  b_int(0, "SELECT
0fa0: 20 72 69 64 20 46 52 4f 4d 20 62 6c 6f 62 20 57   rid FROM blob W
0fb0: 48 45 52 45 20 75 75 69 64 3d 25 42 22 2c 20 26  HERE uuid=%B", &
0fc0: 75 75 69 64 29 3b 0a 20 20 69 66 28 20 76 69 64  uuid);.  if( vid
0fd0: 3d 3d 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 69  ==0 ){.    fossi
0fe0: 6c 5f 70 61 6e 69 63 28 22 6e 6f 20 73 75 63 68  l_panic("no such
0ff0: 20 76 65 72 73 69 6f 6e 3a 20 25 73 22 2c 20 67   version: %s", g
1000: 2e 61 72 67 76 5b 32 5d 29 3b 0a 20 20 7d 0a 20  .argv[2]);.  }. 
1010: 20 6c 6f 61 64 5f 76 66 69 6c 65 5f 66 72 6f 6d   load_vfile_from
1020: 5f 72 69 64 28 76 69 64 29 3b 0a 20 20 72 65 74  _rid(vid);.  ret
1030: 75 72 6e 20 76 69 64 3b 0a 7d 0a 0a 2f 2a 0a 2a  urn vid;.}../*.*
1040: 2a 20 4c 6f 61 64 20 61 20 76 66 69 6c 65 20 66  * Load a vfile f
1050: 72 6f 6d 20 61 20 72 65 63 6f 72 64 20 49 44 2e  rom a record ID.
1060: 0a 2a 2f 0a 76 6f 69 64 20 6c 6f 61 64 5f 76 66  .*/.void load_vf
1070: 69 6c 65 5f 66 72 6f 6d 5f 72 69 64 28 69 6e 74  ile_from_rid(int
1080: 20 76 69 64 29 7b 0a 20 20 42 6c 6f 62 20 6d 61   vid){.  Blob ma
1090: 6e 69 66 65 73 74 3b 0a 0a 20 20 69 66 28 20 64  nifest;..  if( d
10a0: 62 5f 65 78 69 73 74 73 28 22 53 45 4c 45 43 54  b_exists("SELECT
10b0: 20 31 20 46 52 4f 4d 20 76 66 69 6c 65 20 57 48   1 FROM vfile WH
10c0: 45 52 45 20 76 69 64 3d 25 64 22 2c 20 76 69 64  ERE vid=%d", vid
10d0: 29 20 29 7b 0a 20 20 20 20 72 65 74 75 72 6e 3b  ) ){.    return;
10e0: 0a 20 20 7d 0a 20 20 63 6f 6e 74 65 6e 74 5f 67  .  }.  content_g
10f0: 65 74 28 76 69 64 2c 20 26 6d 61 6e 69 66 65 73  et(vid, &manifes
1100: 74 29 3b 0a 20 20 76 66 69 6c 65 5f 62 75 69 6c  t);.  vfile_buil
1110: 64 28 76 69 64 2c 20 26 6d 61 6e 69 66 65 73 74  d(vid, &manifest
1120: 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28  );.  blob_reset(
1130: 26 6d 61 6e 69 66 65 73 74 29 3b 0a 7d 0a 0a 2f  &manifest);.}../
1140: 2a 0a 2a 2a 20 52 65 61 64 20 74 68 65 20 6d 61  *.** Read the ma
1150: 6e 69 66 65 73 74 20 66 69 6c 65 20 67 69 76 65  nifest file give
1160: 6e 20 62 79 20 76 69 64 20 6f 75 74 20 6f 66 20  n by vid out of 
1170: 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 0a 2a  the repository.*
1180: 2a 20 61 6e 64 20 73 74 6f 72 65 20 69 74 20 69  * and store it i
1190: 6e 20 74 68 65 20 72 6f 6f 74 20 6f 66 20 74 68  n the root of th
11a0: 65 20 6c 6f 63 61 6c 20 63 68 65 63 6b 2d 6f 75  e local check-ou
11b0: 74 2e 0a 2a 2f 0a 76 6f 69 64 20 6d 61 6e 69 66  t..*/.void manif
11c0: 65 73 74 5f 74 6f 5f 64 69 73 6b 28 69 6e 74 20  est_to_disk(int 
11d0: 76 69 64 29 7b 0a 20 20 63 68 61 72 20 2a 7a 4d  vid){.  char *zM
11e0: 61 6e 46 69 6c 65 3b 0a 20 20 42 6c 6f 62 20 6d  anFile;.  Blob m
11f0: 61 6e 69 66 65 73 74 3b 0a 20 20 42 6c 6f 62 20  anifest;.  Blob 
1200: 68 61 73 68 3b 0a 20 20 42 6c 6f 62 20 66 69 6c  hash;.  Blob fil
1210: 65 6e 61 6d 65 3b 0a 20 20 69 6e 74 20 62 61 73  ename;.  int bas
1220: 65 4c 65 6e 3b 0a 20 20 69 6e 74 20 69 3b 0a 20  eLen;.  int i;. 
1230: 20 4d 61 6e 69 66 65 73 74 20 6d 3b 0a 0a 20 20   Manifest m;..  
1240: 62 6c 6f 62 5f 7a 65 72 6f 28 26 6d 61 6e 69 66  blob_zero(&manif
1250: 65 73 74 29 3b 0a 20 20 7a 4d 61 6e 46 69 6c 65  est);.  zManFile
1260: 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 6d 61   = mprintf("%sma
1270: 6e 69 66 65 73 74 22 2c 20 67 2e 7a 4c 6f 63 61  nifest", g.zLoca
1280: 6c 52 6f 6f 74 29 3b 0a 20 20 63 6f 6e 74 65 6e  lRoot);.  conten
1290: 74 5f 67 65 74 28 76 69 64 2c 20 26 6d 61 6e 69  t_get(vid, &mani
12a0: 66 65 73 74 29 3b 0a 20 20 62 6c 6f 62 5f 77 72  fest);.  blob_wr
12b0: 69 74 65 5f 74 6f 5f 66 69 6c 65 28 26 6d 61 6e  ite_to_file(&man
12c0: 69 66 65 73 74 2c 20 7a 4d 61 6e 46 69 6c 65 29  ifest, zManFile)
12d0: 3b 0a 20 20 66 72 65 65 28 7a 4d 61 6e 46 69 6c  ;.  free(zManFil
12e0: 65 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28  e);.  blob_zero(
12f0: 26 68 61 73 68 29 3b 0a 20 20 73 68 61 31 73 75  &hash);.  sha1su
1300: 6d 5f 62 6c 6f 62 28 26 6d 61 6e 69 66 65 73 74  m_blob(&manifest
1310: 2c 20 26 68 61 73 68 29 3b 0a 20 20 7a 4d 61 6e  , &hash);.  zMan
1320: 46 69 6c 65 20 3d 20 6d 70 72 69 6e 74 66 28 22  File = mprintf("
1330: 25 73 6d 61 6e 69 66 65 73 74 2e 75 75 69 64 22  %smanifest.uuid"
1340: 2c 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 29 3b  , g.zLocalRoot);
1350: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 26  .  blob_append(&
1360: 68 61 73 68 2c 20 22 5c 6e 22 2c 20 31 29 3b 0a  hash, "\n", 1);.
1370: 20 20 62 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f    blob_write_to_
1380: 66 69 6c 65 28 26 68 61 73 68 2c 20 7a 4d 61 6e  file(&hash, zMan
1390: 46 69 6c 65 29 3b 0a 20 20 66 72 65 65 28 7a 4d  File);.  free(zM
13a0: 61 6e 46 69 6c 65 29 3b 0a 20 20 62 6c 6f 62 5f  anFile);.  blob_
13b0: 72 65 73 65 74 28 26 68 61 73 68 29 3b 0a 20 20  reset(&hash);.  
13c0: 6d 61 6e 69 66 65 73 74 5f 70 61 72 73 65 28 26  manifest_parse(&
13d0: 6d 2c 20 26 6d 61 6e 69 66 65 73 74 29 3b 0a 20  m, &manifest);. 
13e0: 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 66 69 6c 65   blob_zero(&file
13f0: 6e 61 6d 65 29 3b 0a 20 20 62 6c 6f 62 5f 61 70  name);.  blob_ap
1400: 70 65 6e 64 66 28 26 66 69 6c 65 6e 61 6d 65 2c  pendf(&filename,
1410: 20 22 25 73 2f 22 2c 20 67 2e 7a 4c 6f 63 61 6c   "%s/", g.zLocal
1420: 52 6f 6f 74 29 3b 0a 20 20 62 61 73 65 4c 65 6e  Root);.  baseLen
1430: 20 3d 20 62 6c 6f 62 5f 73 69 7a 65 28 26 66 69   = blob_size(&fi
1440: 6c 65 6e 61 6d 65 29 3b 0a 20 20 66 6f 72 28 69  lename);.  for(i
1450: 3d 30 3b 20 69 3c 6d 2e 6e 46 69 6c 65 3b 20 69  =0; i<m.nFile; i
1460: 2b 2b 29 7b 20 0a 20 20 20 20 69 6e 74 20 69 73  ++){ .    int is
1470: 45 78 65 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70  Exe;.    blob_ap
1480: 70 65 6e 64 28 26 66 69 6c 65 6e 61 6d 65 2c 20  pend(&filename, 
1490: 6d 2e 61 46 69 6c 65 5b 69 5d 2e 7a 4e 61 6d 65  m.aFile[i].zName
14a0: 2c 20 2d 31 29 3b 0a 20 20 20 20 69 73 45 78 65  , -1);.    isExe
14b0: 20 3d 20 6d 2e 61 46 69 6c 65 5b 69 5d 2e 7a 50   = m.aFile[i].zP
14c0: 65 72 6d 20 26 26 20 73 74 72 73 74 72 28 6d 2e  erm && strstr(m.
14d0: 61 46 69 6c 65 5b 69 5d 2e 7a 50 65 72 6d 2c 20  aFile[i].zPerm, 
14e0: 22 78 22 29 3b 0a 20 20 20 20 66 69 6c 65 5f 73  "x");.    file_s
14f0: 65 74 65 78 65 28 62 6c 6f 62 5f 73 74 72 28 26  etexe(blob_str(&
1500: 66 69 6c 65 6e 61 6d 65 29 2c 20 69 73 45 78 65  filename), isExe
1510: 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 72 65 73 69  );.    blob_resi
1520: 7a 65 28 26 66 69 6c 65 6e 61 6d 65 2c 20 62 61  ze(&filename, ba
1530: 73 65 4c 65 6e 29 3b 0a 20 20 7d 0a 20 20 62 6c  seLen);.  }.  bl
1540: 6f 62 5f 72 65 73 65 74 28 26 66 69 6c 65 6e 61  ob_reset(&filena
1550: 6d 65 29 3b 0a 20 20 6d 61 6e 69 66 65 73 74 5f  me);.  manifest_
1560: 63 6c 65 61 72 28 26 6d 29 3b 0a 7d 0a 0a 2f 2a  clear(&m);.}../*
1570: 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 63 68 65  .** COMMAND: che
1580: 63 6b 6f 75 74 0a 2a 2a 20 43 4f 4d 4d 41 4e 44  ckout.** COMMAND
1590: 3a 20 63 6f 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65  : co.**.** Usage
15a0: 3a 20 25 66 6f 73 73 69 6c 20 63 68 65 63 6b 6f  : %fossil checko
15b0: 75 74 20 56 45 52 53 49 4f 4e 20 3f 2d 66 7c 2d  ut VERSION ?-f|-
15c0: 2d 66 6f 72 63 65 3f 0a 2a 2a 0a 2a 2a 20 43 68  -force?.**.** Ch
15d0: 65 63 6b 20 6f 75 74 20 61 20 76 65 72 73 69 6f  eck out a versio
15e0: 6e 20 73 70 65 63 69 66 69 65 64 20 6f 6e 20 74  n specified on t
15f0: 68 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 2e  he command-line.
1600: 20 20 54 68 69 73 20 63 6f 6d 6d 61 6e 64 0a 2a    This command.*
1610: 2a 20 77 69 6c 6c 20 6e 6f 74 20 6f 76 65 72 77  * will not overw
1620: 72 69 74 65 20 65 64 69 74 65 64 20 66 69 6c 65  rite edited file
1630: 73 20 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74  s in the current
1640: 20 63 68 65 63 6b 6f 75 74 20 75 6e 6c 65 73 73   checkout unless
1650: 0a 2a 2a 20 74 68 65 20 2d 2d 66 6f 72 63 65 20  .** the --force 
1660: 6f 70 74 69 6f 6e 20 61 70 70 65 61 72 73 20 6f  option appears o
1670: 6e 20 74 68 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69  n the command-li
1680: 6e 65 2e 0a 2a 2a 0a 2a 2a 20 53 65 65 20 61 6c  ne..**.** See al
1690: 73 6f 20 74 68 65 20 22 75 70 64 61 74 65 22 20  so the "update" 
16a0: 63 6f 6d 6d 61 6e 64 2e 0a 2a 2f 0a 76 6f 69 64  command..*/.void
16b0: 20 63 68 65 63 6b 6f 75 74 5f 63 6d 64 28 76 6f   checkout_cmd(vo
16c0: 69 64 29 7b 0a 20 20 69 6e 74 20 66 6f 72 63 65  id){.  int force
16d0: 46 6c 61 67 3b 0a 20 20 69 6e 74 20 6e 6f 57 72  Flag;.  int noWr
16e0: 69 74 65 3b 0a 20 20 69 6e 74 20 76 69 64 2c 20  ite;.  int vid, 
16f0: 70 72 69 6f 72 3b 0a 20 20 42 6c 6f 62 20 63 6b  prior;.  Blob ck
1700: 73 75 6d 31 2c 20 63 6b 73 75 6d 31 62 2c 20 63  sum1, cksum1b, c
1710: 6b 73 75 6d 32 3b 0a 20 20 0a 20 20 64 62 5f 6d  ksum2;.  .  db_m
1720: 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72  ust_be_within_tr
1730: 65 65 28 29 3b 0a 20 20 64 62 5f 62 65 67 69 6e  ee();.  db_begin
1740: 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a  _transaction();.
1750: 20 20 66 6f 72 63 65 46 6c 61 67 20 3d 20 66 69    forceFlag = fi
1760: 6e 64 5f 6f 70 74 69 6f 6e 28 22 66 6f 72 63 65  nd_option("force
1770: 22 2c 22 66 22 2c 30 29 21 3d 30 3b 0a 20 20 6e  ","f",0)!=0;.  n
1780: 6f 57 72 69 74 65 20 3d 20 66 69 6e 64 5f 6f 70  oWrite = find_op
1790: 74 69 6f 6e 28 22 64 6f 6e 74 77 72 69 74 65 22  tion("dontwrite"
17a0: 2c 30 2c 30 29 21 3d 30 3b 0a 20 20 69 66 28 20  ,0,0)!=0;.  if( 
17b0: 67 2e 61 72 67 63 21 3d 33 20 29 20 75 73 61 67  g.argc!=3 ) usag
17c0: 65 28 22 3f 2d 2d 66 6f 72 63 65 3f 20 56 45 52  e("?--force? VER
17d0: 53 49 4f 4e 22 29 3b 0a 20 20 69 66 28 20 21 66  SION");.  if( !f
17e0: 6f 72 63 65 46 6c 61 67 20 26 26 20 75 6e 73 61  orceFlag && unsa
17f0: 76 65 64 5f 63 68 61 6e 67 65 73 28 29 3d 3d 31  ved_changes()==1
1800: 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66   ){.    fossil_f
1810: 61 74 61 6c 28 22 74 68 65 72 65 20 61 72 65 20  atal("there are 
1820: 75 6e 73 61 76 65 64 20 63 68 61 6e 67 65 73 20  unsaved changes 
1830: 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20 63  in the current c
1840: 68 65 63 6b 6f 75 74 22 29 3b 0a 20 20 7d 0a 20  heckout");.  }. 
1850: 20 69 66 28 21 63 68 65 63 6b 6f 75 74 61 62 6c   if(!checkoutabl
1860: 65 28 67 2e 61 72 67 76 5b 32 5d 29 29 7b 0a 20  e(g.argv[2])){. 
1870: 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28     fossil_fatal(
1880: 22 74 68 65 20 56 45 52 53 49 4f 4e 20 79 6f 75  "the VERSION you
1890: 20 72 65 71 75 65 73 74 65 64 20 69 73 20 6e 6f   requested is no
18a0: 74 20 61 20 63 68 65 63 6b 6f 75 74 2d 61 62 6c  t a checkout-abl
18b0: 65 20 61 72 74 69 66 61 63 74 22 29 3b 0a 20 20  e artifact");.  
18c0: 7d 0a 20 20 69 66 28 20 66 6f 72 63 65 46 6c 61  }.  if( forceFla
18d0: 67 20 29 7b 0a 20 20 20 20 64 62 5f 6d 75 6c 74  g ){.    db_mult
18e0: 69 5f 65 78 65 63 28 22 44 45 4c 45 54 45 20 46  i_exec("DELETE F
18f0: 52 4f 4d 20 76 66 69 6c 65 22 29 3b 0a 20 20 20  ROM vfile");.   
1900: 20 70 72 69 6f 72 20 3d 20 30 3b 0a 20 20 7d 65   prior = 0;.  }e
1910: 6c 73 65 7b 0a 20 20 20 20 70 72 69 6f 72 20 3d  lse{.    prior =
1920: 20 64 62 5f 6c 67 65 74 5f 69 6e 74 28 22 63 68   db_lget_int("ch
1930: 65 63 6b 6f 75 74 22 2c 30 29 3b 0a 20 20 7d 0a  eckout",0);.  }.
1940: 20 20 76 69 64 20 3d 20 6c 6f 61 64 5f 76 66 69    vid = load_vfi
1950: 6c 65 28 67 2e 61 72 67 76 5b 32 5d 29 3b 0a 20  le(g.argv[2]);. 
1960: 20 69 66 28 20 70 72 69 6f 72 3d 3d 76 69 64 20   if( prior==vid 
1970: 29 7b 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20  ){.    return;. 
1980: 20 7d 0a 20 20 69 66 28 20 21 6e 6f 57 72 69 74   }.  if( !noWrit
1990: 65 20 29 7b 0a 20 20 20 20 75 6e 63 68 65 63 6b  e ){.    uncheck
19a0: 6f 75 74 28 70 72 69 6f 72 29 3b 0a 20 20 7d 0a  out(prior);.  }.
19b0: 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28    db_multi_exec(
19c0: 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 76 66 69  "DELETE FROM vfi
19d0: 6c 65 20 57 48 45 52 45 20 76 69 64 21 3d 25 64  le WHERE vid!=%d
19e0: 22 2c 20 76 69 64 29 3b 0a 20 20 69 66 28 20 21  ", vid);.  if( !
19f0: 6e 6f 57 72 69 74 65 20 29 7b 0a 20 20 20 20 76  noWrite ){.    v
1a00: 66 69 6c 65 5f 74 6f 5f 64 69 73 6b 28 76 69 64  file_to_disk(vid
1a10: 2c 20 30 2c 20 31 29 3b 0a 20 20 20 20 6d 61 6e  , 0, 1);.    man
1a20: 69 66 65 73 74 5f 74 6f 5f 64 69 73 6b 28 76 69  ifest_to_disk(vi
1a30: 64 29 3b 0a 20 20 20 20 64 62 5f 6c 73 65 74 5f  d);.    db_lset_
1a40: 69 6e 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 20  int("checkout", 
1a50: 76 69 64 29 3b 0a 20 20 20 20 75 6e 64 6f 5f 72  vid);.    undo_r
1a60: 65 73 65 74 28 29 3b 0a 20 20 7d 0a 20 20 64 62  eset();.  }.  db
1a70: 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 44 45 4c  _multi_exec("DEL
1a80: 45 54 45 20 46 52 4f 4d 20 76 6d 65 72 67 65 22  ETE FROM vmerge"
1a90: 29 3b 0a 20 20 76 66 69 6c 65 5f 61 67 67 72 65  );.  vfile_aggre
1aa0: 67 61 74 65 5f 63 68 65 63 6b 73 75 6d 5f 6d 61  gate_checksum_ma
1ab0: 6e 69 66 65 73 74 28 76 69 64 2c 20 26 63 6b 73  nifest(vid, &cks
1ac0: 75 6d 31 2c 20 26 63 6b 73 75 6d 31 62 29 3b 0a  um1, &cksum1b);.
1ad0: 20 20 76 66 69 6c 65 5f 61 67 67 72 65 67 61 74    vfile_aggregat
1ae0: 65 5f 63 68 65 63 6b 73 75 6d 5f 64 69 73 6b 28  e_checksum_disk(
1af0: 76 69 64 2c 20 26 63 6b 73 75 6d 32 29 3b 0a 20  vid, &cksum2);. 
1b00: 20 69 66 28 20 62 6c 6f 62 5f 63 6f 6d 70 61 72   if( blob_compar
1b10: 65 28 26 63 6b 73 75 6d 31 2c 20 26 63 6b 73 75  e(&cksum1, &cksu
1b20: 6d 32 29 20 29 7b 0a 20 20 20 20 70 72 69 6e 74  m2) ){.    print
1b30: 66 28 22 57 41 52 4e 49 4e 47 3a 20 6d 61 6e 69  f("WARNING: mani
1b40: 66 65 73 74 20 63 68 65 63 6b 73 75 6d 20 64 6f  fest checksum do
1b50: 65 73 20 6e 6f 74 20 61 67 72 65 65 20 77 69 74  es not agree wit
1b60: 68 20 64 69 73 6b 5c 6e 22 29 3b 0a 20 20 7d 0a  h disk\n");.  }.
1b70: 20 20 69 66 28 20 62 6c 6f 62 5f 63 6f 6d 70 61    if( blob_compa
1b80: 72 65 28 26 63 6b 73 75 6d 31 2c 20 26 63 6b 73  re(&cksum1, &cks
1b90: 75 6d 31 62 29 20 29 7b 0a 20 20 20 20 70 72 69  um1b) ){.    pri
1ba0: 6e 74 66 28 22 57 41 52 4e 49 4e 47 3a 20 6d 61  ntf("WARNING: ma
1bb0: 6e 69 66 65 73 74 20 63 68 65 63 6b 73 75 6d 20  nifest checksum 
1bc0: 64 6f 65 73 20 6e 6f 74 20 61 67 72 65 65 20 77  does not agree w
1bd0: 69 74 68 20 6d 61 6e 69 66 65 73 74 5c 6e 22 29  ith manifest\n")
1be0: 3b 0a 20 20 7d 0a 20 20 64 62 5f 65 6e 64 5f 74  ;.  }.  db_end_t
1bf0: 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 3b 0a 7d  ransaction(0);.}
1c00: 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a  ../*.** COMMAND:
1c10: 20 63 6c 6f 73 65 0a 2a 2a 0a 2a 2a 20 55 73 61   close.**.** Usa
1c20: 67 65 3a 20 25 66 6f 73 73 69 6c 20 63 6c 6f 73  ge: %fossil clos
1c30: 65 20 3f 2d 66 7c 2d 2d 66 6f 72 63 65 3f 0a 2a  e ?-f|--force?.*
1c40: 2a 0a 2a 2a 20 54 68 65 20 6f 70 70 6f 73 69 74  *.** The opposit
1c50: 65 20 6f 66 20 22 6f 70 65 6e 22 2e 20 20 43 6c  e of "open".  Cl
1c60: 6f 73 65 20 74 68 65 20 63 75 72 72 65 6e 74 20  ose the current 
1c70: 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74  database connect
1c80: 69 6f 6e 2e 0a 2a 2a 20 52 65 71 75 69 72 65 20  ion..** Require 
1c90: 61 20 2d 66 20 6f 72 20 2d 2d 66 6f 72 63 65 20  a -f or --force 
1ca0: 66 6c 61 67 20 69 66 20 74 68 65 72 65 20 61 72  flag if there ar
1cb0: 65 20 75 6e 73 61 76 65 64 20 63 68 61 6e 67 65  e unsaved change
1cc0: 64 20 69 6e 20 74 68 65 0a 2a 2a 20 63 75 72 72  d in the.** curr
1cd0: 65 6e 74 20 63 68 65 63 6b 2d 6f 75 74 2e 0a 2a  ent check-out..*
1ce0: 2f 0a 76 6f 69 64 20 63 6c 6f 73 65 5f 63 6d 64  /.void close_cmd
1cf0: 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 66 6f  (void){.  int fo
1d00: 72 63 65 46 6c 61 67 20 3d 20 66 69 6e 64 5f 6f  rceFlag = find_o
1d10: 70 74 69 6f 6e 28 22 66 6f 72 63 65 22 2c 22 66  ption("force","f
1d20: 22 2c 30 29 21 3d 30 3b 0a 20 20 64 62 5f 6d 75  ",0)!=0;.  db_mu
1d30: 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72 65  st_be_within_tre
1d40: 65 28 29 3b 0a 20 20 69 66 28 20 21 66 6f 72 63  e();.  if( !forc
1d50: 65 46 6c 61 67 20 26 26 20 75 6e 73 61 76 65 64  eFlag && unsaved
1d60: 5f 63 68 61 6e 67 65 73 28 29 3d 3d 31 20 29 7b  _changes()==1 ){
1d70: 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61  .    fossil_fata
1d80: 6c 28 22 74 68 65 72 65 20 61 72 65 20 75 6e 73  l("there are uns
1d90: 61 76 65 64 20 63 68 61 6e 67 65 73 20 69 6e 20  aved changes in 
1da0: 74 68 65 20 63 75 72 72 65 6e 74 20 63 68 65 63  the current chec
1db0: 6b 6f 75 74 22 29 3b 0a 20 20 7d 0a 20 20 64 62  kout");.  }.  db
1dc0: 5f 63 6c 6f 73 65 28 29 3b 0a 20 20 75 6e 6c 69  _close();.  unli
1dd0: 6e 6b 28 6d 70 72 69 6e 74 66 28 22 25 73 5f 46  nk(mprintf("%s_F
1de0: 4f 53 53 49 4c 5f 22 2c 20 67 2e 7a 4c 6f 63 61  OSSIL_", g.zLoca
1df0: 6c 52 6f 6f 74 29 29 3b 0a 20 20 75 6e 6c 69 6e  lRoot));.  unlin
1e00: 6b 28 6d 70 72 69 6e 74 66 28 22 25 73 5f 46 4f  k(mprintf("%s_FO
1e10: 53 53 49 4c 5f 2d 6a 6f 75 72 6e 61 6c 22 2c 20  SSIL_-journal", 
1e20: 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 29 29 3b 0a  g.zLocalRoot));.
1e30: 7d 0a                                            }.