Overview
SHA1 Hash: | e00384d26d5e24bc41daf1788352e38dd85968c9 |
---|---|
Date: | 2007-08-29 02:42:24 |
User: | aku |
Comment: | Moved the core logic of both "rebuild_database" and "create_repository_cmd" into their own functions, for sharing with "reconstruct_cmd". |
Timelines: | ancestors | descendants | both | trunk |
Other Links: | files | ZIP archive | manifest |
Tags And Properties
- branch=trunk inherited from [a28c83647d]
- sym-trunk inherited from [a28c83647d]
Changes
[hide diffs]Modified src/db.c from [f2c507419f] to [ca474c1e96].
@@ -642,32 +642,26 @@ zRepositorySchema2, (char*)0 ); } - /* -** COMMAND: new -** -** Usage: %fossil new FILENAME -** Create a repository for a new project in the file named FILENAME. -** This command is distinct from "clone". The "clone" command makes -** a copy of an existing project. This command starts a new project. +** Fill an empty repository database with the basic information for a +** repository. This function is shared between 'create_repository_cmd' +** ('new') and 'reconstruct_cmd' ('reconstruct'), both of which create +** new repositories. +** +** The caller determines wheter the function inserts an empty root +** manifest (zRoot == TRUE), or not (zRoot == FALSE). */ -void create_repository_cmd(void){ + +void db_initial_setup (int zRoot){ char *zDate; char *zUser; Blob hash; Blob manifest; - if( g.argc!=3 ){ - usage("REPOSITORY-NAME"); - } - db_create_repository(g.argv[2]); - db_open_repository(g.argv[2]); - db_open_config(); - db_begin_transaction(); db_set("content-schema", CONTENT_SCHEMA); db_set("aux-schema", AUX_SCHEMA); db_set_int("authenticate-localhost", 0); db_multi_exec( "INSERT INTO config(name,value) VALUES('server-code', hex(randomblob(20)));" @@ -689,23 +683,45 @@ " VALUES('anonymous','anonymous','hjkorw','Anon');" "INSERT INTO user(login,pw,cap,info)" " VALUES('nobody','','jor','Nobody');" ); user_select(); - blob_zero(&manifest); - blob_appendf(&manifest, "C initial\\sempty\\sbaseline\n"); - zDate = db_text(0, "SELECT datetime('now')"); - zDate[10]='T'; - blob_appendf(&manifest, "D %s\n", zDate); - blob_appendf(&manifest, "P\n"); - md5sum_init(); - blob_appendf(&manifest, "R %s\n", md5sum_finish(0)); - blob_appendf(&manifest, "U %F\n", g.zLogin); - md5sum_blob(&manifest, &hash); - blob_appendf(&manifest, "Z %b\n", &hash); - blob_reset(&hash); - content_put(&manifest, 0, 0); + + if (zRoot){ + blob_zero(&manifest); + blob_appendf(&manifest, "C initial\\sempty\\sbaseline\n"); + zDate = db_text(0, "SELECT datetime('now')"); + zDate[10]='T'; + blob_appendf(&manifest, "D %s\n", zDate); + blob_appendf(&manifest, "P\n"); + md5sum_init(); + blob_appendf(&manifest, "R %s\n", md5sum_finish(0)); + blob_appendf(&manifest, "U %F\n", g.zLogin); + md5sum_blob(&manifest, &hash); + blob_appendf(&manifest, "Z %b\n", &hash); + blob_reset(&hash); + content_put(&manifest, 0, 0); + } +} + +/* +** COMMAND: new +** +** Usage: %fossil new FILENAME +** Create a repository for a new project in the file named FILENAME. +** This command is distinct from "clone". The "clone" command makes +** a copy of an existing project. This command starts a new project. +*/ +void create_repository_cmd(void){ + if( g.argc!=3 ){ + usage("REPOSITORY-NAME"); + } + db_create_repository(g.argv[2]); + db_open_repository(g.argv[2]); + db_open_config(); + db_begin_transaction(); + db_initial_setup (1); db_end_transaction(0); printf("project-id: %s\n", db_get("project-code", 0)); printf("server-id: %s\n", db_get("server-code", 0)); printf("admin-user: %s (no password set yet!)\n", g.zLogin); printf("baseline: %s\n", db_text(0, "SELECT uuid FROM blob"));
Modified src/rebuild.c from [3f04f9d6cb] to [104f7b4bf8].
@@ -25,33 +25,23 @@ */ #include "config.h" #include "rebuild.h" #include <assert.h> - /* -** COMMAND: rebuild -** -** Usage: %fossil rebuild REPOSITORY -** -** Reconstruct the named repository database from the core -** records. Run this command after updating the fossil -** executable in a way that changes the database schema. +** Core function to rebuild the infomration in the derived tables of a +** fossil repository from the blobs. This function is shared between +** 'rebuild_database' ('rebuild') and 'reconstruct_cmd' +** ('reconstruct'), both of which have to regenerate this information +** from scratch. */ -void rebuild_database(void){ + +int rebuild_db(void){ Stmt s; - int errCnt; - int forceFlag; + int errCnt = 0; char *zTable; - forceFlag = find_option("force","f",0)!=0; - if( g.argc!=3 ){ - usage("REPOSITORY-FILENAME"); - } - errCnt = 0; - db_open_repository(g.argv[2]); - db_begin_transaction(); db_multi_exec( "CREATE INDEX IF NOT EXISTS delta_i1 ON delta(srcid);" ); for(;;){ zTable = db_text(0, @@ -75,14 +65,36 @@ blob_reset(&content); }else{ db_multi_exec("INSERT INTO phantom VALUES(%d)", rid); } } + return errCnt; +} + +/* +** COMMAND: rebuild +** +** Usage: %fossil rebuild REPOSITORY +** +** Reconstruct the named repository database from the core +** records. Run this command after updating the fossil +** executable in a way that changes the database schema. +*/ +void rebuild_database(void){ + int forceFlag; + int errCnt; + forceFlag = find_option("force","f",0)!=0; + if( g.argc!=3 ){ + usage("REPOSITORY-FILENAME"); + } + db_open_repository(g.argv[2]); + db_begin_transaction(); + errCnt = rebuild_db(); if( errCnt && !forceFlag ){ printf("%d errors. Rolling back changes. Use --force to force a commit.\n", errCnt); db_end_transaction(1); }else{ db_end_transaction(0); } }