Hex Artifact Content
Not logged in

Artifact 763e35ebbe736af438869e370ba05f5e8a7d4db9:

File src/construct.c part of check-in [7a2c37063a] - merge trunk into creole branch by bob on 2009-09-22 07:49:39. Also file src/construct.c part of check-in [00ac7945a9] - Disconnect the global configuration database in ~/.fossil from the respository database in most cases. This allows multiple "sync" or "commit" operations to be running on different repositories at the same time. by drh on 2009-08-13 14:27:24.

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 41 6e 64 72 65 61 73  (c) 2007 Andreas
0020: 20 4b 75 70 72 69 65 73 0a 2a 2a 0a 2a 2a 20 54   Kupries.**.** 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 61 6b 75 70 72 69 65 73 40 73 68 61 77 2e 63   akupries@shaw.c
02f0: 61 0a 2a 2a 20 20 20 0a 2a 2a 0a 2a 2a 2a 2a 2a  a.**   .**.*****
0300: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0310: 2a 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 0a 2a 2a 0a 2a 2a  **********.**.**
0350: 20 54 68 69 73 20 66 69 6c 65 20 63 6f 6e 74 61   This file conta
0360: 69 6e 73 20 63 6f 64 65 20 75 73 65 64 20 74 6f  ins code used to
0370: 20 64 65 2d 20 61 6e 64 20 72 65 63 6f 6e 73 74   de- and reconst
0380: 72 75 63 74 20 61 20 72 65 70 6f 73 69 74 6f 72  ruct a repositor
0390: 79 0a 2a 2a 20 69 6e 74 6f 20 61 6e 64 20 66 72  y.** into and fr
03a0: 6f 6d 20 61 6e 20 69 6e 64 69 63 61 74 65 64 20  om an indicated 
03b0: 64 69 72 65 63 74 6f 72 79 2e 0a 2a 2f 0a 23 69  directory..*/.#i
03c0: 6e 63 6c 75 64 65 20 22 63 6f 6e 66 69 67 2e 68  nclude "config.h
03d0: 22 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f 6e 73  ".#include "cons
03e0: 74 72 75 63 74 2e 68 22 0a 23 69 6e 63 6c 75 64  truct.h".#includ
03f0: 65 20 3c 61 73 73 65 72 74 2e 68 3e 0a 23 69 6e  e <assert.h>.#in
0400: 63 6c 75 64 65 20 3c 73 79 73 2f 74 79 70 65 73  clude <sys/types
0410: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 64 69  .h>.#include <di
0420: 72 65 6e 74 2e 68 3e 0a 0a 2f 2a 20 54 68 69 73  rent.h>../* This
0430: 20 66 75 6e 63 74 69 6f 6e 20 72 65 63 75 72 73   function recurs
0440: 69 76 65 6c 79 20 73 63 61 6e 73 20 74 68 65 20  ively scans the 
0450: 64 69 72 65 63 74 6f 72 79 20 68 69 65 72 61 72  directory hierar
0460: 63 68 79 20 73 74 61 72 74 69 6e 67 20 61 74 0a  chy starting at.
0470: 2a 2a 20 7a 4f 72 69 67 69 6e 20 61 6e 64 20 65  ** zOrigin and e
0480: 6e 74 65 72 73 20 61 6c 6c 20 66 6f 75 6e 64 20  nters all found 
0490: 66 69 6c 65 73 20 69 6e 74 6f 20 74 68 65 20 72  files into the r
04a0: 65 70 6f 73 69 74 6f 72 79 2e 20 54 68 65 20 75  epository. The u
04b0: 75 69 64 20 69 73 0a 2a 2a 20 67 65 6e 65 72 61  uid is.** genera
04c0: 74 65 64 20 66 72 6f 6d 20 74 68 65 20 66 69 6c  ted from the fil
04d0: 65 20 63 6f 6e 74 65 6e 74 73 2c 20 61 6e 64 20  e contents, and 
04e0: 6e 6f 74 20 74 61 6b 65 6e 20 66 72 6f 6d 20 74  not taken from t
04f0: 68 65 2c 20 70 6f 73 73 69 62 6c 79 0a 2a 2a 20  he, possibly.** 
0500: 6d 6f 64 69 66 69 65 64 2c 20 66 69 6c 65 20 6e  modified, file n
0510: 61 6d 65 2e 20 57 68 69 6c 65 20 66 75 6e 63 74  ame. While funct
0520: 69 6f 6e 20 69 73 20 61 62 6c 65 20 74 6f 20 68  ion is able to h
0530: 61 6e 64 6c 65 20 74 68 65 20 64 69 72 65 63 74  andle the direct
0540: 6f 72 79 0a 2a 2a 20 73 74 72 75 63 74 75 72 65  ory.** structure
0550: 20 63 72 65 61 74 65 64 20 62 79 20 27 64 65 63   created by 'dec
0560: 6f 6e 73 74 72 75 63 74 27 20 69 74 20 63 61 6e  onstruct' it can
0570: 20 61 63 74 75 61 6c 6c 79 20 6d 75 63 68 20 6d   actually much m
0580: 6f 72 65 2e 0a 2a 2f 0a 0a 73 74 61 74 69 63 20  ore..*/..static 
0590: 69 6e 74 20 69 6d 70 6f 72 74 5f 6f 72 69 67 69  int import_origi
05a0: 6e 28 63 6f 6e 73 74 20 63 68 61 72 2a 20 7a 4f  n(const char* zO
05b0: 72 69 67 69 6e 29 7b 0a 20 20 44 49 52 20 2a 64  rigin){.  DIR *d
05c0: 3b 0a 20 20 69 6e 74 20 63 6f 75 6e 74 20 3d 20  ;.  int count = 
05d0: 30 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  0;.  const char 
05e0: 2a 7a 46 6f 72 6d 61 74 3b 0a 20 20 63 6f 6e 73  *zFormat;.  cons
05f0: 74 20 63 68 61 72 20 2a 7a 44 69 72 20 3d 20 7a  t char *zDir = z
0600: 4f 72 69 67 69 6e 3b 0a 20 20 73 74 72 75 63 74  Origin;.  struct
0610: 20 64 69 72 65 6e 74 20 2a 70 45 6e 74 72 79 3b   dirent *pEntry;
0620: 0a 0a 20 20 69 66 28 20 7a 44 69 72 5b 30 5d 3d  ..  if( zDir[0]=
0630: 3d 30 20 29 7b 0a 20 20 20 20 20 7a 44 69 72 20  =0 ){.     zDir 
0640: 3d 20 22 2e 22 3b 0a 20 20 20 20 20 7a 46 6f 72  = ".";.     zFor
0650: 6d 61 74 20 3d 20 22 25 73 25 73 22 3b 0a 20 20  mat = "%s%s";.  
0660: 7d 65 6c 73 65 7b 0a 20 20 20 20 20 7a 46 6f 72  }else{.     zFor
0670: 6d 61 74 20 3d 20 22 25 73 2f 25 73 22 3b 0a 20  mat = "%s/%s";. 
0680: 20 7d 0a 0a 20 20 64 20 3d 20 6f 70 65 6e 64 69   }..  d = opendi
0690: 72 28 7a 44 69 72 29 3b 0a 20 20 69 66 28 20 64  r(zDir);.  if( d
06a0: 20 29 7b 0a 20 20 20 20 77 68 69 6c 65 28 20 28   ){.    while( (
06b0: 70 45 6e 74 72 79 3d 72 65 61 64 64 69 72 28 64  pEntry=readdir(d
06c0: 29 29 21 3d 30 20 29 7b 0a 20 20 20 20 20 20 63  ))!=0 ){.      c
06d0: 68 61 72 20 2a 7a 50 61 74 68 3b 0a 20 20 20 20  har *zPath;.    
06e0: 20 20 69 66 28 20 70 45 6e 74 72 79 2d 3e 64 5f    if( pEntry->d_
06f0: 6e 61 6d 65 5b 30 5d 3d 3d 27 2e 27 20 29 20 63  name[0]=='.' ) c
0700: 6f 6e 74 69 6e 75 65 3b 0a 20 20 20 20 20 20 7a  ontinue;.      z
0710: 50 61 74 68 20 3d 20 6d 70 72 69 6e 74 66 28 7a  Path = mprintf(z
0720: 46 6f 72 6d 61 74 2c 20 7a 4f 72 69 67 69 6e 2c  Format, zOrigin,
0730: 20 70 45 6e 74 72 79 2d 3e 64 5f 6e 61 6d 65 29   pEntry->d_name)
0740: 3b 0a 20 20 20 20 20 20 69 66 28 20 66 69 6c 65  ;.      if( file
0750: 5f 69 73 64 69 72 28 7a 50 61 74 68 29 3d 3d 31  _isdir(zPath)==1
0760: 20 29 7b 0a 20 20 20 20 20 20 20 20 63 6f 75 6e   ){.        coun
0770: 74 20 2b 3d 20 69 6d 70 6f 72 74 5f 6f 72 69 67  t += import_orig
0780: 69 6e 28 7a 50 61 74 68 29 3b 0a 20 20 20 20 20  in(zPath);.     
0790: 20 7d 65 6c 73 65 20 69 66 28 20 66 69 6c 65 5f   }else if( file_
07a0: 69 73 66 69 6c 65 28 7a 50 61 74 68 29 20 29 7b  isfile(zPath) ){
07b0: 0a 09 42 6c 6f 62 20 7a 49 6e 3b 0a 09 62 6c 6f  ..Blob zIn;..blo
07c0: 62 5f 72 65 61 64 5f 66 72 6f 6d 5f 66 69 6c 65  b_read_from_file
07d0: 20 28 26 7a 49 6e 2c 7a 50 61 74 68 29 3b 0a 09   (&zIn,zPath);..
07e0: 63 6f 6e 74 65 6e 74 5f 70 75 74 20 28 26 7a 49  content_put (&zI
07f0: 6e 2c 20 30 2c 20 30 29 3b 0a 09 62 6c 6f 62 5f  n, 0, 0);..blob_
0800: 72 65 73 65 74 20 28 26 7a 49 6e 29 3b 0a 09 63  reset (&zIn);..c
0810: 6f 75 6e 74 2b 2b 3b 0a 20 20 20 20 20 20 7d 0a  ount++;.      }.
0820: 20 20 20 20 20 20 66 72 65 65 20 28 7a 50 61 74        free (zPat
0830: 68 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20  h);.    }.  }.  
0840: 63 6c 6f 73 65 64 69 72 28 64 29 3b 0a 20 20 72  closedir(d);.  r
0850: 65 74 75 72 6e 20 63 6f 75 6e 74 3b 0a 7d 0a 0a  eturn count;.}..
0860: 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 64  /*.** COMMAND: d
0870: 65 63 6f 6e 73 74 72 75 63 74 20 0a 2a 2a 20 55  econstruct .** U
0880: 73 61 67 65 20 25 66 6f 73 73 69 6c 20 64 65 63  sage %fossil dec
0890: 6f 6e 73 74 72 75 63 74 20 3f 2d 52 7c 2d 2d 72  onstruct ?-R|--r
08a0: 65 70 6f 73 69 74 6f 72 79 20 52 45 50 4f 53 49  epository REPOSI
08b0: 54 4f 52 59 3f 20 44 45 53 54 49 4e 41 54 49 4f  TORY? DESTINATIO
08c0: 4e 0a 2a 2a 0a 2a 2a 20 50 6f 70 75 6c 61 74 65  N.**.** Populate
08d0: 73 20 74 68 65 20 69 6e 64 69 63 61 74 65 64 20  s the indicated 
08e0: 44 45 53 54 49 4e 41 54 49 4f 4e 20 64 69 72 65  DESTINATION dire
08f0: 63 74 6f 72 79 20 77 69 74 68 20 63 6f 70 69 65  ctory with copie
0900: 73 20 6f 66 20 61 6c 6c 0a 2a 2a 20 61 72 74 69  s of all.** arti
0910: 66 63 61 74 73 20 63 6f 6e 74 61 69 6e 65 64 20  fcats contained 
0920: 77 69 74 68 69 6e 20 74 68 65 20 72 65 70 6f 73  within the repos
0930: 69 74 6f 72 79 2e 20 20 41 72 74 69 66 61 63 74  itory.  Artifact
0940: 73 20 61 72 65 20 6e 61 6d 65 64 20 41 41 2f 62  s are named AA/b
0950: 62 62 62 62 0a 2a 2a 20 77 68 65 72 65 20 41 41  bbbb.** where AA
0960: 20 69 73 20 74 68 65 20 66 69 72 73 74 20 32 20   is the first 2 
0970: 63 68 61 72 61 63 74 65 72 73 20 6f 66 20 74 68  characters of th
0980: 65 20 61 72 74 69 66 61 63 74 20 49 44 20 61 6e  e artifact ID an
0990: 64 20 62 62 62 62 62 20 69 73 20 74 68 65 0a 2a  d bbbbb is the.*
09a0: 2a 20 72 65 6d 61 69 6e 69 6e 67 20 33 38 20 63  * remaining 38 c
09b0: 68 61 72 61 63 74 65 72 73 2e 0a 2a 2f 0a 0a 76  haracters..*/..v
09c0: 6f 69 64 20 64 65 63 6f 6e 73 74 72 75 63 74 5f  oid deconstruct_
09d0: 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 63 6f 6e  cmd(void){.  con
09e0: 73 74 20 63 68 61 72 2a 20 7a 44 65 73 74 69 6e  st char* zDestin
09f0: 61 74 69 6f 6e 3b 0a 20 20 42 6c 6f 62 20 7a 4f  ation;.  Blob zO
0a00: 75 74 3b 0a 20 20 53 74 6d 74 20 71 3b 0a 20 20  ut;.  Stmt q;.  
0a10: 69 66 28 20 28 67 2e 61 72 67 63 20 21 3d 20 33  if( (g.argc != 3
0a20: 29 20 26 26 20 28 67 2e 61 72 67 63 20 21 3d 20  ) && (g.argc != 
0a30: 35 29 20 29 7b 0a 20 20 20 20 75 73 61 67 65 20  5) ){.    usage 
0a40: 28 22 3f 2d 52 7c 2d 2d 72 65 70 6f 73 69 74 6f  ("?-R|--reposito
0a50: 72 79 20 52 45 50 4f 53 49 54 4f 52 59 3f 20 44  ry REPOSITORY? D
0a60: 45 53 54 49 4e 41 54 49 4f 4e 22 29 3b 0a 20 20  ESTINATION");.  
0a70: 7d 0a 20 20 64 62 5f 66 69 6e 64 5f 61 6e 64 5f  }.  db_find_and_
0a80: 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28  open_repository(
0a90: 31 29 3b 0a 20 20 7a 44 65 73 74 69 6e 61 74 69  1);.  zDestinati
0aa0: 6f 6e 20 3d 20 67 2e 61 72 67 76 5b 67 2e 61 72  on = g.argv[g.ar
0ab0: 67 63 2d 31 5d 3b 0a 20 20 69 66 28 20 21 66 69  gc-1];.  if( !fi
0ac0: 6c 65 5f 69 73 64 69 72 20 28 7a 44 65 73 74 69  le_isdir (zDesti
0ad0: 6e 61 74 69 6f 6e 29 20 29 7b 0a 20 20 20 20 66  nation) ){.    f
0ae0: 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 6e 6f 74  ossil_panic("not
0af0: 20 61 20 64 69 72 65 63 74 6f 72 79 3a 20 25 73   a directory: %s
0b00: 22 2c 20 7a 44 65 73 74 69 6e 61 74 69 6f 6e 29  ", zDestination)
0b10: 3b 0a 20 20 7d 0a 20 20 2f 2a 20 49 74 65 72 61  ;.  }.  /* Itera
0b20: 74 65 20 6f 76 65 72 20 61 6c 6c 20 62 6c 6f 62  te over all blob
0b30: 73 20 69 6e 20 74 68 65 20 72 65 70 6f 73 69 74  s in the reposit
0b40: 6f 72 79 2c 20 72 65 74 72 69 65 76 65 20 74 68  ory, retrieve th
0b50: 65 69 72 0a 20 20 20 2a 20 63 6f 6e 74 65 6e 74  eir.   * content
0b60: 73 2c 20 61 6e 64 20 77 72 69 74 65 20 74 68 65  s, and write the
0b70: 6d 20 74 6f 20 61 20 66 69 6c 65 20 77 69 74 68  m to a file with
0b80: 20 61 20 6e 61 6d 65 20 62 61 73 65 64 20 6f 6e   a name based on
0b90: 20 74 68 65 69 72 0a 20 20 20 2a 20 75 75 69 64   their.   * uuid
0ba0: 2e 20 4e 6f 74 65 3a 20 4e 6f 6e 2d 77 72 69 74  . Note: Non-writ
0bb0: 61 62 6c 65 20 64 65 73 74 69 6e 61 74 69 6f 6e  able destination
0bc0: 20 63 61 75 73 65 73 20 62 61 69 6c 2d 6f 75 74   causes bail-out
0bd0: 20 69 6e 20 74 68 65 20 66 69 72 73 74 0a 20 20   in the first.  
0be0: 20 2a 20 63 61 6c 6c 20 6f 66 20 62 6c 6f 62 5f   * call of blob_
0bf0: 77 72 69 74 65 5f 74 6f 5f 66 69 6c 65 2e 0a 20  write_to_file.. 
0c00: 20 20 2a 2f 0a 20 20 64 62 5f 70 72 65 70 61 72    */.  db_prepar
0c10: 65 28 26 71 2c 20 22 53 45 4c 45 43 54 20 72 69  e(&q, "SELECT ri
0c20: 64 2c 75 75 69 64 20 46 52 4f 4d 20 62 6c 6f 62  d,uuid FROM blob
0c30: 22 29 3b 0a 20 20 77 68 69 6c 65 28 20 64 62 5f  ");.  while( db_
0c40: 73 74 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 45  step(&q)==SQLITE
0c50: 5f 52 4f 57 20 29 7b 0a 20 20 20 20 69 6e 74 20  _ROW ){.    int 
0c60: 20 20 20 20 20 20 20 20 72 69 64 20 20 20 3d 20          rid   = 
0c70: 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 20 28 26  db_column_int (&
0c80: 71 2c 20 30 29 3b 0a 20 20 20 20 63 6f 6e 73 74  q, 0);.    const
0c90: 20 63 68 61 72 20 2a 7a 55 75 69 64 20 3d 20 64   char *zUuid = d
0ca0: 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71  b_column_text(&q
0cb0: 2c 20 31 29 3b 0a 20 20 20 20 63 68 61 72 20 20  , 1);.    char  
0cc0: 20 20 20 20 20 2a 7a 46 69 6c 65 20 3d 20 6d 70       *zFile = mp
0cd0: 72 69 6e 74 66 20 28 22 25 73 2f 25 2e 32 73 2f  rintf ("%s/%.2s/
0ce0: 25 73 22 2c 20 7a 44 65 73 74 69 6e 61 74 69 6f  %s", zDestinatio
0cf0: 6e 2c 20 7a 55 75 69 64 2c 20 7a 55 75 69 64 20  n, zUuid, zUuid 
0d00: 2b 20 32 29 3b 0a 20 20 20 20 63 6f 6e 74 65 6e  + 2);.    conten
0d10: 74 5f 67 65 74 20 28 72 69 64 2c 26 7a 4f 75 74  t_get (rid,&zOut
0d20: 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 77 72 69 74  );.    blob_writ
0d30: 65 5f 74 6f 5f 66 69 6c 65 20 28 26 7a 4f 75 74  e_to_file (&zOut
0d40: 2c 7a 46 69 6c 65 29 3b 0a 20 20 20 20 62 6c 6f  ,zFile);.    blo
0d50: 62 5f 72 65 73 65 74 20 28 26 7a 4f 75 74 29 3b  b_reset (&zOut);
0d60: 0a 20 20 20 20 66 72 65 65 28 7a 46 69 6c 65 29  .    free(zFile)
0d70: 3b 0a 20 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c  ;.  }.  db_final
0d80: 69 7a 65 28 26 71 29 3b 0a 7d 0a 0a 2f 2a 0a 2a  ize(&q);.}../*.*
0d90: 2a 20 43 4f 4d 4d 41 4e 44 3a 20 72 65 63 6f 6e  * COMMAND: recon
0da0: 73 74 72 75 63 74 20 0a 2a 2a 20 55 73 61 67 65  struct .** Usage
0db0: 20 25 66 6f 73 73 69 6c 20 72 65 63 6f 6e 73 74   %fossil reconst
0dc0: 72 75 63 74 20 52 45 50 4f 53 49 54 4f 52 59 20  ruct REPOSITORY 
0dd0: 4f 52 49 47 49 4e 0a 2a 2a 0a 2a 2a 20 43 72 65  ORIGIN.**.** Cre
0de0: 61 74 65 73 20 74 68 65 20 52 45 50 4f 53 49 54  ates the REPOSIT
0df0: 4f 52 59 20 61 6e 64 20 70 6f 70 75 6c 61 74 65  ORY and populate
0e00: 73 20 69 74 20 77 69 74 68 20 74 68 65 20 61 72  s it with the ar
0e10: 74 69 66 61 63 74 73 20 69 6e 20 74 68 65 0a 2a  tifacts in the.*
0e20: 2a 20 69 6e 64 69 63 61 74 65 64 20 4f 52 49 47  * indicated ORIG
0e30: 49 4e 20 64 69 72 65 63 74 6f 72 79 2e 0a 2a 2f  IN directory..*/
0e40: 0a 0a 76 6f 69 64 20 72 65 63 6f 6e 73 74 72 75  ..void reconstru
0e50: 63 74 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20  ct_cmd(void){.  
0e60: 63 6f 6e 73 74 20 63 68 61 72 2a 20 7a 4f 72 69  const char* zOri
0e70: 67 69 6e 3b 0a 20 20 63 6f 6e 73 74 20 63 68 61  gin;.  const cha
0e80: 72 2a 20 7a 52 65 70 6f 73 69 74 6f 72 79 3b 0a  r* zRepository;.
0e90: 20 20 69 6e 74 20 66 69 6c 65 43 6e 74 3b 0a 20    int fileCnt;. 
0ea0: 20 69 6e 74 20 65 72 72 43 6e 74 3b 0a 0a 20 20   int errCnt;..  
0eb0: 69 66 28 20 67 2e 61 72 67 63 20 21 3d 20 34 20  if( g.argc != 4 
0ec0: 29 7b 0a 20 20 20 20 75 73 61 67 65 20 28 22 52  ){.    usage ("R
0ed0: 45 50 4f 53 49 54 4f 52 59 20 4f 52 49 47 49 4e  EPOSITORY ORIGIN
0ee0: 22 29 3b 0a 20 20 7d 0a 20 20 7a 52 65 70 6f 73  ");.  }.  zRepos
0ef0: 69 74 6f 72 79 20 3d 20 67 2e 61 72 67 76 5b 32  itory = g.argv[2
0f00: 5d 3b 0a 20 20 7a 4f 72 69 67 69 6e 20 20 20 20  ];.  zOrigin    
0f10: 20 3d 20 67 2e 61 72 67 76 5b 33 5d 3b 0a 20 20   = g.argv[3];.  
0f20: 69 66 28 20 21 66 69 6c 65 5f 69 73 64 69 72 20  if( !file_isdir 
0f30: 28 7a 4f 72 69 67 69 6e 29 20 29 7b 0a 20 20 20  (zOrigin) ){.   
0f40: 20 66 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 6e   fossil_panic("n
0f50: 6f 74 20 61 20 64 69 72 65 63 74 6f 72 79 3a 20  ot a directory: 
0f60: 25 73 22 2c 20 7a 4f 72 69 67 69 6e 29 3b 0a 20  %s", zOrigin);. 
0f70: 20 7d 0a 0a 20 20 2f 2a 20 43 72 65 61 74 65 20   }..  /* Create 
0f80: 74 68 65 20 66 6f 75 6e 64 61 74 69 6f 6e 20 2a  the foundation *
0f90: 2f 0a 20 20 64 62 5f 63 72 65 61 74 65 5f 72 65  /.  db_create_re
0fa0: 70 6f 73 69 74 6f 72 79 28 7a 52 65 70 6f 73 69  pository(zReposi
0fb0: 74 6f 72 79 29 3b 0a 20 20 64 62 5f 6f 70 65 6e  tory);.  db_open
0fc0: 5f 72 65 70 6f 73 69 74 6f 72 79 28 7a 52 65 70  _repository(zRep
0fd0: 6f 73 69 74 6f 72 79 29 3b 0a 20 20 64 62 5f 6f  ository);.  db_o
0fe0: 70 65 6e 5f 63 6f 6e 66 69 67 28 30 29 3b 0a 20  pen_config(0);. 
0ff0: 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e 73 61   db_begin_transa
1000: 63 74 69 6f 6e 28 29 3b 0a 0a 20 20 64 62 5f 69  ction();..  db_i
1010: 6e 69 74 69 61 6c 5f 73 65 74 75 70 28 30 2c 20  nitial_setup(0, 
1020: 31 29 3b 0a 0a 20 20 70 72 69 6e 74 66 28 22 70  1);..  printf("p
1030: 72 6f 6a 65 63 74 2d 69 64 3a 20 25 73 5c 6e 22  roject-id: %s\n"
1040: 2c 20 64 62 5f 67 65 74 28 22 70 72 6f 6a 65 63  , db_get("projec
1050: 74 2d 63 6f 64 65 22 2c 20 30 29 29 3b 0a 20 20  t-code", 0));.  
1060: 70 72 69 6e 74 66 28 22 73 65 72 76 65 72 2d 69  printf("server-i
1070: 64 3a 20 20 25 73 5c 6e 22 2c 20 64 62 5f 67 65  d:  %s\n", db_ge
1080: 74 28 22 73 65 72 76 65 72 2d 63 6f 64 65 22 2c  t("server-code",
1090: 20 30 29 29 3b 0a 20 20 70 72 69 6e 74 66 28 22   0));.  printf("
10a0: 61 64 6d 69 6e 2d 75 73 65 72 3a 20 25 73 20 28  admin-user: %s (
10b0: 6e 6f 20 70 61 73 73 77 6f 72 64 20 73 65 74 20  no password set 
10c0: 79 65 74 21 29 5c 6e 22 2c 20 67 2e 7a 4c 6f 67  yet!)\n", g.zLog
10d0: 69 6e 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 62  in);.  printf("b
10e0: 61 73 65 6c 69 6e 65 3a 20 20 20 25 73 5c 6e 22  aseline:   %s\n"
10f0: 2c 20 64 62 5f 74 65 78 74 28 30 2c 20 22 53 45  , db_text(0, "SE
1100: 4c 45 43 54 20 75 75 69 64 20 46 52 4f 4d 20 62  LECT uuid FROM b
1110: 6c 6f 62 22 29 29 3b 0a 0a 20 20 2f 2a 20 53 63  lob"));..  /* Sc
1120: 61 6e 20 6f 72 69 67 69 6e 20 61 6e 64 20 69 6e  an origin and in
1130: 73 65 72 74 20 61 6c 6c 20 66 69 6c 65 73 20 66  sert all files f
1140: 6f 75 6e 64 20 69 6e 73 69 64 65 20 2a 2f 0a 20  ound inside */. 
1150: 20 66 69 6c 65 43 6e 74 20 3d 20 69 6d 70 6f 72   fileCnt = impor
1160: 74 5f 6f 72 69 67 69 6e 20 28 7a 4f 72 69 67 69  t_origin (zOrigi
1170: 6e 29 3b 0a 0a 20 20 70 72 69 6e 74 66 28 22 69  n);..  printf("i
1180: 6d 70 6f 72 74 65 64 3a 20 20 20 25 64 20 25 73  mported:   %d %s
1190: 5c 6e 22 2c 20 66 69 6c 65 43 6e 74 2c 20 66 69  \n", fileCnt, fi
11a0: 6c 65 43 6e 74 20 3d 3d 20 31 20 3f 0a 09 20 22  leCnt == 1 ?.. "
11b0: 66 69 6c 65 22 20 3a 20 22 66 69 6c 65 73 22 29  file" : "files")
11c0: 3b 0a 0a 20 20 2f 2a 20 46 69 6e 61 6c 69 7a 65  ;..  /* Finalize
11d0: 20 74 68 65 20 72 65 70 6f 73 69 74 6f 72 79 2c   the repository,
11e0: 20 72 65 62 75 69 6c 64 20 74 68 65 20 64 65 72   rebuild the der
11f0: 69 76 65 64 20 74 61 62 6c 65 73 20 2a 2f 0a 20  ived tables */. 
1200: 20 65 72 72 43 6e 74 20 3d 20 72 65 62 75 69 6c   errCnt = rebuil
1210: 64 5f 64 62 28 30 2c 20 30 29 3b 0a 0a 20 20 69  d_db(0, 0);..  i
1220: 66 28 20 65 72 72 43 6e 74 20 29 7b 0a 20 20 20  f( errCnt ){.   
1230: 20 70 72 69 6e 74 66 28 22 25 64 20 25 73 2e 20   printf("%d %s. 
1240: 52 6f 6c 6c 69 6e 67 20 62 61 63 6b 20 63 68 61  Rolling back cha
1250: 6e 67 65 73 2e 5c 6e 22 2c 20 65 72 72 43 6e 74  nges.\n", errCnt
1260: 2c 20 65 72 72 43 6e 74 20 3d 3d 20 31 20 3f 0a  , errCnt == 1 ?.
1270: 09 20 20 20 22 65 72 72 6f 72 22 20 3a 20 22 65  .   "error" : "e
1280: 72 72 6f 72 73 22 29 3b 0a 20 20 20 20 64 62 5f  rrors");.    db_
1290: 65 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28  end_transaction(
12a0: 31 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20  1);.  }else{.   
12b0: 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 74   db_end_transact
12c0: 69 6f 6e 28 30 29 3b 0a 20 20 7d 0a 7d 0a        ion(0);.  }.}.