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 66 70 72 osed */.){. fpr
07b0: 69 6e 74 66 28 73 74 64 65 72 72 2c 22 49 27 6d intf(stderr,"I'm
07c0: 20 69 6e 20 69 73 5f 74 69 63 6b 65 74 5c 6e 22 in is_ticket\n"
07d0: 29 3b 0a 0a 20 20 73 74 61 74 69 63 20 53 74 6d );.. static Stm
07e0: 74 20 71 3b 0a 20 20 73 74 61 74 69 63 20 69 6e t q;. static in
07f0: 74 20 6f 6e 63 65 20 3d 20 31 3b 0a 20 20 69 6e t once = 1;. in
0800: 74 20 6e 3b 0a 20 20 69 6e 74 20 72 63 3b 0a 20 t n;. int rc;.
0810: 20 63 68 61 72 20 7a 4c 6f 77 65 72 5b 55 55 49 char zLower[UUI
0820: 44 5f 53 49 5a 45 2b 31 5d 3b 0a 20 20 63 68 61 D_SIZE+1];. cha
0830: 72 20 7a 55 70 70 65 72 5b 55 55 49 44 5f 53 49 r zUpper[UUID_SI
0840: 5a 45 2b 31 5d 3b 0a 20 20 6e 20 3d 20 73 74 72 ZE+1];. n = str
0850: 6c 65 6e 28 7a 54 61 72 67 65 74 29 3b 0a 20 20 len(zTarget);.
0860: 6d 65 6d 63 70 79 28 7a 4c 6f 77 65 72 2c 20 7a memcpy(zLower, z
0870: 54 61 72 67 65 74 2c 20 6e 2b 31 29 3b 0a 20 20 Target, n+1);.
0880: 63 61 6e 6f 6e 69 63 61 6c 31 36 28 7a 4c 6f 77 canonical16(zLow
0890: 65 72 2c 20 6e 2b 31 29 3b 0a 20 20 6d 65 6d 63 er, n+1);. memc
08a0: 70 79 28 7a 55 70 70 65 72 2c 20 7a 4c 6f 77 65 py(zUpper, zLowe
08b0: 72 2c 20 6e 2b 31 29 3b 0a 20 20 7a 55 70 70 65 r, n+1);. zUppe
08c0: 72 5b 6e 2d 31 5d 2b 2b 3b 0a 20 20 69 66 28 20 r[n-1]++;. if(
08d0: 6f 6e 63 65 20 29 7b 0a 20 20 20 20 63 6f 6e 73 once ){. cons
08e0: 74 20 63 68 61 72 20 2a 7a 43 6c 6f 73 65 64 45 t char *zClosedE
08f0: 78 70 72 20 3d 20 64 62 5f 67 65 74 28 22 74 69 xpr = db_get("ti
0900: 63 6b 65 74 2d 63 6c 6f 73 65 64 2d 65 78 70 72 cket-closed-expr
0910: 22 2c 20 22 73 74 61 74 75 73 3d 27 43 6c 6f 73 ", "status='Clos
0920: 65 64 27 22 29 3b 0a 20 20 20 20 64 62 5f 73 74 ed'");. db_st
0930: 61 74 69 63 5f 70 72 65 70 61 72 65 28 26 71 2c atic_prepare(&q,
0940: 20 0a 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 . "SELECT
0950: 25 73 20 46 52 4f 4d 20 74 69 63 6b 65 74 20 22 %s FROM ticket "
0960: 0a 20 20 20 20 20 20 22 20 57 48 45 52 45 20 74 . " WHERE t
0970: 6b 74 5f 75 75 69 64 3e 3d 3a 6c 77 72 20 41 4e kt_uuid>=:lwr AN
0980: 44 20 74 6b 74 5f 75 75 69 64 3c 3a 75 70 72 22 D tkt_uuid<:upr"
0990: 2c 0a 20 20 20 20 20 20 7a 43 6c 6f 73 65 64 45 ,. zClosedE
09a0: 78 70 72 0a 20 20 20 20 29 3b 0a 20 20 20 20 6f xpr. );. o
09b0: 6e 63 65 20 3d 20 30 3b 0a 20 20 7d 0a 20 20 64 nce = 0;. }. d
09c0: 62 5f 62 69 6e 64 5f 74 65 78 74 28 26 71 2c 20 b_bind_text(&q,
09d0: 22 3a 6c 77 72 22 2c 20 7a 4c 6f 77 65 72 29 3b ":lwr", zLower);
09e0: 0a 20 20 64 62 5f 62 69 6e 64 5f 74 65 78 74 28 . db_bind_text(
09f0: 26 71 2c 20 22 3a 75 70 72 22 2c 20 7a 55 70 70 &q, ":upr", zUpp
0a00: 65 72 29 3b 0a 20 20 69 66 28 20 64 62 5f 73 74 er);. if( db_st
0a10: 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 ep(&q)==SQLITE_R
0a20: 4f 57 20 29 7b 0a 20 20 20 20 72 63 20 3d 20 31 OW ){. rc = 1
0a30: 3b 0a 20 20 20 20 2a 70 43 6c 6f 73 65 64 20 3d ;. *pClosed =
0a40: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 db_column_int(&
0a50: 71 2c 20 30 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a q, 0);. }else{.
0a60: 20 20 20 20 72 63 20 3d 20 30 3b 0a 20 20 7d 0a rc = 0;. }.
0a70: 20 20 64 62 5f 72 65 73 65 74 28 26 71 29 3b 0a db_reset(&q);.
0a80: 20 20 72 65 74 75 72 6e 20 72 63 3b 0a 7d 0a 0a return rc;.}..
0a90: 2f 2a 0a 2a 2a 20 43 68 65 63 6b 20 74 6f 20 73 /*.** Check to s
0aa0: 65 65 20 69 66 20 74 68 65 20 72 65 71 75 65 73 ee if the reques
0ab0: 74 65 64 20 63 6f 20 69 73 20 69 6e 20 66 61 63 ted co is in fac
0ac0: 74 20 22 63 68 65 63 6b 6f 75 74 2d 61 62 6c 65 t "checkout-able
0ad0: 22 0a 2a 2a 20 52 65 74 75 72 6e 20 76 61 6c 75 ".** Return valu
0ae0: 65 73 3a 0a 2a 2a 20 20 20 30 3a 20 4e 6f 74 20 es:.** 0: Not
0af0: 63 68 65 63 6b 6f 75 74 2d 61 62 6c 65 20 28 64 checkout-able (d
0b00: 6f 65 73 20 6e 6f 74 20 65 78 69 73 74 2c 20 6f oes not exist, o
0b10: 72 20 69 73 20 6e 6f 74 20 61 6e 20 6f 6e 2d 64 r is not an on-d
0b20: 69 73 6b 20 61 72 74 69 66 61 63 74 29 0a 2a 2a isk artifact).**
0b30: 20 20 20 31 3a 20 49 73 20 63 68 65 63 6b 6f 75 1: Is checkou
0b40: 74 2d 61 62 6c 65 2e 0a 2a 2f 0a 69 6e 74 20 63 t-able..*/.int c
0b50: 68 65 63 6b 6f 75 74 61 62 6c 65 28 63 6f 6e 73 heckoutable(cons
0b60: 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 29 7b 0a t char *zName){.
0b70: 20 20 69 6e 74 20 72 63 3b 20 2f 2a 20 72 65 74 int rc; /* ret
0b80: 75 72 6e 20 63 6f 64 65 20 2a 2f 0a 20 20 69 6e urn code */. in
0b90: 74 20 74 68 72 6f 77 61 77 61 79 3b 0a 0a 20 20 t throwaway;..
0ba0: 72 63 20 3d 20 21 69 73 5f 74 69 63 6b 65 74 28 rc = !is_ticket(
0bb0: 7a 4e 61 6d 65 2c 20 26 74 68 72 6f 77 61 77 61 zName, &throwawa
0bc0: 79 29 3b 0a 20 20 66 70 72 69 6e 74 66 28 73 74 y);. fprintf(st
0bd0: 64 65 72 72 2c 22 72 63 20 69 73 3a 20 25 64 5c derr,"rc is: %d\
0be0: 6e 22 2c 20 72 63 29 3b 0a 20 20 72 65 74 75 72 n", rc);. retur
0bf0: 6e 28 72 63 29 3b 0a 0a 20 20 42 6c 6f 62 20 75 n(rc);.. Blob u
0c00: 75 69 64 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 uid;. const cha
0c10: 72 20 2a 72 69 64 3d 28 63 68 61 72 20 2a 29 4e r *rid=(char *)N
0c20: 55 4c 4c 3b 0a 20 20 53 74 6d 74 20 71 3b 20 2f ULL;. Stmt q; /
0c30: 2f 20 64 62 20 71 75 65 72 79 0a 20 20 63 68 61 / db query. cha
0c40: 72 20 2a 7a 53 51 4c 3b 20 2f 2f 62 75 69 6c 64 r *zSQL; //build
0c50: 2d 75 70 20 73 71 6c 0a 0a 20 20 2f 2f 20 20 7a -up sql.. // z
0c60: 53 51 4c 20 3d 20 6d 70 72 69 6e 74 66 28 29 3b SQL = mprintf();
0c70: 0a 0a 20 20 2f 2f 20 5b 63 72 65 61 74 65 20 73 .. // [create s
0c80: 71 6c 20 73 74 61 74 65 6d 65 6e 74 5d 0a 20 20 ql statement].
0c90: 2f 2f 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 // db_prepare(&q
0ca0: 2c 73 71 6c 73 74 6d 74 29 3b 0a 0a 20 20 62 6c ,sqlstmt);.. bl
0cb0: 6f 62 5f 69 6e 69 74 28 26 75 75 69 64 2c 20 7a ob_init(&uuid, z
0cc0: 4e 61 6d 65 2c 20 2d 31 29 3b 0a 20 20 69 66 28 Name, -1);. if(
0cd0: 20 6e 61 6d 65 5f 74 6f 5f 75 75 69 64 28 26 75 name_to_uuid(&u
0ce0: 75 69 64 2c 20 31 29 20 29 7b 0a 20 20 20 20 66 uid, 1) ){. f
0cf0: 6f 73 73 69 6c 5f 70 61 6e 69 63 28 67 2e 7a 45 ossil_panic(g.zE
0d00: 72 72 4d 73 67 29 3b 0a 20 20 7d 0a 0a 20 20 2f rrMsg);. }.. /
0d10: 2a 20 20 6e 50 61 72 65 6e 74 3d 64 62 5f 74 65 * nParent=db_te
0d20: 78 74 28 30 2c 22 73 65 6c 65 63 74 20 72 69 64 xt(0,"select rid
0d30: 20 66 72 6f 6d 20 62 6c 6f 62 20 77 68 65 72 65 from blob where
0d40: 20 75 75 69 64 3d 25 73 22 2c 75 75 69 64 2e 6e uuid=%s",uuid.n
0d50: 61 6d 65 6f 66 6f 62 6a 29 3b 20 2a 2f 0a 0a 20 ameofobj); */..
0d60: 20 2f 2a 20 20 69 6e 74 20 6e 50 61 72 65 6e 74 /* int nParent
0d70: 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 = db_column_int
0d80: 28 71 2c 20 73 6f 6d 65 6e 75 6d 29 3b 20 2a 2f (q, somenum); */
0d90: 0a 20 20 72 65 74 75 72 6e 20 72 63 3b 0a 7d 0a . return rc;.}.
0da0: 0a 0a 2f 2a 0a 2a 2a 20 55 6e 64 6f 20 74 68 65 ../*.** Undo the
0db0: 20 63 75 72 72 65 6e 74 20 63 68 65 63 6b 2d 6f current check-o
0dc0: 75 74 2e 20 20 55 6e 6c 69 6e 6b 20 61 6c 6c 20 ut. Unlink all
0dd0: 66 69 6c 65 73 20 66 72 6f 6d 20 74 68 65 20 64 files from the d
0de0: 69 73 6b 2e 0a 2a 2a 20 43 6c 65 61 72 20 74 68 isk..** Clear th
0df0: 65 20 56 46 49 4c 45 20 74 61 62 6c 65 2e 0a 2a e VFILE table..*
0e00: 2f 0a 76 6f 69 64 20 75 6e 63 68 65 63 6b 6f 75 /.void uncheckou
0e10: 74 28 69 6e 74 20 76 69 64 29 7b 0a 20 20 69 66 t(int vid){. if
0e20: 28 20 76 69 64 3d 3d 30 20 29 20 72 65 74 75 72 ( vid==0 ) retur
0e30: 6e 3b 0a 20 20 76 66 69 6c 65 5f 75 6e 6c 69 6e n;. vfile_unlin
0e40: 6b 28 76 69 64 29 3b 0a 20 20 64 62 5f 6d 75 6c k(vid);. db_mul
0e50: 74 69 5f 65 78 65 63 28 22 44 45 4c 45 54 45 20 ti_exec("DELETE
0e60: 46 52 4f 4d 20 76 66 69 6c 65 20 57 48 45 52 45 FROM vfile WHERE
0e70: 20 76 69 64 3d 25 64 22 2c 20 76 69 64 29 3b 0a vid=%d", vid);.
0e80: 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 47 69 76 65 6e 20 }.../*.** Given
0e90: 74 68 65 20 61 62 62 72 65 76 69 61 74 65 64 20 the abbreviated
0ea0: 55 55 49 44 20 6e 61 6d 65 20 6f 66 20 61 20 76 UUID name of a v
0eb0: 65 72 73 69 6f 6e 2c 20 6c 6f 61 64 20 74 68 65 ersion, load the
0ec0: 20 63 6f 6e 74 65 6e 74 20 6f 66 20 74 68 61 74 content of that
0ed0: 0a 2a 2a 20 76 65 72 73 69 6f 6e 20 69 6e 20 74 .** version in t
0ee0: 68 65 20 56 46 49 4c 45 20 74 61 62 6c 65 2e 20 he VFILE table.
0ef0: 20 52 65 74 75 72 6e 20 74 68 65 20 56 49 44 20 Return the VID
0f00: 66 6f 72 20 74 68 65 20 76 65 72 73 69 6f 6e 2e for the version.
0f10: 0a 2a 2a 0a 2a 2a 20 49 66 20 61 6e 79 74 68 69 .**.** If anythi
0f20: 6e 67 20 67 6f 65 73 20 77 72 6f 6e 67 2c 20 70 ng goes wrong, p
0f30: 61 6e 69 63 2e 0a 2a 2f 0a 69 6e 74 20 6c 6f 61 anic..*/.int loa
0f40: 64 5f 76 66 69 6c 65 28 63 6f 6e 73 74 20 63 68 d_vfile(const ch
0f50: 61 72 20 2a 7a 4e 61 6d 65 29 7b 0a 20 20 42 6c ar *zName){. Bl
0f60: 6f 62 20 75 75 69 64 3b 0a 20 20 69 6e 74 20 76 ob uuid;. int v
0f70: 69 64 3b 0a 0a 20 20 62 6c 6f 62 5f 69 6e 69 74 id;.. blob_init
0f80: 28 26 75 75 69 64 2c 20 7a 4e 61 6d 65 2c 20 2d (&uuid, zName, -
0f90: 31 29 3b 0a 20 20 69 66 28 20 6e 61 6d 65 5f 74 1);. if( name_t
0fa0: 6f 5f 75 75 69 64 28 26 75 75 69 64 2c 20 31 29 o_uuid(&uuid, 1)
0fb0: 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 ){. fossil_p
0fc0: 61 6e 69 63 28 67 2e 7a 45 72 72 4d 73 67 29 3b anic(g.zErrMsg);
0fd0: 0a 20 20 7d 0a 20 20 76 69 64 20 3d 20 64 62 5f . }. vid = db_
0fe0: 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 20 72 int(0, "SELECT r
0ff0: 69 64 20 46 52 4f 4d 20 62 6c 6f 62 20 57 48 45 id FROM blob WHE
1000: 52 45 20 75 75 69 64 3d 25 42 22 2c 20 26 75 75 RE uuid=%B", &uu
1010: 69 64 29 3b 0a 20 20 69 66 28 20 76 69 64 3d 3d id);. if( vid==
1020: 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 0 ){. fossil_
1030: 70 61 6e 69 63 28 22 6e 6f 20 73 75 63 68 20 76 panic("no such v
1040: 65 72 73 69 6f 6e 3a 20 25 73 22 2c 20 67 2e 61 ersion: %s", g.a
1050: 72 67 76 5b 32 5d 29 3b 0a 20 20 7d 0a 20 20 6c rgv[2]);. }. l
1060: 6f 61 64 5f 76 66 69 6c 65 5f 66 72 6f 6d 5f 72 oad_vfile_from_r
1070: 69 64 28 76 69 64 29 3b 0a 20 20 72 65 74 75 72 id(vid);. retur
1080: 6e 20 76 69 64 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 n vid;.}../*.**
1090: 4c 6f 61 64 20 61 20 76 66 69 6c 65 20 66 72 6f Load a vfile fro
10a0: 6d 20 61 20 72 65 63 6f 72 64 20 49 44 2e 0a 2a m a record ID..*
10b0: 2f 0a 76 6f 69 64 20 6c 6f 61 64 5f 76 66 69 6c /.void load_vfil
10c0: 65 5f 66 72 6f 6d 5f 72 69 64 28 69 6e 74 20 76 e_from_rid(int v
10d0: 69 64 29 7b 0a 20 20 42 6c 6f 62 20 6d 61 6e 69 id){. Blob mani
10e0: 66 65 73 74 3b 0a 0a 20 20 69 66 28 20 64 62 5f fest;.. if( db_
10f0: 65 78 69 73 74 73 28 22 53 45 4c 45 43 54 20 31 exists("SELECT 1
1100: 20 46 52 4f 4d 20 76 66 69 6c 65 20 57 48 45 52 FROM vfile WHER
1110: 45 20 76 69 64 3d 25 64 22 2c 20 76 69 64 29 20 E vid=%d", vid)
1120: 29 7b 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 ){. return;.
1130: 20 7d 0a 20 20 63 6f 6e 74 65 6e 74 5f 67 65 74 }. content_get
1140: 28 76 69 64 2c 20 26 6d 61 6e 69 66 65 73 74 29 (vid, &manifest)
1150: 3b 0a 20 20 76 66 69 6c 65 5f 62 75 69 6c 64 28 ;. vfile_build(
1160: 76 69 64 2c 20 26 6d 61 6e 69 66 65 73 74 29 3b vid, &manifest);
1170: 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 6d . blob_reset(&m
1180: 61 6e 69 66 65 73 74 29 3b 0a 7d 0a 0a 2f 2a 0a anifest);.}../*.
1190: 2a 2a 20 52 65 61 64 20 74 68 65 20 6d 61 6e 69 ** Read the mani
11a0: 66 65 73 74 20 66 69 6c 65 20 67 69 76 65 6e 20 fest file given
11b0: 62 79 20 76 69 64 20 6f 75 74 20 6f 66 20 74 68 by vid out of th
11c0: 65 20 72 65 70 6f 73 69 74 6f 72 79 0a 2a 2a 20 e repository.**
11d0: 61 6e 64 20 73 74 6f 72 65 20 69 74 20 69 6e 20 and store it in
11e0: 74 68 65 20 72 6f 6f 74 20 6f 66 20 74 68 65 20 the root of the
11f0: 6c 6f 63 61 6c 20 63 68 65 63 6b 2d 6f 75 74 2e local check-out.
1200: 0a 2a 2f 0a 76 6f 69 64 20 6d 61 6e 69 66 65 73 .*/.void manifes
1210: 74 5f 74 6f 5f 64 69 73 6b 28 69 6e 74 20 76 69 t_to_disk(int vi
1220: 64 29 7b 0a 20 20 63 68 61 72 20 2a 7a 4d 61 6e d){. char *zMan
1230: 46 69 6c 65 3b 0a 20 20 42 6c 6f 62 20 6d 61 6e File;. Blob man
1240: 69 66 65 73 74 3b 0a 20 20 42 6c 6f 62 20 68 61 ifest;. Blob ha
1250: 73 68 3b 0a 20 20 42 6c 6f 62 20 66 69 6c 65 6e sh;. Blob filen
1260: 61 6d 65 3b 0a 20 20 69 6e 74 20 62 61 73 65 4c ame;. int baseL
1270: 65 6e 3b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 4d en;. int i;. M
1280: 61 6e 69 66 65 73 74 20 6d 3b 0a 0a 20 20 62 6c anifest m;.. bl
1290: 6f 62 5f 7a 65 72 6f 28 26 6d 61 6e 69 66 65 73 ob_zero(&manifes
12a0: 74 29 3b 0a 20 20 7a 4d 61 6e 46 69 6c 65 20 3d t);. zManFile =
12b0: 20 6d 70 72 69 6e 74 66 28 22 25 73 6d 61 6e 69 mprintf("%smani
12c0: 66 65 73 74 22 2c 20 67 2e 7a 4c 6f 63 61 6c 52 fest", g.zLocalR
12d0: 6f 6f 74 29 3b 0a 20 20 63 6f 6e 74 65 6e 74 5f oot);. content_
12e0: 67 65 74 28 76 69 64 2c 20 26 6d 61 6e 69 66 65 get(vid, &manife
12f0: 73 74 29 3b 0a 20 20 62 6c 6f 62 5f 77 72 69 74 st);. blob_writ
1300: 65 5f 74 6f 5f 66 69 6c 65 28 26 6d 61 6e 69 66 e_to_file(&manif
1310: 65 73 74 2c 20 7a 4d 61 6e 46 69 6c 65 29 3b 0a est, zManFile);.
1320: 20 20 66 72 65 65 28 7a 4d 61 6e 46 69 6c 65 29 free(zManFile)
1330: 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 68 ;. blob_zero(&h
1340: 61 73 68 29 3b 0a 20 20 73 68 61 31 73 75 6d 5f ash);. sha1sum_
1350: 62 6c 6f 62 28 26 6d 61 6e 69 66 65 73 74 2c 20 blob(&manifest,
1360: 26 68 61 73 68 29 3b 0a 20 20 7a 4d 61 6e 46 69 &hash);. zManFi
1370: 6c 65 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 le = mprintf("%s
1380: 6d 61 6e 69 66 65 73 74 2e 75 75 69 64 22 2c 20 manifest.uuid",
1390: 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 29 3b 0a 20 g.zLocalRoot);.
13a0: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 26 68 61 blob_append(&ha
13b0: 73 68 2c 20 22 5c 6e 22 2c 20 31 29 3b 0a 20 20 sh, "\n", 1);.
13c0: 62 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f 66 69 blob_write_to_fi
13d0: 6c 65 28 26 68 61 73 68 2c 20 7a 4d 61 6e 46 69 le(&hash, zManFi
13e0: 6c 65 29 3b 0a 20 20 66 72 65 65 28 7a 4d 61 6e le);. free(zMan
13f0: 46 69 6c 65 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 File);. blob_re
1400: 73 65 74 28 26 68 61 73 68 29 3b 0a 20 20 6d 61 set(&hash);. ma
1410: 6e 69 66 65 73 74 5f 70 61 72 73 65 28 26 6d 2c nifest_parse(&m,
1420: 20 26 6d 61 6e 69 66 65 73 74 29 3b 0a 20 20 62 &manifest);. b
1430: 6c 6f 62 5f 7a 65 72 6f 28 26 66 69 6c 65 6e 61 lob_zero(&filena
1440: 6d 65 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 me);. blob_appe
1450: 6e 64 66 28 26 66 69 6c 65 6e 61 6d 65 2c 20 22 ndf(&filename, "
1460: 25 73 2f 22 2c 20 67 2e 7a 4c 6f 63 61 6c 52 6f %s/", g.zLocalRo
1470: 6f 74 29 3b 0a 20 20 62 61 73 65 4c 65 6e 20 3d ot);. baseLen =
1480: 20 62 6c 6f 62 5f 73 69 7a 65 28 26 66 69 6c 65 blob_size(&file
1490: 6e 61 6d 65 29 3b 0a 20 20 66 6f 72 28 69 3d 30 name);. for(i=0
14a0: 3b 20 69 3c 6d 2e 6e 46 69 6c 65 3b 20 69 2b 2b ; i<m.nFile; i++
14b0: 29 7b 20 0a 20 20 20 20 69 6e 74 20 69 73 45 78 ){ . int isEx
14c0: 65 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 e;. blob_appe
14d0: 6e 64 28 26 66 69 6c 65 6e 61 6d 65 2c 20 6d 2e nd(&filename, m.
14e0: 61 46 69 6c 65 5b 69 5d 2e 7a 4e 61 6d 65 2c 20 aFile[i].zName,
14f0: 2d 31 29 3b 0a 20 20 20 20 69 73 45 78 65 20 3d -1);. isExe =
1500: 20 6d 2e 61 46 69 6c 65 5b 69 5d 2e 7a 50 65 72 m.aFile[i].zPer
1510: 6d 20 26 26 20 73 74 72 73 74 72 28 6d 2e 61 46 m && strstr(m.aF
1520: 69 6c 65 5b 69 5d 2e 7a 50 65 72 6d 2c 20 22 78 ile[i].zPerm, "x
1530: 22 29 3b 0a 20 20 20 20 66 69 6c 65 5f 73 65 74 ");. file_set
1540: 65 78 65 28 62 6c 6f 62 5f 73 74 72 28 26 66 69 exe(blob_str(&fi
1550: 6c 65 6e 61 6d 65 29 2c 20 69 73 45 78 65 29 3b lename), isExe);
1560: 0a 20 20 20 20 62 6c 6f 62 5f 72 65 73 69 7a 65 . blob_resize
1570: 28 26 66 69 6c 65 6e 61 6d 65 2c 20 62 61 73 65 (&filename, base
1580: 4c 65 6e 29 3b 0a 20 20 7d 0a 20 20 62 6c 6f 62 Len);. }. blob
1590: 5f 72 65 73 65 74 28 26 66 69 6c 65 6e 61 6d 65 _reset(&filename
15a0: 29 3b 0a 20 20 6d 61 6e 69 66 65 73 74 5f 63 6c );. manifest_cl
15b0: 65 61 72 28 26 6d 29 3b 0a 7d 0a 0a 2f 2a 0a 2a ear(&m);.}../*.*
15c0: 2a 20 43 4f 4d 4d 41 4e 44 3a 20 63 68 65 63 6b * COMMAND: check
15d0: 6f 75 74 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 out.** COMMAND:
15e0: 63 6f 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 co.**.** Usage:
15f0: 25 66 6f 73 73 69 6c 20 63 68 65 63 6b 6f 75 74 %fossil checkout
1600: 20 56 45 52 53 49 4f 4e 20 3f 2d 66 7c 2d 2d 66 VERSION ?-f|--f
1610: 6f 72 63 65 3f 0a 2a 2a 0a 2a 2a 20 43 68 65 63 orce?.**.** Chec
1620: 6b 20 6f 75 74 20 61 20 76 65 72 73 69 6f 6e 20 k out a version
1630: 73 70 65 63 69 66 69 65 64 20 6f 6e 20 74 68 65 specified on the
1640: 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 2e 20 20 command-line.
1650: 54 68 69 73 20 63 6f 6d 6d 61 6e 64 0a 2a 2a 20 This command.**
1660: 77 69 6c 6c 20 6e 6f 74 20 6f 76 65 72 77 72 69 will not overwri
1670: 74 65 20 65 64 69 74 65 64 20 66 69 6c 65 73 20 te edited files
1680: 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20 63 in the current c
1690: 68 65 63 6b 6f 75 74 20 75 6e 6c 65 73 73 0a 2a heckout unless.*
16a0: 2a 20 74 68 65 20 2d 2d 66 6f 72 63 65 20 6f 70 * the --force op
16b0: 74 69 6f 6e 20 61 70 70 65 61 72 73 20 6f 6e 20 tion appears on
16c0: 74 68 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 the command-line
16d0: 2e 0a 2a 2a 0a 2a 2a 20 53 65 65 20 61 6c 73 6f ..**.** See also
16e0: 20 74 68 65 20 22 75 70 64 61 74 65 22 20 63 6f the "update" co
16f0: 6d 6d 61 6e 64 2e 0a 2a 2f 0a 76 6f 69 64 20 63 mmand..*/.void c
1700: 68 65 63 6b 6f 75 74 5f 63 6d 64 28 76 6f 69 64 heckout_cmd(void
1710: 29 7b 0a 20 20 69 6e 74 20 66 6f 72 63 65 46 6c ){. int forceFl
1720: 61 67 3b 0a 20 20 69 6e 74 20 6e 6f 57 72 69 74 ag;. int noWrit
1730: 65 3b 0a 20 20 69 6e 74 20 76 69 64 2c 20 70 72 e;. int vid, pr
1740: 69 6f 72 3b 0a 20 20 42 6c 6f 62 20 63 6b 73 75 ior;. Blob cksu
1750: 6d 31 2c 20 63 6b 73 75 6d 31 62 2c 20 63 6b 73 m1, cksum1b, cks
1760: 75 6d 32 3b 0a 20 20 0a 20 20 64 62 5f 6d 75 73 um2;. . db_mus
1770: 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72 65 65 t_be_within_tree
1780: 28 29 3b 0a 20 20 64 62 5f 62 65 67 69 6e 5f 74 ();. db_begin_t
1790: 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a 20 20 ransaction();.
17a0: 66 6f 72 63 65 46 6c 61 67 20 3d 20 66 69 6e 64 forceFlag = find
17b0: 5f 6f 70 74 69 6f 6e 28 22 66 6f 72 63 65 22 2c _option("force",
17c0: 22 66 22 2c 30 29 21 3d 30 3b 0a 20 20 6e 6f 57 "f",0)!=0;. noW
17d0: 72 69 74 65 20 3d 20 66 69 6e 64 5f 6f 70 74 69 rite = find_opti
17e0: 6f 6e 28 22 64 6f 6e 74 77 72 69 74 65 22 2c 30 on("dontwrite",0
17f0: 2c 30 29 21 3d 30 3b 0a 20 20 69 66 28 20 67 2e ,0)!=0;. if( g.
1800: 61 72 67 63 21 3d 33 20 29 20 75 73 61 67 65 28 argc!=3 ) usage(
1810: 22 3f 2d 2d 66 6f 72 63 65 3f 20 56 45 52 53 49 "?--force? VERSI
1820: 4f 4e 22 29 3b 0a 20 20 69 66 28 20 21 66 6f 72 ON");. if( !for
1830: 63 65 46 6c 61 67 20 26 26 20 75 6e 73 61 76 65 ceFlag && unsave
1840: 64 5f 63 68 61 6e 67 65 73 28 29 3d 3d 31 20 29 d_changes()==1 )
1850: 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 {. fossil_fat
1860: 61 6c 28 22 74 68 65 72 65 20 61 72 65 20 75 6e al("there are un
1870: 73 61 76 65 64 20 63 68 61 6e 67 65 73 20 69 6e saved changes in
1880: 20 74 68 65 20 63 75 72 72 65 6e 74 20 63 68 65 the current che
1890: 63 6b 6f 75 74 22 29 3b 0a 20 20 7d 0a 20 20 69 ckout");. }. i
18a0: 66 28 21 63 68 65 63 6b 6f 75 74 61 62 6c 65 28 f(!checkoutable(
18b0: 67 2e 61 72 67 76 5b 32 5d 29 29 7b 0a 20 20 20 g.argv[2])){.
18c0: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 74 fossil_fatal("t
18d0: 68 65 20 56 45 52 53 49 4f 4e 20 79 6f 75 20 72 he VERSION you r
18e0: 65 71 75 65 73 74 65 64 20 69 73 20 6e 6f 74 20 equested is not
18f0: 61 20 63 68 65 63 6b 6f 75 74 2d 61 62 6c 65 20 a checkout-able
1900: 61 72 74 69 66 61 63 74 22 29 3b 0a 20 20 7d 0a artifact");. }.
1910: 20 20 69 66 28 20 66 6f 72 63 65 46 6c 61 67 20 if( forceFlag
1920: 29 7b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f ){. db_multi_
1930: 65 78 65 63 28 22 44 45 4c 45 54 45 20 46 52 4f exec("DELETE FRO
1940: 4d 20 76 66 69 6c 65 22 29 3b 0a 20 20 20 20 70 M vfile");. p
1950: 72 69 6f 72 20 3d 20 30 3b 0a 20 20 7d 65 6c 73 rior = 0;. }els
1960: 65 7b 0a 20 20 20 20 70 72 69 6f 72 20 3d 20 64 e{. prior = d
1970: 62 5f 6c 67 65 74 5f 69 6e 74 28 22 63 68 65 63 b_lget_int("chec
1980: 6b 6f 75 74 22 2c 30 29 3b 0a 20 20 7d 0a 20 20 kout",0);. }.
1990: 76 69 64 20 3d 20 6c 6f 61 64 5f 76 66 69 6c 65 vid = load_vfile
19a0: 28 67 2e 61 72 67 76 5b 32 5d 29 3b 0a 20 20 69 (g.argv[2]);. i
19b0: 66 28 20 70 72 69 6f 72 3d 3d 76 69 64 20 29 7b f( prior==vid ){
19c0: 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 7d . return;. }
19d0: 0a 20 20 69 66 28 20 21 6e 6f 57 72 69 74 65 20 . if( !noWrite
19e0: 29 7b 0a 20 20 20 20 75 6e 63 68 65 63 6b 6f 75 ){. uncheckou
19f0: 74 28 70 72 69 6f 72 29 3b 0a 20 20 7d 0a 20 20 t(prior);. }.
1a00: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 44 db_multi_exec("D
1a10: 45 4c 45 54 45 20 46 52 4f 4d 20 76 66 69 6c 65 ELETE FROM vfile
1a20: 20 57 48 45 52 45 20 76 69 64 21 3d 25 64 22 2c WHERE vid!=%d",
1a30: 20 76 69 64 29 3b 0a 20 20 69 66 28 20 21 6e 6f vid);. if( !no
1a40: 57 72 69 74 65 20 29 7b 0a 20 20 20 20 76 66 69 Write ){. vfi
1a50: 6c 65 5f 74 6f 5f 64 69 73 6b 28 76 69 64 2c 20 le_to_disk(vid,
1a60: 30 2c 20 31 29 3b 0a 20 20 20 20 6d 61 6e 69 66 0, 1);. manif
1a70: 65 73 74 5f 74 6f 5f 64 69 73 6b 28 76 69 64 29 est_to_disk(vid)
1a80: 3b 0a 20 20 20 20 64 62 5f 6c 73 65 74 5f 69 6e ;. db_lset_in
1a90: 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 20 76 69 t("checkout", vi
1aa0: 64 29 3b 0a 20 20 20 20 75 6e 64 6f 5f 72 65 73 d);. undo_res
1ab0: 65 74 28 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 6d et();. }. db_m
1ac0: 75 6c 74 69 5f 65 78 65 63 28 22 44 45 4c 45 54 ulti_exec("DELET
1ad0: 45 20 46 52 4f 4d 20 76 6d 65 72 67 65 22 29 3b E FROM vmerge");
1ae0: 0a 20 20 76 66 69 6c 65 5f 61 67 67 72 65 67 61 . vfile_aggrega
1af0: 74 65 5f 63 68 65 63 6b 73 75 6d 5f 6d 61 6e 69 te_checksum_mani
1b00: 66 65 73 74 28 76 69 64 2c 20 26 63 6b 73 75 6d fest(vid, &cksum
1b10: 31 2c 20 26 63 6b 73 75 6d 31 62 29 3b 0a 20 20 1, &cksum1b);.
1b20: 76 66 69 6c 65 5f 61 67 67 72 65 67 61 74 65 5f vfile_aggregate_
1b30: 63 68 65 63 6b 73 75 6d 5f 64 69 73 6b 28 76 69 checksum_disk(vi
1b40: 64 2c 20 26 63 6b 73 75 6d 32 29 3b 0a 20 20 69 d, &cksum2);. i
1b50: 66 28 20 62 6c 6f 62 5f 63 6f 6d 70 61 72 65 28 f( blob_compare(
1b60: 26 63 6b 73 75 6d 31 2c 20 26 63 6b 73 75 6d 32 &cksum1, &cksum2
1b70: 29 20 29 7b 0a 20 20 20 20 70 72 69 6e 74 66 28 ) ){. printf(
1b80: 22 57 41 52 4e 49 4e 47 3a 20 6d 61 6e 69 66 65 "WARNING: manife
1b90: 73 74 20 63 68 65 63 6b 73 75 6d 20 64 6f 65 73 st checksum does
1ba0: 20 6e 6f 74 20 61 67 72 65 65 20 77 69 74 68 20 not agree with
1bb0: 64 69 73 6b 5c 6e 22 29 3b 0a 20 20 7d 0a 20 20 disk\n");. }.
1bc0: 69 66 28 20 62 6c 6f 62 5f 63 6f 6d 70 61 72 65 if( blob_compare
1bd0: 28 26 63 6b 73 75 6d 31 2c 20 26 63 6b 73 75 6d (&cksum1, &cksum
1be0: 31 62 29 20 29 7b 0a 20 20 20 20 70 72 69 6e 74 1b) ){. print
1bf0: 66 28 22 57 41 52 4e 49 4e 47 3a 20 6d 61 6e 69 f("WARNING: mani
1c00: 66 65 73 74 20 63 68 65 63 6b 73 75 6d 20 64 6f fest checksum do
1c10: 65 73 20 6e 6f 74 20 61 67 72 65 65 20 77 69 74 es not agree wit
1c20: 68 20 6d 61 6e 69 66 65 73 74 5c 6e 22 29 3b 0a h manifest\n");.
1c30: 20 20 7d 0a 20 20 64 62 5f 65 6e 64 5f 74 72 61 }. db_end_tra
1c40: 6e 73 61 63 74 69 6f 6e 28 30 29 3b 0a 7d 0a 0a nsaction(0);.}..
1c50: 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 63 /*.** COMMAND: c
1c60: 6c 6f 73 65 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 lose.**.** Usage
1c70: 3a 20 25 66 6f 73 73 69 6c 20 63 6c 6f 73 65 20 : %fossil close
1c80: 3f 2d 66 7c 2d 2d 66 6f 72 63 65 3f 0a 2a 2a 0a ?-f|--force?.**.
1c90: 2a 2a 20 54 68 65 20 6f 70 70 6f 73 69 74 65 20 ** The opposite
1ca0: 6f 66 20 22 6f 70 65 6e 22 2e 20 20 43 6c 6f 73 of "open". Clos
1cb0: 65 20 74 68 65 20 63 75 72 72 65 6e 74 20 64 61 e the current da
1cc0: 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f tabase connectio
1cd0: 6e 2e 0a 2a 2a 20 52 65 71 75 69 72 65 20 61 20 n..** Require a
1ce0: 2d 66 20 6f 72 20 2d 2d 66 6f 72 63 65 20 66 6c -f or --force fl
1cf0: 61 67 20 69 66 20 74 68 65 72 65 20 61 72 65 20 ag if there are
1d00: 75 6e 73 61 76 65 64 20 63 68 61 6e 67 65 64 20 unsaved changed
1d10: 69 6e 20 74 68 65 0a 2a 2a 20 63 75 72 72 65 6e in the.** curren
1d20: 74 20 63 68 65 63 6b 2d 6f 75 74 2e 0a 2a 2f 0a t check-out..*/.
1d30: 76 6f 69 64 20 63 6c 6f 73 65 5f 63 6d 64 28 76 void close_cmd(v
1d40: 6f 69 64 29 7b 0a 20 20 69 6e 74 20 66 6f 72 63 oid){. int forc
1d50: 65 46 6c 61 67 20 3d 20 66 69 6e 64 5f 6f 70 74 eFlag = find_opt
1d60: 69 6f 6e 28 22 66 6f 72 63 65 22 2c 22 66 22 2c ion("force","f",
1d70: 30 29 21 3d 30 3b 0a 20 20 64 62 5f 6d 75 73 74 0)!=0;. db_must
1d80: 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72 65 65 28 _be_within_tree(
1d90: 29 3b 0a 20 20 69 66 28 20 21 66 6f 72 63 65 46 );. if( !forceF
1da0: 6c 61 67 20 26 26 20 75 6e 73 61 76 65 64 5f 63 lag && unsaved_c
1db0: 68 61 6e 67 65 73 28 29 3d 3d 31 20 29 7b 0a 20 hanges()==1 ){.
1dc0: 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 fossil_fatal(
1dd0: 22 74 68 65 72 65 20 61 72 65 20 75 6e 73 61 76 "there are unsav
1de0: 65 64 20 63 68 61 6e 67 65 73 20 69 6e 20 74 68 ed changes in th
1df0: 65 20 63 75 72 72 65 6e 74 20 63 68 65 63 6b 6f e current checko
1e00: 75 74 22 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 63 ut");. }. db_c
1e10: 6c 6f 73 65 28 29 3b 0a 20 20 75 6e 6c 69 6e 6b lose();. unlink
1e20: 28 6d 70 72 69 6e 74 66 28 22 25 73 5f 46 4f 53 (mprintf("%s_FOS
1e30: 53 49 4c 5f 22 2c 20 67 2e 7a 4c 6f 63 61 6c 52 SIL_", g.zLocalR
1e40: 6f 6f 74 29 29 3b 0a 20 20 75 6e 6c 69 6e 6b 28 oot));. unlink(
1e50: 6d 70 72 69 6e 74 66 28 22 25 73 5f 46 4f 53 53 mprintf("%s_FOSS
1e60: 49 4c 5f 2d 6a 6f 75 72 6e 61 6c 22 2c 20 67 2e IL_-journal", g.
1e70: 7a 4c 6f 63 61 6c 52 6f 6f 74 29 29 3b 0a 7d 0a zLocalRoot));.}.