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 62 6c }. }. . bl
0f70: 6f 62 5f 77 72 69 74 65 5f 74 6f 5f 66 69 6c 65 ob_write_to_file
0f80: 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 6d 61 6e (&manifest, "man
0f90: 69 66 65 73 74 2e 6e 65 77 22 29 3b 0a 0a 20 20 ifest.new");..
0fa0: 6e 76 69 64 20 3d 20 63 6f 6e 74 65 6e 74 5f 70 nvid = content_p
0fb0: 75 74 28 26 6d 61 6e 69 66 65 73 74 2c 20 30 2c ut(&manifest, 0,
0fc0: 20 30 29 3b 0a 20 20 69 66 28 20 6e 76 69 64 3d 0);. if( nvid=
0fd0: 3d 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c =0 ){. fossil
0fe0: 5f 70 61 6e 69 63 28 22 74 72 6f 75 62 6c 65 20 _panic("trouble
0ff0: 63 6f 6d 6d 69 74 74 69 6e 67 20 6d 61 6e 69 66 committing manif
1000: 65 73 74 3a 20 25 73 22 2c 20 67 2e 7a 45 72 72 est: %s", g.zErr
1010: 4d 73 67 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 6d Msg);. }. db_m
1020: 75 6c 74 69 5f 65 78 65 63 28 22 49 4e 53 45 52 ulti_exec("INSER
1030: 54 20 4f 52 20 49 47 4e 4f 52 45 20 49 4e 54 4f T OR IGNORE INTO
1040: 20 75 6e 73 65 6e 74 20 56 41 4c 55 45 53 28 25 unsent VALUES(%
1050: 64 29 22 2c 20 6e 76 69 64 29 3b 0a 20 20 6d 61 d)", nvid);. ma
1060: 6e 69 66 65 73 74 5f 63 72 6f 73 73 6c 69 6e 6b nifest_crosslink
1070: 28 6e 76 69 64 2c 20 26 6d 61 6e 69 66 65 73 74 (nvid, &manifest
1080: 29 3b 0a 20 20 63 6f 6e 74 65 6e 74 5f 64 65 6c );. content_del
1090: 74 69 66 79 28 76 69 64 2c 20 6e 76 69 64 2c 20 tify(vid, nvid,
10a0: 30 29 3b 0a 20 20 7a 55 75 69 64 20 3d 20 64 62 0);. zUuid = db
10b0: 5f 74 65 78 74 28 30 2c 20 22 53 45 4c 45 43 54 _text(0, "SELECT
10c0: 20 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62 20 uuid FROM blob
10d0: 57 48 45 52 45 20 72 69 64 3d 25 64 22 2c 20 6e WHERE rid=%d", n
10e0: 76 69 64 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 vid);. printf("
10f0: 4e 65 77 5f 56 65 72 73 69 6f 6e 3a 20 25 73 5c New_Version: %s\
1100: 6e 22 2c 20 7a 55 75 69 64 29 3b 0a 20 20 2f 2a n", zUuid);. /*
1110: 64 62 5f 6c 73 65 74 5f 69 6e 74 28 22 63 68 65 db_lset_int("che
1120: 63 6b 6f 75 74 22 2c 20 6e 76 69 64 29 3b 2a 2f ckout", nvid);*/
1130: 0a 0a 20 20 2f 2a 20 56 65 72 69 66 79 20 74 68 .. /* Verify th
1140: 61 74 20 74 68 65 20 6d 61 6e 69 66 65 73 74 20 at the manifest
1150: 63 68 65 63 6b 73 75 6d 20 6d 61 74 63 68 65 73 checksum matches
1160: 20 74 68 65 20 65 78 70 65 63 74 65 64 20 63 68 the expected ch
1170: 65 63 6b 73 75 6d 20 2a 2f 0a 20 20 76 66 69 6c ecksum */. vfil
1180: 65 5f 61 67 67 72 65 67 61 74 65 5f 63 68 65 63 e_aggregate_chec
1190: 6b 73 75 6d 5f 72 65 70 6f 73 69 74 6f 72 79 28 ksum_repository(
11a0: 6e 76 69 64 2c 20 26 63 6b 73 75 6d 32 29 3b 0a nvid, &cksum2);.
11b0: 20 20 76 66 69 6c 65 5f 61 67 67 72 65 67 61 74 vfile_aggregat
11c0: 65 5f 63 68 65 63 6b 73 75 6d 5f 6d 61 6e 69 66 e_checksum_manif
11d0: 65 73 74 28 6e 76 69 64 2c 20 26 63 6b 73 75 6d est(nvid, &cksum
11e0: 32 2c 20 26 63 6b 73 75 6d 31 62 29 3b 0a 20 20 2, &cksum1b);.
11f0: 69 66 28 20 62 6c 6f 62 5f 63 6f 6d 70 61 72 65 if( blob_compare
1200: 28 26 63 6b 73 75 6d 31 2c 20 26 63 6b 73 75 6d (&cksum1, &cksum
1210: 31 62 29 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 1b) ){. fossi
1220: 6c 5f 70 61 6e 69 63 28 22 6d 61 6e 69 66 65 73 l_panic("manifes
1230: 74 20 63 68 65 63 6b 73 75 6d 20 64 6f 65 73 20 t checksum does
1240: 6e 6f 74 20 61 67 72 65 65 20 77 69 74 68 20 6d not agree with m
1250: 61 6e 69 66 65 73 74 3a 20 22 0a 20 20 20 20 20 anifest: ".
1260: 20 20 20 20 20 20 20 20 20 20 20 20 22 25 62 20 "%b
1270: 76 65 72 73 75 73 20 25 62 22 2c 20 26 63 6b 73 versus %b", &cks
1280: 75 6d 31 2c 20 26 63 6b 73 75 6d 31 62 29 3b 0a um1, &cksum1b);.
1290: 20 20 7d 0a 20 20 0a 20 20 2f 2a 20 56 65 72 69 }. . /* Veri
12a0: 66 79 20 74 68 61 74 20 74 68 65 20 63 6f 6d 6d fy that the comm
12b0: 69 74 20 64 69 64 20 6e 6f 74 20 6d 6f 64 69 66 it did not modif
12c0: 79 20 61 6e 79 20 64 69 73 6b 20 69 6d 61 67 65 y any disk image
12d0: 73 2e 20 2a 2f 0a 20 20 76 66 69 6c 65 5f 61 67 s. */. vfile_ag
12e0: 67 72 65 67 61 74 65 5f 63 68 65 63 6b 73 75 6d gregate_checksum
12f0: 5f 64 69 73 6b 28 76 69 64 2c 20 26 63 6b 73 75 _disk(vid, &cksu
1300: 6d 32 29 3b 0a 20 20 69 66 28 20 62 6c 6f 62 5f m2);. if( blob_
1310: 63 6f 6d 70 61 72 65 28 26 64 73 6b 63 6b 73 75 compare(&dskcksu
1320: 6d 31 2c 20 26 63 6b 73 75 6d 32 29 20 29 7b 0a m1, &cksum2) ){.
1330: 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 fossil_panic
1340: 28 22 74 72 65 65 20 63 68 65 63 6b 73 75 6d 73 ("tree checksums
1350: 20 62 65 66 6f 72 65 20 61 6e 64 20 61 66 74 65 before and afte
1360: 72 20 63 6f 6d 6d 69 74 20 64 6f 20 6e 6f 74 20 r commit do not
1370: 6d 61 74 63 68 22 29 3b 0a 20 20 7d 0a 0a 20 20 match");. }..
1380: 2f 2a 20 43 6c 65 61 72 20 74 68 65 20 75 6e 64 /* Clear the und
1390: 6f 2f 72 65 64 6f 20 73 74 61 63 6b 20 2a 2f 0a o/redo stack */.
13a0: 20 20 75 6e 64 6f 5f 72 65 73 65 74 28 29 3b 0a undo_reset();.
13b0: 0a 20 20 2f 2a 20 43 6f 6d 6d 69 74 20 2a 2f 0a . /* Commit */.
13c0: 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 db_end_transac
13d0: 74 69 6f 6e 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 2a tion(0);.}../*.*
13e0: 2a 20 43 4f 4d 4d 41 4e 44 3a 20 62 72 61 6e 63 * COMMAND: branc
13f0: 68 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 h.**.** Usage: %
1400: 66 6f 73 73 69 6c 20 62 72 61 6e 63 68 20 53 55 fossil branch SU
1410: 42 43 4f 4d 4d 41 4e 44 20 2e 2e 2e 20 3f 2d 52 BCOMMAND ... ?-R
1420: 7c 2d 2d 72 65 70 6f 73 69 74 6f 72 79 20 46 49 |--repository FI
1430: 4c 45 3f 0a 2a 2a 0a 2a 2a 20 52 75 6e 20 76 61 LE?.**.** Run va
1440: 72 69 6f 75 73 20 73 75 62 63 6f 6d 6d 61 6e 64 rious subcommand
1450: 73 20 6f 6e 20 74 68 65 20 62 72 61 6e 63 68 65 s on the branche
1460: 73 20 6f 66 20 74 68 65 20 6f 70 65 6e 20 72 65 s of the open re
1470: 70 6f 73 69 74 6f 72 79 20 6f 0a 2a 2a 20 6f 66 pository o.** of
1480: 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 20 the repository
1490: 69 64 65 6e 74 69 66 69 65 64 20 62 79 20 74 68 identified by th
14a0: 65 20 2d 52 20 6f 72 20 2d 2d 72 65 70 6f 73 69 e -R or --reposi
14b0: 74 6f 72 79 20 6f 70 74 69 6f 6e 2e 0a 2a 2a 0a tory option..**.
14c0: 2a 2a 20 20 20 20 25 66 6f 73 73 69 6c 20 62 72 ** %fossil br
14d0: 61 6e 63 68 20 6e 65 77 20 3f 2d 62 67 63 6f 6c anch new ?-bgcol
14e0: 6f 72 20 43 4f 4c 4f 52 20 42 52 41 4e 43 48 2d or COLOR BRANCH-
14f0: 4e 41 4d 45 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 NAME.**.**
1500: 20 20 43 72 65 61 74 65 20 61 20 6e 65 77 20 62 Create a new b
1510: 72 61 6e 63 68 20 42 52 41 4e 43 48 2d 4e 41 4d ranch BRANCH-NAM
1520: 45 2e 20 59 6f 75 20 63 61 6e 20 6f 70 74 69 6f E. You can optio
1530: 6e 61 6c 6c 79 20 67 69 76 65 0a 2a 2a 20 20 20 nally give.**
1540: 20 20 20 20 20 61 20 63 6f 6d 6d 69 74 20 6d 65 a commit me
1550: 73 73 61 67 65 20 61 6e 64 20 62 72 61 6e 63 68 ssage and branch
1560: 20 63 6f 6c 6f 72 2e 0a 2a 2a 0a 2a 2a 20 20 20 color..**.**
1570: 20 25 66 6f 73 73 69 6c 20 62 72 61 6e 63 68 20 %fossil branch
1580: 6c 69 73 74 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 list.**.**
1590: 20 20 4c 69 73 74 20 61 6c 6c 20 62 72 61 6e 63 List all branc
15a0: 68 65 73 0a 2a 2a 0a 2a 2f 0a 76 6f 69 64 20 62 hes.**.*/.void b
15b0: 72 61 6e 63 68 5f 63 6d 64 28 76 6f 69 64 29 7b ranch_cmd(void){
15c0: 0a 20 20 69 6e 74 20 6e 3b 0a 20 20 64 62 5f 66 . int n;. db_f
15d0: 69 6e 64 5f 61 6e 64 5f 6f 70 65 6e 5f 72 65 70 ind_and_open_rep
15e0: 6f 73 69 74 6f 72 79 28 29 3b 0a 20 20 69 66 28 ository();. if(
15f0: 20 67 2e 61 72 67 63 3c 33 20 29 7b 0a 20 20 20 g.argc<3 ){.
1600: 20 75 73 61 67 65 28 22 6e 65 77 7c 6c 69 73 74 usage("new|list
1610: 20 2e 2e 2e 22 29 3b 0a 20 20 7d 0a 20 20 6e 20 ...");. }. n
1620: 3d 20 73 74 72 6c 65 6e 28 67 2e 61 72 67 76 5b = strlen(g.argv[
1630: 32 5d 29 3b 0a 20 20 69 66 28 20 6e 3e 3d 32 20 2]);. if( n>=2
1640: 26 26 20 73 74 72 6e 63 6d 70 28 67 2e 61 72 67 && strncmp(g.arg
1650: 76 5b 32 5d 2c 22 6e 65 77 22 2c 6e 29 3d 3d 30 v[2],"new",n)==0
1660: 20 29 7b 0a 20 20 20 20 62 72 61 6e 63 68 5f 6e ){. branch_n
1670: 65 77 28 29 3b 0a 20 20 7d 65 6c 73 65 20 69 66 ew();. }else if
1680: 28 20 6e 3e 3d 32 20 26 26 20 73 74 72 6e 63 6d ( n>=2 && strncm
1690: 70 28 67 2e 61 72 67 76 5b 32 5d 2c 22 6c 69 73 p(g.argv[2],"lis
16a0: 74 22 2c 6e 29 3d 3d 30 20 29 7b 0a 20 20 7d 65 t",n)==0 ){. }e
16b0: 6c 73 65 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f lse{. fossil_
16c0: 70 61 6e 69 63 28 22 62 72 61 6e 63 68 20 73 75 panic("branch su
16d0: 62 63 6f 6d 6d 61 6e 64 20 73 68 6f 75 6c 64 20 bcommand should
16e0: 62 65 20 6f 6e 65 20 6f 66 3a 20 22 0a 20 20 20 be one of: ".
16f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 6e "n
1700: 65 77 20 6c 69 73 74 22 29 3b 0a 20 20 7d 0a 7d ew list");. }.}
1710: 0a .