Fossil SCM

fossil-scm / src / bisect.c
Source Blame History 784 lines
2ce65f2… drh 1 /*
c19f34c… drh 2 ** Copyright (c) 2010 D. Richard Hipp
2ce65f2… drh 3 **
2ce65f2… drh 4 ** This program is free software; you can redistribute it and/or
2ce65f2… drh 5 ** modify it under the terms of the Simplified BSD License (also
2ce65f2… drh 6 ** known as the "2-Clause License" or "FreeBSD License".)
2ce65f2… drh 7
2ce65f2… drh 8 ** This program is distributed in the hope that it will be useful,
2ce65f2… drh 9 ** but without any warranty; without even the implied warranty of
2ce65f2… drh 10 ** merchantability or fitness for a particular purpose.
2ce65f2… drh 11 **
2ce65f2… drh 12 ** Author contact information:
2ce65f2… drh 13 ** [email protected]
2ce65f2… drh 14 **
2ce65f2… drh 15 *******************************************************************************
2ce65f2… drh 16 **
2ce65f2… drh 17 ** This file contains code used to implement the "bisect" command.
28aa0e3… drh 18 **
28aa0e3… drh 19 ** This file also contains logic used to compute the closure of filename
28aa0e3… drh 20 ** changes that have occurred across multiple check-ins.
2ce65f2… drh 21 */
2ce65f2… drh 22 #include "config.h"
2ce65f2… drh 23 #include "bisect.h"
2ce65f2… drh 24 #include <assert.h>
1259da6… stephan 25 #if !defined(_WIN32)
1259da6… stephan 26 # include <sys/wait.h>
1259da6… stephan 27 #endif
2ce65f2… drh 28
2ce65f2… drh 29 /*
2ce65f2… drh 30 ** Local variables for this module
2ce65f2… drh 31 */
2ce65f2… drh 32 static struct {
2ce65f2… drh 33 int bad; /* The bad version */
2ce65f2… drh 34 int good; /* The good version */
2ce65f2… drh 35 } bisect;
2ce65f2… drh 36
2ce65f2… drh 37 /*
2ce65f2… drh 38 ** Find the shortest path between bad and good.
2ce65f2… drh 39 */
e5121b4… drh 40 void bisect_path(void){
e5121b4… drh 41 PathNode *p;
e5121b4… drh 42 bisect.bad = db_lget_int("bisect-bad", 0);
e5121b4… drh 43 bisect.good = db_lget_int("bisect-good", 0);
41c7ac2… drh 44 if( bisect.good>0 && bisect.bad==0 ){
4e23c2a… drh 45 path_shortest(bisect.good, bisect.good, 0, 0, 0, 0);
41c7ac2… drh 46 }else if( bisect.bad>0 && bisect.good==0 ){
4e23c2a… drh 47 path_shortest(bisect.bad, bisect.bad, 0, 0, 0, 0);
41c7ac2… drh 48 }else if( bisect.bad==0 && bisect.good==0 ){
41c7ac2… drh 49 fossil_fatal("neither \"good\" nor \"bad\" versions have been identified");
41c7ac2… drh 50 }else{
9e7262b… drh 51 Bag skip;
9e7262b… drh 52 int bDirect = bisect_option("direct-only");
9e7262b… drh 53 char *zLog = db_lget("bisect-log","");
9e7262b… drh 54 Blob log, id;
9e7262b… drh 55 bag_init(&skip);
9e7262b… drh 56 blob_init(&log, zLog, -1);
9e7262b… drh 57 while( blob_token(&log, &id) ){
9e7262b… drh 58 if( blob_str(&id)[0]=='s' ){
9e7262b… drh 59 bag_insert(&skip, atoi(blob_str(&id)+1));
9e7262b… drh 60 }
9e7262b… drh 61 }
9e7262b… drh 62 blob_reset(&log);
4e23c2a… drh 63 p = path_shortest(bisect.good, bisect.bad, bDirect, 0, &skip, 0);
9e7262b… drh 64 bag_clear(&skip);
41c7ac2… drh 65 if( p==0 ){
41c7ac2… drh 66 char *zBad = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",bisect.bad);
41c7ac2… drh 67 char *zGood = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",bisect.good);
41c7ac2… drh 68 fossil_fatal("no path from good ([%S]) to bad ([%S]) or back",
41c7ac2… drh 69 zGood, zBad);
41c7ac2… drh 70 }
fa81575… drh 71 }
fa81575… drh 72 }
fa81575… drh 73
fa81575… drh 74 /*
fa81575… drh 75 ** The set of all bisect options.
fa81575… drh 76 */
fa81575… drh 77 static const struct {
fa81575… drh 78 const char *zName;
fa81575… drh 79 const char *zDefault;
fa81575… drh 80 const char *zDesc;
fa81575… drh 81 } aBisectOption[] = {
fa81575… drh 82 { "auto-next", "on", "Automatically run \"bisect next\" after each "
79499fc… andygoth 83 "\"bisect good\", \"bisect bad\", or \"bisect "
79499fc… andygoth 84 "skip\"" },
fa81575… drh 85 { "direct-only", "on", "Follow only primary parent-child links, not "
fa81575… drh 86 "merges\n" },
0a7af8d… drh 87 { "display", "chart", "Command to run after \"next\". \"chart\", "
0a7af8d… drh 88 "\"log\", \"status\", or \"none\"" },
ed4ac97… stephan 89 { "linear", "off", "Do a linear scan rather than a true bisect, "
ed4ac97… stephan 90 "stopping at the first \"bad\" result"},
fa81575… drh 91 };
fa81575… drh 92
fa81575… drh 93 /*
fa81575… drh 94 ** Return the value of a boolean bisect option.
fa81575… drh 95 */
fa81575… drh 96 int bisect_option(const char *zName){
fa81575… drh 97 unsigned int i;
fa81575… drh 98 int r = -1;
3cb9ba4… andygoth 99 for(i=0; i<count(aBisectOption); i++){
32ad9a1… drh 100 if( fossil_strcmp(zName, aBisectOption[i].zName)==0 ){
fa81575… drh 101 char *zLabel = mprintf("bisect-%s", zName);
d0749d7… drh 102 char *z;
d0749d7… drh 103 if( g.localOpen ){
d0749d7… drh 104 z = db_lget(zLabel, (char*)aBisectOption[i].zDefault);
d0749d7… drh 105 }else{
d0749d7… drh 106 z = (char*)aBisectOption[i].zDefault;
d0749d7… drh 107 }
fa81575… drh 108 if( is_truth(z) ) r = 1;
fa81575… drh 109 if( is_false(z) ) r = 0;
fa81575… drh 110 if( r<0 ) r = is_truth(aBisectOption[i].zDefault);
fa81575… drh 111 free(zLabel);
fa81575… drh 112 break;
fa81575… drh 113 }
fa81575… drh 114 }
fa81575… drh 115 assert( r>=0 );
fa81575… drh 116 return r;
fa81575… drh 117 }
fa81575… drh 118
fa81575… drh 119 /*
eec1114… drh 120 ** List a bisect path.
eec1114… drh 121 */
eec1114… drh 122 static void bisect_list(int abbreviated){
eec1114… drh 123 PathNode *p;
eec1114… drh 124 int vid = db_lget_int("checkout", 0);
eec1114… drh 125 int n;
eec1114… drh 126 Stmt s;
eec1114… drh 127 int nStep;
eec1114… drh 128 int nHidden = 0;
eec1114… drh 129 bisect_path();
eec1114… drh 130 db_prepare(&s, "SELECT blob.uuid, datetime(event.mtime) "
eec1114… drh 131 " FROM blob, event"
eec1114… drh 132 " WHERE blob.rid=:rid AND event.objid=:rid"
eec1114… drh 133 " AND event.type='ci'");
eec1114… drh 134 nStep = path_length();
eec1114… drh 135 if( abbreviated ){
eec1114… drh 136 for(p=path_last(); p; p=p->pFrom) p->isHidden = 1;
eec1114… drh 137 for(p=path_last(), n=0; p; p=p->pFrom, n++){
eec1114… drh 138 if( p->rid==bisect.good
eec1114… drh 139 || p->rid==bisect.bad
eec1114… drh 140 || p->rid==vid
eec1114… drh 141 || (nStep>1 && n==nStep/2)
eec1114… drh 142 ){
eec1114… drh 143 p->isHidden = 0;
eec1114… drh 144 if( p->pFrom ) p->pFrom->isHidden = 0;
eec1114… drh 145 }
eec1114… drh 146 }
eec1114… drh 147 for(p=path_last(); p; p=p->pFrom){
eec1114… drh 148 if( p->pFrom && p->pFrom->isHidden==0 ) p->isHidden = 0;
eec1114… drh 149 }
eec1114… drh 150 }
eec1114… drh 151 for(p=path_last(), n=0; p; p=p->pFrom, n++){
eec1114… drh 152 if( p->isHidden && (nHidden || (p->pFrom && p->pFrom->isHidden)) ){
eec1114… drh 153 nHidden++;
eec1114… drh 154 continue;
eec1114… drh 155 }else if( nHidden ){
b41ebf2… drh 156 fossil_print(" ... %d other check-ins omitted\n", nHidden);
eec1114… drh 157 nHidden = 0;
eec1114… drh 158 }
eec1114… drh 159 db_bind_int(&s, ":rid", p->rid);
eec1114… drh 160 if( db_step(&s)==SQLITE_ROW ){
eec1114… drh 161 const char *zUuid = db_column_text(&s, 0);
eec1114… drh 162 const char *zDate = db_column_text(&s, 1);
eec1114… drh 163 fossil_print("%s %S", zDate, zUuid);
eec1114… drh 164 if( p->rid==bisect.good ) fossil_print(" GOOD");
eec1114… drh 165 if( p->rid==bisect.bad ) fossil_print(" BAD");
eec1114… drh 166 if( p->rid==vid ) fossil_print(" CURRENT");
eec1114… drh 167 if( nStep>1 && n==nStep/2 ) fossil_print(" NEXT");
eec1114… drh 168 fossil_print("\n");
eec1114… drh 169 }
eec1114… drh 170 db_reset(&s);
eec1114… drh 171 }
eec1114… drh 172 db_finalize(&s);
eec1114… drh 173 }
eec1114… drh 174
eec1114… drh 175 /*
41c7ac2… drh 176 ** Append a new entry to the bisect log. Update the bisect-good or
41c7ac2… drh 177 ** bisect-bad values as appropriate.
41c7ac2… drh 178 **
33d3bf3… km 179 ** The bisect-log consists of a list of tokens. Each token is an
41c7ac2… drh 180 ** integer RID of a check-in. The RID is negative for "bad" check-ins
41c7ac2… drh 181 ** and positive for "good" check-ins.
41c7ac2… drh 182 */
41c7ac2… drh 183 static void bisect_append_log(int rid){
41c7ac2… drh 184 if( rid<0 ){
41c7ac2… drh 185 if( db_lget_int("bisect-bad",0)==(-rid) ) return;
41c7ac2… drh 186 db_lset_int("bisect-bad", -rid);
41c7ac2… drh 187 }else{
41c7ac2… drh 188 if( db_lget_int("bisect-good",0)==rid ) return;
41c7ac2… drh 189 db_lset_int("bisect-good", rid);
41c7ac2… drh 190 }
41c7ac2… drh 191 db_multi_exec(
41c7ac2… drh 192 "REPLACE INTO vvar(name,value) VALUES('bisect-log',"
41c7ac2… drh 193 "COALESCE((SELECT value||' ' FROM vvar WHERE name='bisect-log'),'')"
41c7ac2… drh 194 " || '%d')", rid);
41c7ac2… drh 195 }
41c7ac2… drh 196
41c7ac2… drh 197 /*
9e7262b… drh 198 ** Append a new skip entry to the bisect log.
9e7262b… drh 199 */
9e7262b… drh 200 static void bisect_append_skip(int rid){
9e7262b… drh 201 db_multi_exec(
9e7262b… drh 202 "UPDATE vvar SET value=value||' s%d' WHERE name='bisect-log'", rid
9e7262b… drh 203 );
9e7262b… drh 204 }
9e7262b… drh 205
9e7262b… drh 206 /*
ebd239d… drh 207 ** Append a VALUES entry to the bilog table insert
ebd239d… drh 208 */
ebd239d… drh 209 static void bisect_log_append(Blob *pSql,int iSeq,const char *zStat,int iRid){
ebd239d… drh 210 if( (iSeq%6)==3 ){
ebd239d… drh 211 blob_append_sql(pSql, ",\n ");
ebd239d… drh 212 }else if( iSeq>1 ){
ebd239d… drh 213 blob_append_sql(pSql, ",");
ebd239d… drh 214 }
ebd239d… drh 215 if( zStat ){
ebd239d… drh 216 blob_append_sql(pSql, "(%d,%Q,%d)", iSeq, zStat, iRid);
ebd239d… drh 217 }else{
ebd239d… drh 218 blob_append_sql(pSql, "(NULL,NULL,%d)", iRid);
ebd239d… drh 219 }
ebd239d… drh 220 }
ebd239d… drh 221
ebd239d… drh 222 /*
912711f… drh 223 ** Limits on the bid= query parameter to /timeline. BISECT_MAX_TERM is
912711f… drh 224 ** the maximum number of terms and BISECT_MIN_PREFIX is the minimum number
912711f… drh 225 ** of hash prefix characters in each term. Permalinks generated by
912711f… drh 226 ** bisect_permalink() use 10-character prefixes, and a real bisect needs
912711f… drh 227 ** only about log2(N) steps, so these limits do not affect legitimate use.
912711f… drh 228 */
912711f… drh 229 #define BISECT_MAX_TERM 100
912711f… drh 230 #define BISECT_MIN_PREFIX 4
912711f… drh 231
912711f… drh 232 /*
cbde2cf… drh 233 ** Create a TEMP table named "bilog" that contains the complete history
cbde2cf… drh 234 ** of the current bisect.
9e7262b… drh 235 **
bc36fdc… danield 236 ** If iCurrent>0 then it is the RID of the current check-out and is included
9e7262b… drh 237 ** in the history table.
9e7262b… drh 238 **
9e7262b… drh 239 ** If zDesc is not NULL, then it is the bid= query parameter to /timeline
9e7262b… drh 240 ** that describes a bisect. Use the information in zDesc rather than in
9e7262b… drh 241 ** the bisect-log variable.
9e7262b… drh 242 **
9e7262b… drh 243 ** If bDetail is true, then also include information about every node
9e7262b… drh 244 ** in between the inner-most GOOD and BAD nodes.
912711f… drh 245 **
912711f… drh 246 ** The bilog table is always created. Return true if at least one row
912711f… drh 247 ** was inserted into it, or false if the bilog table is empty.
cbde2cf… drh 248 */
9e7262b… drh 249 int bisect_create_bilog_table(int iCurrent, const char *zDesc, int bDetail){
912711f… drh 250 char *zLog = 0;
cbde2cf… drh 251 Blob log, id;
cbde2cf… drh 252 int cnt = 0;
8a0fd6f… drh 253 int lastGood = -1;
8a0fd6f… drh 254 int lastBad = -1;
ebd239d… drh 255 Blob ins = BLOB_INITIALIZER;
8cb1b23… drh 256
8cb1b23… drh 257 if( zDesc!=0 ){
912711f… drh 258 int nTerm = 0;
8cb1b23… drh 259 blob_init(&log, 0, 0);
912711f… drh 260 while( (zDesc[0]=='y' || zDesc[0]=='n' || zDesc[0]=='s')
912711f… drh 261 && nTerm<BISECT_MAX_TERM
912711f… drh 262 ){
8cb1b23… drh 263 int i;
8cb1b23… drh 264 char c;
8cb1b23… drh 265 int rid;
8cb1b23… drh 266 for(i=1; ((c = zDesc[i])>='0' && c<='9') || (c>='a' && c<='f'); i++){}
912711f… drh 267 if( i-1<BISECT_MIN_PREFIX ) break;
912711f… drh 268 /* Use GLOB, not LIKE, so that the lookup can use the blob.uuid index */
79499fc… andygoth 269 rid = db_int(0,
8cb1b23… drh 270 "SELECT rid FROM blob"
912711f… drh 271 " WHERE uuid GLOB '%.*q*'"
8cb1b23… drh 272 " AND EXISTS(SELECT 1 FROM plink WHERE cid=rid)",
8cb1b23… drh 273 i-1, zDesc+1
8cb1b23… drh 274 );
8cb1b23… drh 275 if( rid==0 ) break;
912711f… drh 276 if( blob_size(&log) ) blob_append(&log, " ", 1);
912711f… drh 277 if( zDesc[0]=='n' ) blob_append(&log, "-", 1);
912711f… drh 278 if( zDesc[0]=='s' ) blob_append(&log, "s", 1);
8cb1b23… drh 279 blob_appendf(&log, "%d", rid);
912711f… drh 280 nTerm++;
8cb1b23… drh 281 zDesc += i;
adfc1a6… drh 282 while( zDesc[0]=='-' ) zDesc++;
8cb1b23… drh 283 }
8cb1b23… drh 284 }else{
8cb1b23… drh 285 zLog = db_lget("bisect-log","");
8cb1b23… drh 286 blob_init(&log, zLog, -1);
8cb1b23… drh 287 }
cbde2cf… drh 288 db_multi_exec(
cbde2cf… drh 289 "CREATE TEMP TABLE bilog("
8a0fd6f… drh 290 " rid INTEGER PRIMARY KEY," /* Sequence of events */
cbde2cf… drh 291 " stat TEXT," /* Type of occurrence */
8a0fd6f… drh 292 " seq INTEGER UNIQUE" /* Check-in number */
cbde2cf… drh 293 ");"
cbde2cf… drh 294 );
ebd239d… drh 295 blob_append_sql(&ins, "INSERT OR IGNORE INTO bilog(seq,stat,rid) VALUES");
cbde2cf… drh 296 while( blob_token(&log, &id) ){
9e7262b… drh 297 int rid;
ebd239d… drh 298 cnt++;
9e7262b… drh 299 if( blob_str(&id)[0]=='s' ){
9e7262b… drh 300 rid = atoi(blob_str(&id)+1);
ebd239d… drh 301 bisect_log_append(&ins, cnt, "SKIP", rid);
8a0fd6f… drh 302 }else{
9e7262b… drh 303 rid = atoi(blob_str(&id));
9e7262b… drh 304 if( rid>0 ){
ebd239d… drh 305 bisect_log_append(&ins, cnt, "GOOD", rid);
9e7262b… drh 306 lastGood = rid;
9e7262b… drh 307 }else{
680acb2… drh 308 bisect_log_append(&ins, cnt, "BAD", -rid);
9e7262b… drh 309 lastBad = -rid;
9e7262b… drh 310 }
8a0fd6f… drh 311 }
cbde2cf… drh 312 }
cbde2cf… drh 313 if( iCurrent>0 ){
ebd239d… drh 314 bisect_log_append(&ins, ++cnt, "CURRENT", iCurrent);
8a0fd6f… drh 315 }
9e7262b… drh 316 if( bDetail && lastGood>0 && lastBad>0 ){
8a0fd6f… drh 317 PathNode *p;
4e23c2a… drh 318 p = path_shortest(lastGood, lastBad, bisect_option("direct-only"),0, 0, 0);
8a0fd6f… drh 319 while( p ){
ebd239d… drh 320 bisect_log_append(&ins, ++cnt, 0, p->rid);
8a0fd6f… drh 321 p = p->u.pTo;
8a0fd6f… drh 322 }
8a0fd6f… drh 323 path_reset();
8cb1b23… drh 324 }
912711f… drh 325 if( cnt>0 ) db_exec_sql(blob_sql_text(&ins));
ebd239d… drh 326 blob_reset(&ins);
912711f… drh 327 blob_reset(&log);
912711f… drh 328 fossil_free(zLog);
912711f… drh 329 return cnt>0;
8cb1b23… drh 330 }
8cb1b23… drh 331
8cb1b23… drh 332 /* Return a permalink description of a bisect. Space is obtained from
8cb1b23… drh 333 ** fossil_malloc() and should be freed by the caller.
8cb1b23… drh 334 **
8cb1b23… drh 335 ** A bisect description consists of characters 'y' and 'n' and lowercase
8cb1b23… drh 336 ** hex digits. Each term begins with 'y' or 'n' (success or failure) and
8cb1b23… drh 337 ** is followed by a hash prefix in lowercase hex.
8cb1b23… drh 338 */
8cb1b23… drh 339 char *bisect_permalink(void){
8cb1b23… drh 340 char *zLog = db_lget("bisect-log","");
8cb1b23… drh 341 char *zResult;
8cb1b23… drh 342 Blob log;
8cb1b23… drh 343 Blob link = BLOB_INITIALIZER;
8cb1b23… drh 344 Blob id;
8cb1b23… drh 345 blob_init(&log, zLog, -1);
8cb1b23… drh 346 while( blob_token(&log, &id) ){
9e7262b… drh 347 const char *zUuid;
9e7262b… drh 348 int rid;
9e7262b… drh 349 char cPrefix = 'y';
9e7262b… drh 350 if( blob_str(&id)[0]=='s' ){
9e7262b… drh 351 rid = atoi(blob_str(&id)+1);
9e7262b… drh 352 cPrefix = 's';
9e7262b… drh 353 }else{
9e7262b… drh 354 rid = atoi(blob_str(&id));
9e7262b… drh 355 if( rid<0 ){
9e7262b… drh 356 cPrefix = 'n';
9e7262b… drh 357 rid = -rid;
9e7262b… drh 358 }
9e7262b… drh 359 }
9e7262b… drh 360 zUuid = db_text(0,"SELECT lower(uuid) FROM blob WHERE rid=%d", rid);
adfc1a6… drh 361 if( blob_size(&link)>0 ) blob_append(&link, "-", 1);
9e7262b… drh 362 blob_appendf(&link, "%c%.10s", cPrefix, zUuid);
cbde2cf… drh 363 }
4c3e172… danield 364 zResult = fossil_strdup(blob_str(&link));
8cb1b23… drh 365 blob_reset(&link);
8cb1b23… drh 366 blob_reset(&log);
8cb1b23… drh 367 blob_reset(&id);
8cb1b23… drh 368 return zResult;
cbde2cf… drh 369 }
cbde2cf… drh 370
cbde2cf… drh 371 /*
0a7af8d… drh 372 ** Show a chart of bisect "good" and "bad" versions. The chart can be
0a7af8d… drh 373 ** sorted either chronologically by bisect time, or by check-in time.
0a7af8d… drh 374 */
0a7af8d… drh 375 static void bisect_chart(int sortByCkinTime){
0a7af8d… drh 376 Stmt q;
4da2f01… drh 377 int iCurrent = db_lget_int("checkout",0);
9e7262b… drh 378 bisect_create_bilog_table(iCurrent, 0, 0);
0a7af8d… drh 379 db_prepare(&q,
0a7af8d… drh 380 "SELECT bilog.seq, bilog.stat,"
4da2f01… drh 381 " substr(blob.uuid,1,16), datetime(event.mtime),"
4da2f01… drh 382 " blob.rid==%d"
0a7af8d… drh 383 " FROM bilog, blob, event"
0a7af8d… drh 384 " WHERE blob.rid=bilog.rid AND event.objid=bilog.rid"
0a7af8d… drh 385 " AND event.type='ci'"
36d63c6… drh 386 " ORDER BY %s bilog.rowid ASC",
4da2f01… drh 387 iCurrent, (sortByCkinTime ? "event.mtime DESC, " : "")
0a7af8d… drh 388 );
0a7af8d… drh 389 while( db_step(&q)==SQLITE_ROW ){
4da2f01… drh 390 const char *zGoodBad = db_column_text(&q, 1);
4da2f01… drh 391 fossil_print("%3d %-7s %s %s%s\n",
0a7af8d… drh 392 db_column_int(&q, 0),
4da2f01… drh 393 zGoodBad,
0a7af8d… drh 394 db_column_text(&q, 3),
4da2f01… drh 395 db_column_text(&q, 2),
4da2f01… drh 396 (db_column_int(&q, 4) && zGoodBad[0]!='C') ? " CURRENT" : "");
0a7af8d… drh 397 }
0a7af8d… drh 398 db_finalize(&q);
4da2f01… drh 399 }
4da2f01… drh 400
fff37e6… drh 401
fff37e6… drh 402 /*
fff37e6… drh 403 ** Reset the bisect subsystem.
fff37e6… drh 404 */
fff37e6… drh 405 void bisect_reset(void){
fff37e6… drh 406 db_multi_exec(
fff37e6… drh 407 "DELETE FROM vvar WHERE name IN "
42f61b6… drh 408 " ('bisect-good', 'bisect-bad', 'bisect-log', 'bisect-complete',"
42f61b6… drh 409 " 'bisect-linear')"
fff37e6… drh 410 );
7d4cf0e… drh 411 }
7d4cf0e… drh 412
7d4cf0e… drh 413 /*
7d4cf0e… drh 414 ** fossil bisect run [OPTIONS] COMMAND
7d4cf0e… drh 415 **
7d4cf0e… drh 416 ** Invoke COMMAND (with arguments) repeatedly to perform the bisect.
7d4cf0e… drh 417 **
2512d2d… km 418 ** Options:
7d4cf0e… drh 419 ** -i|--interactive Prompt user for decisions rather than
7d4cf0e… drh 420 ** using the return code from COMMAND
93c918b… drh 421 ** --ii Like -i but also pause after showing
93c918b… drh 422 ** the status after each step.
7d4cf0e… drh 423 */
7d4cf0e… drh 424 static void bisect_run(void){
7d4cf0e… drh 425 const char *zCmd;
7d4cf0e… drh 426 int isInteractive = 0;
7d4cf0e… drh 427 int i;
7d4cf0e… drh 428 if( g.argc<4 ){
7d4cf0e… drh 429 fossil_fatal("Usage: fossil bisect run [OPTIONS] COMMAND\n");
7d4cf0e… drh 430 }
7d4cf0e… drh 431 for(i=3; i<g.argc-1; i++){
7d4cf0e… drh 432 const char *zArg = g.argv[i];
7d4cf0e… drh 433 if( zArg[0]=='-' && zArg[1]=='-' && zArg[2]!=0 ) zArg++;
7d4cf0e… drh 434 if( strcmp(zArg, "-i")==0 || strcmp(zArg, "-interactive")==0 ){
7d4cf0e… drh 435 isInteractive = 1;
7d4cf0e… drh 436 continue;
7d4cf0e… drh 437 }
93c918b… drh 438 if( strcmp(zArg, "-ii")==0 ){
93c918b… drh 439 isInteractive = 2;
93c918b… drh 440 continue;
93c918b… drh 441 }
7d4cf0e… drh 442 fossil_fatal("unknown command-line option: \"%s\"\n", g.argv[i]);
7d4cf0e… drh 443 }
7d4cf0e… drh 444 zCmd = g.argv[i];
7d4cf0e… drh 445 if( db_int(0, "SELECT count(*) FROM vvar"
7d4cf0e… drh 446 " WHERE name IN ('bisect-good','bisect-bad')")!=2 ){
7d4cf0e… drh 447 fossil_fatal("need good/bad boundaries to use \"fossil bisect run\"");
7d4cf0e… drh 448 }
7d4cf0e… drh 449 while( db_lget_int("bisect-complete",0)==0 ){
7d4cf0e… drh 450 int rc;
7d4cf0e… drh 451 Blob cmd;
7d4cf0e… drh 452 blob_init(&cmd, 0, 0);
4f83d06… drh 453 blob_append_escaped_arg(&cmd, g.nameOfExe, 1);
7d4cf0e… drh 454 rc = fossil_unsafe_system(zCmd);
1259da6… stephan 455 #if !defined(_WIN32)
1259da6… stephan 456 /* system() returns a wait status, not the exit code, so 125
1259da6… stephan 457 ** ("skip") arrives as 125<<8. */
1259da6… stephan 458 if( rc!=-1 && WIFEXITED(rc) ) rc = WEXITSTATUS(rc);
1259da6… stephan 459 #endif
7d4cf0e… drh 460 if( isInteractive ){
7d4cf0e… drh 461 Blob in;
7d4cf0e… drh 462 fossil_print("test-command result: %d\n", rc);
7d4cf0e… drh 463 while(1){
7d4cf0e… drh 464 int n;
7d4cf0e… drh 465 char *z;
7d4cf0e… drh 466 prompt_user("Enter (g)ood, (b)ad, (s)kip, (a)uto, (h)alt: ", &in);
7d4cf0e… drh 467 n = blob_size(&in);
7d4cf0e… drh 468 z = blob_str(&in);
7d4cf0e… drh 469 if( n<1 ) continue;
7d4cf0e… drh 470 if( sqlite3_strnicmp("good", z, n)==0 ){
7d4cf0e… drh 471 rc = 0;
7d4cf0e… drh 472 break;
7d4cf0e… drh 473 }
7d4cf0e… drh 474 if( sqlite3_strnicmp("bad", z, n)==0 ){
7d4cf0e… drh 475 rc = 1;
7d4cf0e… drh 476 break;
7d4cf0e… drh 477 }
7d4cf0e… drh 478 if( sqlite3_strnicmp("skip", z, n)==0 ){
7d4cf0e… drh 479 rc = 125;
7d4cf0e… drh 480 break;
7d4cf0e… drh 481 }
7d4cf0e… drh 482 if( sqlite3_strnicmp("auto", z, n)==0 ){
7d4cf0e… drh 483 isInteractive = 0;
7d4cf0e… drh 484 break;
7d4cf0e… drh 485 }
7d4cf0e… drh 486 if( sqlite3_strnicmp("halt", z, n)==0 ){
7d4cf0e… drh 487 return;
7d4cf0e… drh 488 }
7d4cf0e… drh 489 blob_reset(&in);
7d4cf0e… drh 490 }
7d4cf0e… drh 491 }
7d4cf0e… drh 492 if( rc==0 ){
7d4cf0e… drh 493 blob_append(&cmd, " bisect good", -1);
7d4cf0e… drh 494 }else if( rc==125 ){
7d4cf0e… drh 495 blob_append(&cmd, " bisect skip", -1);
7d4cf0e… drh 496 }else{
7d4cf0e… drh 497 blob_append(&cmd, " bisect bad", -1);
7d4cf0e… drh 498 }
7d4cf0e… drh 499 fossil_print("%s\n", blob_str(&cmd));
7d4cf0e… drh 500 fossil_system(blob_str(&cmd));
7d4cf0e… drh 501 blob_reset(&cmd);
93c918b… drh 502 if( isInteractive>=2 && db_lget_int("bisect-complete", 0)==0 ){
93c918b… drh 503 int n;
93c918b… drh 504 char *z;
93c918b… drh 505 Blob in;
93c918b… drh 506 int bContinue = 1;
93c918b… drh 507 prompt_user("Run testcase again? (Y)es or No: ", &in);
93c918b… drh 508 n = blob_size(&in);
93c918b… drh 509 z = blob_str(&in);
93c918b… drh 510 if( n>0 && sqlite3_strnicmp("no", z, n)==0 ) bContinue = 0;
93c918b… drh 511 blob_reset(&in);
93c918b… drh 512 if( !bContinue ) break;
93c918b… drh 513 }
7d4cf0e… drh 514 }
fff37e6… drh 515 }
fff37e6… drh 516
0a7af8d… drh 517 /*
2ce65f2… drh 518 ** COMMAND: bisect
2ce65f2… drh 519 **
2ce65f2… drh 520 ** Usage: %fossil bisect SUBCOMMAND ...
2ce65f2… drh 521 **
c965636… drh 522 ** Run various subcommands useful for searching back through the change
bc36fdc… danield 523 ** history for a particular check-in that causes or fixes a problem.
e58c76a… drh 524 **
e58c76a… drh 525 ** > fossil bisect bad ?VERSION?
e58c76a… drh 526 **
e58c76a… drh 527 ** Identify version VERSION as non-working. If VERSION is omitted,
bc36fdc… danield 528 ** the current check-out is marked as non-working.
e58c76a… drh 529 **
e58c76a… drh 530 ** > fossil bisect good ?VERSION?
e58c76a… drh 531 **
e58c76a… drh 532 ** Identify version VERSION as working. If VERSION is omitted,
bc36fdc… danield 533 ** the current check-out is marked as working.
e58c76a… drh 534 **
e58c76a… drh 535 ** > fossil bisect log
e58c76a… drh 536 ** > fossil bisect chart
e58c76a… drh 537 **
d4c45b5… drh 538 ** Show a log of "good", "bad", and "skip" versions. "bisect log"
d4c45b5… drh 539 ** shows the events in the order that they were tested.
d4c45b5… drh 540 ** "bisect chart" shows them in order of check-in.
e58c76a… drh 541 **
e58c76a… drh 542 ** > fossil bisect next
e58c76a… drh 543 **
e58c76a… drh 544 ** Update to the next version that is halfway between the working and
e58c76a… drh 545 ** non-working versions.
e58c76a… drh 546 **
e58c76a… drh 547 ** > fossil bisect options ?NAME? ?VALUE?
e58c76a… drh 548 **
e58c76a… drh 549 ** List all bisect options, or the value of a single option, or set the
e58c76a… drh 550 ** value of a bisect option.
e58c76a… drh 551 **
e58c76a… drh 552 ** > fossil bisect reset
e58c76a… drh 553 **
e58c76a… drh 554 ** Reinitialize a bisect session. This cancels prior bisect history
e58c76a… drh 555 ** and allows a bisect session to start over from the beginning.
e58c76a… drh 556 **
7d4cf0e… drh 557 ** > fossil bisect run [OPTIONS] COMMAND
7d4cf0e… drh 558 **
7d4cf0e… drh 559 ** Invoke COMMAND repeatedly to run the bisect. The exit code for
7d4cf0e… drh 560 ** COMMAND should be 0 for "good", 125 for "skip", and any other value
2512d2d… km 561 ** for "bad".
7d4cf0e… drh 562 **
2512d2d… km 563 ** Options:
7d4cf0e… drh 564 ** -i|--interactive Prompt the user for the good/bad/skip decision
7d4cf0e… drh 565 ** after each step, rather than using the exit
7d4cf0e… drh 566 ** code from COMMAND
2355d14… drh 567 ** --ii Like "-i" but also pauses after showing the
2355d14… drh 568 ** status for each step.
7d4cf0e… drh 569 **
9e7262b… drh 570 ** > fossil bisect skip ?VERSION?
9e7262b… drh 571 **
bc36fdc… danield 572 ** Cause VERSION (or the current check-out if VERSION is omitted) to
9e7262b… drh 573 ** be ignored for the purpose of the current bisect. This might
9e7262b… drh 574 ** be done, for example, because VERSION does not compile correctly
9e7262b… drh 575 ** or is otherwise unsuitable to participate in this bisect.
9e7262b… drh 576 **
e58c76a… drh 577 ** > fossil bisect vlist|ls|status ?-a|--all?
e58c76a… drh 578 **
d4c45b5… drh 579 ** List the versions in between the inner-most "bad" and "good".
e58c76a… drh 580 **
a865c62… drh 581 ** > fossil bisect ui ?HOST@USER:PATH?
e58c76a… drh 582 **
e58c76a… drh 583 ** Like "fossil ui" except start on a timeline that shows only the
a865c62… drh 584 ** check-ins that are part of the current bisect. If the optional
c7bfa96… brickviking 585 ** fourth term is added, then information is shown for the bisect that
a865c62… drh 586 ** occurred in the PATH directory by USER on remote machine HOST.
e58c76a… drh 587 **
e58c76a… drh 588 ** > fossil bisect undo
e58c76a… drh 589 **
d4c45b5… drh 590 ** Undo the most recent "good", "bad", or "skip" command.
2ce65f2… drh 591 */
2ce65f2… drh 592 void bisect_cmd(void){
2ce65f2… drh 593 int n;
2ce65f2… drh 594 const char *zCmd;
41c7ac2… drh 595 int foundCmd = 0;
2ce65f2… drh 596 db_must_be_within_tree();
a8b0c6f… drh 597 if( g.argc<3 ){
6e45212… andygoth 598 goto usage;
a8b0c6f… drh 599 }
2ce65f2… drh 600 zCmd = g.argv[2];
2ce65f2… drh 601 n = strlen(zCmd);
bd75ea0… drh 602 if( n==0 ) zCmd = "-";
0a7af8d… drh 603 if( strncmp(zCmd, "bad", n)==0 ){
2ce65f2… drh 604 int ridBad;
41c7ac2… drh 605 foundCmd = 1;
2ce65f2… drh 606 if( g.argc==3 ){
2ce65f2… drh 607 ridBad = db_lget_int("checkout",0);
2ce65f2… drh 608 }else{
2a013f0… drh 609 ridBad = name_to_typed_rid(g.argv[3], "ci");
2a013f0… drh 610 }
41c7ac2… drh 611 if( ridBad>0 ){
41c7ac2… drh 612 bisect_append_log(-ridBad);
41c7ac2… drh 613 if( bisect_option("auto-next") && db_lget_int("bisect-good",0)>0 ){
41c7ac2… drh 614 zCmd = "next";
41c7ac2… drh 615 n = 4;
41c7ac2… drh 616 }
41c7ac2… drh 617 }
0a7af8d… drh 618 }else if( strncmp(zCmd, "good", n)==0 ){
2ce65f2… drh 619 int ridGood;
41c7ac2… drh 620 foundCmd = 1;
2ce65f2… drh 621 if( g.argc==3 ){
2ce65f2… drh 622 ridGood = db_lget_int("checkout",0);
2ce65f2… drh 623 }else{
2a013f0… drh 624 ridGood = name_to_typed_rid(g.argv[3], "ci");
2a013f0… drh 625 }
41c7ac2… drh 626 if( ridGood>0 ){
41c7ac2… drh 627 bisect_append_log(ridGood);
41c7ac2… drh 628 if( bisect_option("auto-next") && db_lget_int("bisect-bad",0)>0 ){
41c7ac2… drh 629 zCmd = "next";
41c7ac2… drh 630 n = 4;
41c7ac2… drh 631 }
41c7ac2… drh 632 }
9e7262b… drh 633 }else if( strncmp(zCmd, "skip", n)==0 ){
9e7262b… drh 634 int ridSkip;
9e7262b… drh 635 foundCmd = 1;
9e7262b… drh 636 if( g.argc==3 ){
9e7262b… drh 637 ridSkip = db_lget_int("checkout",0);
9e7262b… drh 638 }else{
9e7262b… drh 639 ridSkip = name_to_typed_rid(g.argv[3], "ci");
9e7262b… drh 640 }
9e7262b… drh 641 if( ridSkip>0 ){
9e7262b… drh 642 bisect_append_skip(ridSkip);
79499fc… andygoth 643 if( bisect_option("auto-next")
9e7262b… drh 644 && db_lget_int("bisect-bad",0)>0
9e7262b… drh 645 && db_lget_int("bisect-good",0)>0
9e7262b… drh 646 ){
9e7262b… drh 647 zCmd = "next";
9e7262b… drh 648 n = 4;
9e7262b… drh 649 }
9e7262b… drh 650 }
0a7af8d… drh 651 }else if( strncmp(zCmd, "undo", n)==0 ){
41c7ac2… drh 652 char *zLog;
41c7ac2… drh 653 Blob log, id;
41c7ac2… drh 654 int ridBad = 0;
41c7ac2… drh 655 int ridGood = 0;
41c7ac2… drh 656 int cnt = 0, i;
4ee6792… joel 657 foundCmd = 1;
e1962ef… drh 658 db_begin_transaction();
41c7ac2… drh 659 zLog = db_lget("bisect-log","");
41c7ac2… drh 660 blob_init(&log, zLog, -1);
41c7ac2… drh 661 while( blob_token(&log, &id) ){ cnt++; }
41c7ac2… drh 662 if( cnt==0 ){
41c7ac2… drh 663 fossil_fatal("no previous bisect steps to undo");
41c7ac2… drh 664 }
41c7ac2… drh 665 blob_rewind(&log);
41c7ac2… drh 666 for(i=0; i<cnt-1; i++){
41c7ac2… drh 667 int rid;
41c7ac2… drh 668 blob_token(&log, &id);
1259da6… stephan 669 if( blob_str(&id)[0]=='s' ) continue /* a skip */;
41c7ac2… drh 670 rid = atoi(blob_str(&id));
41c7ac2… drh 671 if( rid<0 ) ridBad = -rid;
41c7ac2… drh 672 else ridGood = rid;
41c7ac2… drh 673 }
41c7ac2… drh 674 db_multi_exec(
41c7ac2… drh 675 "UPDATE vvar SET value=substr(value,1,%d) WHERE name='bisect-log'",
41c7ac2… drh 676 log.iCursor-1
41c7ac2… drh 677 );
41c7ac2… drh 678 db_lset_int("bisect-bad", ridBad);
41c7ac2… drh 679 db_lset_int("bisect-good", ridGood);
41c7ac2… drh 680 db_end_transaction(0);
41c7ac2… drh 681 if( ridBad && ridGood ){
41c7ac2… drh 682 zCmd = "next";
41c7ac2… drh 683 n = 4;
41c7ac2… drh 684 }
41c7ac2… drh 685 }
8b17c23… jan.nijtmans 686 /* No else here so that the above commands can morph themselves into
41c7ac2… drh 687 ** a "next" command */
0a7af8d… drh 688 if( strncmp(zCmd, "next", n)==0 ){
41c7ac2… drh 689 PathNode *pMid;
0a7af8d… drh 690 char *zDisplay = db_lget("bisect-display","chart");
0a7af8d… drh 691 int m = (int)strlen(zDisplay);
41c7ac2… drh 692 bisect_path();
42f61b6… drh 693 if( db_lget_boolean("bisect-linear",0) ){
42f61b6… drh 694 pMid = path_next();
e655445… drh 695 if( pMid && pMid->rid==db_lget_int("checkout",0) ) pMid = 0;
42f61b6… drh 696 }else{
42f61b6… drh 697 pMid = path_midpoint();
42f61b6… drh 698 }
41c7ac2… drh 699 if( pMid==0 ){
41c7ac2… drh 700 fossil_print("bisect complete\n");
7d4cf0e… drh 701 db_lset_int("bisect-complete",1);
41c7ac2… drh 702 }else{
9e7262b… drh 703 int nSpan = path_length_not_hidden();
b45dd1c… drh 704 int nStep = path_search_depth();
41c7ac2… drh 705 g.argv[1] = "update";
41c7ac2… drh 706 g.argv[2] = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", pMid->rid);
41c7ac2… drh 707 g.argc = 3;
41c7ac2… drh 708 g.fNoSync = 1;
41c7ac2… drh 709 update_cmd();
b45dd1c… drh 710 fossil_print("span: %d steps-remaining: %d\n", nSpan, nStep);
0a7af8d… drh 711 }
52b35c8… jan.nijtmans 712
0a7af8d… drh 713 if( strncmp(zDisplay,"chart",m)==0 ){
0a7af8d… drh 714 bisect_chart(1);
0a7af8d… drh 715 }else if( strncmp(zDisplay, "log", m)==0 ){
0a7af8d… drh 716 bisect_chart(0);
0a7af8d… drh 717 }else if( strncmp(zDisplay, "status", m)==0 ){
0a7af8d… drh 718 bisect_list(1);
0a7af8d… drh 719 }
0a7af8d… drh 720 }else if( strncmp(zCmd, "log", n)==0 ){
0a7af8d… drh 721 bisect_chart(0);
0a7af8d… drh 722 }else if( strncmp(zCmd, "chart", n)==0 ){
0a7af8d… drh 723 bisect_chart(1);
7d4cf0e… drh 724 }else if( strncmp(zCmd, "run", n)==0 ){
7d4cf0e… drh 725 bisect_run();
0a7af8d… drh 726 }else if( strncmp(zCmd, "options", n)==0 ){
41c7ac2… drh 727 if( g.argc==3 ){
41c7ac2… drh 728 unsigned int i;
3cb9ba4… andygoth 729 for(i=0; i<count(aBisectOption); i++){
d8ec765… drh 730 char *z = mprintf("bisect-%s", aBisectOption[i].zName);
d8ec765… drh 731 fossil_print(" %-15s %-6s ", aBisectOption[i].zName,
d8ec765… drh 732 db_lget(z, (char*)aBisectOption[i].zDefault));
d8ec765… drh 733 fossil_free(z);
2476b81… drh 734 comment_print(aBisectOption[i].zDesc, 0, 27, -1, get_comment_format());
fa81575… drh 735 }
fa81575… drh 736 }else if( g.argc==4 || g.argc==5 ){
fa81575… drh 737 unsigned int i;
fa81575… drh 738 n = strlen(g.argv[3]);
3cb9ba4… andygoth 739 for(i=0; i<count(aBisectOption); i++){
52cb240… drh 740 if( strncmp(g.argv[3], aBisectOption[i].zName, n)==0 ){
fa81575… drh 741 char *z = mprintf("bisect-%s", aBisectOption[i].zName);
fa81575… drh 742 if( g.argc==5 ){
0a5d0e1… drh 743 db_lset(z/*works-like:"bisect-%s"*/, g.argv[4]);
fa81575… drh 744 }
d8ec765… drh 745 fossil_print("%s\n", db_lget(z, (char*)aBisectOption[i].zDefault));
fa81575… drh 746 fossil_free(z);
fa81575… drh 747 break;
fa81575… drh 748 }
fa81575… drh 749 }
3cb9ba4… andygoth 750 if( i>=count(aBisectOption) ){
fa81575… drh 751 fossil_fatal("no such bisect option: %s", g.argv[3]);
fa81575… drh 752 }
fa81575… drh 753 }else{
57f1eae… rberteig 754 usage("options ?NAME? ?VALUE?");
0a7af8d… drh 755 }
0a7af8d… drh 756 }else if( strncmp(zCmd, "reset", n)==0 ){
fff37e6… drh 757 bisect_reset();
cbde2cf… drh 758 }else if( strcmp(zCmd, "ui")==0 ){
cbde2cf… drh 759 char *newArgv[8];
a865c62… drh 760 verify_all_options();
cbde2cf… drh 761 newArgv[0] = g.argv[0];
cbde2cf… drh 762 newArgv[1] = "ui";
cbde2cf… drh 763 newArgv[2] = "--page";
cbde2cf… drh 764 newArgv[3] = "timeline?bisect";
a865c62… drh 765 if( g.argc==4 ){
a865c62… drh 766 newArgv[4] = g.argv[3];
a865c62… drh 767 g.argc = 5;
a865c62… drh 768 }else{
a865c62… drh 769 g.argc = 4;
a865c62… drh 770 }
a865c62… drh 771 newArgv[g.argc] = 0;
cbde2cf… drh 772 g.argv = newArgv;
cbde2cf… drh 773 cmd_webserver();
0a7af8d… drh 774 }else if( strncmp(zCmd, "vlist", n)==0
0a7af8d… drh 775 || strncmp(zCmd, "ls", n)==0
0a7af8d… drh 776 || strncmp(zCmd, "status", n)==0
41c7ac2… drh 777 ){
8b17c23… jan.nijtmans 778 int fAll = find_option("all", "a", 0)!=0;
41c7ac2… drh 779 bisect_list(!fAll);
41c7ac2… drh 780 }else if( !foundCmd ){
6e45212… andygoth 781 usage:
7d4cf0e… drh 782 usage("bad|good|log|chart|next|options|reset|run|skip|status|ui|undo");
e5121b4… drh 783 }
2ce65f2… drh 784 }

Keyboard Shortcuts

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