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
60
61
62
63
|
/*
** Find the shortest path between bad and good.
*/
void bisect_path(void){
PathNode *p;
bisect.bad = db_lget_int("bisect-bad", 0);
if( bisect.bad==0 ){
bisect.bad = db_int(0, "SELECT cid FROM plink ORDER BY mtime DESC LIMIT 1");
db_lset_int("bisect-bad", bisect.bad);
}
bisect.good = db_lget_int("bisect-good", 0);
if( bisect.good==0 ){
bisect.good = db_int(0,"SELECT pid FROM plink ORDER BY mtime LIMIT 1");
db_lset_int("bisect-good", bisect.good);
}
p = path_shortest(bisect.good, bisect.bad, 0);
if( p==0 ){
char *zBad = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", bisect.bad);
char *zGood = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", bisect.good);
fossil_fatal("no path from good ([%S]) to bad ([%S]) or back",
zGood, zBad);
}
}
/*
** COMMAND: bisect
**
** Usage: %fossil bisect SUBCOMMAND ...
**
** Run various subcommands useful for searching for bugs.
|
|
<
|
<
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
60
61
62
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
|
/*
** Find the shortest path between bad and good.
*/
void bisect_path(void){
PathNode *p;
bisect.bad = db_lget_int("bisect-bad", 0);
if( bisect.bad==0 ){
fossil_fatal("no \"bad\" version has been identified");
}
bisect.good = db_lget_int("bisect-good", 0);
if( bisect.good==0 ){
fossil_fatal("no \"good\" version has been identified");
}
p = path_shortest(bisect.good, bisect.bad, bisect_option("direct-only"));
if( p==0 ){
char *zBad = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", bisect.bad);
char *zGood = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", bisect.good);
fossil_fatal("no path from good ([%S]) to bad ([%S]) or back",
zGood, zBad);
}
}
/*
** The set of all bisect options.
*/
static const struct {
const char *zName;
const char *zDefault;
const char *zDesc;
} aBisectOption[] = {
{ "auto-next", "on", "Automatically run \"bisect next\" after each "
"\"bisect good\" or \"bisect bad\"" },
{ "direct-only", "on", "Follow only primary parent-child links, not "
"merges\n" },
};
/*
** Return the value of a boolean bisect option.
*/
int bisect_option(const char *zName){
unsigned int i;
int r = -1;
for(i=0; i<sizeof(aBisectOption)/sizeof(aBisectOption[0]); i++){
if( strcmp(zName, aBisectOption[i].zName)==0 ){
char *zLabel = mprintf("bisect-%s", zName);
char *z = db_lget(zLabel, (char*)aBisectOption[i].zDefault);
if( is_truth(z) ) r = 1;
if( is_false(z) ) r = 0;
if( r<0 ) r = is_truth(aBisectOption[i].zDefault);
free(zLabel);
break;
}
}
assert( r>=0 );
return r;
}
/*
** COMMAND: bisect
**
** Usage: %fossil bisect SUBCOMMAND ...
**
** Run various subcommands useful for searching for bugs.
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
** Identify version VERSION as working. If VERSION is omitted,
** the current checkout is marked as working.
**
** fossil bisect next
**
** Update to the next version that is halfway between the working and
** non-working versions.
**
** fossil bisect reset
**
** Reinitialize a bisect session. This cancels prior bisect history
** and allows a bisect session to start over from the beginning.
**
** fossil bisect vlist
|
>
>
>
>
>
|
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
** Identify version VERSION as working. If VERSION is omitted,
** the current checkout is marked as working.
**
** fossil bisect next
**
** Update to the next version that is halfway between the working and
** non-working versions.
**
** fossil bisect options ?NAME? ?VALUE?
**
** List all bisect options, or the value of a single option, or set the
** value of a bisect option.
**
** fossil bisect reset
**
** Reinitialize a bisect session. This cancels prior bisect history
** and allows a bisect session to start over from the beginning.
**
** fossil bisect vlist
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
int ridBad;
if( g.argc==3 ){
ridBad = db_lget_int("checkout",0);
}else{
ridBad = name_to_rid(g.argv[3]);
}
db_lset_int("bisect-bad", ridBad);
}else if( memcmp(zCmd, "good", n)==0 ){
int ridGood;
if( g.argc==3 ){
ridGood = db_lget_int("checkout",0);
}else{
ridGood = name_to_rid(g.argv[3]);
}
db_lset_int("bisect-good", ridGood);
}else if( memcmp(zCmd, "next", n)==0 ){
PathNode *pMid;
bisect_path();
pMid = path_midpoint();
if( pMid==0 ){
fossil_fatal("bisect is done - there are no more intermediate versions");
}
g.argv[1] = "update";
g.argv[2] = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", pMid->rid);
g.argc = 3;
g.fNoSync = 1;
update_cmd();
}else if( memcmp(zCmd, "reset", n)==0 ){
db_multi_exec(
"REPLACE INTO vvar(name, value) "
" SELECT 'bisect-good', pid FROM plink ORDER BY mtime LIMIT 1;"
"REPLACE INTO vvar(name, value) "
" SELECT 'bisect-bad', cid FROM plink ORDER BY mtime DESC LIMIT 1;"
);
}else if( memcmp(zCmd, "vlist", n)==0 ){
PathNode *p;
int vid = db_lget_int("checkout", 0);
int n;
Stmt s;
int nStep;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
<
|
<
<
|
138
139
140
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
int ridBad;
if( g.argc==3 ){
ridBad = db_lget_int("checkout",0);
}else{
ridBad = name_to_rid(g.argv[3]);
}
db_lset_int("bisect-bad", ridBad);
if( ridBad>0
&& bisect_option("auto-next")
&& db_lget_int("bisect-good",0)>0
){
zCmd = "next";
n = 4;
}else{
return;
}
}else if( memcmp(zCmd, "good", n)==0 ){
int ridGood;
if( g.argc==3 ){
ridGood = db_lget_int("checkout",0);
}else{
ridGood = name_to_rid(g.argv[3]);
}
db_lset_int("bisect-good", ridGood);
if( ridGood>0
&& bisect_option("auto-next")
&& db_lget_int("bisect-bad",0)>0
){
zCmd = "next";
n = 4;
}else{
return;
}
}
if( memcmp(zCmd, "next", n)==0 ){
PathNode *pMid;
bisect_path();
pMid = path_midpoint();
if( pMid==0 ){
fossil_fatal("bisect is done - there are no more intermediate versions");
}
g.argv[1] = "update";
g.argv[2] = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", pMid->rid);
g.argc = 3;
g.fNoSync = 1;
update_cmd();
}else if( memcmp(zCmd, "options", n)==0 ){
if( g.argc==3 ){
unsigned int i;
for(i=0; i<sizeof(aBisectOption)/sizeof(aBisectOption[0]); i++){
char *z = mprintf("bisect-%s", aBisectOption[i].zName);
printf(" %-15s %-6s ", aBisectOption[i].zName,
db_lget(z, (char*)aBisectOption[i].zDefault));
fossil_free(z);
comment_print(aBisectOption[i].zDesc, 27, 79);
}
}else if( g.argc==4 || g.argc==5 ){
unsigned int i;
n = strlen(g.argv[3]);
for(i=0; i<sizeof(aBisectOption)/sizeof(aBisectOption[0]); i++){
if( memcmp(g.argv[3], aBisectOption[i].zName, n)==0 ){
char *z = mprintf("bisect-%s", aBisectOption[i].zName);
if( g.argc==5 ){
db_lset(z, g.argv[4]);
}
printf("%s\n", db_lget(z, (char*)aBisectOption[i].zDefault));
fossil_free(z);
break;
}
}
if( i>=sizeof(aBisectOption)/sizeof(aBisectOption[0]) ){
fossil_fatal("no such bisect option: %s", g.argv[3]);
}
}else{
usage("bisect option ?NAME? ?VALUE?");
}
}else if( memcmp(zCmd, "reset", n)==0 ){
db_multi_exec(
"DELETE FROM vvar WHERE name IN ('bisect-good', 'bisect-bad');"
);
}else if( memcmp(zCmd, "vlist", n)==0 ){
PathNode *p;
int vid = db_lget_int("checkout", 0);
int n;
Stmt s;
int nStep;
|