66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
+
-
+
+
+
|
/*
** Variables used for progress information
*/
static int totalSize; /* Total number of artifacts to process */
static int processCnt; /* Number processed so far */
static int ttyOutput; /* Do progress output */
static Bag bagDone; /* Bag of records rebuilt */
/*
** Called after each artifact is processed
*/
static void rebuild_step_done(void){
static void rebuild_step_done(rid){
assert( bag_find(&bagDone, rid)==0 );
bag_insert(&bagDone, rid);
if( ttyOutput ){
processCnt++;
printf("%d (%d%%)...\r", processCnt, (processCnt*100/totalSize));
fflush(stdout);
}
}
|
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
+
+
-
+
+
|
);
}
/* Find all children of artifact rid */
db_prepare(&q1, "SELECT rid FROM delta WHERE srcid=%d", rid);
bag_init(&children);
while( db_step(&q1)==SQLITE_ROW ){
int cid = db_column_int(&q1, 0);
if( !bag_find(&bagDone, cid) ){
bag_insert(&children, db_column_int(&q1, 0));
bag_insert(&children, cid);
}
}
nChild = bag_count(&children);
db_finalize(&q1);
/* Crosslink the artifact */
if( nChild==0 ){
pUse = pBase;
|
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
-
+
+
|
rebuild_step(cid, sz, pUse);
}else{
db_finalize(&q2);
blob_reset(pUse);
}
}
bag_clear(&children);
rebuild_step_done();
rebuild_step_done(rid);
}
/*
** 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.
**
** If the randomize parameter is true, then the BLOBs are deliberately
** extracted in a random order. This feature is used to test the
** ability of fossil to accept records in any order and still
** construct a sane repository.
*/
int rebuild_db(int randomize, int doOut){
Stmt s;
int errCnt = 0;
char *zTable;
bag_init(&bagDone);
ttyOutput = doOut;
processCnt = 0;
db_multi_exec(zSchemaUpdates);
for(;;){
zTable = db_text(0,
"SELECT name FROM sqlite_master"
" WHERE type='table'"
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
|
while( db_step(&s)==SQLITE_ROW ){
int rid = db_column_int(&s, 0);
int size = db_column_int(&s, 1);
if( size>=0 ){
Blob content;
content_get(rid, &content);
rebuild_step(rid, size, &content);
}
}
db_finalize(&s);
db_prepare(&s,
"SELECT rid, size FROM blob"
" WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
);
while( db_step(&s)==SQLITE_ROW ){
int rid = db_column_int(&s, 0);
int size = db_column_int(&s, 1);
if( size>=0 ){
if( !bag_find(&bagDone, rid) ){
Blob content;
content_get(rid, &content);
rebuild_step(rid, size, &content);
}
}else{
db_multi_exec("INSERT OR IGNORE INTO phantom VALUES(%d)", rid);
rebuild_step_done();
rebuild_step_done(rid);
}
}
db_finalize(&s);
if( ttyOutput ){
printf("\n");
}
return errCnt;
|