Fossil SCM

Add the --randomize parameter to the rebuild command. Used for testing.

drh 2007-09-21 18:33 trunk
Commit ce1c1a2907e9aa10c0426a1a9bb148e43242ae89
2 files changed +1 -1 +13 -4
+1 -1
--- src/construct.c
+++ src/construct.c
@@ -154,11 +154,11 @@
154154
155155
printf("imported: %d %s\n", fileCnt, fileCnt == 1 ?
156156
"file" : "files");
157157
158158
/* Finalize the repository, rebuild the derived tables */
159
- errCnt = rebuild_db ();
159
+ errCnt = rebuild_db(0);
160160
161161
if( errCnt ){
162162
printf("%d %s. Rolling back changes.\n", errCnt, errCnt == 1 ?
163163
"error" : "errors");
164164
db_end_transaction(1);
165165
--- src/construct.c
+++ src/construct.c
@@ -154,11 +154,11 @@
154
155 printf("imported: %d %s\n", fileCnt, fileCnt == 1 ?
156 "file" : "files");
157
158 /* Finalize the repository, rebuild the derived tables */
159 errCnt = rebuild_db ();
160
161 if( errCnt ){
162 printf("%d %s. Rolling back changes.\n", errCnt, errCnt == 1 ?
163 "error" : "errors");
164 db_end_transaction(1);
165
--- src/construct.c
+++ src/construct.c
@@ -154,11 +154,11 @@
154
155 printf("imported: %d %s\n", fileCnt, fileCnt == 1 ?
156 "file" : "files");
157
158 /* Finalize the repository, rebuild the derived tables */
159 errCnt = rebuild_db(0);
160
161 if( errCnt ){
162 printf("%d %s. Rolling back changes.\n", errCnt, errCnt == 1 ?
163 "error" : "errors");
164 db_end_transaction(1);
165
+13 -4
--- src/rebuild.c
+++ src/rebuild.c
@@ -31,13 +31,17 @@
3131
** Core function to rebuild the infomration in the derived tables of a
3232
** fossil repository from the blobs. This function is shared between
3333
** 'rebuild_database' ('rebuild') and 'reconstruct_cmd'
3434
** ('reconstruct'), both of which have to regenerate this information
3535
** from scratch.
36
+**
37
+** If the randomize parameter is true, then the BLOBs are deliberately
38
+** extracted in a random order. This feature is used to test the
39
+** ability of fossil to accept records in any order and still
40
+** construct a sane repository.
3641
*/
37
-
38
-int rebuild_db(void){
42
+int rebuild_db(int randomize){
3943
Stmt s;
4044
int errCnt = 0;
4145
char *zTable;
4246
4347
db_multi_exec(
@@ -56,11 +60,14 @@
5660
5761
db_multi_exec("INSERT INTO unclustered SELECT rid FROM blob");
5862
db_multi_exec(
5963
"DELETE FROM config WHERE name IN ('remote-code', 'remote-maxid')"
6064
);
61
- db_prepare(&s, "SELECT rid, size FROM blob");
65
+ db_prepare(&s,
66
+ "SELECT rid, size FROM blob %s",
67
+ randomize ? "ORDER BY random()" : ""
68
+ );
6269
while( db_step(&s)==SQLITE_ROW ){
6370
int rid = db_column_int(&s, 0);
6471
int size = db_column_int(&s, 1);
6572
if( size>=0 ){
6673
Blob content;
@@ -83,22 +90,24 @@
8390
** records. Run this command after updating the fossil
8491
** executable in a way that changes the database schema.
8592
*/
8693
void rebuild_database(void){
8794
int forceFlag;
95
+ int randomizeFlag;
8896
int errCnt;
8997
9098
forceFlag = find_option("force","f",0)!=0;
99
+ randomizeFlag = find_option("randomize", 0, 0)!=0;
91100
if( g.argc!=3 ){
92101
usage("REPOSITORY-FILENAME");
93102
}
94103
db_open_repository(g.argv[2]);
95104
db_begin_transaction();
96
- errCnt = rebuild_db();
105
+ errCnt = rebuild_db(randomizeFlag);
97106
if( errCnt && !forceFlag ){
98107
printf("%d errors. Rolling back changes. Use --force to force a commit.\n",
99108
errCnt);
100109
db_end_transaction(1);
101110
}else{
102111
db_end_transaction(0);
103112
}
104113
}
105114
--- src/rebuild.c
+++ src/rebuild.c
@@ -31,13 +31,17 @@
31 ** Core function to rebuild the infomration in the derived tables of a
32 ** fossil repository from the blobs. This function is shared between
33 ** 'rebuild_database' ('rebuild') and 'reconstruct_cmd'
34 ** ('reconstruct'), both of which have to regenerate this information
35 ** from scratch.
 
 
 
 
 
36 */
37
38 int rebuild_db(void){
39 Stmt s;
40 int errCnt = 0;
41 char *zTable;
42
43 db_multi_exec(
@@ -56,11 +60,14 @@
56
57 db_multi_exec("INSERT INTO unclustered SELECT rid FROM blob");
58 db_multi_exec(
59 "DELETE FROM config WHERE name IN ('remote-code', 'remote-maxid')"
60 );
61 db_prepare(&s, "SELECT rid, size FROM blob");
 
 
 
62 while( db_step(&s)==SQLITE_ROW ){
63 int rid = db_column_int(&s, 0);
64 int size = db_column_int(&s, 1);
65 if( size>=0 ){
66 Blob content;
@@ -83,22 +90,24 @@
83 ** records. Run this command after updating the fossil
84 ** executable in a way that changes the database schema.
85 */
86 void rebuild_database(void){
87 int forceFlag;
 
88 int errCnt;
89
90 forceFlag = find_option("force","f",0)!=0;
 
91 if( g.argc!=3 ){
92 usage("REPOSITORY-FILENAME");
93 }
94 db_open_repository(g.argv[2]);
95 db_begin_transaction();
96 errCnt = rebuild_db();
97 if( errCnt && !forceFlag ){
98 printf("%d errors. Rolling back changes. Use --force to force a commit.\n",
99 errCnt);
100 db_end_transaction(1);
101 }else{
102 db_end_transaction(0);
103 }
104 }
105
--- src/rebuild.c
+++ src/rebuild.c
@@ -31,13 +31,17 @@
31 ** Core function to rebuild the infomration in the derived tables of a
32 ** fossil repository from the blobs. This function is shared between
33 ** 'rebuild_database' ('rebuild') and 'reconstruct_cmd'
34 ** ('reconstruct'), both of which have to regenerate this information
35 ** from scratch.
36 **
37 ** If the randomize parameter is true, then the BLOBs are deliberately
38 ** extracted in a random order. This feature is used to test the
39 ** ability of fossil to accept records in any order and still
40 ** construct a sane repository.
41 */
42 int rebuild_db(int randomize){
 
43 Stmt s;
44 int errCnt = 0;
45 char *zTable;
46
47 db_multi_exec(
@@ -56,11 +60,14 @@
60
61 db_multi_exec("INSERT INTO unclustered SELECT rid FROM blob");
62 db_multi_exec(
63 "DELETE FROM config WHERE name IN ('remote-code', 'remote-maxid')"
64 );
65 db_prepare(&s,
66 "SELECT rid, size FROM blob %s",
67 randomize ? "ORDER BY random()" : ""
68 );
69 while( db_step(&s)==SQLITE_ROW ){
70 int rid = db_column_int(&s, 0);
71 int size = db_column_int(&s, 1);
72 if( size>=0 ){
73 Blob content;
@@ -83,22 +90,24 @@
90 ** records. Run this command after updating the fossil
91 ** executable in a way that changes the database schema.
92 */
93 void rebuild_database(void){
94 int forceFlag;
95 int randomizeFlag;
96 int errCnt;
97
98 forceFlag = find_option("force","f",0)!=0;
99 randomizeFlag = find_option("randomize", 0, 0)!=0;
100 if( g.argc!=3 ){
101 usage("REPOSITORY-FILENAME");
102 }
103 db_open_repository(g.argv[2]);
104 db_begin_transaction();
105 errCnt = rebuild_db(randomizeFlag);
106 if( errCnt && !forceFlag ){
107 printf("%d errors. Rolling back changes. Use --force to force a commit.\n",
108 errCnt);
109 db_end_transaction(1);
110 }else{
111 db_end_transaction(0);
112 }
113 }
114

Keyboard Shortcuts

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