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 2f 2a 0a 2a 2a e,0)");.}../*.**
0630: 20 55 6e 64 6f 20 74 68 65 20 63 75 72 72 65 6e Undo the curren
0640: 74 20 63 68 65 63 6b 2d 6f 75 74 2e 20 20 55 6e t check-out. Un
0650: 6c 69 6e 6b 20 61 6c 6c 20 66 69 6c 65 73 20 66 link all files f
0660: 72 6f 6d 20 74 68 65 20 64 69 73 6b 2e 0a 2a 2a rom the disk..**
0670: 20 43 6c 65 61 72 20 74 68 65 20 56 46 49 4c 45 Clear the VFILE
0680: 20 74 61 62 6c 65 2e 0a 2a 2f 0a 76 6f 69 64 20 table..*/.void
0690: 75 6e 63 68 65 63 6b 6f 75 74 28 69 6e 74 20 76 uncheckout(int v
06a0: 69 64 29 7b 0a 20 20 69 66 28 20 76 69 64 3d 3d id){. if( vid==
06b0: 30 20 29 20 72 65 74 75 72 6e 3b 0a 20 20 76 66 0 ) return;. vf
06c0: 69 6c 65 5f 75 6e 6c 69 6e 6b 28 76 69 64 29 3b ile_unlink(vid);
06d0: 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 . db_multi_exec
06e0: 28 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 76 66 ("DELETE FROM vf
06f0: 69 6c 65 20 57 48 45 52 45 20 76 69 64 3d 25 64 ile WHERE vid=%d
0700: 22 2c 20 76 69 64 29 3b 0a 7d 0a 0a 0a 2f 2a 0a ", vid);.}.../*.
0710: 2a 2a 20 47 69 76 65 6e 20 74 68 65 20 61 62 62 ** Given the abb
0720: 72 65 76 69 61 74 65 64 20 55 55 49 44 20 6e 61 reviated UUID na
0730: 6d 65 20 6f 66 20 61 20 76 65 72 73 69 6f 6e 2c me of a version,
0740: 20 6c 6f 61 64 20 74 68 65 20 63 6f 6e 74 65 6e load the conten
0750: 74 20 6f 66 20 74 68 61 74 0a 2a 2a 20 76 65 72 t of that.** ver
0760: 73 69 6f 6e 20 69 6e 20 74 68 65 20 56 46 49 4c sion in the VFIL
0770: 45 20 74 61 62 6c 65 2e 20 20 52 65 74 75 72 6e E table. Return
0780: 20 74 68 65 20 56 49 44 20 66 6f 72 20 74 68 65 the VID for the
0790: 20 76 65 72 73 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 version..**.**
07a0: 49 66 20 61 6e 79 74 68 69 6e 67 20 67 6f 65 73 If anything goes
07b0: 20 77 72 6f 6e 67 2c 20 70 61 6e 69 63 2e 0a 2a wrong, panic..*
07c0: 2f 0a 69 6e 74 20 6c 6f 61 64 5f 76 66 69 6c 65 /.int load_vfile
07d0: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 (const char *zNa
07e0: 6d 65 29 7b 0a 20 20 42 6c 6f 62 20 75 75 69 64 me){. Blob uuid
07f0: 3b 0a 20 20 69 6e 74 20 76 69 64 3b 0a 0a 20 20 ;. int vid;..
0800: 62 6c 6f 62 5f 69 6e 69 74 28 26 75 75 69 64 2c blob_init(&uuid,
0810: 20 7a 4e 61 6d 65 2c 20 2d 31 29 3b 0a 20 20 69 zName, -1);. i
0820: 66 28 20 6e 61 6d 65 5f 74 6f 5f 75 75 69 64 28 f( name_to_uuid(
0830: 26 75 75 69 64 2c 20 31 29 20 29 7b 0a 20 20 20 &uuid, 1) ){.
0840: 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 67 2e fossil_panic(g.
0850: 7a 45 72 72 4d 73 67 29 3b 0a 20 20 7d 0a 20 20 zErrMsg);. }.
0860: 76 69 64 20 3d 20 64 62 5f 69 6e 74 28 30 2c 20 vid = db_int(0,
0870: 22 53 45 4c 45 43 54 20 72 69 64 20 46 52 4f 4d "SELECT rid FROM
0880: 20 62 6c 6f 62 20 57 48 45 52 45 20 75 75 69 64 blob WHERE uuid
0890: 3d 25 42 22 2c 20 26 75 75 69 64 29 3b 0a 20 20 =%B", &uuid);.
08a0: 69 66 28 20 76 69 64 3d 3d 30 20 29 7b 0a 20 20 if( vid==0 ){.
08b0: 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 fossil_fatal("
08c0: 6e 6f 20 73 75 63 68 20 63 68 65 63 6b 2d 69 6e no such check-in
08d0: 3a 20 25 73 22 2c 20 67 2e 61 72 67 76 5b 32 5d : %s", g.argv[2]
08e0: 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 21 64 62 );. }. if( !db
08f0: 5f 65 78 69 73 74 73 28 22 53 45 4c 45 43 54 20 _exists("SELECT
0900: 31 20 46 52 4f 4d 20 6d 6c 69 6e 6b 20 57 48 45 1 FROM mlink WHE
0910: 52 45 20 6d 69 64 3d 25 64 22 2c 20 76 69 64 29 RE mid=%d", vid)
0920: 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 ){. fossil_f
0930: 61 74 61 6c 28 22 6f 62 6a 65 63 74 20 5b 25 2e atal("object [%.
0940: 31 30 73 5d 20 69 73 20 6e 6f 74 20 61 20 63 68 10s] is not a ch
0950: 65 63 6b 2d 69 6e 22 2c 20 62 6c 6f 62 5f 73 74 eck-in", blob_st
0960: 72 28 26 75 75 69 64 29 29 3b 0a 20 20 7d 0a 20 r(&uuid));. }.
0970: 20 6c 6f 61 64 5f 76 66 69 6c 65 5f 66 72 6f 6d load_vfile_from
0980: 5f 72 69 64 28 76 69 64 29 3b 0a 20 20 72 65 74 _rid(vid);. ret
0990: 75 72 6e 20 76 69 64 3b 0a 7d 0a 0a 2f 2a 0a 2a urn vid;.}../*.*
09a0: 2a 20 4c 6f 61 64 20 61 20 76 66 69 6c 65 20 66 * Load a vfile f
09b0: 72 6f 6d 20 61 20 72 65 63 6f 72 64 20 49 44 2e rom a record ID.
09c0: 0a 2a 2f 0a 76 6f 69 64 20 6c 6f 61 64 5f 76 66 .*/.void load_vf
09d0: 69 6c 65 5f 66 72 6f 6d 5f 72 69 64 28 69 6e 74 ile_from_rid(int
09e0: 20 76 69 64 29 7b 0a 20 20 42 6c 6f 62 20 6d 61 vid){. Blob ma
09f0: 6e 69 66 65 73 74 3b 0a 0a 20 20 69 66 28 20 64 nifest;.. if( d
0a00: 62 5f 65 78 69 73 74 73 28 22 53 45 4c 45 43 54 b_exists("SELECT
0a10: 20 31 20 46 52 4f 4d 20 76 66 69 6c 65 20 57 48 1 FROM vfile WH
0a20: 45 52 45 20 76 69 64 3d 25 64 22 2c 20 76 69 64 ERE vid=%d", vid
0a30: 29 20 29 7b 0a 20 20 20 20 72 65 74 75 72 6e 3b ) ){. return;
0a40: 0a 20 20 7d 0a 20 20 63 6f 6e 74 65 6e 74 5f 67 . }. content_g
0a50: 65 74 28 76 69 64 2c 20 26 6d 61 6e 69 66 65 73 et(vid, &manifes
0a60: 74 29 3b 0a 20 20 76 66 69 6c 65 5f 62 75 69 6c t);. vfile_buil
0a70: 64 28 76 69 64 2c 20 26 6d 61 6e 69 66 65 73 74 d(vid, &manifest
0a80: 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 );. blob_reset(
0a90: 26 6d 61 6e 69 66 65 73 74 29 3b 0a 7d 0a 0a 2f &manifest);.}../
0aa0: 2a 0a 2a 2a 20 52 65 61 64 20 74 68 65 20 6d 61 *.** Read the ma
0ab0: 6e 69 66 65 73 74 20 66 69 6c 65 20 67 69 76 65 nifest file give
0ac0: 6e 20 62 79 20 76 69 64 20 6f 75 74 20 6f 66 20 n by vid out of
0ad0: 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 0a 2a the repository.*
0ae0: 2a 20 61 6e 64 20 73 74 6f 72 65 20 69 74 20 69 * and store it i
0af0: 6e 20 74 68 65 20 72 6f 6f 74 20 6f 66 20 74 68 n the root of th
0b00: 65 20 6c 6f 63 61 6c 20 63 68 65 63 6b 2d 6f 75 e local check-ou
0b10: 74 2e 0a 2a 2f 0a 76 6f 69 64 20 6d 61 6e 69 66 t..*/.void manif
0b20: 65 73 74 5f 74 6f 5f 64 69 73 6b 28 69 6e 74 20 est_to_disk(int
0b30: 76 69 64 29 7b 0a 20 20 63 68 61 72 20 2a 7a 4d vid){. char *zM
0b40: 61 6e 46 69 6c 65 3b 0a 20 20 42 6c 6f 62 20 6d anFile;. Blob m
0b50: 61 6e 69 66 65 73 74 3b 0a 20 20 42 6c 6f 62 20 anifest;. Blob
0b60: 68 61 73 68 3b 0a 20 20 42 6c 6f 62 20 66 69 6c hash;. Blob fil
0b70: 65 6e 61 6d 65 3b 0a 20 20 69 6e 74 20 62 61 73 ename;. int bas
0b80: 65 4c 65 6e 3b 0a 20 20 69 6e 74 20 69 3b 0a 20 eLen;. int i;.
0b90: 20 4d 61 6e 69 66 65 73 74 20 6d 3b 0a 0a 20 20 Manifest m;..
0ba0: 62 6c 6f 62 5f 7a 65 72 6f 28 26 6d 61 6e 69 66 blob_zero(&manif
0bb0: 65 73 74 29 3b 0a 20 20 7a 4d 61 6e 46 69 6c 65 est);. zManFile
0bc0: 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 6d 61 = mprintf("%sma
0bd0: 6e 69 66 65 73 74 22 2c 20 67 2e 7a 4c 6f 63 61 nifest", g.zLoca
0be0: 6c 52 6f 6f 74 29 3b 0a 20 20 63 6f 6e 74 65 6e lRoot);. conten
0bf0: 74 5f 67 65 74 28 76 69 64 2c 20 26 6d 61 6e 69 t_get(vid, &mani
0c00: 66 65 73 74 29 3b 0a 20 20 62 6c 6f 62 5f 77 72 fest);. blob_wr
0c10: 69 74 65 5f 74 6f 5f 66 69 6c 65 28 26 6d 61 6e ite_to_file(&man
0c20: 69 66 65 73 74 2c 20 7a 4d 61 6e 46 69 6c 65 29 ifest, zManFile)
0c30: 3b 0a 20 20 66 72 65 65 28 7a 4d 61 6e 46 69 6c ;. free(zManFil
0c40: 65 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 e);. blob_zero(
0c50: 26 68 61 73 68 29 3b 0a 20 20 73 68 61 31 73 75 &hash);. sha1su
0c60: 6d 5f 62 6c 6f 62 28 26 6d 61 6e 69 66 65 73 74 m_blob(&manifest
0c70: 2c 20 26 68 61 73 68 29 3b 0a 20 20 7a 4d 61 6e , &hash);. zMan
0c80: 46 69 6c 65 20 3d 20 6d 70 72 69 6e 74 66 28 22 File = mprintf("
0c90: 25 73 6d 61 6e 69 66 65 73 74 2e 75 75 69 64 22 %smanifest.uuid"
0ca0: 2c 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 29 3b , g.zLocalRoot);
0cb0: 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 26 . blob_append(&
0cc0: 68 61 73 68 2c 20 22 5c 6e 22 2c 20 31 29 3b 0a hash, "\n", 1);.
0cd0: 20 20 62 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f blob_write_to_
0ce0: 66 69 6c 65 28 26 68 61 73 68 2c 20 7a 4d 61 6e file(&hash, zMan
0cf0: 46 69 6c 65 29 3b 0a 20 20 66 72 65 65 28 7a 4d File);. free(zM
0d00: 61 6e 46 69 6c 65 29 3b 0a 20 20 62 6c 6f 62 5f anFile);. blob_
0d10: 72 65 73 65 74 28 26 68 61 73 68 29 3b 0a 20 20 reset(&hash);.
0d20: 6d 61 6e 69 66 65 73 74 5f 70 61 72 73 65 28 26 manifest_parse(&
0d30: 6d 2c 20 26 6d 61 6e 69 66 65 73 74 29 3b 0a 20 m, &manifest);.
0d40: 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 66 69 6c 65 blob_zero(&file
0d50: 6e 61 6d 65 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 name);. blob_ap
0d60: 70 65 6e 64 66 28 26 66 69 6c 65 6e 61 6d 65 2c pendf(&filename,
0d70: 20 22 25 73 2f 22 2c 20 67 2e 7a 4c 6f 63 61 6c "%s/", g.zLocal
0d80: 52 6f 6f 74 29 3b 0a 20 20 62 61 73 65 4c 65 6e Root);. baseLen
0d90: 20 3d 20 62 6c 6f 62 5f 73 69 7a 65 28 26 66 69 = blob_size(&fi
0da0: 6c 65 6e 61 6d 65 29 3b 0a 20 20 66 6f 72 28 69 lename);. for(i
0db0: 3d 30 3b 20 69 3c 6d 2e 6e 46 69 6c 65 3b 20 69 =0; i<m.nFile; i
0dc0: 2b 2b 29 7b 20 0a 20 20 20 20 69 6e 74 20 69 73 ++){ . int is
0dd0: 45 78 65 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 Exe;. blob_ap
0de0: 70 65 6e 64 28 26 66 69 6c 65 6e 61 6d 65 2c 20 pend(&filename,
0df0: 6d 2e 61 46 69 6c 65 5b 69 5d 2e 7a 4e 61 6d 65 m.aFile[i].zName
0e00: 2c 20 2d 31 29 3b 0a 20 20 20 20 69 73 45 78 65 , -1);. isExe
0e10: 20 3d 20 6d 2e 61 46 69 6c 65 5b 69 5d 2e 7a 50 = m.aFile[i].zP
0e20: 65 72 6d 20 26 26 20 73 74 72 73 74 72 28 6d 2e erm && strstr(m.
0e30: 61 46 69 6c 65 5b 69 5d 2e 7a 50 65 72 6d 2c 20 aFile[i].zPerm,
0e40: 22 78 22 29 3b 0a 20 20 20 20 66 69 6c 65 5f 73 "x");. file_s
0e50: 65 74 65 78 65 28 62 6c 6f 62 5f 73 74 72 28 26 etexe(blob_str(&
0e60: 66 69 6c 65 6e 61 6d 65 29 2c 20 69 73 45 78 65 filename), isExe
0e70: 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 72 65 73 69 );. blob_resi
0e80: 7a 65 28 26 66 69 6c 65 6e 61 6d 65 2c 20 62 61 ze(&filename, ba
0e90: 73 65 4c 65 6e 29 3b 0a 20 20 7d 0a 20 20 62 6c seLen);. }. bl
0ea0: 6f 62 5f 72 65 73 65 74 28 26 66 69 6c 65 6e 61 ob_reset(&filena
0eb0: 6d 65 29 3b 0a 20 20 6d 61 6e 69 66 65 73 74 5f me);. manifest_
0ec0: 63 6c 65 61 72 28 26 6d 29 3b 0a 7d 0a 0a 2f 2a clear(&m);.}../*
0ed0: 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 63 68 65 .** COMMAND: che
0ee0: 63 6b 6f 75 74 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 ckout.** COMMAND
0ef0: 3a 20 63 6f 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 : co.**.** Usage
0f00: 3a 20 25 66 6f 73 73 69 6c 20 63 68 65 63 6b 6f : %fossil checko
0f10: 75 74 20 56 45 52 53 49 4f 4e 20 3f 2d 66 7c 2d ut VERSION ?-f|-
0f20: 2d 66 6f 72 63 65 3f 20 3f 2d 2d 6b 65 65 70 3f -force? ?--keep?
0f30: 0a 2a 2a 0a 2a 2a 20 43 68 65 63 6b 20 6f 75 74 .**.** Check out
0f40: 20 61 20 76 65 72 73 69 6f 6e 20 73 70 65 63 69 a version speci
0f50: 66 69 65 64 20 6f 6e 20 74 68 65 20 63 6f 6d 6d fied on the comm
0f60: 61 6e 64 2d 6c 69 6e 65 2e 20 20 54 68 69 73 20 and-line. This
0f70: 63 6f 6d 6d 61 6e 64 0a 2a 2a 20 77 69 6c 6c 20 command.** will
0f80: 61 62 6f 72 74 20 69 66 20 74 68 65 72 65 20 61 abort if there a
0f90: 72 65 20 65 64 69 74 65 64 20 66 69 6c 65 73 20 re edited files
0fa0: 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20 63 in the current c
0fb0: 68 65 63 6b 6f 75 74 20 75 6e 6c 65 73 73 0a 2a heckout unless.*
0fc0: 2a 20 74 68 65 20 2d 2d 66 6f 72 63 65 20 6f 70 * the --force op
0fd0: 74 69 6f 6e 20 61 70 70 65 61 72 73 20 6f 6e 20 tion appears on
0fe0: 74 68 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 the command-line
0ff0: 2e 20 20 54 68 65 20 2d 2d 6b 65 65 70 20 6f 70 . The --keep op
1000: 74 69 6f 6e 0a 2a 2a 20 6c 65 61 76 65 73 20 66 tion.** leaves f
1010: 69 6c 65 73 20 6f 6e 20 64 69 73 6b 20 75 6e 63 iles on disk unc
1020: 68 61 6e 67 65 64 2c 20 65 78 63 65 70 74 20 74 hanged, except t
1030: 68 65 20 6d 61 6e 69 66 65 73 74 20 61 6e 64 20 he manifest and
1040: 6d 61 6e 69 66 65 73 74 2e 75 75 69 64 0a 2a 2a manifest.uuid.**
1050: 20 66 69 6c 65 73 2e 0a 2a 2a 0a 2a 2a 20 54 68 files..**.** Th
1060: 65 20 2d 2d 6c 61 74 65 73 74 20 66 6c 61 67 20 e --latest flag
1070: 63 61 6e 20 62 65 20 75 73 65 64 20 69 6e 20 70 can be used in p
1080: 6c 61 63 65 20 6f 66 20 56 45 52 53 49 4f 4e 20 lace of VERSION
1090: 74 6f 20 63 68 65 63 6b 6f 75 74 20 74 68 65 0a to checkout the.
10a0: 2a 2a 20 6c 61 74 65 73 74 20 76 65 72 73 69 6f ** latest versio
10b0: 6e 20 69 6e 20 74 68 65 20 72 65 70 6f 73 69 74 n in the reposit
10c0: 6f 72 79 2e 0a 2a 2a 0a 2a 2a 20 53 65 65 20 61 ory..**.** See a
10d0: 6c 73 6f 20 74 68 65 20 22 75 70 64 61 74 65 22 lso the "update"
10e0: 20 63 6f 6d 6d 61 6e 64 2e 0a 2a 2f 0a 76 6f 69 command..*/.voi
10f0: 64 20 63 68 65 63 6b 6f 75 74 5f 63 6d 64 28 76 d checkout_cmd(v
1100: 6f 69 64 29 7b 0a 20 20 69 6e 74 20 66 6f 72 63 oid){. int forc
1110: 65 46 6c 61 67 3b 20 20 20 20 20 20 20 20 20 20 eFlag;
1120: 20 20 20 20 20 20 20 2f 2a 20 46 6f 72 63 65 20 /* Force
1130: 63 68 65 63 6b 6f 75 74 20 65 76 65 6e 20 69 66 checkout even if
1140: 20 65 64 69 74 73 20 65 78 69 73 74 20 2a 2f 0a edits exist */.
1150: 20 20 69 6e 74 20 6b 65 65 70 46 6c 61 67 3b 20 int keepFlag;
1160: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1170: 20 2f 2a 20 44 6f 20 6e 6f 74 20 63 68 61 6e 67 /* Do not chang
1180: 65 20 61 6e 79 20 66 69 6c 65 73 20 6f 6e 20 64 e any files on d
1190: 69 73 6b 20 2a 2f 0a 20 20 69 6e 74 20 6c 61 74 isk */. int lat
11a0: 65 73 74 46 6c 61 67 3b 20 20 20 20 20 20 20 20 estFlag;
11b0: 20 20 20 20 20 20 20 20 2f 2a 20 43 68 65 63 6b /* Check
11c0: 6f 75 74 20 74 68 65 20 6c 61 74 65 73 74 20 76 out the latest v
11d0: 65 72 73 69 6f 6e 20 2a 2f 0a 20 20 63 68 61 72 ersion */. char
11e0: 20 2a 7a 56 65 72 73 3b 20 20 20 20 20 20 20 20 *zVers;
11f0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 65 /* Ve
1200: 72 73 69 6f 6e 20 74 6f 20 63 68 65 63 6b 6f 75 rsion to checkou
1210: 74 20 2a 2f 0a 20 20 69 6e 74 20 76 69 64 2c 20 t */. int vid,
1220: 70 72 69 6f 72 3b 0a 20 20 42 6c 6f 62 20 63 6b prior;. Blob ck
1230: 73 75 6d 31 2c 20 63 6b 73 75 6d 31 62 2c 20 63 sum1, cksum1b, c
1240: 6b 73 75 6d 32 3b 0a 20 20 0a 20 20 64 62 5f 6d ksum2;. . db_m
1250: 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72 ust_be_within_tr
1260: 65 65 28 29 3b 0a 20 20 64 62 5f 62 65 67 69 6e ee();. db_begin
1270: 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a _transaction();.
1280: 20 20 66 6f 72 63 65 46 6c 61 67 20 3d 20 66 69 forceFlag = fi
1290: 6e 64 5f 6f 70 74 69 6f 6e 28 22 66 6f 72 63 65 nd_option("force
12a0: 22 2c 22 66 22 2c 30 29 21 3d 30 3b 0a 20 20 6b ","f",0)!=0;. k
12b0: 65 65 70 46 6c 61 67 20 3d 20 66 69 6e 64 5f 6f eepFlag = find_o
12c0: 70 74 69 6f 6e 28 22 6b 65 65 70 22 2c 30 2c 30 ption("keep",0,0
12d0: 29 21 3d 30 3b 0a 20 20 6c 61 74 65 73 74 46 6c )!=0;. latestFl
12e0: 61 67 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e ag = find_option
12f0: 28 22 6c 61 74 65 73 74 22 2c 30 2c 30 29 21 3d ("latest",0,0)!=
1300: 30 3b 0a 20 20 69 66 28 20 28 6c 61 74 65 73 74 0;. if( (latest
1310: 46 6c 61 67 21 3d 30 20 26 26 20 67 2e 61 72 67 Flag!=0 && g.arg
1320: 63 21 3d 32 29 20 7c 7c 20 28 6c 61 74 65 73 74 c!=2) || (latest
1330: 46 6c 61 67 3d 3d 30 20 26 26 20 67 2e 61 72 67 Flag==0 && g.arg
1340: 63 21 3d 33 29 20 29 7b 0a 20 20 20 20 20 75 73 c!=3) ){. us
1350: 61 67 65 28 22 56 45 52 53 49 4f 4e 7c 2d 2d 6c age("VERSION|--l
1360: 61 74 65 73 74 20 3f 2d 2d 66 6f 72 63 65 3f 20 atest ?--force?
1370: 3f 2d 2d 6b 65 65 70 3f 22 29 3b 0a 20 20 7d 0a ?--keep?");. }.
1380: 20 20 69 66 28 20 21 66 6f 72 63 65 46 6c 61 67 if( !forceFlag
1390: 20 26 26 20 75 6e 73 61 76 65 64 5f 63 68 61 6e && unsaved_chan
13a0: 67 65 73 28 29 3d 3d 31 20 29 7b 0a 20 20 20 20 ges()==1 ){.
13b0: 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 74 68 fossil_fatal("th
13c0: 65 72 65 20 61 72 65 20 75 6e 73 61 76 65 64 20 ere are unsaved
13d0: 63 68 61 6e 67 65 73 20 69 6e 20 74 68 65 20 63 changes in the c
13e0: 75 72 72 65 6e 74 20 63 68 65 63 6b 6f 75 74 22 urrent checkout"
13f0: 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 66 6f 72 );. }. if( for
1400: 63 65 46 6c 61 67 20 29 7b 0a 20 20 20 20 64 62 ceFlag ){. db
1410: 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 44 45 4c _multi_exec("DEL
1420: 45 54 45 20 46 52 4f 4d 20 76 66 69 6c 65 22 29 ETE FROM vfile")
1430: 3b 0a 20 20 20 20 70 72 69 6f 72 20 3d 20 30 3b ;. prior = 0;
1440: 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 70 72 . }else{. pr
1450: 69 6f 72 20 3d 20 64 62 5f 6c 67 65 74 5f 69 6e ior = db_lget_in
1460: 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 30 29 3b t("checkout",0);
1470: 0a 20 20 7d 0a 20 20 69 66 28 20 6c 61 74 65 73 . }. if( lates
1480: 74 46 6c 61 67 20 29 7b 0a 20 20 20 20 63 6f 6d tFlag ){. com
1490: 70 75 74 65 5f 6c 65 61 76 65 73 28 64 62 5f 6c pute_leaves(db_l
14a0: 67 65 74 5f 69 6e 74 28 22 63 68 65 63 6b 6f 75 get_int("checkou
14b0: 74 22 2c 30 29 2c 20 31 29 3b 0a 20 20 20 20 7a t",0), 1);. z
14c0: 56 65 72 73 20 3d 20 64 62 5f 74 65 78 74 28 30 Vers = db_text(0
14d0: 2c 20 22 53 45 4c 45 43 54 20 75 75 69 64 20 46 , "SELECT uuid F
14e0: 52 4f 4d 20 6c 65 61 76 65 73 2c 20 65 76 65 6e ROM leaves, even
14f0: 74 2c 20 62 6c 6f 62 22 0a 20 20 20 20 20 20 20 t, blob".
1500: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1510: 22 20 57 48 45 52 45 20 65 76 65 6e 74 2e 6f 62 " WHERE event.ob
1520: 6a 69 64 3d 6c 65 61 76 65 73 2e 72 69 64 20 41 jid=leaves.rid A
1530: 4e 44 20 62 6c 6f 62 2e 72 69 64 3d 6c 65 61 76 ND blob.rid=leav
1540: 65 73 2e 72 69 64 22 0a 20 20 20 20 20 20 20 20 es.rid".
1550: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
1560: 20 4f 52 44 45 52 20 42 59 20 65 76 65 6e 74 2e ORDER BY event.
1570: 6d 74 69 6d 65 20 44 45 53 43 22 29 3b 0a 20 20 mtime DESC");.
1580: 20 20 69 66 28 20 7a 56 65 72 73 3d 3d 30 20 29 if( zVers==0 )
1590: 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 {. fossil_f
15a0: 61 74 61 6c 28 22 63 61 6e 6e 6f 74 20 6c 6f 63 atal("cannot loc
15b0: 61 74 65 20 5c 22 6c 61 74 65 73 74 5c 22 20 63 ate \"latest\" c
15c0: 68 65 63 6b 6f 75 74 22 29 3b 0a 20 20 20 20 7d heckout");. }
15d0: 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 7a 56 . }else{. zV
15e0: 65 72 73 20 3d 20 67 2e 61 72 67 76 5b 32 5d 3b ers = g.argv[2];
15f0: 0a 20 20 7d 0a 20 20 76 69 64 20 3d 20 6c 6f 61 . }. vid = loa
1600: 64 5f 76 66 69 6c 65 28 7a 56 65 72 73 29 3b 0a d_vfile(zVers);.
1610: 20 20 69 66 28 20 70 72 69 6f 72 3d 3d 76 69 64 if( prior==vid
1620: 20 29 7b 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a ){. return;.
1630: 20 20 7d 0a 20 20 69 66 28 20 21 6b 65 65 70 46 }. if( !keepF
1640: 6c 61 67 20 29 7b 0a 20 20 20 20 75 6e 63 68 65 lag ){. unche
1650: 63 6b 6f 75 74 28 70 72 69 6f 72 29 3b 0a 20 20 ckout(prior);.
1660: 7d 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 }. db_multi_exe
1670: 63 28 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 76 c("DELETE FROM v
1680: 66 69 6c 65 20 57 48 45 52 45 20 76 69 64 21 3d file WHERE vid!=
1690: 25 64 22 2c 20 76 69 64 29 3b 0a 20 20 69 66 28 %d", vid);. if(
16a0: 20 21 6b 65 65 70 46 6c 61 67 20 29 7b 0a 20 20 !keepFlag ){.
16b0: 20 20 76 66 69 6c 65 5f 74 6f 5f 64 69 73 6b 28 vfile_to_disk(
16c0: 76 69 64 2c 20 30 2c 20 31 29 3b 0a 20 20 7d 0a vid, 0, 1);. }.
16d0: 20 20 6d 61 6e 69 66 65 73 74 5f 74 6f 5f 64 69 manifest_to_di
16e0: 73 6b 28 76 69 64 29 3b 0a 20 20 64 62 5f 6c 73 sk(vid);. db_ls
16f0: 65 74 5f 69 6e 74 28 22 63 68 65 63 6b 6f 75 74 et_int("checkout
1700: 22 2c 20 76 69 64 29 3b 0a 20 20 75 6e 64 6f 5f ", vid);. undo_
1710: 72 65 73 65 74 28 29 3b 0a 20 20 64 62 5f 6d 75 reset();. db_mu
1720: 6c 74 69 5f 65 78 65 63 28 22 44 45 4c 45 54 45 lti_exec("DELETE
1730: 20 46 52 4f 4d 20 76 6d 65 72 67 65 22 29 3b 0a FROM vmerge");.
1740: 20 20 69 66 28 20 21 6b 65 65 70 46 6c 61 67 20 if( !keepFlag
1750: 29 7b 0a 20 20 20 20 76 66 69 6c 65 5f 61 67 67 ){. vfile_agg
1760: 72 65 67 61 74 65 5f 63 68 65 63 6b 73 75 6d 5f regate_checksum_
1770: 6d 61 6e 69 66 65 73 74 28 76 69 64 2c 20 26 63 manifest(vid, &c
1780: 6b 73 75 6d 31 2c 20 26 63 6b 73 75 6d 31 62 29 ksum1, &cksum1b)
1790: 3b 0a 20 20 20 20 76 66 69 6c 65 5f 61 67 67 72 ;. vfile_aggr
17a0: 65 67 61 74 65 5f 63 68 65 63 6b 73 75 6d 5f 64 egate_checksum_d
17b0: 69 73 6b 28 76 69 64 2c 20 26 63 6b 73 75 6d 32 isk(vid, &cksum2
17c0: 29 3b 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f );. if( blob_
17d0: 63 6f 6d 70 61 72 65 28 26 63 6b 73 75 6d 31 2c compare(&cksum1,
17e0: 20 26 63 6b 73 75 6d 32 29 20 29 7b 0a 20 20 20 &cksum2) ){.
17f0: 20 20 20 70 72 69 6e 74 66 28 22 57 41 52 4e 49 printf("WARNI
1800: 4e 47 3a 20 6d 61 6e 69 66 65 73 74 20 63 68 65 NG: manifest che
1810: 63 6b 73 75 6d 20 64 6f 65 73 20 6e 6f 74 20 61 cksum does not a
1820: 67 72 65 65 20 77 69 74 68 20 64 69 73 6b 5c 6e gree with disk\n
1830: 22 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 ");. }. if
1840: 28 20 62 6c 6f 62 5f 63 6f 6d 70 61 72 65 28 26 ( blob_compare(&
1850: 63 6b 73 75 6d 31 2c 20 26 63 6b 73 75 6d 31 62 cksum1, &cksum1b
1860: 29 20 29 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 ) ){. print
1870: 66 28 22 57 41 52 4e 49 4e 47 3a 20 6d 61 6e 69 f("WARNING: mani
1880: 66 65 73 74 20 63 68 65 63 6b 73 75 6d 20 64 6f fest checksum do
1890: 65 73 20 6e 6f 74 20 61 67 72 65 65 20 77 69 74 es not agree wit
18a0: 68 20 6d 61 6e 69 66 65 73 74 5c 6e 22 29 3b 0a h manifest\n");.
18b0: 20 20 20 20 7d 0a 20 20 7d 0a 20 20 64 62 5f 65 }. }. db_e
18c0: 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 nd_transaction(0
18d0: 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 55 6e 6c 69 );.}../*.** Unli
18e0: 6e 6b 20 74 68 65 20 6c 6f 63 61 6c 20 64 61 74 nk the local dat
18f0: 61 62 61 73 65 20 66 69 6c 65 0a 2a 2f 0a 76 6f abase file.*/.vo
1900: 69 64 20 75 6e 6c 69 6e 6b 5f 6c 6f 63 61 6c 5f id unlink_local_
1910: 64 61 74 61 62 61 73 65 28 76 6f 69 64 29 7b 0a database(void){.
1920: 20 20 73 74 61 74 69 63 20 63 6f 6e 73 74 20 63 static const c
1930: 68 61 72 20 2a 61 7a 46 69 6c 65 5b 5d 20 3d 20 har *azFile[] =
1940: 7b 0a 20 20 20 20 20 22 25 73 5f 46 4f 53 53 49 {. "%s_FOSSI
1950: 4c 5f 22 2c 0a 20 20 20 20 20 22 25 73 5f 46 4f L_",. "%s_FO
1960: 53 53 49 4c 5f 2d 6a 6f 75 72 6e 61 6c 22 2c 0a SSIL_-journal",.
1970: 20 20 20 20 20 22 25 73 2e 66 6f 73 22 2c 0a 20 "%s.fos",.
1980: 20 20 20 20 22 25 73 2e 66 6f 73 2d 6a 6f 75 72 "%s.fos-jour
1990: 6e 61 6c 22 2c 0a 20 20 7d 3b 0a 20 20 69 6e 74 nal",. };. int
19a0: 20 69 3b 0a 20 20 66 6f 72 28 69 3d 30 3b 20 69 i;. for(i=0; i
19b0: 3c 73 69 7a 65 6f 66 28 61 7a 46 69 6c 65 29 2f <sizeof(azFile)/
19c0: 73 69 7a 65 6f 66 28 61 7a 46 69 6c 65 5b 30 5d sizeof(azFile[0]
19d0: 29 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 63 68 61 ); i++){. cha
19e0: 72 20 2a 7a 20 3d 20 6d 70 72 69 6e 74 66 28 61 r *z = mprintf(a
19f0: 7a 46 69 6c 65 5b 69 5d 2c 20 67 2e 7a 4c 6f 63 zFile[i], g.zLoc
1a00: 61 6c 52 6f 6f 74 29 3b 0a 20 20 20 20 75 6e 6c alRoot);. unl
1a10: 69 6e 6b 28 7a 29 3b 0a 20 20 20 20 66 72 65 65 ink(z);. free
1a20: 28 7a 29 3b 0a 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a (z);. }.}../*.*
1a30: 2a 20 43 4f 4d 4d 41 4e 44 3a 20 63 6c 6f 73 65 * COMMAND: close
1a40: 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 .**.** Usage: %f
1a50: 6f 73 73 69 6c 20 63 6c 6f 73 65 20 3f 2d 66 7c ossil close ?-f|
1a60: 2d 2d 66 6f 72 63 65 3f 0a 2a 2a 0a 2a 2a 20 54 --force?.**.** T
1a70: 68 65 20 6f 70 70 6f 73 69 74 65 20 6f 66 20 22 he opposite of "
1a80: 6f 70 65 6e 22 2e 20 20 43 6c 6f 73 65 20 74 68 open". Close th
1a90: 65 20 63 75 72 72 65 6e 74 20 64 61 74 61 62 61 e current databa
1aa0: 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e 0a 2a se connection..*
1ab0: 2a 20 52 65 71 75 69 72 65 20 61 20 2d 66 20 6f * Require a -f o
1ac0: 72 20 2d 2d 66 6f 72 63 65 20 66 6c 61 67 20 69 r --force flag i
1ad0: 66 20 74 68 65 72 65 20 61 72 65 20 75 6e 73 61 f there are unsa
1ae0: 76 65 64 20 63 68 61 6e 67 65 64 20 69 6e 20 74 ved changed in t
1af0: 68 65 0a 2a 2a 20 63 75 72 72 65 6e 74 20 63 68 he.** current ch
1b00: 65 63 6b 2d 6f 75 74 2e 0a 2a 2f 0a 76 6f 69 64 eck-out..*/.void
1b10: 20 63 6c 6f 73 65 5f 63 6d 64 28 76 6f 69 64 29 close_cmd(void)
1b20: 7b 0a 20 20 69 6e 74 20 66 6f 72 63 65 46 6c 61 {. int forceFla
1b30: 67 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 g = find_option(
1b40: 22 66 6f 72 63 65 22 2c 22 66 22 2c 30 29 21 3d "force","f",0)!=
1b50: 30 3b 0a 20 20 64 62 5f 6d 75 73 74 5f 62 65 5f 0;. db_must_be_
1b60: 77 69 74 68 69 6e 5f 74 72 65 65 28 29 3b 0a 20 within_tree();.
1b70: 20 69 66 28 20 21 66 6f 72 63 65 46 6c 61 67 20 if( !forceFlag
1b80: 26 26 20 75 6e 73 61 76 65 64 5f 63 68 61 6e 67 && unsaved_chang
1b90: 65 73 28 29 3d 3d 31 20 29 7b 0a 20 20 20 20 66 es()==1 ){. f
1ba0: 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 74 68 65 ossil_fatal("the
1bb0: 72 65 20 61 72 65 20 75 6e 73 61 76 65 64 20 63 re are unsaved c
1bc0: 68 61 6e 67 65 73 20 69 6e 20 74 68 65 20 63 75 hanges in the cu
1bd0: 72 72 65 6e 74 20 63 68 65 63 6b 6f 75 74 22 29 rrent checkout")
1be0: 3b 0a 20 20 7d 0a 20 20 64 62 5f 63 6c 6f 73 65 ;. }. db_close
1bf0: 28 29 3b 0a 20 20 75 6e 6c 69 6e 6b 5f 6c 6f 63 ();. unlink_loc
1c00: 61 6c 5f 64 61 74 61 62 61 73 65 28 29 3b 0a 7d al_database();.}
1c10: 0a .