Fossil SCM

Reimplement the reconstruct command that was removed in the GPL to BSD license change.

bcsmith 2010-08-12 19:39 trunk
Commit 3332895df8fa173cb0a2c0586c7b8cad4bd300a1
1 file changed +61
--- src/rebuild.c
+++ src/rebuild.c
@@ -18,10 +18,12 @@
1818
** This file contains code used to rebuild the database.
1919
*/
2020
#include "config.h"
2121
#include "rebuild.h"
2222
#include <assert.h>
23
+#include <dirent.h>
24
+#include <errno.h>
2325
2426
/*
2527
** Schema changes
2628
*/
2729
static const char zSchemaUpdates[] =
@@ -399,5 +401,64 @@
399401
}else{
400402
rebuild_db(0, 1);
401403
db_end_transaction(0);
402404
}
403405
}
406
+
407
+/*
408
+** COMMAND: reconstruct
409
+**
410
+** Usage: %fossil reconstruct FILENAME DIRECTORY
411
+**
412
+** This command studies the artifacts (files) in DIRECTORY and
413
+** reconstructs the fossil record from them. It places the new
414
+** fossil repository in FILENAME
415
+**
416
+*/
417
+void reconstruct_cmd(void) {
418
+ char *zPassword;
419
+ DIR *d;
420
+ struct dirent *pEntry;
421
+ Blob aContent; /* content of the just read artifact */
422
+ if( g.argc!=4 ){
423
+ usage("FILENAME DIRECTORY");
424
+ }
425
+ if( file_isdir(g.argv[3])!=1 ){
426
+ printf("\"%s\" is not a directory\n\n", g.argv[3]);
427
+ usage("FILENAME DIRECTORY");
428
+ }
429
+ db_create_repository(g.argv[2]);
430
+ db_open_repository(g.argv[2]);
431
+ db_open_config(0);
432
+ db_begin_transaction();
433
+ db_initial_setup(0, 0, 1);
434
+
435
+ d = opendir(g.argv[3]);
436
+ if( d ){
437
+ while( (pEntry=readdir(d))!=0 ){
438
+ Blob path;
439
+ blob_init(&path, 0, 0);
440
+ if( pEntry->d_name[0]=='.' ){
441
+ continue;
442
+ }
443
+ if( file_isdir(pEntry->d_name)==1 ){
444
+ continue;
445
+ }
446
+ blob_appendf(&path, "%s/%s", g.argv[3], pEntry->d_name);
447
+ if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
448
+ fossil_panic("Some unknown error occurred while reading \"%s\"", blob_str(&path));
449
+ }
450
+ content_put(&aContent, 0, 0);
451
+ }
452
+ }
453
+ else {
454
+ fossil_panic("Encountered error %d while trying to open \"%s\".", errno, g.argv[3]);
455
+ }
456
+
457
+ rebuild_db(0, 1);
458
+
459
+ db_end_transaction(0);
460
+ printf("project-id: %s\n", db_get("project-code", 0));
461
+ printf("server-id: %s\n", db_get("server-code", 0));
462
+ zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
463
+ printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword);
464
+}
404465
--- src/rebuild.c
+++ src/rebuild.c
@@ -18,10 +18,12 @@
18 ** This file contains code used to rebuild the database.
19 */
20 #include "config.h"
21 #include "rebuild.h"
22 #include <assert.h>
 
 
23
24 /*
25 ** Schema changes
26 */
27 static const char zSchemaUpdates[] =
@@ -399,5 +401,64 @@
399 }else{
400 rebuild_db(0, 1);
401 db_end_transaction(0);
402 }
403 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
--- src/rebuild.c
+++ src/rebuild.c
@@ -18,10 +18,12 @@
18 ** This file contains code used to rebuild the database.
19 */
20 #include "config.h"
21 #include "rebuild.h"
22 #include <assert.h>
23 #include <dirent.h>
24 #include <errno.h>
25
26 /*
27 ** Schema changes
28 */
29 static const char zSchemaUpdates[] =
@@ -399,5 +401,64 @@
401 }else{
402 rebuild_db(0, 1);
403 db_end_transaction(0);
404 }
405 }
406
407 /*
408 ** COMMAND: reconstruct
409 **
410 ** Usage: %fossil reconstruct FILENAME DIRECTORY
411 **
412 ** This command studies the artifacts (files) in DIRECTORY and
413 ** reconstructs the fossil record from them. It places the new
414 ** fossil repository in FILENAME
415 **
416 */
417 void reconstruct_cmd(void) {
418 char *zPassword;
419 DIR *d;
420 struct dirent *pEntry;
421 Blob aContent; /* content of the just read artifact */
422 if( g.argc!=4 ){
423 usage("FILENAME DIRECTORY");
424 }
425 if( file_isdir(g.argv[3])!=1 ){
426 printf("\"%s\" is not a directory\n\n", g.argv[3]);
427 usage("FILENAME DIRECTORY");
428 }
429 db_create_repository(g.argv[2]);
430 db_open_repository(g.argv[2]);
431 db_open_config(0);
432 db_begin_transaction();
433 db_initial_setup(0, 0, 1);
434
435 d = opendir(g.argv[3]);
436 if( d ){
437 while( (pEntry=readdir(d))!=0 ){
438 Blob path;
439 blob_init(&path, 0, 0);
440 if( pEntry->d_name[0]=='.' ){
441 continue;
442 }
443 if( file_isdir(pEntry->d_name)==1 ){
444 continue;
445 }
446 blob_appendf(&path, "%s/%s", g.argv[3], pEntry->d_name);
447 if( blob_read_from_file(&aContent, blob_str(&path))==-1 ){
448 fossil_panic("Some unknown error occurred while reading \"%s\"", blob_str(&path));
449 }
450 content_put(&aContent, 0, 0);
451 }
452 }
453 else {
454 fossil_panic("Encountered error %d while trying to open \"%s\".", errno, g.argv[3]);
455 }
456
457 rebuild_db(0, 1);
458
459 db_end_transaction(0);
460 printf("project-id: %s\n", db_get("project-code", 0));
461 printf("server-id: %s\n", db_get("server-code", 0));
462 zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
463 printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword);
464 }
465

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button