Hex Artifact Content
Not logged in

Artifact 1d4c15b285af4e360b83f6d0879737f53878c852:

File src/branch.c part of check-in [e4517465f3] - Autosync is now working. Added autosync to tag add, tag branch and branch create. by jnc on 2007-09-25 07:19:55.

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 20 20 0a 20 20  action(0);.  .  
1470: 2f 2a 20 41 75 74 6f 73 79 6e 63 20 61 6e 64 20  /* Autosync and 
1480: 64 6f 20 61 20 70 75 73 68 3f 20 2a 2f 0a 20 20  do a push? */.  
1490: 69 66 28 20 64 6f 5f 61 75 74 6f 73 79 6e 63 28  if( do_autosync(
14a0: 29 20 29 7b 20 20 0a 20 20 20 20 67 2e 61 72 67  ) ){  .    g.arg
14b0: 63 3d 32 3b 0a 20 20 20 20 67 2e 61 72 67 76 5b  c=2;.    g.argv[
14c0: 31 5d 3d 22 70 75 73 68 22 3b 0a 20 20 20 20 70  1]="push";.    p
14d0: 75 73 68 5f 63 6d 64 28 29 3b 0a 20 20 7d 0a 7d  ush_cmd();.  }.}
14e0: 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a  ../*.** COMMAND:
14f0: 20 62 72 61 6e 63 68 0a 2a 2a 0a 2a 2a 20 55 73   branch.**.** Us
1500: 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 62 72 61  age: %fossil bra
1510: 6e 63 68 20 53 55 42 43 4f 4d 4d 41 4e 44 20 2e  nch SUBCOMMAND .
1520: 2e 2e 20 3f 2d 52 7c 2d 2d 72 65 70 6f 73 69 74  .. ?-R|--reposit
1530: 6f 72 79 20 46 49 4c 45 3f 0a 2a 2a 0a 2a 2a 20  ory FILE?.**.** 
1540: 52 75 6e 20 76 61 72 69 6f 75 73 20 73 75 62 63  Run various subc
1550: 6f 6d 6d 61 6e 64 73 20 6f 6e 20 74 68 65 20 62  ommands on the b
1560: 72 61 6e 63 68 65 73 20 6f 66 20 74 68 65 20 6f  ranches of the o
1570: 70 65 6e 20 72 65 70 6f 73 69 74 6f 72 79 20 6f  pen repository o
1580: 0a 2a 2a 20 6f 66 20 74 68 65 20 72 65 70 6f 73  .** of the repos
1590: 69 74 6f 72 79 20 69 64 65 6e 74 69 66 69 65 64  itory identified
15a0: 20 62 79 20 74 68 65 20 2d 52 20 6f 72 20 2d 2d   by the -R or --
15b0: 72 65 70 6f 73 69 74 6f 72 79 20 6f 70 74 69 6f  repository optio
15c0: 6e 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 25 66 6f 73  n..**.**    %fos
15d0: 73 69 6c 20 62 72 61 6e 63 68 20 6e 65 77 20 3f  sil branch new ?
15e0: 2d 62 67 63 6f 6c 6f 72 20 43 4f 4c 4f 52 20 42  -bgcolor COLOR B
15f0: 52 41 4e 43 48 2d 4e 41 4d 45 0a 2a 2a 0a 2a 2a  RANCH-NAME.**.**
1600: 20 20 20 20 20 20 20 20 43 72 65 61 74 65 20 61          Create a
1610: 20 6e 65 77 20 62 72 61 6e 63 68 20 42 52 41 4e   new branch BRAN
1620: 43 48 2d 4e 41 4d 45 2e 20 59 6f 75 20 63 61 6e  CH-NAME. You can
1630: 20 6f 70 74 69 6f 6e 61 6c 6c 79 20 67 69 76 65   optionally give
1640: 0a 2a 2a 20 20 20 20 20 20 20 20 61 20 63 6f 6d  .**        a com
1650: 6d 69 74 20 6d 65 73 73 61 67 65 20 61 6e 64 20  mit message and 
1660: 62 72 61 6e 63 68 20 63 6f 6c 6f 72 2e 0a 2a 2a  branch color..**
1670: 0a 2a 2a 20 20 20 20 25 66 6f 73 73 69 6c 20 62  .**    %fossil b
1680: 72 61 6e 63 68 20 6c 69 73 74 0a 2a 2a 0a 2a 2a  ranch list.**.**
1690: 20 20 20 20 20 20 20 20 4c 69 73 74 20 61 6c 6c          List all
16a0: 20 62 72 61 6e 63 68 65 73 0a 2a 2a 0a 2a 2f 0a   branches.**.*/.
16b0: 76 6f 69 64 20 62 72 61 6e 63 68 5f 63 6d 64 28  void branch_cmd(
16c0: 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 6e 3b 0a  void){.  int n;.
16d0: 20 20 64 62 5f 66 69 6e 64 5f 61 6e 64 5f 6f 70    db_find_and_op
16e0: 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28 29 3b  en_repository();
16f0: 0a 20 20 69 66 28 20 67 2e 61 72 67 63 3c 33 20  .  if( g.argc<3 
1700: 29 7b 0a 20 20 20 20 75 73 61 67 65 28 22 6e 65  ){.    usage("ne
1710: 77 7c 6c 69 73 74 20 2e 2e 2e 22 29 3b 0a 20 20  w|list ...");.  
1720: 7d 0a 20 20 6e 20 3d 20 73 74 72 6c 65 6e 28 67  }.  n = strlen(g
1730: 2e 61 72 67 76 5b 32 5d 29 3b 0a 20 20 69 66 28  .argv[2]);.  if(
1740: 20 6e 3e 3d 32 20 26 26 20 73 74 72 6e 63 6d 70   n>=2 && strncmp
1750: 28 67 2e 61 72 67 76 5b 32 5d 2c 22 6e 65 77 22  (g.argv[2],"new"
1760: 2c 6e 29 3d 3d 30 20 29 7b 0a 20 20 20 20 62 72  ,n)==0 ){.    br
1770: 61 6e 63 68 5f 6e 65 77 28 29 3b 0a 20 20 7d 65  anch_new();.  }e
1780: 6c 73 65 20 69 66 28 20 6e 3e 3d 32 20 26 26 20  lse if( n>=2 && 
1790: 73 74 72 6e 63 6d 70 28 67 2e 61 72 67 76 5b 32  strncmp(g.argv[2
17a0: 5d 2c 22 6c 69 73 74 22 2c 6e 29 3d 3d 30 20 29  ],"list",n)==0 )
17b0: 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e  {.    fossil_pan
17c0: 69 63 28 22 62 72 61 6e 63 68 20 6c 69 73 74 20  ic("branch list 
17d0: 69 73 20 6e 6f 74 20 79 65 74 20 63 6f 6d 70 6c  is not yet compl
17e0: 65 74 65 64 22 29 3b 0a 20 20 7d 65 6c 73 65 7b  eted");.  }else{
17f0: 0a 20 20 20 20 66 6f 73 73 69 6c 5f 70 61 6e 69  .    fossil_pani
1800: 63 28 22 62 72 61 6e 63 68 20 73 75 62 63 6f 6d  c("branch subcom
1810: 6d 61 6e 64 20 73 68 6f 75 6c 64 20 62 65 20 6f  mand should be o
1820: 6e 65 20 6f 66 3a 20 22 0a 20 20 20 20 20 20 20  ne of: ".       
1830: 20 20 20 20 20 20 20 20 20 20 22 6e 65 77 20 6c            "new l
1840: 69 73 74 22 29 3b 0a 20 20 7d 0a 7d 0a           ist");.  }.}.