Diff
Not logged in

Differences From:

File src/rebuild.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/rebuild.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]

@@ -26,31 +26,21 @@
 #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(;;){
@@ -76,9 +66,31 @@
     }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);