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 29 3b 0a WHERE chnged");.
05f0: 7d 0a 0a 2f 2a 0a 2a 2a 20 55 6e 64 6f 20 74 68 }../*.** Undo th
0600: 65 20 63 75 72 72 65 6e 74 20 63 68 65 63 6b 2d e current check-
0610: 6f 75 74 2e 20 20 55 6e 6c 69 6e 6b 20 61 6c 6c out. Unlink all
0620: 20 66 69 6c 65 73 20 66 72 6f 6d 20 74 68 65 20 files from the
0630: 64 69 73 6b 2e 0a 2a 2a 20 43 6c 65 61 72 20 74 disk..** Clear t
0640: 68 65 20 56 46 49 4c 45 20 74 61 62 6c 65 2e 0a he VFILE table..
0650: 2a 2f 0a 76 6f 69 64 20 75 6e 63 68 65 63 6b 6f */.void unchecko
0660: 75 74 28 69 6e 74 20 76 69 64 29 7b 0a 20 20 69 ut(int vid){. i
0670: 66 28 20 76 69 64 3d 3d 30 20 29 20 72 65 74 75 f( vid==0 ) retu
0680: 72 6e 3b 0a 20 20 76 66 69 6c 65 5f 75 6e 6c 69 rn;. vfile_unli
0690: 6e 6b 28 76 69 64 29 3b 0a 20 20 64 62 5f 6d 75 nk(vid);. db_mu
06a0: 6c 74 69 5f 65 78 65 63 28 22 44 45 4c 45 54 45 lti_exec("DELETE
06b0: 20 46 52 4f 4d 20 76 66 69 6c 65 20 57 48 45 52 FROM vfile WHER
06c0: 45 20 76 69 64 3d 25 64 22 2c 20 76 69 64 29 3b E vid=%d", vid);
06d0: 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 47 69 76 65 6e .}.../*.** Given
06e0: 20 74 68 65 20 61 62 62 72 65 76 69 61 74 65 64 the abbreviated
06f0: 20 55 55 49 44 20 6e 61 6d 65 20 6f 66 20 61 20 UUID name of a
0700: 76 65 72 73 69 6f 6e 2c 20 6c 6f 61 64 20 74 68 version, load th
0710: 65 20 63 6f 6e 74 65 6e 74 20 6f 66 20 74 68 61 e content of tha
0720: 74 0a 2a 2a 20 76 65 72 73 69 6f 6e 20 69 6e 20 t.** version in
0730: 74 68 65 20 56 46 49 4c 45 20 74 61 62 6c 65 2e the VFILE table.
0740: 20 20 52 65 74 75 72 6e 20 74 68 65 20 56 49 44 Return the VID
0750: 20 66 6f 72 20 74 68 65 20 76 65 72 73 69 6f 6e for the version
0760: 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 61 6e 79 74 68 ..**.** If anyth
0770: 69 6e 67 20 67 6f 65 73 20 77 72 6f 6e 67 2c 20 ing goes wrong,
0780: 70 61 6e 69 63 2e 0a 2a 2f 0a 69 6e 74 20 6c 6f panic..*/.int lo
0790: 61 64 5f 76 66 69 6c 65 28 63 6f 6e 73 74 20 63 ad_vfile(const c
07a0: 68 61 72 20 2a 7a 4e 61 6d 65 29 7b 0a 20 20 42 har *zName){. B
07b0: 6c 6f 62 20 75 75 69 64 3b 0a 20 20 69 6e 74 20 lob uuid;. int
07c0: 76 69 64 3b 0a 0a 20 20 62 6c 6f 62 5f 69 6e 69 vid;.. blob_ini
07d0: 74 28 26 75 75 69 64 2c 20 7a 4e 61 6d 65 2c 20 t(&uuid, zName,
07e0: 2d 31 29 3b 0a 20 20 69 66 28 20 6e 61 6d 65 5f -1);. if( name_
07f0: 74 6f 5f 75 75 69 64 28 26 75 75 69 64 2c 20 31 to_uuid(&uuid, 1
0800: 29 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f ) ){. fossil_
0810: 70 61 6e 69 63 28 67 2e 7a 45 72 72 4d 73 67 29 panic(g.zErrMsg)
0820: 3b 0a 20 20 7d 0a 20 20 76 69 64 20 3d 20 64 62 ;. }. vid = db
0830: 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 20 _int(0, "SELECT
0840: 72 69 64 20 46 52 4f 4d 20 62 6c 6f 62 20 57 48 rid FROM blob WH
0850: 45 52 45 20 75 75 69 64 3d 25 42 22 2c 20 26 75 ERE uuid=%B", &u
0860: 75 69 64 29 3b 0a 20 20 69 66 28 20 76 69 64 3d uid);. if( vid=
0870: 3d 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c =0 ){. fossil
0880: 5f 70 61 6e 69 63 28 22 6e 6f 20 73 75 63 68 20 _panic("no such
0890: 76 65 72 73 69 6f 6e 3a 20 25 73 22 2c 20 67 2e version: %s", g.
08a0: 61 72 67 76 5b 32 5d 29 3b 0a 20 20 7d 0a 20 20 argv[2]);. }.
08b0: 6c 6f 61 64 5f 76 66 69 6c 65 5f 66 72 6f 6d 5f load_vfile_from_
08c0: 72 69 64 28 76 69 64 29 3b 0a 20 20 72 65 74 75 rid(vid);. retu
08d0: 72 6e 20 76 69 64 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a rn vid;.}../*.**
08e0: 20 4c 6f 61 64 20 61 20 76 66 69 6c 65 20 66 72 Load a vfile fr
08f0: 6f 6d 20 61 20 72 65 63 6f 72 64 20 49 44 2e 0a om a record ID..
0900: 2a 2f 0a 76 6f 69 64 20 6c 6f 61 64 5f 76 66 69 */.void load_vfi
0910: 6c 65 5f 66 72 6f 6d 5f 72 69 64 28 69 6e 74 20 le_from_rid(int
0920: 76 69 64 29 7b 0a 20 20 42 6c 6f 62 20 6d 61 6e vid){. Blob man
0930: 69 66 65 73 74 3b 0a 0a 20 20 69 66 28 20 64 62 ifest;.. if( db
0940: 5f 65 78 69 73 74 73 28 22 53 45 4c 45 43 54 20 _exists("SELECT
0950: 31 20 46 52 4f 4d 20 76 66 69 6c 65 20 57 48 45 1 FROM vfile WHE
0960: 52 45 20 76 69 64 3d 25 64 22 2c 20 76 69 64 29 RE vid=%d", vid)
0970: 20 29 7b 0a 20 20 20 20 72 65 74 75 72 6e 3b 0a ){. return;.
0980: 20 20 7d 0a 20 20 63 6f 6e 74 65 6e 74 5f 67 65 }. content_ge
0990: 74 28 76 69 64 2c 20 26 6d 61 6e 69 66 65 73 74 t(vid, &manifest
09a0: 29 3b 0a 20 20 76 66 69 6c 65 5f 62 75 69 6c 64 );. vfile_build
09b0: 28 76 69 64 2c 20 26 6d 61 6e 69 66 65 73 74 29 (vid, &manifest)
09c0: 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 ;. blob_reset(&
09d0: 6d 61 6e 69 66 65 73 74 29 3b 0a 7d 0a 0a 2f 2a manifest);.}../*
09e0: 0a 2a 2a 20 52 65 61 64 20 74 68 65 20 6d 61 6e .** Read the man
09f0: 69 66 65 73 74 20 66 69 6c 65 20 67 69 76 65 6e ifest file given
0a00: 20 62 79 20 76 69 64 20 6f 75 74 20 6f 66 20 74 by vid out of t
0a10: 68 65 20 72 65 70 6f 73 69 74 6f 72 79 0a 2a 2a he repository.**
0a20: 20 61 6e 64 20 73 74 6f 72 65 20 69 74 20 69 6e and store it in
0a30: 20 74 68 65 20 72 6f 6f 74 20 6f 66 20 74 68 65 the root of the
0a40: 20 6c 6f 63 61 6c 20 63 68 65 63 6b 2d 6f 75 74 local check-out
0a50: 2e 0a 2a 2f 0a 76 6f 69 64 20 6d 61 6e 69 66 65 ..*/.void manife
0a60: 73 74 5f 74 6f 5f 64 69 73 6b 28 69 6e 74 20 76 st_to_disk(int v
0a70: 69 64 29 7b 0a 20 20 63 68 61 72 20 2a 7a 4d 61 id){. char *zMa
0a80: 6e 46 69 6c 65 3b 0a 20 20 42 6c 6f 62 20 6d 61 nFile;. Blob ma
0a90: 6e 69 66 65 73 74 3b 0a 20 20 42 6c 6f 62 20 68 nifest;. Blob h
0aa0: 61 73 68 3b 0a 20 20 42 6c 6f 62 20 66 69 6c 65 ash;. Blob file
0ab0: 6e 61 6d 65 3b 0a 20 20 69 6e 74 20 62 61 73 65 name;. int base
0ac0: 4c 65 6e 3b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 Len;. int i;.
0ad0: 4d 61 6e 69 66 65 73 74 20 6d 3b 0a 0a 20 20 62 Manifest m;.. b
0ae0: 6c 6f 62 5f 7a 65 72 6f 28 26 6d 61 6e 69 66 65 lob_zero(&manife
0af0: 73 74 29 3b 0a 20 20 7a 4d 61 6e 46 69 6c 65 20 st);. zManFile
0b00: 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 6d 61 6e = mprintf("%sman
0b10: 69 66 65 73 74 22 2c 20 67 2e 7a 4c 6f 63 61 6c ifest", g.zLocal
0b20: 52 6f 6f 74 29 3b 0a 20 20 63 6f 6e 74 65 6e 74 Root);. content
0b30: 5f 67 65 74 28 76 69 64 2c 20 26 6d 61 6e 69 66 _get(vid, &manif
0b40: 65 73 74 29 3b 0a 20 20 62 6c 6f 62 5f 77 72 69 est);. blob_wri
0b50: 74 65 5f 74 6f 5f 66 69 6c 65 28 26 6d 61 6e 69 te_to_file(&mani
0b60: 66 65 73 74 2c 20 7a 4d 61 6e 46 69 6c 65 29 3b fest, zManFile);
0b70: 0a 20 20 66 72 65 65 28 7a 4d 61 6e 46 69 6c 65 . free(zManFile
0b80: 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 );. blob_zero(&
0b90: 68 61 73 68 29 3b 0a 20 20 73 68 61 31 73 75 6d hash);. sha1sum
0ba0: 5f 62 6c 6f 62 28 26 6d 61 6e 69 66 65 73 74 2c _blob(&manifest,
0bb0: 20 26 68 61 73 68 29 3b 0a 20 20 7a 4d 61 6e 46 &hash);. zManF
0bc0: 69 6c 65 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 ile = mprintf("%
0bd0: 73 6d 61 6e 69 66 65 73 74 2e 75 75 69 64 22 2c smanifest.uuid",
0be0: 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 29 3b 0a g.zLocalRoot);.
0bf0: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28 26 68 blob_append(&h
0c00: 61 73 68 2c 20 22 5c 6e 22 2c 20 31 29 3b 0a 20 ash, "\n", 1);.
0c10: 20 62 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f 66 blob_write_to_f
0c20: 69 6c 65 28 26 68 61 73 68 2c 20 7a 4d 61 6e 46 ile(&hash, zManF
0c30: 69 6c 65 29 3b 0a 20 20 66 72 65 65 28 7a 4d 61 ile);. free(zMa
0c40: 6e 46 69 6c 65 29 3b 0a 20 20 62 6c 6f 62 5f 72 nFile);. blob_r
0c50: 65 73 65 74 28 26 68 61 73 68 29 3b 0a 20 20 6d eset(&hash);. m
0c60: 61 6e 69 66 65 73 74 5f 70 61 72 73 65 28 26 6d anifest_parse(&m
0c70: 2c 20 26 6d 61 6e 69 66 65 73 74 29 3b 0a 20 20 , &manifest);.
0c80: 62 6c 6f 62 5f 7a 65 72 6f 28 26 66 69 6c 65 6e blob_zero(&filen
0c90: 61 6d 65 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 ame);. blob_app
0ca0: 65 6e 64 66 28 26 66 69 6c 65 6e 61 6d 65 2c 20 endf(&filename,
0cb0: 22 25 73 2f 22 2c 20 67 2e 7a 4c 6f 63 61 6c 52 "%s/", g.zLocalR
0cc0: 6f 6f 74 29 3b 0a 20 20 62 61 73 65 4c 65 6e 20 oot);. baseLen
0cd0: 3d 20 62 6c 6f 62 5f 73 69 7a 65 28 26 66 69 6c = blob_size(&fil
0ce0: 65 6e 61 6d 65 29 3b 0a 20 20 66 6f 72 28 69 3d ename);. for(i=
0cf0: 30 3b 20 69 3c 6d 2e 6e 46 69 6c 65 3b 20 69 2b 0; i<m.nFile; i+
0d00: 2b 29 7b 20 0a 20 20 20 20 69 6e 74 20 69 73 45 +){ . int isE
0d10: 78 65 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 xe;. blob_app
0d20: 65 6e 64 28 26 66 69 6c 65 6e 61 6d 65 2c 20 6d end(&filename, m
0d30: 2e 61 46 69 6c 65 5b 69 5d 2e 7a 4e 61 6d 65 2c .aFile[i].zName,
0d40: 20 2d 31 29 3b 0a 20 20 20 20 69 73 45 78 65 20 -1);. isExe
0d50: 3d 20 6d 2e 61 46 69 6c 65 5b 69 5d 2e 7a 50 65 = m.aFile[i].zPe
0d60: 72 6d 20 26 26 20 73 74 72 73 74 72 28 6d 2e 61 rm && strstr(m.a
0d70: 46 69 6c 65 5b 69 5d 2e 7a 50 65 72 6d 2c 20 22 File[i].zPerm, "
0d80: 78 22 29 3b 0a 20 20 20 20 66 69 6c 65 5f 73 65 x");. file_se
0d90: 74 65 78 65 28 62 6c 6f 62 5f 73 74 72 28 26 66 texe(blob_str(&f
0da0: 69 6c 65 6e 61 6d 65 29 2c 20 69 73 45 78 65 29 ilename), isExe)
0db0: 3b 0a 20 20 20 20 62 6c 6f 62 5f 72 65 73 69 7a ;. blob_resiz
0dc0: 65 28 26 66 69 6c 65 6e 61 6d 65 2c 20 62 61 73 e(&filename, bas
0dd0: 65 4c 65 6e 29 3b 0a 20 20 7d 0a 20 20 62 6c 6f eLen);. }. blo
0de0: 62 5f 72 65 73 65 74 28 26 66 69 6c 65 6e 61 6d b_reset(&filenam
0df0: 65 29 3b 0a 20 20 6d 61 6e 69 66 65 73 74 5f 63 e);. manifest_c
0e00: 6c 65 61 72 28 26 6d 29 3b 0a 7d 0a 0a 2f 2a 0a lear(&m);.}../*.
0e10: 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 63 68 65 63 ** COMMAND: chec
0e20: 6b 6f 75 74 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 kout.**.** Usage
0e30: 3a 20 25 66 6f 73 73 69 6c 20 63 68 65 63 6b 6f : %fossil checko
0e40: 75 74 20 56 45 52 53 49 4f 4e 20 3f 2d 66 7c 2d ut VERSION ?-f|-
0e50: 2d 66 6f 72 63 65 3f 0a 2a 2a 0a 2a 2a 20 43 68 -force?.**.** Ch
0e60: 65 63 6b 20 6f 75 74 20 61 20 76 65 72 73 69 6f eck out a versio
0e70: 6e 20 73 70 65 63 69 66 69 65 64 20 6f 6e 20 74 n specified on t
0e80: 68 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 2e he command-line.
0e90: 20 20 54 68 69 73 20 63 6f 6d 6d 61 6e 64 0a 2a This command.*
0ea0: 2a 20 77 69 6c 6c 20 6e 6f 74 20 6f 76 65 72 77 * will not overw
0eb0: 72 69 74 65 20 65 64 69 74 65 64 20 66 69 6c 65 rite edited file
0ec0: 73 20 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74 s in the current
0ed0: 20 63 68 65 63 6b 6f 75 74 20 75 6e 6c 65 73 73 checkout unless
0ee0: 0a 2a 2a 20 74 68 65 20 2d 2d 66 6f 72 63 65 20 .** the --force
0ef0: 6f 70 74 69 6f 6e 20 61 70 70 65 61 72 73 20 6f option appears o
0f00: 6e 20 74 68 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69 n the command-li
0f10: 6e 65 2e 0a 2a 2a 0a 2a 2a 20 53 65 65 20 61 6c ne..**.** See al
0f20: 73 6f 20 74 68 65 20 22 75 70 64 61 74 65 22 20 so the "update"
0f30: 63 6f 6d 6d 61 6e 64 2e 0a 2a 2f 0a 76 6f 69 64 command..*/.void
0f40: 20 63 68 65 63 6b 6f 75 74 5f 63 6d 64 28 76 6f checkout_cmd(vo
0f50: 69 64 29 7b 0a 20 20 69 6e 74 20 66 6f 72 63 65 id){. int force
0f60: 46 6c 61 67 3b 0a 20 20 69 6e 74 20 6e 6f 57 72 Flag;. int noWr
0f70: 69 74 65 3b 0a 20 20 69 6e 74 20 76 69 64 2c 20 ite;. int vid,
0f80: 70 72 69 6f 72 3b 0a 20 20 42 6c 6f 62 20 63 6b prior;. Blob ck
0f90: 73 75 6d 31 2c 20 63 6b 73 75 6d 31 62 2c 20 63 sum1, cksum1b, c
0fa0: 6b 73 75 6d 32 3b 0a 20 20 0a 20 20 64 62 5f 6d ksum2;. . db_m
0fb0: 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72 ust_be_within_tr
0fc0: 65 65 28 29 3b 0a 20 20 64 62 5f 62 65 67 69 6e ee();. db_begin
0fd0: 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a _transaction();.
0fe0: 20 20 66 6f 72 63 65 46 6c 61 67 20 3d 20 66 69 forceFlag = fi
0ff0: 6e 64 5f 6f 70 74 69 6f 6e 28 22 66 6f 72 63 65 nd_option("force
1000: 22 2c 22 66 22 2c 30 29 21 3d 30 3b 0a 20 20 6e ","f",0)!=0;. n
1010: 6f 57 72 69 74 65 20 3d 20 66 69 6e 64 5f 6f 70 oWrite = find_op
1020: 74 69 6f 6e 28 22 64 6f 6e 74 77 72 69 74 65 22 tion("dontwrite"
1030: 2c 30 2c 30 29 21 3d 30 3b 0a 20 20 69 66 28 20 ,0,0)!=0;. if(
1040: 67 2e 61 72 67 63 21 3d 33 20 29 20 75 73 61 67 g.argc!=3 ) usag
1050: 65 28 22 3f 2d 2d 66 6f 72 63 65 3f 20 56 45 52 e("?--force? VER
1060: 53 49 4f 4e 22 29 3b 0a 20 20 69 66 28 20 21 66 SION");. if( !f
1070: 6f 72 63 65 46 6c 61 67 20 26 26 20 75 6e 73 61 orceFlag && unsa
1080: 76 65 64 5f 63 68 61 6e 67 65 73 28 29 3d 3d 31 ved_changes()==1
1090: 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 ){. fossil_f
10a0: 61 74 61 6c 28 22 74 68 65 72 65 20 61 72 65 20 atal("there are
10b0: 75 6e 73 61 76 65 64 20 63 68 61 6e 67 65 73 20 unsaved changes
10c0: 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20 63 in the current c
10d0: 68 65 63 6b 6f 75 74 22 29 3b 0a 20 20 7d 0a 20 heckout");. }.
10e0: 20 69 66 28 20 66 6f 72 63 65 46 6c 61 67 20 29 if( forceFlag )
10f0: 7b 0a 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 {. db_multi_e
1100: 78 65 63 28 22 44 45 4c 45 54 45 20 46 52 4f 4d xec("DELETE FROM
1110: 20 76 66 69 6c 65 22 29 3b 0a 20 20 20 20 70 72 vfile");. pr
1120: 69 6f 72 20 3d 20 30 3b 0a 20 20 7d 65 6c 73 65 ior = 0;. }else
1130: 7b 0a 20 20 20 20 70 72 69 6f 72 20 3d 20 64 62 {. prior = db
1140: 5f 6c 67 65 74 5f 69 6e 74 28 22 63 68 65 63 6b _lget_int("check
1150: 6f 75 74 22 2c 30 29 3b 0a 20 20 7d 0a 20 20 76 out",0);. }. v
1160: 69 64 20 3d 20 6c 6f 61 64 5f 76 66 69 6c 65 28 id = load_vfile(
1170: 67 2e 61 72 67 76 5b 32 5d 29 3b 0a 20 20 69 66 g.argv[2]);. if
1180: 28 20 70 72 69 6f 72 3d 3d 76 69 64 20 29 7b 0a ( prior==vid ){.
1190: 20 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 7d 0a return;. }.
11a0: 20 20 69 66 28 20 21 6e 6f 57 72 69 74 65 20 29 if( !noWrite )
11b0: 7b 0a 20 20 20 20 75 6e 63 68 65 63 6b 6f 75 74 {. uncheckout
11c0: 28 70 72 69 6f 72 29 3b 0a 20 20 7d 0a 20 20 64 (prior);. }. d
11d0: 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 44 45 b_multi_exec("DE
11e0: 4c 45 54 45 20 46 52 4f 4d 20 76 66 69 6c 65 20 LETE FROM vfile
11f0: 57 48 45 52 45 20 76 69 64 21 3d 25 64 22 2c 20 WHERE vid!=%d",
1200: 76 69 64 29 3b 0a 20 20 69 66 28 20 21 6e 6f 57 vid);. if( !noW
1210: 72 69 74 65 20 29 7b 0a 20 20 20 20 76 66 69 6c rite ){. vfil
1220: 65 5f 74 6f 5f 64 69 73 6b 28 76 69 64 2c 20 30 e_to_disk(vid, 0
1230: 2c 20 31 29 3b 0a 20 20 20 20 6d 61 6e 69 66 65 , 1);. manife
1240: 73 74 5f 74 6f 5f 64 69 73 6b 28 76 69 64 29 3b st_to_disk(vid);
1250: 0a 20 20 20 20 64 62 5f 6c 73 65 74 5f 69 6e 74 . db_lset_int
1260: 28 22 63 68 65 63 6b 6f 75 74 22 2c 20 76 69 64 ("checkout", vid
1270: 29 3b 0a 20 20 20 20 75 6e 64 6f 5f 72 65 73 65 );. undo_rese
1280: 74 28 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 6d 75 t();. }. db_mu
1290: 6c 74 69 5f 65 78 65 63 28 22 44 45 4c 45 54 45 lti_exec("DELETE
12a0: 20 46 52 4f 4d 20 76 6d 65 72 67 65 22 29 3b 0a FROM vmerge");.
12b0: 20 20 76 66 69 6c 65 5f 61 67 67 72 65 67 61 74 vfile_aggregat
12c0: 65 5f 63 68 65 63 6b 73 75 6d 5f 6d 61 6e 69 66 e_checksum_manif
12d0: 65 73 74 28 76 69 64 2c 20 26 63 6b 73 75 6d 31 est(vid, &cksum1
12e0: 2c 20 26 63 6b 73 75 6d 31 62 29 3b 0a 20 20 76 , &cksum1b);. v
12f0: 66 69 6c 65 5f 61 67 67 72 65 67 61 74 65 5f 63 file_aggregate_c
1300: 68 65 63 6b 73 75 6d 5f 64 69 73 6b 28 76 69 64 hecksum_disk(vid
1310: 2c 20 26 63 6b 73 75 6d 32 29 3b 0a 20 20 69 66 , &cksum2);. if
1320: 28 20 62 6c 6f 62 5f 63 6f 6d 70 61 72 65 28 26 ( blob_compare(&
1330: 63 6b 73 75 6d 31 2c 20 26 63 6b 73 75 6d 32 29 cksum1, &cksum2)
1340: 20 29 7b 0a 20 20 20 20 70 72 69 6e 74 66 28 22 ){. printf("
1350: 57 41 52 4e 49 4e 47 3a 20 6d 61 6e 69 66 65 73 WARNING: manifes
1360: 74 20 63 68 65 63 6b 73 75 6d 20 64 6f 65 73 20 t checksum does
1370: 6e 6f 74 20 61 67 72 65 65 20 77 69 74 68 20 64 not agree with d
1380: 69 73 6b 5c 6e 22 29 3b 0a 20 20 7d 0a 20 20 69 isk\n");. }. i
1390: 66 28 20 62 6c 6f 62 5f 63 6f 6d 70 61 72 65 28 f( blob_compare(
13a0: 26 63 6b 73 75 6d 31 2c 20 26 63 6b 73 75 6d 31 &cksum1, &cksum1
13b0: 62 29 20 29 7b 0a 20 20 20 20 70 72 69 6e 74 66 b) ){. printf
13c0: 28 22 57 41 52 4e 49 4e 47 3a 20 6d 61 6e 69 66 ("WARNING: manif
13d0: 65 73 74 20 63 68 65 63 6b 73 75 6d 20 64 6f 65 est checksum doe
13e0: 73 20 6e 6f 74 20 61 67 72 65 65 20 77 69 74 68 s not agree with
13f0: 20 6d 61 6e 69 66 65 73 74 5c 6e 22 29 3b 0a 20 manifest\n");.
1400: 20 7d 0a 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e }. db_end_tran
1410: 73 61 63 74 69 6f 6e 28 30 29 3b 0a 7d 0a 0a 2f saction(0);.}../
1420: 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 63 6c *.** COMMAND: cl
1430: 6f 73 65 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a ose.**.** Usage:
1440: 20 25 66 6f 73 73 69 6c 20 63 6c 6f 73 65 20 3f %fossil close ?
1450: 2d 66 7c 2d 2d 66 6f 72 63 65 3f 0a 2a 2a 0a 2a -f|--force?.**.*
1460: 2a 20 54 68 65 20 6f 70 70 6f 73 69 74 65 20 6f * The opposite o
1470: 66 20 22 6f 70 65 6e 22 2e 20 20 43 6c 6f 73 65 f "open". Close
1480: 20 74 68 65 20 63 75 72 72 65 6e 74 20 64 61 74 the current dat
1490: 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e abase connection
14a0: 2e 0a 2a 2a 20 52 65 71 75 69 72 65 20 61 20 2d ..** Require a -
14b0: 66 20 6f 72 20 2d 2d 66 6f 72 63 65 20 66 6c 61 f or --force fla
14c0: 67 20 69 66 20 74 68 65 72 65 20 61 72 65 20 75 g if there are u
14d0: 6e 73 61 76 65 64 20 63 68 61 6e 67 65 64 20 69 nsaved changed i
14e0: 6e 20 74 68 65 0a 2a 2a 20 63 75 72 72 65 6e 74 n the.** current
14f0: 20 63 68 65 63 6b 2d 6f 75 74 2e 0a 2a 2f 0a 76 check-out..*/.v
1500: 6f 69 64 20 63 6c 6f 73 65 5f 63 6d 64 28 76 6f oid close_cmd(vo
1510: 69 64 29 7b 0a 20 20 69 6e 74 20 66 6f 72 63 65 id){. int force
1520: 46 6c 61 67 20 3d 20 66 69 6e 64 5f 6f 70 74 69 Flag = find_opti
1530: 6f 6e 28 22 66 6f 72 63 65 22 2c 22 66 22 2c 30 on("force","f",0
1540: 29 21 3d 30 3b 0a 20 20 64 62 5f 6d 75 73 74 5f )!=0;. db_must_
1550: 62 65 5f 77 69 74 68 69 6e 5f 74 72 65 65 28 29 be_within_tree()
1560: 3b 0a 20 20 69 66 28 20 21 66 6f 72 63 65 46 6c ;. if( !forceFl
1570: 61 67 20 26 26 20 75 6e 73 61 76 65 64 5f 63 68 ag && unsaved_ch
1580: 61 6e 67 65 73 28 29 3d 3d 31 20 29 7b 0a 20 20 anges()==1 ){.
1590: 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 fossil_fatal("
15a0: 74 68 65 72 65 20 61 72 65 20 75 6e 73 61 76 65 there are unsave
15b0: 64 20 63 68 61 6e 67 65 73 20 69 6e 20 74 68 65 d changes in the
15c0: 20 63 75 72 72 65 6e 74 20 63 68 65 63 6b 6f 75 current checkou
15d0: 74 22 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 63 6c t");. }. db_cl
15e0: 6f 73 65 28 29 3b 0a 20 20 75 6e 6c 69 6e 6b 28 ose();. unlink(
15f0: 6d 70 72 69 6e 74 66 28 22 25 73 5f 46 4f 53 53 mprintf("%s_FOSS
1600: 49 4c 5f 22 2c 20 67 2e 7a 4c 6f 63 61 6c 52 6f IL_", g.zLocalRo
1610: 6f 74 29 29 3b 0a 20 20 75 6e 6c 69 6e 6b 28 6d ot));. unlink(m
1620: 70 72 69 6e 74 66 28 22 25 73 5f 46 4f 53 53 49 printf("%s_FOSSI
1630: 4c 5f 2d 6a 6f 75 72 6e 61 6c 22 2c 20 67 2e 7a L_-journal", g.z
1640: 4c 6f 63 61 6c 52 6f 6f 74 29 29 3b 0a 7d 0a LocalRoot));.}.