Hex Artifact Content
Not logged in

Artifact 165ad3ffc2e80d0dd5e34a4cecad0a3227fde6ed:

Attachment "reconstruct_cmd.patch" to ticket [dfe1fc608a] added by anonymous 2010-07-28 03:06:25.
0000: 49 6e 64 65 78 3a 20 73 72 63 2f 72 65 62 75 69  Index: src/rebui
0010: 6c 64 2e 63 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ld.c.===========
0020: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0030: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0040: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0050: 3d 3d 3d 3d 3d 3d 3d 3d 0a 2d 2d 2d 20 73 72 63  ========.--- src
0060: 2f 72 65 62 75 69 6c 64 2e 63 0a 2b 2b 2b 20 73  /rebuild.c.+++ s
0070: 72 63 2f 72 65 62 75 69 6c 64 2e 63 0a 40 40 20  rc/rebuild.c.@@ 
0080: 2d 31 38 2c 31 30 20 2b 31 38 2c 31 32 20 40 40  -18,10 +18,12 @@
0090: 0a 20 2a 2a 20 54 68 69 73 20 66 69 6c 65 20 63  . ** This file c
00a0: 6f 6e 74 61 69 6e 73 20 63 6f 64 65 20 75 73 65  ontains code use
00b0: 64 20 74 6f 20 72 65 62 75 69 6c 64 20 74 68 65  d to rebuild the
00c0: 20 64 61 74 61 62 61 73 65 2e 0a 20 2a 2f 0a 20   database.. */. 
00d0: 23 69 6e 63 6c 75 64 65 20 22 63 6f 6e 66 69 67  #include "config
00e0: 2e 68 22 0a 20 23 69 6e 63 6c 75 64 65 20 22 72  .h". #include "r
00f0: 65 62 75 69 6c 64 2e 68 22 0a 20 23 69 6e 63 6c  ebuild.h". #incl
0100: 75 64 65 20 3c 61 73 73 65 72 74 2e 68 3e 0a 2b  ude <assert.h>.+
0110: 23 69 6e 63 6c 75 64 65 20 3c 64 69 72 65 6e 74  #include <dirent
0120: 2e 68 3e 0a 2b 23 69 6e 63 6c 75 64 65 20 3c 65  .h>.+#include <e
0130: 72 72 6e 6f 2e 68 3e 0a 20 0a 20 2f 2a 0a 20 2a  rrno.h>. . /*. *
0140: 2a 20 53 63 68 65 6d 61 20 63 68 61 6e 67 65 73  * Schema changes
0150: 0a 20 2a 2f 0a 20 73 74 61 74 69 63 20 63 6f 6e  . */. static con
0160: 73 74 20 63 68 61 72 20 7a 53 63 68 65 6d 61 55  st char zSchemaU
0170: 70 64 61 74 65 73 5b 5d 20 3d 0a 40 40 20 2d 33  pdates[] =.@@ -3
0180: 39 38 2c 36 20 2b 34 30 30 2c 36 35 20 40 40 0a  98,6 +400,65 @@.
0190: 20 20 20 20 20 64 62 5f 6d 75 6c 74 69 5f 65 78       db_multi_ex
01a0: 65 63 28 22 56 41 43 55 55 4d 3b 22 29 3b 0a 20  ec("VACUUM;");. 
01b0: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 72 65    }else{.     re
01c0: 62 75 69 6c 64 5f 64 62 28 30 2c 20 31 29 3b 0a  build_db(0, 1);.
01d0: 20 20 20 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e       db_end_tran
01e0: 73 61 63 74 69 6f 6e 28 30 29 3b 0a 20 20 20 7d  saction(0);.   }
01f0: 0a 2b 7d 0a 2b 0a 2b 2f 2a 0a 2b 2a 2a 20 43 4f  .+}.+.+/*.+** CO
0200: 4d 4d 41 4e 44 3a 20 72 65 63 6f 6e 73 74 72 75  MMAND: reconstru
0210: 63 74 0a 2b 2a 2a 0a 2b 2a 2a 20 55 73 61 67 65  ct.+**.+** Usage
0220: 3a 20 25 66 6f 73 73 69 6c 20 72 65 63 6f 6e 73  : %fossil recons
0230: 74 72 75 63 74 20 46 49 4c 45 4e 41 4d 45 20 44  truct FILENAME D
0240: 49 52 45 43 54 4f 52 59 0a 2b 2a 2a 0a 2b 2a 2a  IRECTORY.+**.+**
0250: 20 54 68 69 73 20 63 6f 6d 6d 61 6e 64 20 73 74   This command st
0260: 75 64 69 65 73 20 74 68 65 20 61 72 74 69 66 61  udies the artifa
0270: 63 74 73 20 28 66 69 6c 65 73 29 20 69 6e 20 44  cts (files) in D
0280: 49 52 45 43 54 4f 52 59 20 61 6e 64 0a 2b 2a 2a  IRECTORY and.+**
0290: 20 72 65 63 6f 6e 73 74 72 75 63 74 73 20 74 68   reconstructs th
02a0: 65 20 66 6f 73 73 69 6c 20 72 65 63 6f 72 64 20  e fossil record 
02b0: 66 72 6f 6d 20 74 68 65 6d 2e 20 49 74 20 70 6c  from them. It pl
02c0: 61 63 65 73 20 74 68 65 20 6e 65 77 0a 2b 2a 2a  aces the new.+**
02d0: 20 66 6f 73 73 69 6c 20 72 65 70 6f 73 69 74 6f   fossil reposito
02e0: 72 79 20 69 6e 20 46 49 4c 45 4e 41 4d 45 0a 2b  ry in FILENAME.+
02f0: 2a 2a 0a 2b 2a 2f 0a 2b 76 6f 69 64 20 72 65 63  **.+*/.+void rec
0300: 6f 6e 73 74 72 75 63 74 5f 63 6d 64 28 76 6f 69  onstruct_cmd(voi
0310: 64 29 20 7b 0a 2b 20 20 63 68 61 72 20 2a 7a 50  d) {.+  char *zP
0320: 61 73 73 77 6f 72 64 3b 0a 2b 20 20 44 49 52 20  assword;.+  DIR 
0330: 2a 64 3b 0a 2b 20 20 73 74 72 75 63 74 20 64 69  *d;.+  struct di
0340: 72 65 6e 74 20 2a 70 45 6e 74 72 79 3b 0a 2b 20  rent *pEntry;.+ 
0350: 20 42 6c 6f 62 20 61 43 6f 6e 74 65 6e 74 3b 20   Blob aContent; 
0360: 2f 2a 20 63 6f 6e 74 65 6e 74 20 6f 66 20 74 68  /* content of th
0370: 65 20 6a 75 73 74 20 72 65 61 64 20 61 72 74 69  e just read arti
0380: 66 61 63 74 20 2a 2f 0a 2b 20 20 69 66 28 20 67  fact */.+  if( g
0390: 2e 61 72 67 63 21 3d 34 20 29 7b 0a 2b 20 20 20  .argc!=4 ){.+   
03a0: 20 75 73 61 67 65 28 22 46 49 4c 45 4e 41 4d 45   usage("FILENAME
03b0: 20 44 49 52 45 43 54 4f 52 59 22 29 3b 0a 2b 20   DIRECTORY");.+ 
03c0: 20 7d 0a 2b 20 20 69 66 28 20 66 69 6c 65 5f 69   }.+  if( file_i
03d0: 73 64 69 72 28 67 2e 61 72 67 76 5b 33 5d 29 21  sdir(g.argv[3])!
03e0: 3d 31 20 29 7b 0a 2b 20 20 20 20 70 72 69 6e 74  =1 ){.+    print
03f0: 66 28 22 5c 22 25 73 5c 22 20 69 73 20 6e 6f 74  f("\"%s\" is not
0400: 20 61 20 64 69 72 65 63 74 6f 72 79 5c 6e 5c 6e   a directory\n\n
0410: 22 2c 20 67 2e 61 72 67 76 5b 33 5d 29 3b 0a 2b  ", g.argv[3]);.+
0420: 20 20 20 20 75 73 61 67 65 28 22 46 49 4c 45 4e      usage("FILEN
0430: 41 4d 45 20 44 49 52 45 43 54 4f 52 59 22 29 3b  AME DIRECTORY");
0440: 0a 2b 20 20 7d 0a 2b 20 20 64 62 5f 63 72 65 61  .+  }.+  db_crea
0450: 74 65 5f 72 65 70 6f 73 69 74 6f 72 79 28 67 2e  te_repository(g.
0460: 61 72 67 76 5b 32 5d 29 3b 0a 2b 20 20 64 62 5f  argv[2]);.+  db_
0470: 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28  open_repository(
0480: 67 2e 61 72 67 76 5b 32 5d 29 3b 0a 2b 20 20 64  g.argv[2]);.+  d
0490: 62 5f 6f 70 65 6e 5f 63 6f 6e 66 69 67 28 30 29  b_open_config(0)
04a0: 3b 0a 2b 20 20 64 62 5f 62 65 67 69 6e 5f 74 72  ;.+  db_begin_tr
04b0: 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a 2b 20 20  ansaction();.+  
04c0: 64 62 5f 69 6e 69 74 69 61 6c 5f 73 65 74 75 70  db_initial_setup
04d0: 28 30 2c 20 30 2c 20 31 29 3b 0a 2b 0a 2b 20 20  (0, 0, 1);.+.+  
04e0: 64 20 3d 20 6f 70 65 6e 64 69 72 28 67 2e 61 72  d = opendir(g.ar
04f0: 67 76 5b 33 5d 29 3b 0a 2b 20 20 69 66 28 20 64  gv[3]);.+  if( d
0500: 20 29 7b 0a 2b 20 20 20 20 77 68 69 6c 65 28 20   ){.+    while( 
0510: 28 70 45 6e 74 72 79 3d 72 65 61 64 64 69 72 28  (pEntry=readdir(
0520: 64 29 29 21 3d 30 20 29 7b 0a 2b 20 20 20 20 20  d))!=0 ){.+     
0530: 20 42 6c 6f 62 20 70 61 74 68 3b 0a 2b 20 20 20   Blob path;.+   
0540: 20 20 20 62 6c 6f 62 5f 69 6e 69 74 28 26 70 61     blob_init(&pa
0550: 74 68 2c 20 30 2c 20 30 29 3b 0a 2b 20 20 20 20  th, 0, 0);.+    
0560: 20 20 69 66 28 20 70 45 6e 74 72 79 2d 3e 64 5f    if( pEntry->d_
0570: 6e 61 6d 65 5b 30 5d 3d 3d 27 2e 27 20 29 7b 0a  name[0]=='.' ){.
0580: 2b 20 20 20 20 20 20 20 20 63 6f 6e 74 69 6e 75  +        continu
0590: 65 3b 0a 2b 20 20 20 20 20 20 7d 0a 2b 20 20 20  e;.+      }.+   
05a0: 20 20 20 69 66 28 20 66 69 6c 65 5f 69 73 64 69     if( file_isdi
05b0: 72 28 70 45 6e 74 72 79 2d 3e 64 5f 6e 61 6d 65  r(pEntry->d_name
05c0: 29 3d 3d 31 20 29 7b 0a 2b 20 20 20 20 20 20 20  )==1 ){.+       
05d0: 20 63 6f 6e 74 69 6e 75 65 3b 0a 2b 20 20 20 20   continue;.+    
05e0: 20 20 7d 0a 2b 20 20 20 20 20 20 62 6c 6f 62 5f    }.+      blob_
05f0: 61 70 70 65 6e 64 66 28 26 70 61 74 68 2c 20 22  appendf(&path, "
0600: 25 73 2f 25 73 22 2c 20 67 2e 61 72 67 76 5b 33  %s/%s", g.argv[3
0610: 5d 2c 20 70 45 6e 74 72 79 2d 3e 64 5f 6e 61 6d  ], pEntry->d_nam
0620: 65 29 3b 0a 2b 20 20 20 20 20 20 69 66 28 20 62  e);.+      if( b
0630: 6c 6f 62 5f 72 65 61 64 5f 66 72 6f 6d 5f 66 69  lob_read_from_fi
0640: 6c 65 28 26 61 43 6f 6e 74 65 6e 74 2c 20 62 6c  le(&aContent, bl
0650: 6f 62 5f 73 74 72 28 26 70 61 74 68 29 29 3d 3d  ob_str(&path))==
0660: 2d 31 20 29 7b 0a 2b 20 20 20 20 20 20 20 20 66  -1 ){.+        f
0670: 6f 73 73 69 6c 5f 70 61 6e 69 63 28 22 53 6f 6d  ossil_panic("Som
0680: 65 20 75 6e 6b 6e 6f 77 6e 20 65 72 72 6f 72 20  e unknown error 
0690: 6f 63 63 75 72 72 65 64 20 77 68 69 6c 65 20 72  occurred while r
06a0: 65 61 64 69 6e 67 20 5c 22 25 73 5c 22 22 2c 20  eading \"%s\"", 
06b0: 62 6c 6f 62 5f 73 74 72 28 26 70 61 74 68 29 29  blob_str(&path))
06c0: 3b 0a 2b 20 20 20 20 20 20 7d 0a 2b 20 20 20 20  ;.+      }.+    
06d0: 20 20 63 6f 6e 74 65 6e 74 5f 70 75 74 28 26 61    content_put(&a
06e0: 43 6f 6e 74 65 6e 74 2c 20 30 2c 20 30 29 3b 0a  Content, 0, 0);.
06f0: 2b 20 20 20 20 7d 0a 2b 20 20 7d 0a 2b 20 20 65  +    }.+  }.+  e
0700: 6c 73 65 20 7b 0a 2b 20 20 20 20 66 6f 73 73 69  lse {.+    fossi
0710: 6c 5f 70 61 6e 69 63 28 22 45 6e 63 6f 75 6e 74  l_panic("Encount
0720: 65 72 65 64 20 65 72 72 6f 72 20 25 64 20 77 68  ered error %d wh
0730: 69 6c 65 20 74 72 79 69 6e 67 20 74 6f 20 6f 70  ile trying to op
0740: 65 6e 20 5c 22 25 73 5c 22 2e 22 2c 20 65 72 72  en \"%s\".", err
0750: 6e 6f 2c 20 67 2e 61 72 67 76 5b 33 5d 29 3b 0a  no, g.argv[3]);.
0760: 2b 20 20 7d 0a 2b 0a 2b 20 20 72 65 62 75 69 6c  +  }.+.+  rebuil
0770: 64 5f 64 62 28 30 2c 20 31 29 3b 0a 2b 0a 2b 20  d_db(0, 1);.+.+ 
0780: 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 74   db_end_transact
0790: 69 6f 6e 28 30 29 3b 0a 2b 20 20 70 72 69 6e 74  ion(0);.+  print
07a0: 66 28 22 70 72 6f 6a 65 63 74 2d 69 64 3a 20 25  f("project-id: %
07b0: 73 5c 6e 22 2c 20 64 62 5f 67 65 74 28 22 70 72  s\n", db_get("pr
07c0: 6f 6a 65 63 74 2d 63 6f 64 65 22 2c 20 30 29 29  oject-code", 0))
07d0: 3b 0a 2b 20 20 70 72 69 6e 74 66 28 22 73 65 72  ;.+  printf("ser
07e0: 76 65 72 2d 69 64 3a 20 25 73 5c 6e 22 2c 20 64  ver-id: %s\n", d
07f0: 62 5f 67 65 74 28 22 73 65 72 76 65 72 2d 63 6f  b_get("server-co
0800: 64 65 22 2c 20 30 29 29 3b 0a 2b 20 20 7a 50 61  de", 0));.+  zPa
0810: 73 73 77 6f 72 64 20 3d 20 64 62 5f 74 65 78 74  ssword = db_text
0820: 28 30 2c 20 22 53 45 4c 45 43 54 20 70 77 20 46  (0, "SELECT pw F
0830: 52 4f 4d 20 75 73 65 72 20 57 48 45 52 45 20 6c  ROM user WHERE l
0840: 6f 67 69 6e 3d 25 51 22 2c 20 67 2e 7a 4c 6f 67  ogin=%Q", g.zLog
0850: 69 6e 29 3b 0a 2b 20 20 70 72 69 6e 74 66 28 22  in);.+  printf("
0860: 61 64 6d 69 6e 2d 75 73 65 72 3a 20 25 73 20 28  admin-user: %s (
0870: 69 6e 69 74 69 61 6c 20 70 61 73 73 77 6f 72 64  initial password
0880: 20 69 73 20 5c 22 25 73 5c 22 29 5c 6e 22 2c 20   is \"%s\")\n", 
0890: 67 2e 7a 4c 6f 67 69 6e 2c 20 7a 50 61 73 73 77  g.zLogin, zPassw
08a0: 6f 72 64 29 3b 0a 20 7d 0a 0a                    ord);. }..