Diff
Not logged in

Differences From:

File src/db.c part of check-in [6607844a01] - Added options to the "timeline" CLI command. Additional help comments. by drh on 2007-08-18 11:42:24. [view]

To:

File src/db.c part of check-in [e00384d26d] - Moved the core logic of both "rebuild_database" and "create_repository_cmd" into their own functions, for sharing with "reconstruct_cmd". by aku on 2007-08-29 02:42:24. [view]

@@ -643,30 +643,24 @@
      (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(
@@ -690,21 +684,43 @@
      "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);