23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
**
** This file contains code used to rebuild the database.
*/
#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.
*/
void rebuild_database(void){
Stmt s;
int errCnt;
int forceFlag;
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,
"SELECT name FROM sqlite_master"
" WHERE type='table'"
|
<
|
<
|
>
>
|
<
<
<
>
|
|
<
<
<
<
<
<
<
<
|
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
**
** This file contains code used to rebuild the database.
*/
#include "config.h"
#include "rebuild.h"
#include <assert.h>
/*
** 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.
*/
int rebuild_db(void){
Stmt s;
int errCnt = 0;
char *zTable;
db_multi_exec(
"CREATE INDEX IF NOT EXISTS delta_i1 ON delta(srcid);"
);
for(;;){
zTable = db_text(0,
"SELECT name FROM sqlite_master"
" WHERE type='table'"
|
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
content_get(rid, &content);
manifest_crosslink(rid, &content);
blob_reset(&content);
}else{
db_multi_exec("INSERT INTO phantom VALUES(%d)", rid);
}
}
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);
}
}
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
content_get(rid, &content);
manifest_crosslink(rid, &content);
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);
}
}
|