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 62 72 61 6e 63 68 2e 68 nclude "branch.h
03f0: 22 0a 23 69 6e 63 6c 75 64 65 20 3c 61 73 73 65 ".#include <asse
0400: 72 74 2e 68 3e 0a 0a 76 6f 69 64 20 62 72 61 6e rt.h>..void bran
0410: 63 68 5f 6e 65 77 28 76 6f 69 64 29 7b 0a 20 20 ch_new(void){.
0420: 69 6e 74 20 76 69 64 2c 20 6e 76 69 64 2c 20 6e int vid, nvid, n
0430: 6f 53 69 67 6e 3b 0a 20 20 53 74 6d 74 20 71 3b oSign;. Stmt q;
0440: 0a 20 20 63 68 61 72 20 2a 7a 42 72 61 6e 63 68 . char *zBranch
0450: 2c 20 2a 7a 55 75 69 64 2c 20 2a 7a 44 61 74 65 , *zUuid, *zDate
0460: 2c 20 2a 7a 43 6f 6d 6d 65 6e 74 2c 20 2a 7a 4d , *zComment, *zM
0470: 61 6e 69 66 65 73 74 46 69 6c 65 3b 0a 20 20 63 anifestFile;. c
0480: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 43 6f 6c 6f onst char *zColo
0490: 72 3b 0a 20 20 42 6c 6f 62 20 6d 61 6e 69 66 65 r;. Blob manife
04a0: 73 74 3b 0a 20 20 42 6c 6f 62 20 6d 63 6b 73 75 st;. Blob mcksu
04b0: 6d 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 m; /*
04c0: 53 65 6c 66 2d 63 68 65 63 6b 73 75 6d 20 6f 6e Self-checksum on
04d0: 20 74 68 65 20 6d 61 6e 69 66 65 73 74 20 2a 2f the manifest */
04e0: 0a 20 20 42 6c 6f 62 20 63 6b 73 75 6d 31 2c 20 . Blob cksum1,
04f0: 63 6b 73 75 6d 32 2c 20 64 73 6b 63 6b 73 75 6d cksum2, dskcksum
0500: 31 3b 20 20 20 2f 2a 20 42 65 66 6f 72 65 20 61 1; /* Before a
0510: 6e 64 20 61 66 74 65 72 20 63 6f 6d 6d 69 74 20 nd after commit
0520: 63 68 65 63 6b 73 75 6d 73 20 2a 2f 0a 20 20 42 checksums */. B
0530: 6c 6f 62 20 63 6b 73 75 6d 31 62 3b 20 20 20 20 lob cksum1b;
0540: 20 20 20 20 20 20 2f 2a 20 43 68 65 63 6b 73 75 /* Checksu
0550: 6d 20 72 65 63 6f 72 64 65 64 20 69 6e 20 74 68 m recorded in th
0560: 65 20 6d 61 6e 69 66 65 73 74 20 2a 2f 0a 20 0a e manifest */. .
0570: 20 20 6e 6f 53 69 67 6e 20 3d 20 66 69 6e 64 5f noSign = find_
0580: 6f 70 74 69 6f 6e 28 22 6e 6f 73 69 67 6e 22 2c option("nosign",
0590: 22 22 2c 30 29 21 3d 30 3b 0a 20 20 64 62 5f 6d "",0)!=0;. db_m
05a0: 75 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72 ust_be_within_tr
05b0: 65 65 28 29 3b 0a 20 20 6e 6f 53 69 67 6e 20 3d ee();. noSign =
05c0: 20 64 62 5f 67 65 74 5f 69 6e 74 28 22 6f 6d 69 db_get_int("omi
05d0: 74 2d 63 69 2d 73 69 67 22 2c 20 30 29 7c 6e 6f t-ci-sig", 0)|no
05e0: 53 69 67 6e 3b 0a 20 20 7a 43 6f 6c 6f 72 20 3d Sign;. zColor =
05f0: 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 62 67 find_option("bg
0600: 63 6f 6c 6f 72 22 2c 22 63 22 2c 31 29 3b 0a 20 color","c",1);.
0610: 20 0a 20 20 76 65 72 69 66 79 5f 61 6c 6c 5f 6f . verify_all_o
0620: 70 74 69 6f 6e 73 28 29 3b 0a 20 20 0a 20 20 2f ptions();. . /
0630: 2a 20 66 6f 73 73 69 6c 20 62 72 61 6e 63 68 20 * fossil branch
0640: 6e 65 77 20 6e 61 6d 65 20 2a 2f 0a 20 20 69 66 new name */. if
0650: 28 20 67 2e 61 72 67 63 3c 33 20 29 7b 0a 20 20 ( g.argc<3 ){.
0660: 20 20 75 73 61 67 65 28 22 62 72 61 6e 63 68 20 usage("branch
0670: 6e 65 77 20 3f 2d 62 67 63 6f 6c 6f 72 20 43 4f new ?-bgcolor CO
0680: 4c 4f 52 20 42 52 41 4e 43 48 2d 4e 41 4d 45 22 LOR BRANCH-NAME"
0690: 29 3b 0a 20 20 7d 0a 20 20 7a 42 72 61 6e 63 68 );. }. zBranch
06a0: 20 3d 20 67 2e 61 72 67 76 5b 33 5d 3b 0a 0a 20 = g.argv[3];..
06b0: 20 75 73 65 72 5f 73 65 6c 65 63 74 28 29 3b 0a user_select();.
06c0: 20 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 db_begin_trans
06d0: 61 63 74 69 6f 6e 28 29 3b 0a 20 20 69 66 28 20 action();. if(
06e0: 75 6e 73 61 76 65 64 5f 63 68 61 6e 67 65 73 28 unsaved_changes(
06f0: 29 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f ) ){. fossil_
0700: 70 61 6e 69 63 28 22 74 68 65 72 65 20 61 72 65 panic("there are
0710: 20 75 6e 63 6f 6d 6d 69 74 74 65 64 20 63 68 61 uncommitted cha
0720: 6e 67 65 73 2e 20 70 6c 65 61 73 65 20 63 6f 6d nges. please com
0730: 6d 69 74 20 66 69 72 73 74 22 29 3b 0a 20 20 7d mit first");. }
0740: 0a 0a 20 20 2f 2a 20 43 72 65 61 74 65 20 61 20 .. /* Create a
0750: 6e 65 77 20 72 69 64 3f 20 2a 2f 0a 20 20 7a 4d new rid? */. zM
0760: 61 6e 69 66 65 73 74 46 69 6c 65 20 3d 20 6d 70 anifestFile = mp
0770: 72 69 6e 74 66 28 22 25 73 6d 61 6e 69 66 65 73 rintf("%smanifes
0780: 74 22 2c 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 t", g.zLocalRoot
0790: 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 61 64 5f 66 );. blob_read_f
07a0: 72 6f 6d 5f 66 69 6c 65 28 26 6d 61 6e 69 66 65 rom_file(&manife
07b0: 73 74 2c 20 7a 4d 61 6e 69 66 65 73 74 46 69 6c st, zManifestFil
07c0: 65 29 3b 0a 20 20 66 72 65 65 28 7a 4d 61 6e 69 e);. free(zMani
07d0: 66 65 73 74 46 69 6c 65 29 3b 0a 20 20 0a 20 20 festFile);. .
07e0: 7a 44 61 74 65 20 3d 20 64 62 5f 74 65 78 74 28 zDate = db_text(
07f0: 30 2c 20 22 53 45 4c 45 43 54 20 64 61 74 65 74 0, "SELECT datet
0800: 69 6d 65 28 27 6e 6f 77 27 29 22 29 3b 0a 20 20 ime('now')");.
0810: 7a 44 61 74 65 5b 31 30 5d 20 3d 20 27 54 27 3b zDate[10] = 'T';
0820: 0a 20 20 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e . . blob_appen
0830: 64 66 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 44 df(&manifest, "D
0840: 20 25 73 5c 6e 22 2c 20 7a 44 61 74 65 29 3b 0a %s\n", zDate);.
0850: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 blob_appendf(&
0860: 6d 61 6e 69 66 65 73 74 2c 20 22 54 20 2a 25 46 manifest, "T *%F
0870: 20 2a 5c 6e 22 2c 20 7a 42 72 61 6e 63 68 29 3b *\n", zBranch);
0880: 0a 0a 20 20 6d 64 35 73 75 6d 5f 69 6e 69 74 28 .. md5sum_init(
0890: 29 3b 0a 20 20 6d 64 35 73 75 6d 5f 73 74 65 70 );. md5sum_step
08a0: 5f 62 6c 6f 62 28 26 6d 61 6e 69 66 65 73 74 29 _blob(&manifest)
08b0: 3b 0a 20 20 6d 64 35 73 75 6d 5f 66 69 6e 69 73 ;. md5sum_finis
08c0: 68 28 26 63 6b 73 75 6d 31 29 3b 0a 20 20 0a 20 h(&cksum1);. .
08d0: 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 6d 61 6e blob_reset(&man
08e0: 69 66 65 73 74 29 3b 0a 0a 20 20 76 69 64 20 3d ifest);.. vid =
08f0: 20 64 62 5f 6c 67 65 74 5f 69 6e 74 28 22 63 68 db_lget_int("ch
0900: 65 63 6b 6f 75 74 22 2c 20 30 29 3b 0a 20 20 76 eckout", 0);. v
0910: 66 69 6c 65 5f 61 67 67 72 65 67 61 74 65 5f 63 file_aggregate_c
0920: 68 65 63 6b 73 75 6d 5f 64 69 73 6b 28 76 69 64 hecksum_disk(vid
0930: 2c 20 26 64 73 6b 63 6b 73 75 6d 31 29 3b 0a 20 , &dskcksum1);.
0940: 20 0a 20 20 2f 2a 20 43 72 65 61 74 65 20 6f 75 . /* Create ou
0950: 72 20 6e 65 77 20 6d 61 6e 69 66 65 73 74 20 2a r new manifest *
0960: 2f 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 6d /. blob_zero(&m
0970: 61 6e 69 66 65 73 74 29 3b 0a 20 20 7a 43 6f 6d anifest);. zCom
0980: 6d 65 6e 74 20 3d 20 6d 70 72 69 6e 74 66 28 22 ment = mprintf("
0990: 42 72 61 6e 63 68 20 63 72 65 61 74 65 64 20 25 Branch created %
09a0: 73 22 2c 20 7a 42 72 61 6e 63 68 29 3b 0a 20 20 s", zBranch);.
09b0: 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 blob_appendf(&ma
09c0: 6e 69 66 65 73 74 2c 20 22 43 20 25 46 5c 6e 22 nifest, "C %F\n"
09d0: 2c 20 7a 43 6f 6d 6d 65 6e 74 29 3b 0a 20 20 62 , zComment);. b
09e0: 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e lob_appendf(&man
09f0: 69 66 65 73 74 2c 20 22 44 20 25 73 5c 6e 22 2c ifest, "D %s\n",
0a00: 20 7a 44 61 74 65 29 3b 0a 0a 20 20 64 62 5f 70 zDate);.. db_p
0a10: 72 65 70 61 72 65 28 26 71 2c 0a 20 20 20 20 22 repare(&q,. "
0a20: 53 45 4c 45 43 54 20 70 61 74 68 6e 61 6d 65 2c SELECT pathname,
0a30: 20 75 75 69 64 20 46 52 4f 4d 20 76 66 69 6c 65 uuid FROM vfile
0a40: 20 4a 4f 49 4e 20 62 6c 6f 62 20 4f 4e 20 76 66 JOIN blob ON vf
0a50: 69 6c 65 2e 6d 72 69 64 3d 62 6c 6f 62 2e 72 69 ile.mrid=blob.ri
0a60: 64 22 0a 20 20 20 20 22 20 57 48 45 52 45 20 4e d". " WHERE N
0a70: 4f 54 20 64 65 6c 65 74 65 64 20 41 4e 44 20 76 OT deleted AND v
0a80: 66 69 6c 65 2e 76 69 64 3d 25 64 22 0a 20 20 20 file.vid=%d".
0a90: 20 22 20 4f 52 44 45 52 20 42 59 20 31 22 2c 20 " ORDER BY 1",
0aa0: 76 69 64 29 3b 0a 20 20 77 68 69 6c 65 28 20 64 vid);. while( d
0ab0: 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 b_step(&q)==SQLI
0ac0: 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 63 6f TE_ROW ){. co
0ad0: 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 20 nst char *zName
0ae0: 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 = db_column_text
0af0: 28 26 71 2c 20 30 29 3b 0a 20 20 20 20 63 6f 6e (&q, 0);. con
0b00: 73 74 20 63 68 61 72 20 2a 7a 55 75 69 64 20 3d st char *zUuid =
0b10: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 db_column_text(
0b20: 26 71 2c 20 31 29 3b 0a 20 20 20 20 62 6c 6f 62 &q, 1);. blob
0b30: 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 _appendf(&manife
0b40: 73 74 2c 20 22 46 20 25 46 20 25 73 5c 6e 22 2c st, "F %F %s\n",
0b50: 20 7a 4e 61 6d 65 2c 20 7a 55 75 69 64 29 3b 0a zName, zUuid);.
0b60: 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a }. db_finaliz
0b70: 65 28 26 71 29 3b 0a 20 20 0a 20 20 7a 55 75 69 e(&q);. . zUui
0b80: 64 20 3d 20 64 62 5f 74 65 78 74 28 30 2c 20 22 d = db_text(0, "
0b90: 53 45 4c 45 43 54 20 75 75 69 64 20 46 52 4f 4d SELECT uuid FROM
0ba0: 20 62 6c 6f 62 20 57 48 45 52 45 20 72 69 64 3d blob WHERE rid=
0bb0: 25 64 22 2c 20 76 69 64 29 3b 0a 20 20 62 6c 6f %d", vid);. blo
0bc0: 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 b_appendf(&manif
0bd0: 65 73 74 2c 20 22 50 20 25 73 5c 6e 22 2c 20 7a est, "P %s\n", z
0be0: 55 75 69 64 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 Uuid);. blob_ap
0bf0: 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 74 2c pendf(&manifest,
0c00: 20 22 52 20 25 62 5c 6e 22 2c 20 26 63 6b 73 75 "R %b\n", &cksu
0c10: 6d 31 29 3b 0a 20 20 0a 20 20 69 66 28 20 7a 43 m1);. . if( zC
0c20: 6f 6c 6f 72 21 3d 30 20 29 7b 0a 20 20 20 20 62 olor!=0 ){. b
0c30: 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e lob_appendf(&man
0c40: 69 66 65 73 74 2c 20 22 54 20 2a 62 67 63 6f 6c ifest, "T *bgcol
0c50: 6f 72 20 2a 20 25 46 5c 6e 22 2c 20 7a 43 6f 6c or * %F\n", zCol
0c60: 6f 72 29 3b 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f or);. }. blob_
0c70: 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 appendf(&manifes
0c80: 74 2c 20 22 54 20 2a 25 46 20 2a 5c 6e 22 2c 20 t, "T *%F *\n",
0c90: 7a 42 72 61 6e 63 68 29 3b 0a 0a 20 20 2f 2a 20 zBranch);.. /*
0ca0: 43 61 6e 63 65 6c 20 61 6e 79 20 74 61 67 73 20 Cancel any tags
0cb0: 74 68 61 74 20 70 72 6f 70 61 67 61 74 65 20 2a that propagate *
0cc0: 2f 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 /. db_prepare(&
0cd0: 71 2c 20 0a 20 20 20 20 20 20 22 53 45 4c 45 43 q, . "SELEC
0ce0: 54 20 74 61 67 6e 61 6d 65 22 0a 20 20 20 20 20 T tagname".
0cf0: 20 22 20 20 46 52 4f 4d 20 74 61 67 78 72 65 66 " FROM tagxref
0d00: 20 4a 4f 49 4e 20 74 61 67 20 4f 4e 20 74 61 67 JOIN tag ON tag
0d10: 78 72 65 66 2e 74 61 67 69 64 3d 74 61 67 2e 74 xref.tagid=tag.t
0d20: 61 67 69 64 22 0a 20 20 20 20 20 20 22 20 57 48 agid". " WH
0d30: 45 52 45 20 72 69 64 3d 25 64 20 41 4e 44 20 74 ERE rid=%d AND t
0d40: 61 67 74 79 70 65 3d 32 22 2c 20 76 69 64 29 3b agtype=2", vid);
0d50: 0a 20 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65 . while( db_ste
0d60: 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f p(&q)==SQLITE_RO
0d70: 57 20 29 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 W ){. const c
0d80: 68 61 72 20 2a 7a 54 61 67 6e 61 6d 65 20 3d 20 har *zTagname =
0d90: 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 db_column_text(&
0da0: 71 2c 20 30 29 3b 0a 20 20 20 20 62 6c 6f 62 5f q, 0);. blob_
0db0: 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 appendf(&manifes
0dc0: 74 2c 20 22 54 20 2d 25 73 20 2a 5c 6e 22 2c 20 t, "T -%s *\n",
0dd0: 7a 54 61 67 6e 61 6d 65 29 3b 0a 20 20 7d 0a 20 zTagname);. }.
0de0: 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 db_finalize(&q)
0df0: 3b 0a 20 20 0a 20 20 62 6c 6f 62 5f 61 70 70 65 ;. . blob_appe
0e00: 6e 64 66 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 ndf(&manifest, "
0e10: 55 20 25 46 5c 6e 22 2c 20 67 2e 7a 4c 6f 67 69 U %F\n", g.zLogi
0e20: 6e 29 3b 0a 20 20 6d 64 35 73 75 6d 5f 62 6c 6f n);. md5sum_blo
0e30: 62 28 26 6d 61 6e 69 66 65 73 74 2c 20 26 6d 63 b(&manifest, &mc
0e40: 6b 73 75 6d 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 ksum);. blob_ap
0e50: 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 74 2c pendf(&manifest,
0e60: 20 22 5a 20 25 62 5c 6e 22 2c 20 26 6d 63 6b 73 "Z %b\n", &mcks
0e70: 75 6d 29 3b 0a 20 20 69 66 28 20 21 6e 6f 53 69 um);. if( !noSi
0e80: 67 6e 20 26 26 20 63 6c 65 61 72 73 69 67 6e 28 gn && clearsign(
0e90: 26 6d 61 6e 69 66 65 73 74 2c 20 26 6d 61 6e 69 &manifest, &mani
0ea0: 66 65 73 74 29 20 29 7b 0a 20 20 20 20 42 6c 6f fest) ){. Blo
0eb0: 62 20 61 6e 73 3b 0a 20 20 20 20 62 6c 6f 62 5f b ans;. blob_
0ec0: 7a 65 72 6f 28 26 61 6e 73 29 3b 0a 20 20 20 20 zero(&ans);.
0ed0: 70 72 6f 6d 70 74 5f 75 73 65 72 28 22 75 6e 61 prompt_user("una
0ee0: 62 6c 65 20 74 6f 20 73 69 67 6e 20 6d 61 6e 69 ble to sign mani
0ef0: 66 65 73 74 2e 20 20 63 6f 6e 74 69 6e 75 65 20 fest. continue
0f00: 5b 79 2f 4e 5d 3f 20 22 2c 20 26 61 6e 73 29 3b [y/N]? ", &ans);
0f10: 0a 20 20 20 20 69 66 28 20 62 6c 6f 62 5f 73 74 . if( blob_st
0f20: 72 28 26 61 6e 73 29 5b 30 5d 21 3d 27 79 27 20 r(&ans)[0]!='y'
0f30: 29 7b 0a 20 20 20 20 20 20 64 62 5f 65 6e 64 5f ){. db_end_
0f40: 74 72 61 6e 73 61 63 74 69 6f 6e 28 31 29 3b 0a transaction(1);.
0f50: 20 20 20 20 20 20 65 78 69 74 28 31 29 3b 0a 20 exit(1);.
0f60: 20 20 20 7d 0a 20 20 7d 0a 20 20 0a 20 20 2f 2a }. }. . /*
0f70: 62 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f 66 69 blob_write_to_fi
0f80: 6c 65 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 6d le(&manifest, "m
0f90: 61 6e 69 66 65 73 74 2e 6e 65 77 22 29 3b 2a 2f anifest.new");*/
0fa0: 0a 0a 20 20 6e 76 69 64 20 3d 20 63 6f 6e 74 65 .. nvid = conte
0fb0: 6e 74 5f 70 75 74 28 26 6d 61 6e 69 66 65 73 74 nt_put(&manifest
0fc0: 2c 20 30 2c 20 30 29 3b 0a 20 20 69 66 28 20 6e , 0, 0);. if( n
0fd0: 76 69 64 3d 3d 30 20 29 7b 0a 20 20 20 20 66 6f vid==0 ){. fo
0fe0: 73 73 69 6c 5f 70 61 6e 69 63 28 22 74 72 6f 75 ssil_panic("trou
0ff0: 62 6c 65 20 63 6f 6d 6d 69 74 74 69 6e 67 20 6d ble committing m
1000: 61 6e 69 66 65 73 74 3a 20 25 73 22 2c 20 67 2e anifest: %s", g.
1010: 7a 45 72 72 4d 73 67 29 3b 0a 20 20 7d 0a 20 20 zErrMsg);. }.
1020: 64 62 5f 6d 75 6c 74 69 5f 65 78 65 63 28 22 49 db_multi_exec("I
1030: 4e 53 45 52 54 20 4f 52 20 49 47 4e 4f 52 45 20 NSERT OR IGNORE
1040: 49 4e 54 4f 20 75 6e 73 65 6e 74 20 56 41 4c 55 INTO unsent VALU
1050: 45 53 28 25 64 29 22 2c 20 6e 76 69 64 29 3b 0a ES(%d)", nvid);.
1060: 20 20 6d 61 6e 69 66 65 73 74 5f 63 72 6f 73 73 manifest_cross
1070: 6c 69 6e 6b 28 6e 76 69 64 2c 20 26 6d 61 6e 69 link(nvid, &mani
1080: 66 65 73 74 29 3b 0a 20 20 63 6f 6e 74 65 6e 74 fest);. content
1090: 5f 64 65 6c 74 69 66 79 28 76 69 64 2c 20 6e 76 _deltify(vid, nv
10a0: 69 64 2c 20 30 29 3b 0a 20 20 7a 55 75 69 64 20 id, 0);. zUuid
10b0: 3d 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 45 = db_text(0, "SE
10c0: 4c 45 43 54 20 75 75 69 64 20 46 52 4f 4d 20 62 LECT uuid FROM b
10d0: 6c 6f 62 20 57 48 45 52 45 20 72 69 64 3d 25 64 lob WHERE rid=%d
10e0: 22 2c 20 6e 76 69 64 29 3b 0a 20 20 70 72 69 6e ", nvid);. prin
10f0: 74 66 28 22 4e 65 77 5f 56 65 72 73 69 6f 6e 3a tf("New_Version:
1100: 20 25 73 5c 6e 22 2c 20 7a 55 75 69 64 29 3b 0a %s\n", zUuid);.
1110: 0a 20 20 2f 2a 20 56 65 72 69 66 79 20 74 68 61 . /* Verify tha
1120: 74 20 74 68 65 20 6d 61 6e 69 66 65 73 74 20 63 t the manifest c
1130: 68 65 63 6b 73 75 6d 20 6d 61 74 63 68 65 73 20 hecksum matches
1140: 74 68 65 20 65 78 70 65 63 74 65 64 20 63 68 65 the expected che
1150: 63 6b 73 75 6d 20 2a 2f 0a 20 20 76 66 69 6c 65 cksum */. vfile
1160: 5f 61 67 67 72 65 67 61 74 65 5f 63 68 65 63 6b _aggregate_check
1170: 73 75 6d 5f 72 65 70 6f 73 69 74 6f 72 79 28 6e sum_repository(n
1180: 76 69 64 2c 20 26 63 6b 73 75 6d 32 29 3b 0a 20 vid, &cksum2);.
1190: 20 76 66 69 6c 65 5f 61 67 67 72 65 67 61 74 65 vfile_aggregate
11a0: 5f 63 68 65 63 6b 73 75 6d 5f 6d 61 6e 69 66 65 _checksum_manife
11b0: 73 74 28 6e 76 69 64 2c 20 26 63 6b 73 75 6d 32 st(nvid, &cksum2
11c0: 2c 20 26 63 6b 73 75 6d 31 62 29 3b 0a 20 20 69 , &cksum1b);. i
11d0: 66 28 20 62 6c 6f 62 5f 63 6f 6d 70 61 72 65 28 f( blob_compare(
11e0: 26 63 6b 73 75 6d 31 2c 20 26 63 6b 73 75 6d 31 &cksum1, &cksum1
11f0: 62 29 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c b) ){. fossil
1200: 5f 70 61 6e 69 63 28 22 6d 61 6e 69 66 65 73 74 _panic("manifest
1210: 20 63 68 65 63 6b 73 75 6d 20 64 6f 65 73 20 6e checksum does n
1220: 6f 74 20 61 67 72 65 65 20 77 69 74 68 20 6d 61 ot agree with ma
1230: 6e 69 66 65 73 74 3a 20 22 0a 20 20 20 20 20 20 nifest: ".
1240: 20 20 20 20 20 20 20 20 20 20 20 22 25 62 20 76 "%b v
1250: 65 72 73 75 73 20 25 62 22 2c 20 26 63 6b 73 75 ersus %b", &cksu
1260: 6d 31 2c 20 26 63 6b 73 75 6d 31 62 29 3b 0a 20 m1, &cksum1b);.
1270: 20 7d 0a 20 20 0a 20 20 2f 2a 20 56 65 72 69 66 }. . /* Verif
1280: 79 20 74 68 61 74 20 74 68 65 20 63 6f 6d 6d 69 y that the commi
1290: 74 20 64 69 64 20 6e 6f 74 20 6d 6f 64 69 66 79 t did not modify
12a0: 20 61 6e 79 20 64 69 73 6b 20 69 6d 61 67 65 73 any disk images
12b0: 2e 20 2a 2f 0a 20 20 76 66 69 6c 65 5f 61 67 67 . */. vfile_agg
12c0: 72 65 67 61 74 65 5f 63 68 65 63 6b 73 75 6d 5f regate_checksum_
12d0: 64 69 73 6b 28 76 69 64 2c 20 26 63 6b 73 75 6d disk(vid, &cksum
12e0: 32 29 3b 0a 20 20 69 66 28 20 62 6c 6f 62 5f 63 2);. if( blob_c
12f0: 6f 6d 70 61 72 65 28 26 64 73 6b 63 6b 73 75 6d ompare(&dskcksum
1300: 31 2c 20 26 63 6b 73 75 6d 32 29 20 29 7b 0a 20 1, &cksum2) ){.
1310: 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 fossil_panic(
1320: 22 74 72 65 65 20 63 68 65 63 6b 73 75 6d 73 20 "tree checksums
1330: 62 65 66 6f 72 65 20 61 6e 64 20 61 66 74 65 72 before and after
1340: 20 63 6f 6d 6d 69 74 20 64 6f 20 6e 6f 74 20 6d commit do not m
1350: 61 74 63 68 22 29 3b 0a 20 20 7d 0a 0a 20 20 2f atch");. }.. /
1360: 2a 20 43 6c 65 61 72 20 74 68 65 20 75 6e 64 6f * Clear the undo
1370: 2f 72 65 64 6f 20 73 74 61 63 6b 20 2a 2f 0a 20 /redo stack */.
1380: 20 75 6e 64 6f 5f 72 65 73 65 74 28 29 3b 0a 0a undo_reset();..
1390: 20 20 2f 2a 20 43 6f 6d 6d 69 74 20 2a 2f 0a 20 /* Commit */.
13a0: 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 74 db_end_transact
13b0: 69 6f 6e 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a ion(0);.}../*.**
13c0: 20 43 4f 4d 4d 41 4e 44 3a 20 62 72 61 6e 63 68 COMMAND: branch
13d0: 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 .**.** Usage: %f
13e0: 6f 73 73 69 6c 20 62 72 61 6e 63 68 20 53 55 42 ossil branch SUB
13f0: 43 4f 4d 4d 41 4e 44 20 2e 2e 2e 20 3f 2d 52 7c COMMAND ... ?-R|
1400: 2d 2d 72 65 70 6f 73 69 74 6f 72 79 20 46 49 4c --repository FIL
1410: 45 3f 0a 2a 2a 0a 2a 2a 20 52 75 6e 20 76 61 72 E?.**.** Run var
1420: 69 6f 75 73 20 73 75 62 63 6f 6d 6d 61 6e 64 73 ious subcommands
1430: 20 6f 6e 20 74 68 65 20 62 72 61 6e 63 68 65 73 on the branches
1440: 20 6f 66 20 74 68 65 20 6f 70 65 6e 20 72 65 70 of the open rep
1450: 6f 73 69 74 6f 72 79 20 6f 0a 2a 2a 20 6f 66 20 ository o.** of
1460: 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 69 the repository i
1470: 64 65 6e 74 69 66 69 65 64 20 62 79 20 74 68 65 dentified by the
1480: 20 2d 52 20 6f 72 20 2d 2d 72 65 70 6f 73 69 74 -R or --reposit
1490: 6f 72 79 20 6f 70 74 69 6f 6e 2e 0a 2a 2a 0a 2a ory option..**.*
14a0: 2a 20 20 20 20 25 66 6f 73 73 69 6c 20 62 72 61 * %fossil bra
14b0: 6e 63 68 20 6e 65 77 20 3f 2d 62 67 63 6f 6c 6f nch new ?-bgcolo
14c0: 72 20 43 4f 4c 4f 52 20 42 52 41 4e 43 48 2d 4e r COLOR BRANCH-N
14d0: 41 4d 45 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 AME.**.**
14e0: 20 43 72 65 61 74 65 20 61 20 6e 65 77 20 62 72 Create a new br
14f0: 61 6e 63 68 20 42 52 41 4e 43 48 2d 4e 41 4d 45 anch BRANCH-NAME
1500: 2e 20 59 6f 75 20 63 61 6e 20 6f 70 74 69 6f 6e . You can option
1510: 61 6c 6c 79 20 67 69 76 65 0a 2a 2a 20 20 20 20 ally give.**
1520: 20 20 20 20 61 20 63 6f 6d 6d 69 74 20 6d 65 73 a commit mes
1530: 73 61 67 65 20 61 6e 64 20 62 72 61 6e 63 68 20 sage and branch
1540: 63 6f 6c 6f 72 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 color..**.**
1550: 25 66 6f 73 73 69 6c 20 62 72 61 6e 63 68 20 6c %fossil branch l
1560: 69 73 74 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 ist.**.**
1570: 20 4c 69 73 74 20 61 6c 6c 20 62 72 61 6e 63 68 List all branch
1580: 65 73 0a 2a 2a 0a 2a 2f 0a 76 6f 69 64 20 62 72 es.**.*/.void br
1590: 61 6e 63 68 5f 63 6d 64 28 76 6f 69 64 29 7b 0a anch_cmd(void){.
15a0: 20 20 69 6e 74 20 6e 3b 0a 20 20 64 62 5f 66 69 int n;. db_fi
15b0: 6e 64 5f 61 6e 64 5f 6f 70 65 6e 5f 72 65 70 6f nd_and_open_repo
15c0: 73 69 74 6f 72 79 28 29 3b 0a 20 20 69 66 28 20 sitory();. if(
15d0: 67 2e 61 72 67 63 3c 33 20 29 7b 0a 20 20 20 20 g.argc<3 ){.
15e0: 75 73 61 67 65 28 22 6e 65 77 7c 6c 69 73 74 20 usage("new|list
15f0: 2e 2e 2e 22 29 3b 0a 20 20 7d 0a 20 20 6e 20 3d ...");. }. n =
1600: 20 73 74 72 6c 65 6e 28 67 2e 61 72 67 76 5b 32 strlen(g.argv[2
1610: 5d 29 3b 0a 20 20 69 66 28 20 6e 3e 3d 32 20 26 ]);. if( n>=2 &
1620: 26 20 73 74 72 6e 63 6d 70 28 67 2e 61 72 67 76 & strncmp(g.argv
1630: 5b 32 5d 2c 22 6e 65 77 22 2c 6e 29 3d 3d 30 20 [2],"new",n)==0
1640: 29 7b 0a 20 20 20 20 62 72 61 6e 63 68 5f 6e 65 ){. branch_ne
1650: 77 28 29 3b 0a 20 20 7d 65 6c 73 65 20 69 66 28 w();. }else if(
1660: 20 6e 3e 3d 32 20 26 26 20 73 74 72 6e 63 6d 70 n>=2 && strncmp
1670: 28 67 2e 61 72 67 76 5b 32 5d 2c 22 6c 69 73 74 (g.argv[2],"list
1680: 22 2c 6e 29 3d 3d 30 20 29 7b 0a 20 20 7d 65 6c ",n)==0 ){. }el
1690: 73 65 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 se{. fossil_p
16a0: 61 6e 69 63 28 22 62 72 61 6e 63 68 20 73 75 62 anic("branch sub
16b0: 63 6f 6d 6d 61 6e 64 20 73 68 6f 75 6c 64 20 62 command should b
16c0: 65 20 6f 6e 65 20 6f 66 3a 20 22 0a 20 20 20 20 e one of: ".
16d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 6e 65 "ne
16e0: 77 20 6c 69 73 74 22 29 3b 0a 20 20 7d 0a 7d 0a w list");. }.}.