Hex Artifact Content
Not logged in

Artifact 97ebfed53d9d2170c26e5a0b1cd62befad874fff:

File src/branch.c part of check-in [07eaead5dc] - Added RSS feed. You can set the RSS title, description in Setup. Added header to style to include title and pointer to the new RSS feed. The new RSS feed is BaseURL/timeline.rss by jnc on 2007-09-23 18:24:21. Also file src/branch.c part of check-in [dad40ffac0] - Merge the RSS changes. by drh on 2007-09-23 20:18:58.

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: 63 69 2d 73 69 67 22 2c 20 30 29 7c 6e 6f 53 69  ci-sig", 0)|noSi
05b0: 67 6e 3b 0a 20 20 7a 43 6f 6c 6f 72 20 3d 20 66  gn;.  zColor = f
05c0: 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 62 67 63 6f  ind_option("bgco
05d0: 6c 6f 72 22 2c 22 63 22 2c 31 29 3b 0a 20 20 0a  lor","c",1);.  .
05e0: 20 20 76 65 72 69 66 79 5f 61 6c 6c 5f 6f 70 74    verify_all_opt
05f0: 69 6f 6e 73 28 29 3b 0a 20 20 0a 20 20 2f 2a 20  ions();.  .  /* 
0600: 66 6f 73 73 69 6c 20 62 72 61 6e 63 68 20 6e 65  fossil branch ne
0610: 77 20 6e 61 6d 65 20 2a 2f 0a 20 20 69 66 28 20  w name */.  if( 
0620: 67 2e 61 72 67 63 3c 33 20 29 7b 0a 20 20 20 20  g.argc<3 ){.    
0630: 75 73 61 67 65 28 22 62 72 61 6e 63 68 20 6e 65  usage("branch ne
0640: 77 20 3f 2d 62 67 63 6f 6c 6f 72 20 43 4f 4c 4f  w ?-bgcolor COLO
0650: 52 20 42 52 41 4e 43 48 2d 4e 41 4d 45 22 29 3b  R BRANCH-NAME");
0660: 0a 20 20 7d 0a 20 20 7a 42 72 61 6e 63 68 20 3d  .  }.  zBranch =
0670: 20 67 2e 61 72 67 76 5b 33 5d 3b 0a 20 20 69 66   g.argv[3];.  if
0680: 28 20 7a 42 72 61 6e 63 68 3d 3d 30 20 7c 7c 20  ( zBranch==0 || 
0690: 7a 42 72 61 6e 63 68 5b 30 5d 3d 3d 30 20 29 7b  zBranch[0]==0 ){
06a0: 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69  .    fossil_pani
06b0: 63 28 22 62 72 61 6e 63 68 20 6e 61 6d 65 20 63  c("branch name c
06c0: 61 6e 6e 6f 74 20 62 65 20 65 6d 70 74 79 22 29  annot be empty")
06d0: 3b 0a 20 20 7d 0a 0a 20 20 75 73 65 72 5f 73 65  ;.  }..  user_se
06e0: 6c 65 63 74 28 29 3b 0a 20 20 64 62 5f 62 65 67  lect();.  db_beg
06f0: 69 6e 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 29  in_transaction()
0700: 3b 0a 20 20 69 66 28 20 75 6e 73 61 76 65 64 5f  ;.  if( unsaved_
0710: 63 68 61 6e 67 65 73 28 29 20 29 7b 0a 20 20 20  changes() ){.   
0720: 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 74   fossil_panic("t
0730: 68 65 72 65 20 61 72 65 20 75 6e 63 6f 6d 6d 69  here are uncommi
0740: 74 74 65 64 20 63 68 61 6e 67 65 73 2e 20 70 6c  tted changes. pl
0750: 65 61 73 65 20 63 6f 6d 6d 69 74 20 66 69 72 73  ease commit firs
0760: 74 22 29 3b 0a 20 20 7d 0a 0a 20 20 76 69 64 20  t");.  }..  vid 
0770: 3d 20 64 62 5f 6c 67 65 74 5f 69 6e 74 28 22 63  = db_lget_int("c
0780: 68 65 63 6b 6f 75 74 22 2c 20 30 29 3b 0a 20 20  heckout", 0);.  
0790: 76 66 69 6c 65 5f 61 67 67 72 65 67 61 74 65 5f  vfile_aggregate_
07a0: 63 68 65 63 6b 73 75 6d 5f 64 69 73 6b 28 76 69  checksum_disk(vi
07b0: 64 2c 20 26 63 6b 73 75 6d 31 29 3b 0a 20 20 0a  d, &cksum1);.  .
07c0: 20 20 2f 2a 20 43 72 65 61 74 65 20 6f 75 72 20    /* Create our 
07d0: 6e 65 77 20 6d 61 6e 69 66 65 73 74 20 2a 2f 0a  new manifest */.
07e0: 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 6d 61 6e    blob_zero(&man
07f0: 69 66 65 73 74 29 3b 0a 20 20 7a 43 6f 6d 6d 65  ifest);.  zComme
0800: 6e 74 20 3d 20 6d 70 72 69 6e 74 66 28 22 42 72  nt = mprintf("Br
0810: 61 6e 63 68 20 63 72 65 61 74 65 64 20 25 73 22  anch created %s"
0820: 2c 20 7a 42 72 61 6e 63 68 29 3b 0a 20 20 62 6c  , zBranch);.  bl
0830: 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e 69  ob_appendf(&mani
0840: 66 65 73 74 2c 20 22 43 20 25 46 5c 6e 22 2c 20  fest, "C %F\n", 
0850: 7a 43 6f 6d 6d 65 6e 74 29 3b 0a 20 20 7a 44 61  zComment);.  zDa
0860: 74 65 20 3d 20 64 62 5f 74 65 78 74 28 30 2c 20  te = db_text(0, 
0870: 22 53 45 4c 45 43 54 20 64 61 74 65 74 69 6d 65  "SELECT datetime
0880: 28 27 6e 6f 77 27 29 22 29 3b 0a 20 20 7a 44 61  ('now')");.  zDa
0890: 74 65 5b 31 30 5d 20 3d 20 27 54 27 3b 0a 20 20  te[10] = 'T';.  
08a0: 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d 61  blob_appendf(&ma
08b0: 6e 69 66 65 73 74 2c 20 22 44 20 25 73 5c 6e 22  nifest, "D %s\n"
08c0: 2c 20 7a 44 61 74 65 29 3b 0a 0a 20 20 64 62 5f  , zDate);..  db_
08d0: 70 72 65 70 61 72 65 28 26 71 2c 0a 20 20 20 20  prepare(&q,.    
08e0: 22 53 45 4c 45 43 54 20 70 61 74 68 6e 61 6d 65  "SELECT pathname
08f0: 2c 20 75 75 69 64 20 46 52 4f 4d 20 76 66 69 6c  , uuid FROM vfil
0900: 65 20 4a 4f 49 4e 20 62 6c 6f 62 20 4f 4e 20 76  e JOIN blob ON v
0910: 66 69 6c 65 2e 6d 72 69 64 3d 62 6c 6f 62 2e 72  file.mrid=blob.r
0920: 69 64 22 0a 20 20 20 20 22 20 57 48 45 52 45 20  id".    " WHERE 
0930: 4e 4f 54 20 64 65 6c 65 74 65 64 20 41 4e 44 20  NOT deleted AND 
0940: 76 66 69 6c 65 2e 76 69 64 3d 25 64 22 0a 20 20  vfile.vid=%d".  
0950: 20 20 22 20 4f 52 44 45 52 20 42 59 20 31 22 2c    " ORDER BY 1",
0960: 20 76 69 64 29 3b 0a 20 20 77 68 69 6c 65 28 20   vid);.  while( 
0970: 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53 51 4c  db_step(&q)==SQL
0980: 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20 20 63  ITE_ROW ){.    c
0990: 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65  onst char *zName
09a0: 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78   = db_column_tex
09b0: 74 28 26 71 2c 20 30 29 3b 0a 20 20 20 20 63 6f  t(&q, 0);.    co
09c0: 6e 73 74 20 63 68 61 72 20 2a 7a 55 75 69 64 20  nst char *zUuid 
09d0: 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74  = db_column_text
09e0: 28 26 71 2c 20 31 29 3b 0a 20 20 20 20 62 6c 6f  (&q, 1);.    blo
09f0: 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e 69 66  b_appendf(&manif
0a00: 65 73 74 2c 20 22 46 20 25 46 20 25 73 5c 6e 22  est, "F %F %s\n"
0a10: 2c 20 7a 4e 61 6d 65 2c 20 7a 55 75 69 64 29 3b  , zName, zUuid);
0a20: 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69  .  }.  db_finali
0a30: 7a 65 28 26 71 29 3b 0a 20 20 0a 20 20 7a 55 75  ze(&q);.  .  zUu
0a40: 69 64 20 3d 20 64 62 5f 74 65 78 74 28 30 2c 20  id = db_text(0, 
0a50: 22 53 45 4c 45 43 54 20 75 75 69 64 20 46 52 4f  "SELECT uuid FRO
0a60: 4d 20 62 6c 6f 62 20 57 48 45 52 45 20 72 69 64  M blob WHERE rid
0a70: 3d 25 64 22 2c 20 76 69 64 29 3b 0a 20 20 62 6c  =%d", vid);.  bl
0a80: 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e 69  ob_appendf(&mani
0a90: 66 65 73 74 2c 20 22 50 20 25 73 5c 6e 22 2c 20  fest, "P %s\n", 
0aa0: 7a 55 75 69 64 29 3b 0a 20 20 62 6c 6f 62 5f 61  zUuid);.  blob_a
0ab0: 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 74  ppendf(&manifest
0ac0: 2c 20 22 52 20 25 62 5c 6e 22 2c 20 26 63 6b 73  , "R %b\n", &cks
0ad0: 75 6d 31 29 3b 0a 20 20 0a 20 20 69 66 28 20 7a  um1);.  .  if( z
0ae0: 43 6f 6c 6f 72 21 3d 30 20 29 7b 0a 20 20 20 20  Color!=0 ){.    
0af0: 69 66 28 20 73 74 72 63 6d 70 28 22 62 67 63 6f  if( strcmp("bgco
0b00: 6c 6f 72 22 2c 7a 42 72 61 6e 63 68 29 3e 3d 30  lor",zBranch)>=0
0b10: 20 29 7b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 61   ){.      blob_a
0b20: 70 70 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 74  ppendf(&manifest
0b30: 2c 20 22 54 20 2a 25 46 20 2a 5c 6e 22 2c 20 7a  , "T *%F *\n", z
0b40: 42 72 61 6e 63 68 29 3b 0a 20 20 20 20 20 20 62  Branch);.      b
0b50: 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26 6d 61 6e  lob_appendf(&man
0b60: 69 66 65 73 74 2c 20 22 54 20 2a 62 67 63 6f 6c  ifest, "T *bgcol
0b70: 6f 72 20 2a 20 25 46 5c 6e 22 2c 20 7a 43 6f 6c  or * %F\n", zCol
0b80: 6f 72 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a  or);.    }else{.
0b90: 20 20 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e        blob_appen
0ba0: 64 66 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 54  df(&manifest, "T
0bb0: 20 2a 62 67 63 6f 6c 6f 72 20 2a 20 25 46 5c 6e   *bgcolor * %F\n
0bc0: 22 2c 20 7a 43 6f 6c 6f 72 29 3b 0a 20 20 20 20  ", zColor);.    
0bd0: 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 26    blob_appendf(&
0be0: 6d 61 6e 69 66 65 73 74 2c 20 22 54 20 2a 25 46  manifest, "T *%F
0bf0: 20 2a 5c 6e 22 2c 20 7a 42 72 61 6e 63 68 29 3b   *\n", zBranch);
0c00: 0a 20 20 20 20 7d 0a 20 20 7d 65 6c 73 65 7b 0a  .    }.  }else{.
0c10: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66      blob_appendf
0c20: 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 54 20 2a  (&manifest, "T *
0c30: 25 46 20 2a 5c 6e 22 2c 20 7a 42 72 61 6e 63 68  %F *\n", zBranch
0c40: 29 3b 0a 20 20 7d 0a 0a 20 20 2f 2a 20 43 61 6e  );.  }..  /* Can
0c50: 63 65 6c 20 61 6e 79 20 74 61 67 73 20 74 68 61  cel any tags tha
0c60: 74 20 70 72 6f 70 61 67 61 74 65 20 2a 2f 0a 20  t propagate */. 
0c70: 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c 20   db_prepare(&q, 
0c80: 0a 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 74  .      "SELECT t
0c90: 61 67 6e 61 6d 65 22 0a 20 20 20 20 20 20 22 20  agname".      " 
0ca0: 20 46 52 4f 4d 20 74 61 67 78 72 65 66 20 4a 4f   FROM tagxref JO
0cb0: 49 4e 20 74 61 67 20 4f 4e 20 74 61 67 78 72 65  IN tag ON tagxre
0cc0: 66 2e 74 61 67 69 64 3d 74 61 67 2e 74 61 67 69  f.tagid=tag.tagi
0cd0: 64 22 0a 20 20 20 20 20 20 22 20 57 48 45 52 45  d".      " WHERE
0ce0: 20 72 69 64 3d 25 64 20 41 4e 44 20 74 61 67 74   rid=%d AND tagt
0cf0: 79 70 65 3d 32 22 2c 20 76 69 64 29 3b 0a 20 20  ype=2", vid);.  
0d00: 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26  while( db_step(&
0d10: 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29  q)==SQLITE_ROW )
0d20: 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72  {.    const char
0d30: 20 2a 7a 54 61 67 6e 61 6d 65 20 3d 20 64 62 5f   *zTagname = db_
0d40: 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 20  column_text(&q, 
0d50: 30 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70  0);.    blob_app
0d60: 65 6e 64 66 28 26 6d 61 6e 69 66 65 73 74 2c 20  endf(&manifest, 
0d70: 22 54 20 2d 25 73 20 2a 5c 6e 22 2c 20 7a 54 61  "T -%s *\n", zTa
0d80: 67 6e 61 6d 65 29 3b 0a 20 20 7d 0a 20 20 64 62  gname);.  }.  db
0d90: 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20  _finalize(&q);. 
0da0: 20 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66   .  blob_appendf
0db0: 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 55 20 25  (&manifest, "U %
0dc0: 46 5c 6e 22 2c 20 67 2e 7a 4c 6f 67 69 6e 29 3b  F\n", g.zLogin);
0dd0: 0a 20 20 6d 64 35 73 75 6d 5f 62 6c 6f 62 28 26  .  md5sum_blob(&
0de0: 6d 61 6e 69 66 65 73 74 2c 20 26 6d 63 6b 73 75  manifest, &mcksu
0df0: 6d 29 3b 0a 20 20 62 6c 6f 62 5f 61 70 70 65 6e  m);.  blob_appen
0e00: 64 66 28 26 6d 61 6e 69 66 65 73 74 2c 20 22 5a  df(&manifest, "Z
0e10: 20 25 62 5c 6e 22 2c 20 26 6d 63 6b 73 75 6d 29   %b\n", &mcksum)
0e20: 3b 0a 20 20 69 66 28 20 21 6e 6f 53 69 67 6e 20  ;.  if( !noSign 
0e30: 26 26 20 63 6c 65 61 72 73 69 67 6e 28 26 6d 61  && clearsign(&ma
0e40: 6e 69 66 65 73 74 2c 20 26 6d 61 6e 69 66 65 73  nifest, &manifes
0e50: 74 29 20 29 7b 0a 20 20 20 20 42 6c 6f 62 20 61  t) ){.    Blob a
0e60: 6e 73 3b 0a 20 20 20 20 62 6c 6f 62 5f 7a 65 72  ns;.    blob_zer
0e70: 6f 28 26 61 6e 73 29 3b 0a 20 20 20 20 70 72 6f  o(&ans);.    pro
0e80: 6d 70 74 5f 75 73 65 72 28 22 75 6e 61 62 6c 65  mpt_user("unable
0e90: 20 74 6f 20 73 69 67 6e 20 6d 61 6e 69 66 65 73   to sign manifes
0ea0: 74 2e 20 20 63 6f 6e 74 69 6e 75 65 20 5b 79 2f  t.  continue [y/
0eb0: 4e 5d 3f 20 22 2c 20 26 61 6e 73 29 3b 0a 20 20  N]? ", &ans);.  
0ec0: 20 20 69 66 28 20 62 6c 6f 62 5f 73 74 72 28 26    if( blob_str(&
0ed0: 61 6e 73 29 5b 30 5d 21 3d 27 79 27 20 29 7b 0a  ans)[0]!='y' ){.
0ee0: 20 20 20 20 20 20 64 62 5f 65 6e 64 5f 74 72 61        db_end_tra
0ef0: 6e 73 61 63 74 69 6f 6e 28 31 29 3b 0a 20 20 20  nsaction(1);.   
0f00: 20 20 20 65 78 69 74 28 31 29 3b 0a 20 20 20 20     exit(1);.    
0f10: 7d 0a 20 20 7d 0a 20 20 0a 20 20 2f 2a 62 6c 6f  }.  }.  .  /*blo
0f20: 62 5f 77 72 69 74 65 5f 74 6f 5f 66 69 6c 65 28  b_write_to_file(
0f30: 26 6d 61 6e 69 66 65 73 74 2c 20 22 6d 61 6e 69  &manifest, "mani
0f40: 66 65 73 74 2e 6e 65 77 22 29 3b 2a 2f 0a 0a 20  fest.new");*/.. 
0f50: 20 6e 76 69 64 20 3d 20 63 6f 6e 74 65 6e 74 5f   nvid = content_
0f60: 70 75 74 28 26 6d 61 6e 69 66 65 73 74 2c 20 30  put(&manifest, 0
0f70: 2c 20 30 29 3b 0a 20 20 69 66 28 20 6e 76 69 64  , 0);.  if( nvid
0f80: 3d 3d 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 69  ==0 ){.    fossi
0f90: 6c 5f 70 61 6e 69 63 28 22 74 72 6f 75 62 6c 65  l_panic("trouble
0fa0: 20 63 6f 6d 6d 69 74 74 69 6e 67 20 6d 61 6e 69   committing mani
0fb0: 66 65 73 74 3a 20 25 73 22 2c 20 67 2e 7a 45 72  fest: %s", g.zEr
0fc0: 72 4d 73 67 29 3b 0a 20 20 7d 0a 20 20 64 62 5f  rMsg);.  }.  db_
0fd0: 6d 75 6c 74 69 5f 65 78 65 63 28 22 49 4e 53 45  multi_exec("INSE
0fe0: 52 54 20 4f 52 20 49 47 4e 4f 52 45 20 49 4e 54  RT OR IGNORE INT
0ff0: 4f 20 75 6e 73 65 6e 74 20 56 41 4c 55 45 53 28  O unsent VALUES(
1000: 25 64 29 22 2c 20 6e 76 69 64 29 3b 0a 20 20 6d  %d)", nvid);.  m
1010: 61 6e 69 66 65 73 74 5f 63 72 6f 73 73 6c 69 6e  anifest_crosslin
1020: 6b 28 6e 76 69 64 2c 20 26 6d 61 6e 69 66 65 73  k(nvid, &manifes
1030: 74 29 3b 0a 20 20 63 6f 6e 74 65 6e 74 5f 64 65  t);.  content_de
1040: 6c 74 69 66 79 28 76 69 64 2c 20 6e 76 69 64 2c  ltify(vid, nvid,
1050: 20 30 29 3b 0a 20 20 7a 55 75 69 64 20 3d 20 64   0);.  zUuid = d
1060: 62 5f 74 65 78 74 28 30 2c 20 22 53 45 4c 45 43  b_text(0, "SELEC
1070: 54 20 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62  T uuid FROM blob
1080: 20 57 48 45 52 45 20 72 69 64 3d 25 64 22 2c 20   WHERE rid=%d", 
1090: 6e 76 69 64 29 3b 0a 20 20 70 72 69 6e 74 66 28  nvid);.  printf(
10a0: 22 42 72 61 6e 63 68 20 56 65 72 73 69 6f 6e 3a  "Branch Version:
10b0: 20 25 73 5c 6e 22 2c 20 7a 55 75 69 64 29 3b 0a   %s\n", zUuid);.
10c0: 20 20 70 72 69 6e 74 66 28 22 5c 6e 22 29 3b 0a    printf("\n");.
10d0: 20 20 70 72 69 6e 74 66 28 22 4e 6f 74 69 63 65    printf("Notice
10e0: 3a 20 77 6f 72 6b 69 6e 67 20 63 6f 70 79 20 6e  : working copy n
10f0: 6f 74 20 75 70 64 61 74 65 64 20 74 6f 20 74 68  ot updated to th
1100: 65 20 6e 65 77 20 62 72 61 6e 63 68 2e 20 49 66  e new branch. If
1110: 5c 6e 22 29 3b 0a 20 20 70 72 69 6e 74 66 28 22  \n");.  printf("
1120: 20 20 20 20 20 20 20 20 79 6f 75 20 77 69 73 68          you wish
1130: 20 74 6f 20 77 6f 72 6b 20 6f 6e 20 74 68 65 20   to work on the 
1140: 6e 65 77 20 62 72 61 6e 63 68 2c 20 75 70 64 61  new branch, upda
1150: 74 65 20 74 6f 5c 6e 22 29 3b 0a 20 20 70 72 69  te to\n");.  pri
1160: 6e 74 66 28 22 20 20 20 20 20 20 20 20 74 68 61  ntf("        tha
1170: 74 20 62 72 61 6e 63 68 20 66 69 72 73 74 3a 5c  t branch first:\
1180: 6e 22 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 5c  n");.  printf("\
1190: 6e 22 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 20  n");.  printf(" 
11a0: 20 20 20 20 20 20 20 66 6f 73 73 69 6c 20 75 70         fossil up
11b0: 64 61 74 65 20 25 73 5c 6e 22 2c 20 7a 42 72 61  date %s\n", zBra
11c0: 6e 63 68 29 3b 0a 0a 20 20 2f 2a 20 56 65 72 69  nch);..  /* Veri
11d0: 66 79 20 74 68 61 74 20 74 68 65 20 6d 61 6e 69  fy that the mani
11e0: 66 65 73 74 20 63 68 65 63 6b 73 75 6d 20 6d 61  fest checksum ma
11f0: 74 63 68 65 73 20 74 68 65 20 65 78 70 65 63 74  tches the expect
1200: 65 64 20 63 68 65 63 6b 73 75 6d 20 2a 2f 0a 20  ed checksum */. 
1210: 20 76 66 69 6c 65 5f 61 67 67 72 65 67 61 74 65   vfile_aggregate
1220: 5f 63 68 65 63 6b 73 75 6d 5f 72 65 70 6f 73 69  _checksum_reposi
1230: 74 6f 72 79 28 6e 76 69 64 2c 20 26 63 6b 73 75  tory(nvid, &cksu
1240: 6d 32 29 3b 0a 20 20 76 66 69 6c 65 5f 61 67 67  m2);.  vfile_agg
1250: 72 65 67 61 74 65 5f 63 68 65 63 6b 73 75 6d 5f  regate_checksum_
1260: 6d 61 6e 69 66 65 73 74 28 6e 76 69 64 2c 20 26  manifest(nvid, &
1270: 63 6b 73 75 6d 32 2c 20 26 63 6b 73 75 6d 31 62  cksum2, &cksum1b
1280: 29 3b 0a 20 20 69 66 28 20 62 6c 6f 62 5f 63 6f  );.  if( blob_co
1290: 6d 70 61 72 65 28 26 63 6b 73 75 6d 31 2c 20 26  mpare(&cksum1, &
12a0: 63 6b 73 75 6d 31 62 29 20 29 7b 0a 20 20 20 20  cksum1b) ){.    
12b0: 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 6d 61  fossil_panic("ma
12c0: 6e 69 66 65 73 74 20 63 68 65 63 6b 73 75 6d 20  nifest checksum 
12d0: 64 6f 65 73 20 6e 6f 74 20 61 67 72 65 65 20 77  does not agree w
12e0: 69 74 68 20 6d 61 6e 69 66 65 73 74 3a 20 22 0a  ith manifest: ".
12f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1300: 20 22 25 62 20 76 65 72 73 75 73 20 25 62 22 2c   "%b versus %b",
1310: 20 26 63 6b 73 75 6d 31 2c 20 26 63 6b 73 75 6d   &cksum1, &cksum
1320: 31 62 29 3b 0a 20 20 7d 0a 20 20 0a 20 20 2f 2a  1b);.  }.  .  /*
1330: 20 56 65 72 69 66 79 20 74 68 61 74 20 74 68 65   Verify that the
1340: 20 63 6f 6d 6d 69 74 20 64 69 64 20 6e 6f 74 20   commit did not 
1350: 6d 6f 64 69 66 79 20 61 6e 79 20 64 69 73 6b 20  modify any disk 
1360: 69 6d 61 67 65 73 2e 20 2a 2f 0a 20 20 76 66 69  images. */.  vfi
1370: 6c 65 5f 61 67 67 72 65 67 61 74 65 5f 63 68 65  le_aggregate_che
1380: 63 6b 73 75 6d 5f 64 69 73 6b 28 76 69 64 2c 20  cksum_disk(vid, 
1390: 26 63 6b 73 75 6d 32 29 3b 0a 20 20 69 66 28 20  &cksum2);.  if( 
13a0: 62 6c 6f 62 5f 63 6f 6d 70 61 72 65 28 26 63 6b  blob_compare(&ck
13b0: 73 75 6d 31 2c 20 26 63 6b 73 75 6d 32 29 20 29  sum1, &cksum2) )
13c0: 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e  {.    fossil_pan
13d0: 69 63 28 22 74 72 65 65 20 63 68 65 63 6b 73 75  ic("tree checksu
13e0: 6d 73 20 62 65 66 6f 72 65 20 61 6e 64 20 61 66  ms before and af
13f0: 74 65 72 20 63 6f 6d 6d 69 74 20 64 6f 20 6e 6f  ter commit do no
1400: 74 20 6d 61 74 63 68 22 29 3b 0a 20 20 7d 0a 0a  t match");.  }..
1410: 20 20 2f 2a 20 43 6c 65 61 72 20 74 68 65 20 75    /* Clear the u
1420: 6e 64 6f 2f 72 65 64 6f 20 73 74 61 63 6b 20 2a  ndo/redo stack *
1430: 2f 0a 20 20 75 6e 64 6f 5f 72 65 73 65 74 28 29  /.  undo_reset()
1440: 3b 0a 0a 20 20 2f 2a 20 43 6f 6d 6d 69 74 20 2a  ;..  /* Commit *
1450: 2f 0a 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73  /.  db_end_trans
1460: 61 63 74 69 6f 6e 28 30 29 3b 0a 7d 0a 0a 2f 2a  action(0);.}../*
1470: 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 62 72 61  .** COMMAND: bra
1480: 6e 63 68 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a  nch.**.** Usage:
1490: 20 25 66 6f 73 73 69 6c 20 62 72 61 6e 63 68 20   %fossil branch 
14a0: 53 55 42 43 4f 4d 4d 41 4e 44 20 2e 2e 2e 20 3f  SUBCOMMAND ... ?
14b0: 2d 52 7c 2d 2d 72 65 70 6f 73 69 74 6f 72 79 20  -R|--repository 
14c0: 46 49 4c 45 3f 0a 2a 2a 0a 2a 2a 20 52 75 6e 20  FILE?.**.** Run 
14d0: 76 61 72 69 6f 75 73 20 73 75 62 63 6f 6d 6d 61  various subcomma
14e0: 6e 64 73 20 6f 6e 20 74 68 65 20 62 72 61 6e 63  nds on the branc
14f0: 68 65 73 20 6f 66 20 74 68 65 20 6f 70 65 6e 20  hes of the open 
1500: 72 65 70 6f 73 69 74 6f 72 79 20 6f 0a 2a 2a 20  repository o.** 
1510: 6f 66 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72  of the repositor
1520: 79 20 69 64 65 6e 74 69 66 69 65 64 20 62 79 20  y identified by 
1530: 74 68 65 20 2d 52 20 6f 72 20 2d 2d 72 65 70 6f  the -R or --repo
1540: 73 69 74 6f 72 79 20 6f 70 74 69 6f 6e 2e 0a 2a  sitory option..*
1550: 2a 0a 2a 2a 20 20 20 20 25 66 6f 73 73 69 6c 20  *.**    %fossil 
1560: 62 72 61 6e 63 68 20 6e 65 77 20 3f 2d 62 67 63  branch new ?-bgc
1570: 6f 6c 6f 72 20 43 4f 4c 4f 52 20 42 52 41 4e 43  olor COLOR BRANC
1580: 48 2d 4e 41 4d 45 0a 2a 2a 0a 2a 2a 20 20 20 20  H-NAME.**.**    
1590: 20 20 20 20 43 72 65 61 74 65 20 61 20 6e 65 77      Create a new
15a0: 20 62 72 61 6e 63 68 20 42 52 41 4e 43 48 2d 4e   branch BRANCH-N
15b0: 41 4d 45 2e 20 59 6f 75 20 63 61 6e 20 6f 70 74  AME. You can opt
15c0: 69 6f 6e 61 6c 6c 79 20 67 69 76 65 0a 2a 2a 20  ionally give.** 
15d0: 20 20 20 20 20 20 20 61 20 63 6f 6d 6d 69 74 20         a commit 
15e0: 6d 65 73 73 61 67 65 20 61 6e 64 20 62 72 61 6e  message and bran
15f0: 63 68 20 63 6f 6c 6f 72 2e 0a 2a 2a 0a 2a 2a 20  ch color..**.** 
1600: 20 20 20 25 66 6f 73 73 69 6c 20 62 72 61 6e 63     %fossil branc
1610: 68 20 6c 69 73 74 0a 2a 2a 0a 2a 2a 20 20 20 20  h list.**.**    
1620: 20 20 20 20 4c 69 73 74 20 61 6c 6c 20 62 72 61      List all bra
1630: 6e 63 68 65 73 0a 2a 2a 0a 2a 2f 0a 76 6f 69 64  nches.**.*/.void
1640: 20 62 72 61 6e 63 68 5f 63 6d 64 28 76 6f 69 64   branch_cmd(void
1650: 29 7b 0a 20 20 69 6e 74 20 6e 3b 0a 20 20 64 62  ){.  int n;.  db
1660: 5f 66 69 6e 64 5f 61 6e 64 5f 6f 70 65 6e 5f 72  _find_and_open_r
1670: 65 70 6f 73 69 74 6f 72 79 28 29 3b 0a 20 20 69  epository();.  i
1680: 66 28 20 67 2e 61 72 67 63 3c 33 20 29 7b 0a 20  f( g.argc<3 ){. 
1690: 20 20 20 75 73 61 67 65 28 22 6e 65 77 7c 6c 69     usage("new|li
16a0: 73 74 20 2e 2e 2e 22 29 3b 0a 20 20 7d 0a 20 20  st ...");.  }.  
16b0: 6e 20 3d 20 73 74 72 6c 65 6e 28 67 2e 61 72 67  n = strlen(g.arg
16c0: 76 5b 32 5d 29 3b 0a 20 20 69 66 28 20 6e 3e 3d  v[2]);.  if( n>=
16d0: 32 20 26 26 20 73 74 72 6e 63 6d 70 28 67 2e 61  2 && strncmp(g.a
16e0: 72 67 76 5b 32 5d 2c 22 6e 65 77 22 2c 6e 29 3d  rgv[2],"new",n)=
16f0: 3d 30 20 29 7b 0a 20 20 20 20 62 72 61 6e 63 68  =0 ){.    branch
1700: 5f 6e 65 77 28 29 3b 0a 20 20 7d 65 6c 73 65 20  _new();.  }else 
1710: 69 66 28 20 6e 3e 3d 32 20 26 26 20 73 74 72 6e  if( n>=2 && strn
1720: 63 6d 70 28 67 2e 61 72 67 76 5b 32 5d 2c 22 6c  cmp(g.argv[2],"l
1730: 69 73 74 22 2c 6e 29 3d 3d 30 20 29 7b 0a 20 20  ist",n)==0 ){.  
1740: 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22    fossil_panic("
1750: 62 72 61 6e 63 68 20 6c 69 73 74 20 69 73 20 6e  branch list is n
1760: 6f 74 20 79 65 74 20 63 6f 6d 70 6c 65 74 65 64  ot yet completed
1770: 22 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20  ");.  }else{.   
1780: 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 62   fossil_panic("b
1790: 72 61 6e 63 68 20 73 75 62 63 6f 6d 6d 61 6e 64  ranch subcommand
17a0: 20 73 68 6f 75 6c 64 20 62 65 20 6f 6e 65 20 6f   should be one o
17b0: 66 3a 20 22 0a 20 20 20 20 20 20 20 20 20 20 20  f: ".           
17c0: 20 20 20 20 20 20 22 6e 65 77 20 6c 69 73 74 22        "new list"
17d0: 29 3b 0a 20 20 7d 0a 7d 0a                       );.  }.}.