1
1
#include "builtin.h"
2
2
#include "cache.h"
3
- #include "parse-options.h"
4
3
#include "bisect.h"
5
4
#include "refs.h"
6
5
#include "dir.h"
@@ -15,25 +14,50 @@ static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
15
14
static GIT_PATH_FUNC (git_path_bisect_ancestors_ok , "BISECT_ANCESTORS_OK ")
16
15
static GIT_PATH_FUNC (git_path_bisect_start , "BISECT_START ")
17
16
static GIT_PATH_FUNC (git_path_bisect_log , "BISECT_LOG ")
18
- static GIT_PATH_FUNC (git_path_head_name , "head - name ")
19
17
static GIT_PATH_FUNC (git_path_bisect_names , "BISECT_NAMES ")
20
18
static GIT_PATH_FUNC (git_path_bisect_first_parent , "BISECT_FIRST_PARENT ")
21
19
static GIT_PATH_FUNC (git_path_bisect_run , "BISECT_RUN ")
22
20
23
- static const char * const git_bisect_helper_usage [] = {
24
- N_ ("git bisect--helper --bisect-reset [<commit>]" ),
25
- "git bisect--helper --bisect-terms [--term-good | --term-old | --term-bad | --term-new]" ,
26
- N_ ("git bisect--helper --bisect-start [--term-{new,bad}=<term> --term-{old,good}=<term>]"
27
- " [--no-checkout] [--first-parent] [<bad> [<good>...]] [--] [<paths>...]" ),
28
- "git bisect--helper --bisect-next" ,
29
- N_ ("git bisect--helper --bisect-state (bad|new) [<rev>]" ),
30
- N_ ("git bisect--helper --bisect-state (good|old) [<rev>...]" ),
31
- N_ ("git bisect--helper --bisect-replay <filename>" ),
32
- N_ ("git bisect--helper --bisect-skip [(<rev>|<range>)...]" ),
33
- "git bisect--helper --bisect-visualize" ,
34
- N_ ("git bisect--helper --bisect-run <cmd>..." ),
35
- NULL
36
- };
21
+ static const char * bisect_usage =
22
+ N_ ("git bisect [help|start|bad|good|new|old|terms|skip|next|reset|"
23
+ "visualize|view|replay|log|run]" );
24
+
25
+ static const char * bisect_long_usage =
26
+ N_ ("git bisect [help|start|bad|good|new|old|terms|skip|next|reset|"
27
+ "visualize|view|replay|log|run]\n"
28
+ "\n"
29
+ "git bisect help\n"
30
+ "\tprint this long help message.\n"
31
+ "git bisect start [--term-{new,bad}=<term> "
32
+ "--term-{old,good}=<term>]\n"
33
+ "\t [--no-checkout] [--first-parent] [<bad> [<good>...]] [--] "
34
+ "[<pathspec>...]\n"
35
+ "\treset bisect state and start bisection.\n"
36
+ "git bisect (bad|new) [<rev>]\n"
37
+ "\tmark <rev> a known-bad revision/\n"
38
+ "\t a revision after change in a given property.\n"
39
+ "git bisect (good|old) [<rev>...]\n"
40
+ "\tmark <rev>... known-good revisions/\n"
41
+ "\t revisions before change in a given property.\n"
42
+ "git bisect terms [--term-good | --term-bad]\n"
43
+ "\tshow the terms used for old and new commits "
44
+ "(default: bad, good)\n"
45
+ "git bisect skip [(<rev>|<range>)...]\n"
46
+ "\tmark <rev>... untestable revisions.\n"
47
+ "git bisect next\n"
48
+ "\tfind next bisection to test and check it out.\n"
49
+ "git bisect reset [<commit>]\n"
50
+ "\tfinish bisection search and go back to commit.\n"
51
+ "git bisect (visualize|view)\n"
52
+ "\tshow bisect status in gitk.\n"
53
+ "git bisect replay <logfile>\n"
54
+ "\treplay bisection log.\n"
55
+ "git bisect log\n"
56
+ "\tshow bisect log.\n"
57
+ "git bisect run <cmd>...\n"
58
+ "\tuse <cmd>... to automatically bisect.\n"
59
+ "\n"
60
+ "Please use \"git help bisect\" to get the full man page." );
37
61
38
62
struct add_bisect_ref_data {
39
63
struct rev_info * revs ;
@@ -784,13 +808,6 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, const char **a
784
808
strbuf_addstr (& start_head , oid_to_hex (& head_oid ));
785
809
} else if (!get_oid (head , & head_oid ) &&
786
810
skip_prefix (head , "refs/heads/" , & head )) {
787
- /*
788
- * This error message should only be triggered by
789
- * cogito usage, and cogito users should understand
790
- * it relates to cg-seek.
791
- */
792
- if (!is_empty_or_missing_file (git_path_head_name ()))
793
- return error (_ ("won't bisect on cg-seek'ed tree" ));
794
811
strbuf_addstr (& start_head , head );
795
812
} else {
796
813
return error (_ ("bad HEAD - strange symbolic ref" ));
@@ -900,7 +917,7 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, const char **a
900
917
struct oid_array revs = OID_ARRAY_INIT ;
901
918
902
919
if (!argc )
903
- return error ( _ ( "Please call `--bisect-state` with at least one argument") );
920
+ BUG ( "bisect_state() called without argument" );
904
921
905
922
if (bisect_autostart (terms ))
906
923
return BISECT_FAILED ;
@@ -1223,7 +1240,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1223
1240
1224
1241
if (res < 0 || 128 <= res ) {
1225
1242
error (_ ("bisect run failed: exit code %d from"
1226
- " '%s' is < 0 or >= 128" ), res , command .buf );
1243
+ " %s is < 0 or >= 128" ), res , command .buf );
1227
1244
break ;
1228
1245
}
1229
1246
@@ -1263,7 +1280,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1263
1280
printf (_ ("bisect found first bad commit" ));
1264
1281
res = BISECT_OK ;
1265
1282
} else if (res ) {
1266
- error (_ ("bisect run failed: 'git bisect--helper --bisect-state "
1283
+ error (_ ("bisect run failed: 'git bisect"
1267
1284
" %s' exited with error code %d" ), new_state , res );
1268
1285
} else {
1269
1286
continue ;
@@ -1276,114 +1293,69 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1276
1293
return res ;
1277
1294
}
1278
1295
1279
- int cmd_bisect__helper (int argc , const char * * argv , const char * prefix )
1296
+ int cmd_bisect (int argc , const char * * argv , const char * prefix )
1280
1297
{
1281
- enum {
1282
- BISECT_RESET = 1 ,
1283
- BISECT_NEXT_CHECK ,
1284
- BISECT_TERMS ,
1285
- BISECT_START ,
1286
- BISECT_AUTOSTART ,
1287
- BISECT_NEXT ,
1288
- BISECT_STATE ,
1289
- BISECT_LOG ,
1290
- BISECT_REPLAY ,
1291
- BISECT_SKIP ,
1292
- BISECT_VISUALIZE ,
1293
- BISECT_RUN ,
1294
- } cmdmode = 0 ;
1295
- int res = 0 , nolog = 0 ;
1296
- struct option options [] = {
1297
- OPT_CMDMODE (0 , "bisect-reset" , & cmdmode ,
1298
- N_ ("reset the bisection state" ), BISECT_RESET ),
1299
- OPT_CMDMODE (0 , "bisect-next-check" , & cmdmode ,
1300
- N_ ("check whether bad or good terms exist" ), BISECT_NEXT_CHECK ),
1301
- OPT_CMDMODE (0 , "bisect-terms" , & cmdmode ,
1302
- N_ ("print out the bisect terms" ), BISECT_TERMS ),
1303
- OPT_CMDMODE (0 , "bisect-start" , & cmdmode ,
1304
- N_ ("start the bisect session" ), BISECT_START ),
1305
- OPT_CMDMODE (0 , "bisect-next" , & cmdmode ,
1306
- N_ ("find the next bisection commit" ), BISECT_NEXT ),
1307
- OPT_CMDMODE (0 , "bisect-state" , & cmdmode ,
1308
- N_ ("mark the state of ref (or refs)" ), BISECT_STATE ),
1309
- OPT_CMDMODE (0 , "bisect-log" , & cmdmode ,
1310
- N_ ("list the bisection steps so far" ), BISECT_LOG ),
1311
- OPT_CMDMODE (0 , "bisect-replay" , & cmdmode ,
1312
- N_ ("replay the bisection process from the given file" ), BISECT_REPLAY ),
1313
- OPT_CMDMODE (0 , "bisect-skip" , & cmdmode ,
1314
- N_ ("skip some commits for checkout" ), BISECT_SKIP ),
1315
- OPT_CMDMODE (0 , "bisect-visualize" , & cmdmode ,
1316
- N_ ("visualize the bisection" ), BISECT_VISUALIZE ),
1317
- OPT_CMDMODE (0 , "bisect-run" , & cmdmode ,
1318
- N_ ("use <cmd>... to automatically bisect" ), BISECT_RUN ),
1319
- OPT_BOOL (0 , "no-log" , & nolog ,
1320
- N_ ("no log for BISECT_WRITE" )),
1321
- OPT_END ()
1322
- };
1298
+ int res = 0 ;
1323
1299
struct bisect_terms terms = { .term_good = NULL , .term_bad = NULL };
1300
+ const char * command = argc > 1 ? argv [1 ] : "help" ;
1324
1301
1325
- argc = parse_options (argc , argv , prefix , options ,
1326
- git_bisect_helper_usage ,
1327
- PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN );
1302
+ if (!strcmp ("-h" , command ) || !strcmp ("help" , command ))
1303
+ usage (bisect_long_usage );
1328
1304
1329
- if (! cmdmode )
1330
- usage_with_options ( git_bisect_helper_usage , options ) ;
1305
+ argc -= 2 ;
1306
+ argv += 2 ;
1331
1307
1332
- switch (cmdmode ) {
1333
- case BISECT_RESET :
1334
- if (argc > 1 )
1335
- return error (_ ("--bisect-reset requires either no argument or a commit" ));
1336
- res = bisect_reset (argc ? argv [0 ] : NULL );
1337
- break ;
1338
- case BISECT_TERMS :
1308
+ if (!strcmp ("start" , command )) {
1309
+ set_terms (& terms , "bad" , "good" );
1310
+ res = bisect_start (& terms , argv , argc );
1311
+ } else if (!strcmp ("terms" , command )) {
1339
1312
if (argc > 1 )
1340
- return error (_ ("--bisect- terms requires 0 or 1 argument" ));
1313
+ die (_ ("' terms' requires 0 or 1 argument" ));
1341
1314
res = bisect_terms (& terms , argc == 1 ? argv [0 ] : NULL );
1342
- break ;
1343
- case BISECT_START :
1315
+ } else if (!strcmp ("skip" , command )) {
1344
1316
set_terms (& terms , "bad" , "good" );
1345
- res = bisect_start (& terms , argv , argc );
1346
- break ;
1347
- case BISECT_NEXT :
1317
+ get_terms (& terms );
1318
+ res = bisect_skip ( & terms , argv , argc ) ;
1319
+ } else if (! strcmp ( "next" , command )) {
1348
1320
if (argc )
1349
- return error (_ ("--bisect- next requires 0 arguments" ));
1321
+ die (_ ("' next' requires 0 arguments" ));
1350
1322
get_terms (& terms );
1351
1323
res = bisect_next (& terms , prefix );
1352
- break ;
1353
- case BISECT_STATE :
1354
- set_terms (& terms , "bad" , "good" );
1324
+ } else if (!strcmp ("reset" , command )) {
1325
+ if (argc > 1 )
1326
+ die (_ ("'reset' requires either no argument or a commit" ));
1327
+ res = bisect_reset (argc ? argv [0 ] : NULL );
1328
+ } else if (one_of (command , "visualize" , "view" , NULL )) {
1355
1329
get_terms (& terms );
1356
- res = bisect_state (& terms , argv , argc );
1357
- break ;
1358
- case BISECT_LOG :
1359
- if (argc )
1360
- return error (_ ("--bisect-log requires 0 arguments" ));
1361
- res = bisect_log ();
1362
- break ;
1363
- case BISECT_REPLAY :
1330
+ res = bisect_visualize (& terms , argv , argc );
1331
+ } else if (!strcmp ("replay" , command )) {
1364
1332
if (argc != 1 )
1365
- return error (_ ("no logfile given" ));
1333
+ die (_ ("no logfile given" ));
1366
1334
set_terms (& terms , "bad" , "good" );
1367
1335
res = bisect_replay (& terms , argv [0 ]);
1368
- break ;
1369
- case BISECT_SKIP :
1370
- set_terms (& terms , "bad" , "good" );
1371
- get_terms (& terms );
1372
- res = bisect_skip (& terms , argv , argc );
1373
- break ;
1374
- case BISECT_VISUALIZE :
1375
- get_terms (& terms );
1376
- res = bisect_visualize (& terms , argv , argc );
1377
- break ;
1378
- case BISECT_RUN :
1336
+ } else if (!strcmp ("log" , command )) {
1337
+ if (argc )
1338
+ die (_ ("'log' requires 0 arguments" ));
1339
+ res = bisect_log ();
1340
+ } else if (!strcmp ("run" , command )) {
1379
1341
if (!argc )
1380
- return error (_ ("bisect run failed: no command provided." ));
1342
+ die (_ ("bisect run failed: no command provided." ));
1381
1343
get_terms (& terms );
1382
1344
res = bisect_run (& terms , argv , argc );
1383
- break ;
1384
- default :
1385
- BUG ("unknown subcommand %d" , cmdmode );
1345
+ } else {
1346
+ if (!file_is_not_empty (git_path_bisect_start ()) &&
1347
+ !one_of (command , "bad" , "good" , "new" , "old" , NULL ))
1348
+ usage (bisect_usage );
1349
+ set_terms (& terms , "bad" , "good" );
1350
+ get_terms (& terms );
1351
+ if (check_and_set_terms (& terms , command ))
1352
+ usage (bisect_usage );
1353
+ /* shift the `command` back in */
1354
+ argc ++ ;
1355
+ argv -- ;
1356
+ res = bisect_state (& terms , argv , argc );
1386
1357
}
1358
+
1387
1359
free_terms (& terms );
1388
1360
1389
1361
/*
0 commit comments