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 3b 0a 20 20 63 , *zComment;. c
0470: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 43 6f 6c 6f onst char *zColo
0480: 72 3b 0a 20 20 42 6c 6f 62 20 6d 61 6e 69 66 65 r;. Blob manife
0490: 73 74 3b 0a 20 20 42 6c 6f 62 20 6d 63 6b 73 75 st;. Blob mcksu
04a0: 6d 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 m; /*
04b0: 53 65 6c 66 2d 63 68 65 63 6b 73 75 6d 20 6f 6e Self-checksum on
04c0: 20 74 68 65 20 6d 61 6e 69 66 65 73 74 20 2a 2f the manifest */
04d0: 0a 20 20 42 6c 6f 62 20 63 6b 73 75 6d 31 2c 20 . Blob cksum1,
04e0: 63 6b 73 75 6d 32 3b 20 20 20 2f 2a 20 42 65 66 cksum2; /* Bef
04f0: 6f 72 65 20 61 6e 64 20 61 66 74 65 72 20 63 6f ore and after co
0500: 6d 6d 69 74 20 63 68 65 63 6b 73 75 6d 73 20 2a mmit checksums *
0510: 2f 0a 20 20 42 6c 6f 62 20 63 6b 73 75 6d 31 62 /. Blob cksum1b
0520: 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 68 ; /* Ch
0530: 65 63 6b 73 75 6d 20 72 65 63 6f 72 64 65 64 20 ecksum recorded
0540: 69 6e 20 74 68 65 20 6d 61 6e 69 66 65 73 74 20 in the manifest
0550: 2a 2f 0a 20 0a 20 20 6e 6f 53 69 67 6e 20 3d 20 */. . noSign =
0560: 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 6e 6f 73 find_option("nos
0570: 69 67 6e 22 2c 22 22 2c 30 29 21 3d 30 3b 0a 20 ign","",0)!=0;.
0580: 20 64 62 5f 6d 75 73 74 5f 62 65 5f 77 69 74 68 db_must_be_with
0590: 69 6e 5f 74 72 65 65 28 29 3b 0a 20 20 6e 6f 53 in_tree();. noS
05a0: 69 67 6e 20 3d 20 64 62 5f 67 65 74 5f 69 6e 74 ign = db_get_int
05b0: 28 22 6f 6d 69 74 2d 63 69 2d 73 69 67 22 2c 20 ("omit-ci-sig",
05c0: 30 29 7c 6e 6f 53 69 67 6e 3b 0a 20 20 7a 43 6f 0)|noSign;. zCo
05d0: 6c 6f 72 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f lor = find_optio
05e0: 6e 28 22 62 67 63 6f 6c 6f 72 22 2c 22 63 22 2c n("bgcolor","c",
05f0: 31 29 3b 0a 20 20 0a 20 20 76 65 72 69 66 79 5f 1);. . verify_
0600: 61 6c 6c 5f 6f 70 74 69 6f 6e 73 28 29 3b 0a 20 all_options();.
0610: 20 0a 20 20 2f 2a 20 66 6f 73 73 69 6c 20 62 72 . /* fossil br
0620: 61 6e 63 68 20 6e 65 77 20 6e 61 6d 65 20 2a 2f anch new name */
0630: 0a 20 20 69 66 28 20 67 2e 61 72 67 63 3c 33 20 . if( g.argc<3
0640: 29 7b 0a 20 20 20 20 75 73 61 67 65 28 22 62 72 ){. usage("br
0650: 61 6e 63 68 20 6e 65 77 20 3f 2d 62 67 63 6f 6c anch new ?-bgcol
0660: 6f 72 20 43 4f 4c 4f 52 20 42 52 41 4e 43 48 2d or COLOR BRANCH-
0670: 4e 41 4d 45 22 29 3b 0a 20 20 7d 0a 20 20 7a 42 NAME");. }. zB
0680: 72 61 6e 63 68 20 3d 20 67 2e 61 72 67 76 5b 33 ranch = g.argv[3
0690: 5d 3b 0a 20 20 69 66 28 20 7a 42 72 61 6e 63 68 ];. if( zBranch
06a0: 3d 3d 30 20 7c 7c 20 7a 42 72 61 6e 63 68 5b 30 ==0 || zBranch[0
06b0: 5d 3d 3d 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 ]==0 ){. foss
06c0: 69 6c 5f 70 61 6e 69 63 28 22 62 72 61 6e 63 68 il_panic("branch
06d0: 20 6e 61 6d 65 20 63 61 6e 6e 6f 74 20 62 65 20 name cannot be
06e0: 65 6d 70 74 79 22 29 3b 0a 20 20 7d 0a 0a 20 20 empty");. }..
06f0: 75 73 65 72 5f 73 65 6c 65 63 74 28 29 3b 0a 20 user_select();.
0700: 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61 db_begin_transa
0710: 63 74 69 6f 6e 28 29 3b 0a 20 20 69 66 28 20 75 ction();. if( u
0720: 6e 73 61 76 65 64 5f 63 68 61 6e 67 65 73 28 29 nsaved_changes()
0730: 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 ){. fossil_p
0740: 61 6e 69 63 28 22 74 68 65 72 65 20 61 72 65 20 anic("there are
0750: 75 6e 63 6f 6d 6d 69 74 74 65 64 20 63 68 61 6e uncommitted chan
0760: 67 65 73 2e 20 70 6c 65 61 73 65 20 63 6f 6d 6d ges. please comm
0770: 69 74 20 66 69 72 73 74 22 29 3b 0a 20 20 7d 0a it first");. }.
0780: 0a 20 20 76 69 64 20 3d 20 64 62 5f 6c 67 65 74 . vid = db_lget
0790: 5f 69 6e 74 28 22 63 68 65 63 6b 6f 75 74 22 2c _int("checkout",
07a0: 20 30 29 3b 0a 20 20 76 66 69 6c 65 5f 61 67 67 0);. vfile_agg
07b0: 72 65 67 61 74 65 5f 63 68 65 63 6b 73 75 6d 5f regate_checksum_
07c0: 64 69 73 6b 28 76 69 64 2c 20 26 63 6b 73 75 6d disk(vid, &cksum
07d0: 31 29 3b 0a 20 20 0a 20 20 2f 2a 20 43 72 65 61 1);. . /* Crea
07e0: 74 65 20 6f 75 72 20 6e 65 77 20 6d 61 6e 69 66 te our new manif
07f0: 65 73 74 20 2a 2f 0a 20 20 62 6c 6f 62 5f 7a 65 est */. blob_ze
0800: 72 6f 28 26 6d 61 6e 69 66 65 73 74 29 3b 0a 20 ro(&manifest);.
0810: 20 7a 43 6f 6d 6d 65 6e 74 20 3d 20 6d 70 72 69 zComment = mpri
0820: 6e 74 66 28 22 42 72 61 6e 63 68 20 63 72 65 61 ntf("Branch crea
0830: 74 65 64 20 25 73 22 2c 20 7a 42 72 61 6e 63 68 ted %s", zBranch
0840: 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 );. blob_append
0850: 66 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 43 20 f(&manifest, "C
0860: 25 46 5c 6e 22 2c 20 7a 43 6f 6d 6d 65 6e 74 29 %F\n", zComment)
0870: 3b 0a 20 20 7a 44 61 74 65 20 3d 20 64 62 5f 74 ;. zDate = db_t
0880: 65 78 74 28 30 2c 20 22 53 45 4c 45 43 54 20 64 ext(0, "SELECT d
0890: 61 74 65 74 69 6d 65 28 27 6e 6f 77 27 29 22 29 atetime('now')")
08a0: 3b 0a 20 20 7a 44 61 74 65 5b 31 30 5d 20 3d 20 ;. zDate[10] =
08b0: 27 54 27 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 'T';. blob_appe
08c0: 6e 64 66 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 ndf(&manifest, "
08d0: 44 20 25 73 5c 6e 22 2c 20 7a 44 61 74 65 29 3b D %s\n", zDate);
08e0: 0a 0a 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 .. db_prepare(&
08f0: 71 2c 0a 20 20 20 20 22 53 45 4c 45 43 54 20 70 q,. "SELECT p
0900: 61 74 68 6e 61 6d 65 2c 20 75 75 69 64 20 46 52 athname, uuid FR
0910: 4f 4d 20 76 66 69 6c 65 20 4a 4f 49 4e 20 62 6c OM vfile JOIN bl
0920: 6f 62 20 4f 4e 20 76 66 69 6c 65 2e 6d 72 69 64 ob ON vfile.mrid
0930: 3d 62 6c 6f 62 2e 72 69 64 22 0a 20 20 20 20 22 =blob.rid". "
0940: 20 57 48 45 52 45 20 4e 4f 54 20 64 65 6c 65 74 WHERE NOT delet
0950: 65 64 20 41 4e 44 20 76 66 69 6c 65 2e 76 69 64 ed AND vfile.vid
0960: 3d 25 64 22 0a 20 20 20 20 22 20 4f 52 44 45 52 =%d". " ORDER
0970: 20 42 59 20 31 22 2c 20 76 69 64 29 3b 0a 20 20 BY 1", vid);.
0980: 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 while( db_step(&
0990: 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 q)==SQLITE_ROW )
09a0: 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 {. const char
09b0: 20 2a 7a 4e 61 6d 65 20 3d 20 64 62 5f 63 6f 6c *zName = db_col
09c0: 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30 29 3b umn_text(&q, 0);
09d0: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 . const char
09e0: 2a 7a 55 75 69 64 20 3d 20 64 62 5f 63 6f 6c 75 *zUuid = db_colu
09f0: 6d 6e 5f 74 65 78 74 28 26 71 2c 20 31 29 3b 0a mn_text(&q, 1);.
0a00: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 blob_appendf
0a10: 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 46 20 25 (&manifest, "F %
0a20: 46 20 25 73 5c 6e 22 2c 20 7a 4e 61 6d 65 2c 20 F %s\n", zName,
0a30: 7a 55 75 69 64 29 3b 0a 20 20 7d 0a 20 20 64 62 zUuid);. }. db
0a40: 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 _finalize(&q);.
0a50: 20 0a 20 20 7a 55 75 69 64 20 3d 20 64 62 5f 74 . zUuid = db_t
0a60: 65 78 74 28 30 2c 20 22 53 45 4c 45 43 54 20 75 ext(0, "SELECT u
0a70: 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62 20 57 48 uid FROM blob WH
0a80: 45 52 45 20 72 69 64 3d 25 64 22 2c 20 76 69 64 ERE rid=%d", vid
0a90: 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 );. blob_append
0aa0: 66 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 50 20 f(&manifest, "P
0ab0: 25 73 5c 6e 22 2c 20 7a 55 75 69 64 29 3b 0a 20 %s\n", zUuid);.
0ac0: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d blob_appendf(&m
0ad0: 61 6e 69 66 65 73 74 2c 20 22 52 20 25 62 5c 6e anifest, "R %b\n
0ae0: 22 2c 20 26 63 6b 73 75 6d 31 29 3b 0a 20 20 0a ", &cksum1);. .
0af0: 20 20 69 66 28 20 7a 43 6f 6c 6f 72 21 3d 30 20 if( zColor!=0
0b00: 29 7b 0a 20 20 20 20 69 66 28 20 73 74 72 63 6d ){. if( strcm
0b10: 70 28 22 62 67 63 6f 6c 6f 72 22 2c 7a 42 72 61 p("bgcolor",zBra
0b20: 6e 63 68 29 3e 3d 30 20 29 7b 0a 20 20 20 20 20 nch)>=0 ){.
0b30: 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d blob_appendf(&m
0b40: 61 6e 69 66 65 73 74 2c 20 22 54 20 2a 25 46 20 anifest, "T *%F
0b50: 2a 5c 6e 22 2c 20 7a 42 72 61 6e 63 68 29 3b 0a *\n", zBranch);.
0b60: 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e blob_appen
0b70: 64 66 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 54 df(&manifest, "T
0b80: 20 2a 62 67 63 6f 6c 6f 72 20 2a 20 25 46 5c 6e *bgcolor * %F\n
0b90: 22 2c 20 7a 43 6f 6c 6f 72 29 3b 0a 20 20 20 20 ", zColor);.
0ba0: 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 62 6c 6f }else{. blo
0bb0: 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 b_appendf(&manif
0bc0: 65 73 74 2c 20 22 54 20 2a 62 67 63 6f 6c 6f 72 est, "T *bgcolor
0bd0: 20 2a 20 25 46 5c 6e 22 2c 20 7a 43 6f 6c 6f 72 * %F\n", zColor
0be0: 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 );. blob_ap
0bf0: 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 74 2c pendf(&manifest,
0c00: 20 22 54 20 2a 25 46 20 2a 5c 6e 22 2c 20 7a 42 "T *%F *\n", zB
0c10: 72 61 6e 63 68 29 3b 0a 20 20 20 20 7d 0a 20 20 ranch);. }.
0c20: 7d 65 6c 73 65 7b 0a 20 20 20 20 62 6c 6f 62 5f }else{. blob_
0c30: 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 appendf(&manifes
0c40: 74 2c 20 22 54 20 2a 25 46 20 2a 5c 6e 22 2c 20 t, "T *%F *\n",
0c50: 7a 42 72 61 6e 63 68 29 3b 0a 20 20 7d 0a 0a 20 zBranch);. }..
0c60: 20 2f 2a 20 43 61 6e 63 65 6c 20 61 6e 79 20 74 /* Cancel any t
0c70: 61 67 73 20 74 68 61 74 20 70 72 6f 70 61 67 61 ags that propaga
0c80: 74 65 20 2a 2f 0a 20 20 64 62 5f 70 72 65 70 61 te */. db_prepa
0c90: 72 65 28 26 71 2c 20 0a 20 20 20 20 20 20 22 53 re(&q, . "S
0ca0: 45 4c 45 43 54 20 74 61 67 6e 61 6d 65 22 0a 20 ELECT tagname".
0cb0: 20 20 20 20 20 22 20 20 46 52 4f 4d 20 74 61 67 " FROM tag
0cc0: 78 72 65 66 20 4a 4f 49 4e 20 74 61 67 20 4f 4e xref JOIN tag ON
0cd0: 20 74 61 67 78 72 65 66 2e 74 61 67 69 64 3d 74 tagxref.tagid=t
0ce0: 61 67 2e 74 61 67 69 64 22 0a 20 20 20 20 20 20 ag.tagid".
0cf0: 22 20 57 48 45 52 45 20 72 69 64 3d 25 64 20 41 " WHERE rid=%d A
0d00: 4e 44 20 74 61 67 74 79 70 65 3d 32 22 2c 20 76 ND tagtype=2", v
0d10: 69 64 29 3b 0a 20 20 77 68 69 6c 65 28 20 64 62 id);. while( db
0d20: 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 _step(&q)==SQLIT
0d30: 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 63 6f 6e E_ROW ){. con
0d40: 73 74 20 63 68 61 72 20 2a 7a 54 61 67 6e 61 6d st char *zTagnam
0d50: 65 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 e = db_column_te
0d60: 78 74 28 26 71 2c 20 30 29 3b 0a 20 20 20 20 62 xt(&q, 0);. b
0d70: 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e lob_appendf(&man
0d80: 69 66 65 73 74 2c 20 22 54 20 2d 25 73 20 2a 5c ifest, "T -%s *\
0d90: 6e 22 2c 20 7a 54 61 67 6e 61 6d 65 29 3b 0a 20 n", zTagname);.
0da0: 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 }. db_finalize
0db0: 28 26 71 29 3b 0a 20 20 0a 20 20 62 6c 6f 62 5f (&q);. . blob_
0dc0: 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 appendf(&manifes
0dd0: 74 2c 20 22 55 20 25 46 5c 6e 22 2c 20 67 2e 7a t, "U %F\n", g.z
0de0: 4c 6f 67 69 6e 29 3b 0a 20 20 6d 64 35 73 75 6d Login);. md5sum
0df0: 5f 62 6c 6f 62 28 26 6d 61 6e 69 66 65 73 74 2c _blob(&manifest,
0e00: 20 26 6d 63 6b 73 75 6d 29 3b 0a 20 20 62 6c 6f &mcksum);. blo
0e10: 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 b_appendf(&manif
0e20: 65 73 74 2c 20 22 5a 20 25 62 5c 6e 22 2c 20 26 est, "Z %b\n", &
0e30: 6d 63 6b 73 75 6d 29 3b 0a 20 20 69 66 28 20 21 mcksum);. if( !
0e40: 6e 6f 53 69 67 6e 20 26 26 20 63 6c 65 61 72 73 noSign && clears
0e50: 69 67 6e 28 26 6d 61 6e 69 66 65 73 74 2c 20 26 ign(&manifest, &
0e60: 6d 61 6e 69 66 65 73 74 29 20 29 7b 0a 20 20 20 manifest) ){.
0e70: 20 42 6c 6f 62 20 61 6e 73 3b 0a 20 20 20 20 62 Blob ans;. b
0e80: 6c 6f 62 5f 7a 65 72 6f 28 26 61 6e 73 29 3b 0a lob_zero(&ans);.
0e90: 20 20 20 20 70 72 6f 6d 70 74 5f 75 73 65 72 28 prompt_user(
0ea0: 22 75 6e 61 62 6c 65 20 74 6f 20 73 69 67 6e 20 "unable to sign
0eb0: 6d 61 6e 69 66 65 73 74 2e 20 20 63 6f 6e 74 69 manifest. conti
0ec0: 6e 75 65 20 5b 79 2f 4e 5d 3f 20 22 2c 20 26 61 nue [y/N]? ", &a
0ed0: 6e 73 29 3b 0a 20 20 20 20 69 66 28 20 62 6c 6f ns);. if( blo
0ee0: 62 5f 73 74 72 28 26 61 6e 73 29 5b 30 5d 21 3d b_str(&ans)[0]!=
0ef0: 27 79 27 20 29 7b 0a 20 20 20 20 20 20 64 62 5f 'y' ){. db_
0f00: 65 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 end_transaction(
0f10: 31 29 3b 0a 20 20 20 20 20 20 65 78 69 74 28 31 1);. exit(1
0f20: 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 0a );. }. }. .
0f30: 20 20 2f 2a 62 6c 6f 62 5f 77 72 69 74 65 5f 74 /*blob_write_t
0f40: 6f 5f 66 69 6c 65 28 26 6d 61 6e 69 66 65 73 74 o_file(&manifest
0f50: 2c 20 22 6d 61 6e 69 66 65 73 74 2e 6e 65 77 22 , "manifest.new"
0f60: 29 3b 2a 2f 0a 0a 20 20 6e 76 69 64 20 3d 20 63 );*/.. nvid = c
0f70: 6f 6e 74 65 6e 74 5f 70 75 74 28 26 6d 61 6e 69 ontent_put(&mani
0f80: 66 65 73 74 2c 20 30 2c 20 30 29 3b 0a 20 20 69 fest, 0, 0);. i
0f90: 66 28 20 6e 76 69 64 3d 3d 30 20 29 7b 0a 20 20 f( nvid==0 ){.
0fa0: 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 fossil_panic("
0fb0: 74 72 6f 75 62 6c 65 20 63 6f 6d 6d 69 74 74 69 trouble committi
0fc0: 6e 67 20 6d 61 6e 69 66 65 73 74 3a 20 25 73 22 ng manifest: %s"
0fd0: 2c 20 67 2e 7a 45 72 72 4d 73 67 29 3b 0a 20 20 , g.zErrMsg);.
0fe0: 7d 0a 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78 65 }. db_multi_exe
0ff0: 63 28 22 49 4e 53 45 52 54 20 4f 52 20 49 47 4e c("INSERT OR IGN
1000: 4f 52 45 20 49 4e 54 4f 20 75 6e 73 65 6e 74 20 ORE INTO unsent
1010: 56 41 4c 55 45 53 28 25 64 29 22 2c 20 6e 76 69 VALUES(%d)", nvi
1020: 64 29 3b 0a 20 20 6d 61 6e 69 66 65 73 74 5f 63 d);. manifest_c
1030: 72 6f 73 73 6c 69 6e 6b 28 6e 76 69 64 2c 20 26 rosslink(nvid, &
1040: 6d 61 6e 69 66 65 73 74 29 3b 0a 20 20 63 6f 6e manifest);. con
1050: 74 65 6e 74 5f 64 65 6c 74 69 66 79 28 76 69 64 tent_deltify(vid
1060: 2c 20 6e 76 69 64 2c 20 30 29 3b 0a 20 20 7a 55 , nvid, 0);. zU
1070: 75 69 64 20 3d 20 64 62 5f 74 65 78 74 28 30 2c uid = db_text(0,
1080: 20 22 53 45 4c 45 43 54 20 75 75 69 64 20 46 52 "SELECT uuid FR
1090: 4f 4d 20 62 6c 6f 62 20 57 48 45 52 45 20 72 69 OM blob WHERE ri
10a0: 64 3d 25 64 22 2c 20 6e 76 69 64 29 3b 0a 20 20 d=%d", nvid);.
10b0: 70 72 69 6e 74 66 28 22 42 72 61 6e 63 68 20 56 printf("Branch V
10c0: 65 72 73 69 6f 6e 3a 20 25 73 5c 6e 22 2c 20 7a ersion: %s\n", z
10d0: 55 75 69 64 29 3b 0a 20 20 70 72 69 6e 74 66 28 Uuid);. printf(
10e0: 22 5c 6e 22 29 3b 0a 20 20 70 72 69 6e 74 66 28 "\n");. printf(
10f0: 22 4e 6f 74 69 63 65 3a 20 77 6f 72 6b 69 6e 67 "Notice: working
1100: 20 63 6f 70 79 20 6e 6f 74 20 75 70 64 61 74 65 copy not update
1110: 64 20 74 6f 20 74 68 65 20 6e 65 77 20 62 72 61 d to the new bra
1120: 6e 63 68 2e 20 49 66 5c 6e 22 29 3b 0a 20 20 70 nch. If\n");. p
1130: 72 69 6e 74 66 28 22 20 20 20 20 20 20 20 20 79 rintf(" y
1140: 6f 75 20 77 69 73 68 20 74 6f 20 77 6f 72 6b 20 ou wish to work
1150: 6f 6e 20 74 68 65 20 6e 65 77 20 62 72 61 6e 63 on the new branc
1160: 68 2c 20 75 70 64 61 74 65 20 74 6f 5c 6e 22 29 h, update to\n")
1170: 3b 0a 20 20 70 72 69 6e 74 66 28 22 20 20 20 20 ;. printf("
1180: 20 20 20 20 74 68 61 74 20 62 72 61 6e 63 68 20 that branch
1190: 66 69 72 73 74 3a 5c 6e 22 29 3b 0a 20 20 70 72 first:\n");. pr
11a0: 69 6e 74 66 28 22 5c 6e 22 29 3b 0a 20 20 70 72 intf("\n");. pr
11b0: 69 6e 74 66 28 22 20 20 20 20 20 20 20 20 66 6f intf(" fo
11c0: 73 73 69 6c 20 75 70 64 61 74 65 20 25 73 5c 6e ssil update %s\n
11d0: 22 2c 20 7a 42 72 61 6e 63 68 29 3b 0a 0a 20 20 ", zBranch);..
11e0: 2f 2a 20 56 65 72 69 66 79 20 74 68 61 74 20 74 /* Verify that t
11f0: 68 65 20 6d 61 6e 69 66 65 73 74 20 63 68 65 63 he manifest chec
1200: 6b 73 75 6d 20 6d 61 74 63 68 65 73 20 74 68 65 ksum matches the
1210: 20 65 78 70 65 63 74 65 64 20 63 68 65 63 6b 73 expected checks
1220: 75 6d 20 2a 2f 0a 20 20 76 66 69 6c 65 5f 61 67 um */. vfile_ag
1230: 67 72 65 67 61 74 65 5f 63 68 65 63 6b 73 75 6d gregate_checksum
1240: 5f 72 65 70 6f 73 69 74 6f 72 79 28 6e 76 69 64 _repository(nvid
1250: 2c 20 26 63 6b 73 75 6d 32 29 3b 0a 20 20 76 66 , &cksum2);. vf
1260: 69 6c 65 5f 61 67 67 72 65 67 61 74 65 5f 63 68 ile_aggregate_ch
1270: 65 63 6b 73 75 6d 5f 6d 61 6e 69 66 65 73 74 28 ecksum_manifest(
1280: 6e 76 69 64 2c 20 26 63 6b 73 75 6d 32 2c 20 26 nvid, &cksum2, &
1290: 63 6b 73 75 6d 31 62 29 3b 0a 20 20 69 66 28 20 cksum1b);. if(
12a0: 62 6c 6f 62 5f 63 6f 6d 70 61 72 65 28 26 63 6b blob_compare(&ck
12b0: 73 75 6d 31 2c 20 26 63 6b 73 75 6d 31 62 29 20 sum1, &cksum1b)
12c0: 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 ){. fossil_pa
12d0: 6e 69 63 28 22 6d 61 6e 69 66 65 73 74 20 63 68 nic("manifest ch
12e0: 65 63 6b 73 75 6d 20 64 6f 65 73 20 6e 6f 74 20 ecksum does not
12f0: 61 67 72 65 65 20 77 69 74 68 20 6d 61 6e 69 66 agree with manif
1300: 65 73 74 3a 20 22 0a 20 20 20 20 20 20 20 20 20 est: ".
1310: 20 20 20 20 20 20 20 20 22 25 62 20 76 65 72 73 "%b vers
1320: 75 73 20 25 62 22 2c 20 26 63 6b 73 75 6d 31 2c us %b", &cksum1,
1330: 20 26 63 6b 73 75 6d 31 62 29 3b 0a 20 20 7d 0a &cksum1b);. }.
1340: 20 20 0a 20 20 2f 2a 20 56 65 72 69 66 79 20 74 . /* Verify t
1350: 68 61 74 20 74 68 65 20 63 6f 6d 6d 69 74 20 64 hat the commit d
1360: 69 64 20 6e 6f 74 20 6d 6f 64 69 66 79 20 61 6e id not modify an
1370: 79 20 64 69 73 6b 20 69 6d 61 67 65 73 2e 20 2a y disk images. *
1380: 2f 0a 20 20 76 66 69 6c 65 5f 61 67 67 72 65 67 /. vfile_aggreg
1390: 61 74 65 5f 63 68 65 63 6b 73 75 6d 5f 64 69 73 ate_checksum_dis
13a0: 6b 28 76 69 64 2c 20 26 63 6b 73 75 6d 32 29 3b k(vid, &cksum2);
13b0: 0a 20 20 69 66 28 20 62 6c 6f 62 5f 63 6f 6d 70 . if( blob_comp
13c0: 61 72 65 28 26 63 6b 73 75 6d 31 2c 20 26 63 6b are(&cksum1, &ck
13d0: 73 75 6d 32 29 20 29 7b 0a 20 20 20 20 66 6f 73 sum2) ){. fos
13e0: 73 69 6c 5f 70 61 6e 69 63 28 22 74 72 65 65 20 sil_panic("tree
13f0: 63 68 65 63 6b 73 75 6d 73 20 62 65 66 6f 72 65 checksums before
1400: 20 61 6e 64 20 61 66 74 65 72 20 63 6f 6d 6d 69 and after commi
1410: 74 20 64 6f 20 6e 6f 74 20 6d 61 74 63 68 22 29 t do not match")
1420: 3b 0a 20 20 7d 0a 0a 20 20 2f 2a 20 43 6c 65 61 ;. }.. /* Clea
1430: 72 20 74 68 65 20 75 6e 64 6f 2f 72 65 64 6f 20 r the undo/redo
1440: 73 74 61 63 6b 20 2a 2f 0a 20 20 75 6e 64 6f 5f stack */. undo_
1450: 72 65 73 65 74 28 29 3b 0a 0a 20 20 2f 2a 20 43 reset();.. /* C
1460: 6f 6d 6d 69 74 20 2a 2f 0a 20 20 64 62 5f 65 6e ommit */. db_en
1470: 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 30 29 d_transaction(0)
1480: 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 ;.}../*.** COMMA
1490: 4e 44 3a 20 62 72 61 6e 63 68 0a 2a 2a 0a 2a 2a ND: branch.**.**
14a0: 20 55 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 Usage: %fossil
14b0: 62 72 61 6e 63 68 20 53 55 42 43 4f 4d 4d 41 4e branch SUBCOMMAN
14c0: 44 20 2e 2e 2e 20 3f 2d 52 7c 2d 2d 72 65 70 6f D ... ?-R|--repo
14d0: 73 69 74 6f 72 79 20 46 49 4c 45 3f 0a 2a 2a 0a sitory FILE?.**.
14e0: 2a 2a 20 52 75 6e 20 76 61 72 69 6f 75 73 20 73 ** Run various s
14f0: 75 62 63 6f 6d 6d 61 6e 64 73 20 6f 6e 20 74 68 ubcommands on th
1500: 65 20 62 72 61 6e 63 68 65 73 20 6f 66 20 74 68 e branches of th
1510: 65 20 6f 70 65 6e 20 72 65 70 6f 73 69 74 6f 72 e open repositor
1520: 79 20 6f 0a 2a 2a 20 6f 66 20 74 68 65 20 72 65 y o.** of the re
1530: 70 6f 73 69 74 6f 72 79 20 69 64 65 6e 74 69 66 pository identif
1540: 69 65 64 20 62 79 20 74 68 65 20 2d 52 20 6f 72 ied by the -R or
1550: 20 2d 2d 72 65 70 6f 73 69 74 6f 72 79 20 6f 70 --repository op
1560: 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 25 tion..**.** %
1570: 66 6f 73 73 69 6c 20 62 72 61 6e 63 68 20 6e 65 fossil branch ne
1580: 77 20 3f 2d 62 67 63 6f 6c 6f 72 20 43 4f 4c 4f w ?-bgcolor COLO
1590: 52 20 42 52 41 4e 43 48 2d 4e 41 4d 45 0a 2a 2a R BRANCH-NAME.**
15a0: 0a 2a 2a 20 20 20 20 20 20 20 20 43 72 65 61 74 .** Creat
15b0: 65 20 61 20 6e 65 77 20 62 72 61 6e 63 68 20 42 e a new branch B
15c0: 52 41 4e 43 48 2d 4e 41 4d 45 2e 20 59 6f 75 20 RANCH-NAME. You
15d0: 63 61 6e 20 6f 70 74 69 6f 6e 61 6c 6c 79 20 67 can optionally g
15e0: 69 76 65 0a 2a 2a 20 20 20 20 20 20 20 20 61 20 ive.** a
15f0: 63 6f 6d 6d 69 74 20 6d 65 73 73 61 67 65 20 61 commit message a
1600: 6e 64 20 62 72 61 6e 63 68 20 63 6f 6c 6f 72 2e nd branch color.
1610: 0a 2a 2a 0a 2a 2a 20 20 20 20 25 66 6f 73 73 69 .**.** %fossi
1620: 6c 20 62 72 61 6e 63 68 20 6c 69 73 74 0a 2a 2a l branch list.**
1630: 0a 2a 2a 20 20 20 20 20 20 20 20 4c 69 73 74 20 .** List
1640: 61 6c 6c 20 62 72 61 6e 63 68 65 73 0a 2a 2a 0a all branches.**.
1650: 2a 2f 0a 76 6f 69 64 20 62 72 61 6e 63 68 5f 63 */.void branch_c
1660: 6d 64 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 md(void){. int
1670: 6e 3b 0a 20 20 64 62 5f 66 69 6e 64 5f 61 6e 64 n;. db_find_and
1680: 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 _open_repository
1690: 28 29 3b 0a 20 20 69 66 28 20 67 2e 61 72 67 63 ();. if( g.argc
16a0: 3c 33 20 29 7b 0a 20 20 20 20 75 73 61 67 65 28 <3 ){. usage(
16b0: 22 6e 65 77 7c 6c 69 73 74 20 2e 2e 2e 22 29 3b "new|list ...");
16c0: 0a 20 20 7d 0a 20 20 6e 20 3d 20 73 74 72 6c 65 . }. n = strle
16d0: 6e 28 67 2e 61 72 67 76 5b 32 5d 29 3b 0a 20 20 n(g.argv[2]);.
16e0: 69 66 28 20 6e 3e 3d 32 20 26 26 20 73 74 72 6e if( n>=2 && strn
16f0: 63 6d 70 28 67 2e 61 72 67 76 5b 32 5d 2c 22 6e cmp(g.argv[2],"n
1700: 65 77 22 2c 6e 29 3d 3d 30 20 29 7b 0a 20 20 20 ew",n)==0 ){.
1710: 20 62 72 61 6e 63 68 5f 6e 65 77 28 29 3b 0a 20 branch_new();.
1720: 20 7d 65 6c 73 65 20 69 66 28 20 6e 3e 3d 32 20 }else if( n>=2
1730: 26 26 20 73 74 72 6e 63 6d 70 28 67 2e 61 72 67 && strncmp(g.arg
1740: 76 5b 32 5d 2c 22 6c 69 73 74 22 2c 6e 29 3d 3d v[2],"list",n)==
1750: 30 20 29 7b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 0 ){. }else{.
1760: 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 fossil_panic("
1770: 62 72 61 6e 63 68 20 73 75 62 63 6f 6d 6d 61 6e branch subcomman
1780: 64 20 73 68 6f 75 6c 64 20 62 65 20 6f 6e 65 20 d should be one
1790: 6f 66 3a 20 22 0a 20 20 20 20 20 20 20 20 20 20 of: ".
17a0: 20 20 20 20 20 20 20 22 6e 65 77 20 6c 69 73 74 "new list
17b0: 22 29 3b 0a 20 20 7d 0a 7d 0a ");. }.}.