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 72 65 61 74 65 20 6e 65 sed to create ne
0390: 77 20 62 72 61 6e 63 68 65 73 20 77 69 74 68 69 w branches withi
03a0: 6e 20 61 20 72 65 70 6f 73 69 74 6f 72 79 2e 0a n a repository..
03b0: 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f 6e */.#include "con
03c0: 66 69 67 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 fig.h".#include
03d0: 22 62 72 61 6e 63 68 2e 68 22 0a 23 69 6e 63 6c "branch.h".#incl
03e0: 75 64 65 20 3c 61 73 73 65 72 74 2e 68 3e 0a 0a ude <assert.h>..
03f0: 76 6f 69 64 20 62 72 61 6e 63 68 5f 6e 65 77 28 void branch_new(
0400: 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 76 69 64 void){. int vid
0410: 2c 20 6e 76 69 64 2c 20 6e 6f 53 69 67 6e 3b 0a , nvid, noSign;.
0420: 20 20 53 74 6d 74 20 71 3b 0a 20 20 63 68 61 72 Stmt q;. char
0430: 20 2a 7a 42 72 61 6e 63 68 2c 20 2a 7a 55 75 69 *zBranch, *zUui
0440: 64 2c 20 2a 7a 44 61 74 65 2c 20 2a 7a 43 6f 6d d, *zDate, *zCom
0450: 6d 65 6e 74 3b 0a 20 20 63 6f 6e 73 74 20 63 68 ment;. const ch
0460: 61 72 20 2a 7a 43 6f 6c 6f 72 3b 0a 20 20 42 6c ar *zColor;. Bl
0470: 6f 62 20 6d 61 6e 69 66 65 73 74 3b 0a 20 20 42 ob manifest;. B
0480: 6c 6f 62 20 6d 63 6b 73 75 6d 3b 20 20 20 20 20 lob mcksum;
0490: 20 20 20 20 20 20 2f 2a 20 53 65 6c 66 2d 63 68 /* Self-ch
04a0: 65 63 6b 73 75 6d 20 6f 6e 20 74 68 65 20 6d 61 ecksum on the ma
04b0: 6e 69 66 65 73 74 20 2a 2f 0a 20 20 42 6c 6f 62 nifest */. Blob
04c0: 20 63 6b 73 75 6d 31 2c 20 63 6b 73 75 6d 32 3b cksum1, cksum2;
04d0: 20 20 20 2f 2a 20 42 65 66 6f 72 65 20 61 6e 64 /* Before and
04e0: 20 61 66 74 65 72 20 63 6f 6d 6d 69 74 20 63 68 after commit ch
04f0: 65 63 6b 73 75 6d 73 20 2a 2f 0a 20 20 42 6c 6f ecksums */. Blo
0500: 62 20 63 6b 73 75 6d 31 62 3b 20 20 20 20 20 20 b cksum1b;
0510: 20 20 20 20 2f 2a 20 43 68 65 63 6b 73 75 6d 20 /* Checksum
0520: 72 65 63 6f 72 64 65 64 20 69 6e 20 74 68 65 20 recorded in the
0530: 6d 61 6e 69 66 65 73 74 20 2a 2f 0a 20 0a 20 20 manifest */. .
0540: 6e 6f 53 69 67 6e 20 3d 20 66 69 6e 64 5f 6f 70 noSign = find_op
0550: 74 69 6f 6e 28 22 6e 6f 73 69 67 6e 22 2c 22 22 tion("nosign",""
0560: 2c 30 29 21 3d 30 3b 0a 20 20 64 62 5f 6d 75 73 ,0)!=0;. db_mus
0570: 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72 65 65 t_be_within_tree
0580: 28 29 3b 0a 20 20 6e 6f 53 69 67 6e 20 3d 20 64 ();. noSign = d
0590: 62 5f 67 65 74 5f 69 6e 74 28 22 6f 6d 69 74 2d b_get_int("omit-
05a0: 73 69 67 6e 22 2c 20 30 29 7c 6e 6f 53 69 67 6e sign", 0)|noSign
05b0: 3b 0a 20 20 7a 43 6f 6c 6f 72 20 3d 20 66 69 6e ;. zColor = fin
05c0: 64 5f 6f 70 74 69 6f 6e 28 22 62 67 63 6f 6c 6f d_option("bgcolo
05d0: 72 22 2c 22 63 22 2c 31 29 3b 0a 20 20 0a 20 20 r","c",1);. .
05e0: 76 65 72 69 66 79 5f 61 6c 6c 5f 6f 70 74 69 6f verify_all_optio
05f0: 6e 73 28 29 3b 0a 20 20 0a 20 20 2f 2a 20 66 6f ns();. . /* fo
0600: 73 73 69 6c 20 62 72 61 6e 63 68 20 6e 65 77 20 ssil branch new
0610: 6e 61 6d 65 20 2a 2f 0a 20 20 69 66 28 20 67 2e name */. if( g.
0620: 61 72 67 63 3c 33 20 29 7b 0a 20 20 20 20 75 73 argc<3 ){. us
0630: 61 67 65 28 22 62 72 61 6e 63 68 20 6e 65 77 20 age("branch new
0640: 3f 2d 62 67 63 6f 6c 6f 72 20 43 4f 4c 4f 52 20 ?-bgcolor COLOR
0650: 42 52 41 4e 43 48 2d 4e 41 4d 45 22 29 3b 0a 20 BRANCH-NAME");.
0660: 20 7d 0a 20 20 7a 42 72 61 6e 63 68 20 3d 20 67 }. zBranch = g
0670: 2e 61 72 67 76 5b 33 5d 3b 0a 20 20 69 66 28 20 .argv[3];. if(
0680: 7a 42 72 61 6e 63 68 3d 3d 30 20 7c 7c 20 7a 42 zBranch==0 || zB
0690: 72 61 6e 63 68 5b 30 5d 3d 3d 30 20 29 7b 0a 20 ranch[0]==0 ){.
06a0: 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 fossil_panic(
06b0: 22 62 72 61 6e 63 68 20 6e 61 6d 65 20 63 61 6e "branch name can
06c0: 6e 6f 74 20 62 65 20 65 6d 70 74 79 22 29 3b 0a not be empty");.
06d0: 20 20 7d 0a 0a 20 20 75 73 65 72 5f 73 65 6c 65 }.. user_sele
06e0: 63 74 28 29 3b 0a 20 20 64 62 5f 62 65 67 69 6e ct();. db_begin
06f0: 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a _transaction();.
0700: 20 20 69 66 28 20 75 6e 73 61 76 65 64 5f 63 68 if( unsaved_ch
0710: 61 6e 67 65 73 28 29 20 29 7b 0a 20 20 20 20 66 anges() ){. f
0720: 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 74 68 65 ossil_panic("the
0730: 72 65 20 61 72 65 20 75 6e 63 6f 6d 6d 69 74 74 re are uncommitt
0740: 65 64 20 63 68 61 6e 67 65 73 2e 20 70 6c 65 61 ed changes. plea
0750: 73 65 20 63 6f 6d 6d 69 74 20 66 69 72 73 74 22 se commit first"
0760: 29 3b 0a 20 20 7d 0a 0a 20 20 76 69 64 20 3d 20 );. }.. vid =
0770: 64 62 5f 6c 67 65 74 5f 69 6e 74 28 22 63 68 65 db_lget_int("che
0780: 63 6b 6f 75 74 22 2c 20 30 29 3b 0a 20 20 76 66 ckout", 0);. vf
0790: 69 6c 65 5f 61 67 67 72 65 67 61 74 65 5f 63 68 ile_aggregate_ch
07a0: 65 63 6b 73 75 6d 5f 64 69 73 6b 28 76 69 64 2c ecksum_disk(vid,
07b0: 20 26 63 6b 73 75 6d 31 29 3b 0a 20 20 0a 20 20 &cksum1);. .
07c0: 2f 2a 20 43 72 65 61 74 65 20 6f 75 72 20 6e 65 /* Create our ne
07d0: 77 20 6d 61 6e 69 66 65 73 74 20 2a 2f 0a 20 20 w manifest */.
07e0: 62 6c 6f 62 5f 7a 65 72 6f 28 26 6d 61 6e 69 66 blob_zero(&manif
07f0: 65 73 74 29 3b 0a 20 20 7a 43 6f 6d 6d 65 6e 74 est);. zComment
0800: 20 3d 20 6d 70 72 69 6e 74 66 28 22 42 72 61 6e = mprintf("Bran
0810: 63 68 20 63 72 65 61 74 65 64 20 25 73 22 2c 20 ch created %s",
0820: 7a 42 72 61 6e 63 68 29 3b 0a 20 20 62 6c 6f 62 zBranch);. blob
0830: 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 _appendf(&manife
0840: 73 74 2c 20 22 43 20 25 46 5c 6e 22 2c 20 7a 43 st, "C %F\n", zC
0850: 6f 6d 6d 65 6e 74 29 3b 0a 20 20 7a 44 61 74 65 omment);. zDate
0860: 20 3d 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 = db_text(0, "S
0870: 45 4c 45 43 54 20 64 61 74 65 74 69 6d 65 28 27 ELECT datetime('
0880: 6e 6f 77 27 29 22 29 3b 0a 20 20 7a 44 61 74 65 now')");. zDate
0890: 5b 31 30 5d 20 3d 20 27 54 27 3b 0a 20 20 62 6c [10] = 'T';. bl
08a0: 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 ob_appendf(&mani
08b0: 66 65 73 74 2c 20 22 44 20 25 73 5c 6e 22 2c 20 fest, "D %s\n",
08c0: 7a 44 61 74 65 29 3b 0a 0a 20 20 64 62 5f 70 72 zDate);.. db_pr
08d0: 65 70 61 72 65 28 26 71 2c 0a 20 20 20 20 22 53 epare(&q,. "S
08e0: 45 4c 45 43 54 20 70 61 74 68 6e 61 6d 65 2c 20 ELECT pathname,
08f0: 75 75 69 64 20 46 52 4f 4d 20 76 66 69 6c 65 20 uuid FROM vfile
0900: 4a 4f 49 4e 20 62 6c 6f 62 20 4f 4e 20 76 66 69 JOIN blob ON vfi
0910: 6c 65 2e 6d 72 69 64 3d 62 6c 6f 62 2e 72 69 64 le.mrid=blob.rid
0920: 22 0a 20 20 20 20 22 20 57 48 45 52 45 20 4e 4f ". " WHERE NO
0930: 54 20 64 65 6c 65 74 65 64 20 41 4e 44 20 76 66 T deleted AND vf
0940: 69 6c 65 2e 76 69 64 3d 25 64 22 0a 20 20 20 20 ile.vid=%d".
0950: 22 20 4f 52 44 45 52 20 42 59 20 31 22 2c 20 76 " ORDER BY 1", v
0960: 69 64 29 3b 0a 20 20 77 68 69 6c 65 28 20 64 62 id);. while( db
0970: 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 _step(&q)==SQLIT
0980: 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 63 6f 6e E_ROW ){. con
0990: 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 20 3d st char *zName =
09a0: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 db_column_text(
09b0: 26 71 2c 20 30 29 3b 0a 20 20 20 20 63 6f 6e 73 &q, 0);. cons
09c0: 74 20 63 68 61 72 20 2a 7a 55 75 69 64 20 3d 20 t char *zUuid =
09d0: 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 db_column_text(&
09e0: 71 2c 20 31 29 3b 0a 20 20 20 20 62 6c 6f 62 5f q, 1);. blob_
09f0: 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 appendf(&manifes
0a00: 74 2c 20 22 46 20 25 46 20 25 73 5c 6e 22 2c 20 t, "F %F %s\n",
0a10: 7a 4e 61 6d 65 2c 20 7a 55 75 69 64 29 3b 0a 20 zName, zUuid);.
0a20: 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 }. db_finalize
0a30: 28 26 71 29 3b 0a 20 20 0a 20 20 7a 55 75 69 64 (&q);. . zUuid
0a40: 20 3d 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 = db_text(0, "S
0a50: 45 4c 45 43 54 20 75 75 69 64 20 46 52 4f 4d 20 ELECT uuid FROM
0a60: 62 6c 6f 62 20 57 48 45 52 45 20 72 69 64 3d 25 blob WHERE rid=%
0a70: 64 22 2c 20 76 69 64 29 3b 0a 20 20 62 6c 6f 62 d", vid);. blob
0a80: 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 _appendf(&manife
0a90: 73 74 2c 20 22 50 20 25 73 5c 6e 22 2c 20 7a 55 st, "P %s\n", zU
0aa0: 75 69 64 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 uid);. blob_app
0ab0: 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 74 2c 20 endf(&manifest,
0ac0: 22 52 20 25 62 5c 6e 22 2c 20 26 63 6b 73 75 6d "R %b\n", &cksum
0ad0: 31 29 3b 0a 20 20 0a 20 20 69 66 28 20 7a 43 6f 1);. . if( zCo
0ae0: 6c 6f 72 21 3d 30 20 29 7b 0a 20 20 20 20 69 66 lor!=0 ){. if
0af0: 28 20 73 74 72 63 6d 70 28 22 62 67 63 6f 6c 6f ( strcmp("bgcolo
0b00: 72 22 2c 7a 42 72 61 6e 63 68 29 3e 3d 30 20 29 r",zBranch)>=0 )
0b10: 7b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 {. blob_app
0b20: 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 74 2c 20 endf(&manifest,
0b30: 22 54 20 2a 25 46 20 2a 5c 6e 22 2c 20 7a 42 72 "T *%F *\n", zBr
0b40: 61 6e 63 68 29 3b 0a 20 20 20 20 20 20 62 6c 6f anch);. blo
0b50: 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 b_appendf(&manif
0b60: 65 73 74 2c 20 22 54 20 2a 62 67 63 6f 6c 6f 72 est, "T *bgcolor
0b70: 20 2a 20 25 46 5c 6e 22 2c 20 7a 43 6f 6c 6f 72 * %F\n", zColor
0b80: 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 );. }else{.
0b90: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 blob_appendf
0ba0: 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 54 20 2a (&manifest, "T *
0bb0: 62 67 63 6f 6c 6f 72 20 2a 20 25 46 5c 6e 22 2c bgcolor * %F\n",
0bc0: 20 7a 43 6f 6c 6f 72 29 3b 0a 20 20 20 20 20 20 zColor);.
0bd0: 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 blob_appendf(&ma
0be0: 6e 69 66 65 73 74 2c 20 22 54 20 2a 25 46 20 2a nifest, "T *%F *
0bf0: 5c 6e 22 2c 20 7a 42 72 61 6e 63 68 29 3b 0a 20 \n", zBranch);.
0c00: 20 20 20 7d 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 }. }else{.
0c10: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 blob_appendf(&
0c20: 6d 61 6e 69 66 65 73 74 2c 20 22 54 20 2a 25 46 manifest, "T *%F
0c30: 20 2a 5c 6e 22 2c 20 7a 42 72 61 6e 63 68 29 3b *\n", zBranch);
0c40: 0a 20 20 7d 0a 0a 20 20 2f 2a 20 43 61 6e 63 65 . }.. /* Cance
0c50: 6c 20 61 6e 79 20 74 61 67 73 20 74 68 61 74 20 l any tags that
0c60: 70 72 6f 70 61 67 61 74 65 20 2a 2f 0a 20 20 64 propagate */. d
0c70: 62 5f 70 72 65 70 61 72 65 28 26 71 2c 20 0a 20 b_prepare(&q, .
0c80: 20 20 20 20 20 22 53 45 4c 45 43 54 20 74 61 67 "SELECT tag
0c90: 6e 61 6d 65 22 0a 20 20 20 20 20 20 22 20 20 46 name". " F
0ca0: 52 4f 4d 20 74 61 67 78 72 65 66 20 4a 4f 49 4e ROM tagxref JOIN
0cb0: 20 74 61 67 20 4f 4e 20 74 61 67 78 72 65 66 2e tag ON tagxref.
0cc0: 74 61 67 69 64 3d 74 61 67 2e 74 61 67 69 64 22 tagid=tag.tagid"
0cd0: 0a 20 20 20 20 20 20 22 20 57 48 45 52 45 20 72 . " WHERE r
0ce0: 69 64 3d 25 64 20 41 4e 44 20 74 61 67 74 79 70 id=%d AND tagtyp
0cf0: 65 3d 32 22 2c 20 76 69 64 29 3b 0a 20 20 77 68 e=2", vid);. wh
0d00: 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 29 ile( db_step(&q)
0d10: 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a ==SQLITE_ROW ){.
0d20: 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a const char *
0d30: 7a 54 61 67 6e 61 6d 65 20 3d 20 64 62 5f 63 6f zTagname = db_co
0d40: 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20 30 29 lumn_text(&q, 0)
0d50: 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e ;. blob_appen
0d60: 64 66 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 54 df(&manifest, "T
0d70: 20 2d 25 73 20 2a 5c 6e 22 2c 20 7a 54 61 67 6e -%s *\n", zTagn
0d80: 61 6d 65 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 66 ame);. }. db_f
0d90: 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 0a inalize(&q);. .
0da0: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 blob_appendf(&
0db0: 6d 61 6e 69 66 65 73 74 2c 20 22 55 20 25 46 5c manifest, "U %F\
0dc0: 6e 22 2c 20 67 2e 7a 4c 6f 67 69 6e 29 3b 0a 20 n", g.zLogin);.
0dd0: 20 6d 64 35 73 75 6d 5f 62 6c 6f 62 28 26 6d 61 md5sum_blob(&ma
0de0: 6e 69 66 65 73 74 2c 20 26 6d 63 6b 73 75 6d 29 nifest, &mcksum)
0df0: 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 ;. blob_appendf
0e00: 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 5a 20 25 (&manifest, "Z %
0e10: 62 5c 6e 22 2c 20 26 6d 63 6b 73 75 6d 29 3b 0a b\n", &mcksum);.
0e20: 20 20 69 66 28 20 21 6e 6f 53 69 67 6e 20 26 26 if( !noSign &&
0e30: 20 63 6c 65 61 72 73 69 67 6e 28 26 6d 61 6e 69 clearsign(&mani
0e40: 66 65 73 74 2c 20 26 6d 61 6e 69 66 65 73 74 29 fest, &manifest)
0e50: 20 29 7b 0a 20 20 20 20 42 6c 6f 62 20 61 6e 73 ){. Blob ans
0e60: 3b 0a 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 ;. blob_zero(
0e70: 26 61 6e 73 29 3b 0a 20 20 20 20 70 72 6f 6d 70 &ans);. promp
0e80: 74 5f 75 73 65 72 28 22 75 6e 61 62 6c 65 20 74 t_user("unable t
0e90: 6f 20 73 69 67 6e 20 6d 61 6e 69 66 65 73 74 2e o sign manifest.
0ea0: 20 20 63 6f 6e 74 69 6e 75 65 20 5b 79 2f 4e 5d continue [y/N]
0eb0: 3f 20 22 2c 20 26 61 6e 73 29 3b 0a 20 20 20 20 ? ", &ans);.
0ec0: 69 66 28 20 62 6c 6f 62 5f 73 74 72 28 26 61 6e if( blob_str(&an
0ed0: 73 29 5b 30 5d 21 3d 27 79 27 20 29 7b 0a 20 20 s)[0]!='y' ){.
0ee0: 20 20 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 db_end_trans
0ef0: 61 63 74 69 6f 6e 28 31 29 3b 0a 20 20 20 20 20 action(1);.
0f00: 20 65 78 69 74 28 31 29 3b 0a 20 20 20 20 7d 0a exit(1);. }.
0f10: 20 20 7d 0a 20 20 0a 20 20 2f 2a 62 6c 6f 62 5f }. . /*blob_
0f20: 77 72 69 74 65 5f 74 6f 5f 66 69 6c 65 28 26 6d write_to_file(&m
0f30: 61 6e 69 66 65 73 74 2c 20 22 6d 61 6e 69 66 65 anifest, "manife
0f40: 73 74 2e 6e 65 77 22 29 3b 2a 2f 0a 0a 20 20 6e st.new");*/.. n
0f50: 76 69 64 20 3d 20 63 6f 6e 74 65 6e 74 5f 70 75 vid = content_pu
0f60: 74 28 26 6d 61 6e 69 66 65 73 74 2c 20 30 2c 20 t(&manifest, 0,
0f70: 30 29 3b 0a 20 20 69 66 28 20 6e 76 69 64 3d 3d 0);. if( nvid==
0f80: 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 0 ){. fossil_
0f90: 70 61 6e 69 63 28 22 74 72 6f 75 62 6c 65 20 63 panic("trouble c
0fa0: 6f 6d 6d 69 74 74 69 6e 67 20 6d 61 6e 69 66 65 ommitting manife
0fb0: 73 74 3a 20 25 73 22 2c 20 67 2e 7a 45 72 72 4d st: %s", g.zErrM
0fc0: 73 67 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 6d 75 sg);. }. db_mu
0fd0: 6c 74 69 5f 65 78 65 63 28 22 49 4e 53 45 52 54 lti_exec("INSERT
0fe0: 20 4f 52 20 49 47 4e 4f 52 45 20 49 4e 54 4f 20 OR IGNORE INTO
0ff0: 75 6e 73 65 6e 74 20 56 41 4c 55 45 53 28 25 64 unsent VALUES(%d
1000: 29 22 2c 20 6e 76 69 64 29 3b 0a 20 20 6d 61 6e )", nvid);. man
1010: 69 66 65 73 74 5f 63 72 6f 73 73 6c 69 6e 6b 28 ifest_crosslink(
1020: 6e 76 69 64 2c 20 26 6d 61 6e 69 66 65 73 74 29 nvid, &manifest)
1030: 3b 0a 20 20 63 6f 6e 74 65 6e 74 5f 64 65 6c 74 ;. content_delt
1040: 69 66 79 28 76 69 64 2c 20 6e 76 69 64 2c 20 30 ify(vid, nvid, 0
1050: 29 3b 0a 20 20 7a 55 75 69 64 20 3d 20 64 62 5f );. zUuid = db_
1060: 74 65 78 74 28 30 2c 20 22 53 45 4c 45 43 54 20 text(0, "SELECT
1070: 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62 20 57 uuid FROM blob W
1080: 48 45 52 45 20 72 69 64 3d 25 64 22 2c 20 6e 76 HERE rid=%d", nv
1090: 69 64 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 42 id);. printf("B
10a0: 72 61 6e 63 68 20 56 65 72 73 69 6f 6e 3a 20 25 ranch Version: %
10b0: 73 5c 6e 22 2c 20 7a 55 75 69 64 29 3b 0a 20 20 s\n", zUuid);.
10c0: 70 72 69 6e 74 66 28 22 5c 6e 22 29 3b 0a 20 20 printf("\n");.
10d0: 70 72 69 6e 74 66 28 22 4e 6f 74 69 63 65 3a 20 printf("Notice:
10e0: 77 6f 72 6b 69 6e 67 20 63 6f 70 79 20 6e 6f 74 working copy not
10f0: 20 75 70 64 61 74 65 64 20 74 6f 20 74 68 65 20 updated to the
1100: 6e 65 77 20 62 72 61 6e 63 68 2e 20 49 66 5c 6e new branch. If\n
1110: 22 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 20 20 ");. printf("
1120: 20 20 20 20 20 20 79 6f 75 20 77 69 73 68 20 74 you wish t
1130: 6f 20 77 6f 72 6b 20 6f 6e 20 74 68 65 20 6e 65 o work on the ne
1140: 77 20 62 72 61 6e 63 68 2c 20 75 70 64 61 74 65 w branch, update
1150: 20 74 6f 5c 6e 22 29 3b 0a 20 20 70 72 69 6e 74 to\n");. print
1160: 66 28 22 20 20 20 20 20 20 20 20 74 68 61 74 20 f(" that
1170: 62 72 61 6e 63 68 20 66 69 72 73 74 3a 5c 6e 22 branch first:\n"
1180: 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 5c 6e 22 );. printf("\n"
1190: 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 20 20 20 );. printf("
11a0: 20 20 20 20 20 66 6f 73 73 69 6c 20 75 70 64 61 fossil upda
11b0: 74 65 20 25 73 5c 6e 22 2c 20 7a 42 72 61 6e 63 te %s\n", zBranc
11c0: 68 29 3b 0a 0a 20 20 2f 2a 20 56 65 72 69 66 79 h);.. /* Verify
11d0: 20 74 68 61 74 20 74 68 65 20 6d 61 6e 69 66 65 that the manife
11e0: 73 74 20 63 68 65 63 6b 73 75 6d 20 6d 61 74 63 st checksum matc
11f0: 68 65 73 20 74 68 65 20 65 78 70 65 63 74 65 64 hes the expected
1200: 20 63 68 65 63 6b 73 75 6d 20 2a 2f 0a 20 20 76 checksum */. v
1210: 66 69 6c 65 5f 61 67 67 72 65 67 61 74 65 5f 63 file_aggregate_c
1220: 68 65 63 6b 73 75 6d 5f 72 65 70 6f 73 69 74 6f hecksum_reposito
1230: 72 79 28 6e 76 69 64 2c 20 26 63 6b 73 75 6d 32 ry(nvid, &cksum2
1240: 29 3b 0a 20 20 76 66 69 6c 65 5f 61 67 67 72 65 );. vfile_aggre
1250: 67 61 74 65 5f 63 68 65 63 6b 73 75 6d 5f 6d 61 gate_checksum_ma
1260: 6e 69 66 65 73 74 28 6e 76 69 64 2c 20 26 63 6b nifest(nvid, &ck
1270: 73 75 6d 32 2c 20 26 63 6b 73 75 6d 31 62 29 3b sum2, &cksum1b);
1280: 0a 20 20 69 66 28 20 62 6c 6f 62 5f 63 6f 6d 70 . if( blob_comp
1290: 61 72 65 28 26 63 6b 73 75 6d 31 2c 20 26 63 6b are(&cksum1, &ck
12a0: 73 75 6d 31 62 29 20 29 7b 0a 20 20 20 20 66 6f sum1b) ){. fo
12b0: 73 73 69 6c 5f 70 61 6e 69 63 28 22 6d 61 6e 69 ssil_panic("mani
12c0: 66 65 73 74 20 63 68 65 63 6b 73 75 6d 20 64 6f fest checksum do
12d0: 65 73 20 6e 6f 74 20 61 67 72 65 65 20 77 69 74 es not agree wit
12e0: 68 20 6d 61 6e 69 66 65 73 74 3a 20 22 0a 20 20 h manifest: ".
12f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
1300: 25 62 20 76 65 72 73 75 73 20 25 62 22 2c 20 26 %b versus %b", &
1310: 63 6b 73 75 6d 31 2c 20 26 63 6b 73 75 6d 31 62 cksum1, &cksum1b
1320: 29 3b 0a 20 20 7d 0a 20 20 0a 20 20 2f 2a 20 56 );. }. . /* V
1330: 65 72 69 66 79 20 74 68 61 74 20 74 68 65 20 63 erify that the c
1340: 6f 6d 6d 69 74 20 64 69 64 20 6e 6f 74 20 6d 6f ommit did not mo
1350: 64 69 66 79 20 61 6e 79 20 64 69 73 6b 20 69 6d dify any disk im
1360: 61 67 65 73 2e 20 2a 2f 0a 20 20 76 66 69 6c 65 ages. */. vfile
1370: 5f 61 67 67 72 65 67 61 74 65 5f 63 68 65 63 6b _aggregate_check
1380: 73 75 6d 5f 64 69 73 6b 28 76 69 64 2c 20 26 63 sum_disk(vid, &c
1390: 6b 73 75 6d 32 29 3b 0a 20 20 69 66 28 20 62 6c ksum2);. if( bl
13a0: 6f 62 5f 63 6f 6d 70 61 72 65 28 26 63 6b 73 75 ob_compare(&cksu
13b0: 6d 31 2c 20 26 63 6b 73 75 6d 32 29 20 29 7b 0a m1, &cksum2) ){.
13c0: 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 fossil_panic
13d0: 28 22 74 72 65 65 20 63 68 65 63 6b 73 75 6d 73 ("tree checksums
13e0: 20 62 65 66 6f 72 65 20 61 6e 64 20 61 66 74 65 before and afte
13f0: 72 20 63 6f 6d 6d 69 74 20 64 6f 20 6e 6f 74 20 r commit do not
1400: 6d 61 74 63 68 22 29 3b 0a 20 20 7d 0a 0a 20 20 match");. }..
1410: 2f 2a 20 43 6c 65 61 72 20 74 68 65 20 75 6e 64 /* Clear the und
1420: 6f 2f 72 65 64 6f 20 73 74 61 63 6b 20 2a 2f 0a o/redo stack */.
1430: 20 20 75 6e 64 6f 5f 72 65 73 65 74 28 29 3b 0a undo_reset();.
1440: 0a 20 20 2f 2a 20 43 6f 6d 6d 69 74 20 2a 2f 0a . /* Commit */.
1450: 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 db_end_transac
1460: 74 69 6f 6e 28 30 29 3b 0a 20 20 0a 20 20 2f 2a tion(0);. . /*
1470: 20 44 6f 20 61 6e 20 61 75 74 6f 73 79 6e 63 20 Do an autosync
1480: 70 75 73 68 2c 20 69 66 20 72 65 71 75 65 73 74 push, if request
1490: 65 64 20 2a 2f 0a 20 20 61 75 74 6f 73 79 6e 63 ed */. autosync
14a0: 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f (0);.}../*.** CO
14b0: 4d 4d 41 4e 44 3a 20 62 72 61 6e 63 68 0a 2a 2a MMAND: branch.**
14c0: 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f 73 73 .** Usage: %foss
14d0: 69 6c 20 62 72 61 6e 63 68 20 53 55 42 43 4f 4d il branch SUBCOM
14e0: 4d 41 4e 44 20 2e 2e 2e 20 3f 2d 52 7c 2d 2d 72 MAND ... ?-R|--r
14f0: 65 70 6f 73 69 74 6f 72 79 20 46 49 4c 45 3f 0a epository FILE?.
1500: 2a 2a 0a 2a 2a 20 52 75 6e 20 76 61 72 69 6f 75 **.** Run variou
1510: 73 20 73 75 62 63 6f 6d 6d 61 6e 64 73 20 6f 6e s subcommands on
1520: 20 74 68 65 20 62 72 61 6e 63 68 65 73 20 6f 66 the branches of
1530: 20 74 68 65 20 6f 70 65 6e 20 72 65 70 6f 73 69 the open reposi
1540: 74 6f 72 79 20 6f 0a 2a 2a 20 6f 66 20 74 68 65 tory o.** of the
1550: 20 72 65 70 6f 73 69 74 6f 72 79 20 69 64 65 6e repository iden
1560: 74 69 66 69 65 64 20 62 79 20 74 68 65 20 2d 52 tified by the -R
1570: 20 6f 72 20 2d 2d 72 65 70 6f 73 69 74 6f 72 79 or --repository
1580: 20 6f 70 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 20 option..**.**
1590: 20 20 25 66 6f 73 73 69 6c 20 62 72 61 6e 63 68 %fossil branch
15a0: 20 6e 65 77 20 3f 2d 62 67 63 6f 6c 6f 72 20 43 new ?-bgcolor C
15b0: 4f 4c 4f 52 20 42 52 41 4e 43 48 2d 4e 41 4d 45 OLOR BRANCH-NAME
15c0: 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 43 72 .**.** Cr
15d0: 65 61 74 65 20 61 20 6e 65 77 20 62 72 61 6e 63 eate a new branc
15e0: 68 20 42 52 41 4e 43 48 2d 4e 41 4d 45 2e 20 59 h BRANCH-NAME. Y
15f0: 6f 75 20 63 61 6e 20 6f 70 74 69 6f 6e 61 6c 6c ou can optionall
1600: 79 20 67 69 76 65 0a 2a 2a 20 20 20 20 20 20 20 y give.**
1610: 20 61 20 63 6f 6d 6d 69 74 20 6d 65 73 73 61 67 a commit messag
1620: 65 20 61 6e 64 20 62 72 61 6e 63 68 20 63 6f 6c e and branch col
1630: 6f 72 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 25 66 6f or..**.** %fo
1640: 73 73 69 6c 20 62 72 61 6e 63 68 20 6c 69 73 74 ssil branch list
1650: 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 4c 69 .**.** Li
1660: 73 74 20 61 6c 6c 20 62 72 61 6e 63 68 65 73 0a st all branches.
1670: 2a 2a 0a 2a 2f 0a 76 6f 69 64 20 62 72 61 6e 63 **.*/.void branc
1680: 68 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 69 h_cmd(void){. i
1690: 6e 74 20 6e 3b 0a 20 20 64 62 5f 66 69 6e 64 5f nt n;. db_find_
16a0: 61 6e 64 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 and_open_reposit
16b0: 6f 72 79 28 29 3b 0a 20 20 69 66 28 20 67 2e 61 ory();. if( g.a
16c0: 72 67 63 3c 33 20 29 7b 0a 20 20 20 20 75 73 61 rgc<3 ){. usa
16d0: 67 65 28 22 6e 65 77 7c 6c 69 73 74 20 2e 2e 2e ge("new|list ...
16e0: 22 29 3b 0a 20 20 7d 0a 20 20 6e 20 3d 20 73 74 ");. }. n = st
16f0: 72 6c 65 6e 28 67 2e 61 72 67 76 5b 32 5d 29 3b rlen(g.argv[2]);
1700: 0a 20 20 69 66 28 20 6e 3e 3d 32 20 26 26 20 73 . if( n>=2 && s
1710: 74 72 6e 63 6d 70 28 67 2e 61 72 67 76 5b 32 5d trncmp(g.argv[2]
1720: 2c 22 6e 65 77 22 2c 6e 29 3d 3d 30 20 29 7b 0a ,"new",n)==0 ){.
1730: 20 20 20 20 62 72 61 6e 63 68 5f 6e 65 77 28 29 branch_new()
1740: 3b 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 6e 3e ;. }else if( n>
1750: 3d 32 20 26 26 20 73 74 72 6e 63 6d 70 28 67 2e =2 && strncmp(g.
1760: 61 72 67 76 5b 32 5d 2c 22 6c 69 73 74 22 2c 6e argv[2],"list",n
1770: 29 3d 3d 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 )==0 ){. foss
1780: 69 6c 5f 70 61 6e 69 63 28 22 62 72 61 6e 63 68 il_panic("branch
1790: 20 6c 69 73 74 20 69 73 20 6e 6f 74 20 79 65 74 list is not yet
17a0: 20 63 6f 6d 70 6c 65 74 65 64 22 29 3b 0a 20 20 completed");.
17b0: 7d 65 6c 73 65 7b 0a 20 20 20 20 66 6f 73 73 69 }else{. fossi
17c0: 6c 5f 70 61 6e 69 63 28 22 62 72 61 6e 63 68 20 l_panic("branch
17d0: 73 75 62 63 6f 6d 6d 61 6e 64 20 73 68 6f 75 6c subcommand shoul
17e0: 64 20 62 65 20 6f 6e 65 20 6f 66 3a 20 22 0a 20 d be one of: ".
17f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1800: 22 6e 65 77 20 6c 69 73 74 22 29 3b 0a 20 20 7d "new list");. }
1810: 0a 7d 0a .}.