@@ -20,18 +20,40 @@ static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
20
20
static GIT_PATH_FUNC (git_path_bisect_first_parent , "BISECT_FIRST_PARENT ")
21
21
static GIT_PATH_FUNC (git_path_bisect_run , "BISECT_RUN ")
22
22
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>..." ),
23
+ #define BUILTIN_GIT_BISECT_START_USAGE \
24
+ N_ ("git bisect start [--term-{new,bad}=<term> --term-{old,good}=<term>]" \
25
+ " [--no-checkout] [--first-parent] [<bad> [<good>...]] [--]" \
26
+ " [<pathspec>...]" )
27
+ #define BUILTIN_GIT_BISECT_STATE_USAGE \
28
+ N_("git bisect (good|bad) [<rev>...]")
29
+ #define BUILTIN_GIT_BISECT_TERMS_USAGE \
30
+ "git bisect terms [--term-good | --term-bad]"
31
+ #define BUILTIN_GIT_BISECT_SKIP_USAGE \
32
+ N_("git bisect skip [(<rev>|<range>)...]")
33
+ #define BUILTIN_GIT_BISECT_NEXT_USAGE \
34
+ "git bisect next"
35
+ #define BUILTIN_GIT_BISECT_RESET_USAGE \
36
+ N_("git bisect reset [<commit>]")
37
+ #define BUILTIN_GIT_BISECT_VISUALIZE_USAGE \
38
+ "git bisect visualize"
39
+ #define BUILTIN_GIT_BISECT_REPLAY_USAGE \
40
+ N_("git bisect replay <logfile>")
41
+ #define BUILTIN_GIT_BISECT_LOG_USAGE \
42
+ "git bisect log"
43
+ #define BUILTIN_GIT_BISECT_RUN_USAGE \
44
+ N_("git bisect run <cmd>...")
45
+
46
+ static const char * const git_bisect_usage [] = {
47
+ BUILTIN_GIT_BISECT_START_USAGE ,
48
+ BUILTIN_GIT_BISECT_STATE_USAGE ,
49
+ BUILTIN_GIT_BISECT_TERMS_USAGE ,
50
+ BUILTIN_GIT_BISECT_SKIP_USAGE ,
51
+ BUILTIN_GIT_BISECT_NEXT_USAGE ,
52
+ BUILTIN_GIT_BISECT_RESET_USAGE ,
53
+ BUILTIN_GIT_BISECT_VISUALIZE_USAGE ,
54
+ BUILTIN_GIT_BISECT_REPLAY_USAGE ,
55
+ BUILTIN_GIT_BISECT_LOG_USAGE ,
56
+ BUILTIN_GIT_BISECT_RUN_USAGE ,
35
57
NULL
36
58
};
37
59
@@ -1191,13 +1213,13 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1191
1213
if (bisect_next_check (terms , NULL ))
1192
1214
return BISECT_FAILED ;
1193
1215
1194
- if (argc )
1195
- sq_quote_argv (& command , argv );
1196
- else {
1216
+ if (!argc ) {
1197
1217
error (_ ("bisect run failed: no command provided." ));
1198
1218
return BISECT_FAILED ;
1199
1219
}
1200
1220
1221
+ sq_quote_argv (& command , argv );
1222
+ strbuf_ltrim (& command );
1201
1223
while (1 ) {
1202
1224
res = do_bisect_run (command .buf );
1203
1225
@@ -1211,8 +1233,8 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1211
1233
if (is_first_run && (res == 126 || res == 127 )) {
1212
1234
int rc = verify_good (terms , command .buf );
1213
1235
is_first_run = 0 ;
1214
- if (rc < 0 ) {
1215
- error (_ ("unable to verify '%s' on good"
1236
+ if (rc < 0 || 128 <= rc ) {
1237
+ error (_ ("unable to verify %s on good"
1216
1238
" revision" ), command .buf );
1217
1239
res = BISECT_FAILED ;
1218
1240
break ;
@@ -1227,7 +1249,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1227
1249
1228
1250
if (res < 0 || 128 <= res ) {
1229
1251
error (_ ("bisect run failed: exit code %d from"
1230
- " '%s' is < 0 or >= 128" ), res , command .buf );
1252
+ " %s is < 0 or >= 128" ), res , command .buf );
1231
1253
break ;
1232
1254
}
1233
1255
@@ -1261,14 +1283,14 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1261
1283
if (res == BISECT_ONLY_SKIPPED_LEFT )
1262
1284
error (_ ("bisect run cannot continue any more" ));
1263
1285
else if (res == BISECT_INTERNAL_SUCCESS_MERGE_BASE ) {
1264
- printf (_ ("bisect run success" ));
1286
+ puts (_ ("bisect run success" ));
1265
1287
res = BISECT_OK ;
1266
1288
} else if (res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND ) {
1267
- printf (_ ("bisect found first bad commit" ));
1289
+ puts (_ ("bisect found first bad commit" ));
1268
1290
res = BISECT_OK ;
1269
1291
} else if (res ) {
1270
- error (_ ("bisect run failed: 'git bisect--helper --bisect- state"
1271
- " %s' exited with error code %d" ), new_state , res );
1292
+ error (_ ("bisect run failed: 'bisect-state %s' "
1293
+ " exited with error code %d" ), new_state , res );
1272
1294
} else {
1273
1295
continue ;
1274
1296
}
@@ -1282,7 +1304,8 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1282
1304
static int cmd_bisect__reset (int argc , const char * * argv , const char * prefix UNUSED )
1283
1305
{
1284
1306
if (argc > 1 )
1285
- return error (_ ("--bisect-reset requires either no argument or a commit" ));
1307
+ return error (_ ("'%s' requires either no argument or a commit" ),
1308
+ "git bisect reset" );
1286
1309
return bisect_reset (argc ? argv [0 ] : NULL );
1287
1310
}
1288
1311
@@ -1292,7 +1315,8 @@ static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNU
1292
1315
struct bisect_terms terms = { 0 };
1293
1316
1294
1317
if (argc > 1 )
1295
- return error (_ ("--bisect-terms requires 0 or 1 argument" ));
1318
+ return error (_ ("'%s' requires 0 or 1 argument" ),
1319
+ "git bisect terms" );
1296
1320
res = bisect_terms (& terms , argc == 1 ? argv [0 ] : NULL );
1297
1321
free_terms (& terms );
1298
1322
return res ;
@@ -1315,29 +1339,16 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref
1315
1339
struct bisect_terms terms = { 0 };
1316
1340
1317
1341
if (argc )
1318
- return error (_ ("--bisect-next requires 0 arguments" ));
1342
+ return error (_ ("'%s' requires 0 arguments" ),
1343
+ "git bisect next" );
1319
1344
get_terms (& terms );
1320
1345
res = bisect_next (& terms , prefix );
1321
1346
free_terms (& terms );
1322
1347
return res ;
1323
1348
}
1324
1349
1325
- static int cmd_bisect__state (int argc , const char * * argv , const char * prefix UNUSED )
1350
+ static int cmd_bisect__log (int argc UNUSED , const char * * argv UNUSED , const char * prefix UNUSED )
1326
1351
{
1327
- int res ;
1328
- struct bisect_terms terms = { 0 };
1329
-
1330
- set_terms (& terms , "bad" , "good" );
1331
- get_terms (& terms );
1332
- res = bisect_state (& terms , argv , argc );
1333
- free_terms (& terms );
1334
- return res ;
1335
- }
1336
-
1337
- static int cmd_bisect__log (int argc , const char * * argv UNUSED , const char * prefix UNUSED )
1338
- {
1339
- if (argc )
1340
- return error (_ ("--bisect-log requires 0 arguments" ));
1341
1352
return bisect_log ();
1342
1353
}
1343
1354
@@ -1383,14 +1394,14 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE
1383
1394
struct bisect_terms terms = { 0 };
1384
1395
1385
1396
if (!argc )
1386
- return error (_ ("bisect run failed: no command provided." ));
1397
+ return error (_ ("'%s' failed: no command provided." ), "git bisect run" );
1387
1398
get_terms (& terms );
1388
1399
res = bisect_run (& terms , argv , argc );
1389
1400
free_terms (& terms );
1390
1401
return res ;
1391
1402
}
1392
1403
1393
- int cmd_bisect__helper (int argc , const char * * argv , const char * prefix )
1404
+ int cmd_bisect (int argc , const char * * argv , const char * prefix )
1394
1405
{
1395
1406
int res = 0 ;
1396
1407
parse_opt_subcommand_fn * fn = NULL ;
@@ -1399,7 +1410,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1399
1410
OPT_SUBCOMMAND ("terms" , & fn , cmd_bisect__terms ),
1400
1411
OPT_SUBCOMMAND ("start" , & fn , cmd_bisect__start ),
1401
1412
OPT_SUBCOMMAND ("next" , & fn , cmd_bisect__next ),
1402
- OPT_SUBCOMMAND ("state" , & fn , cmd_bisect__state ),
1403
1413
OPT_SUBCOMMAND ("log" , & fn , cmd_bisect__log ),
1404
1414
OPT_SUBCOMMAND ("replay" , & fn , cmd_bisect__replay ),
1405
1415
OPT_SUBCOMMAND ("skip" , & fn , cmd_bisect__skip ),
@@ -1408,15 +1418,27 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1408
1418
OPT_SUBCOMMAND ("run" , & fn , cmd_bisect__run ),
1409
1419
OPT_END ()
1410
1420
};
1411
- argc = parse_options (argc , argv , prefix , options ,
1412
- git_bisect_helper_usage , 0 );
1413
-
1414
- if (!fn )
1415
- usage_with_options (git_bisect_helper_usage , options );
1416
- argc -- ;
1417
- argv ++ ;
1418
-
1419
- res = fn (argc , argv , prefix );
1421
+ argc = parse_options (argc , argv , prefix , options , git_bisect_usage ,
1422
+ PARSE_OPT_SUBCOMMAND_OPTIONAL );
1423
+
1424
+ if (!fn ) {
1425
+ struct bisect_terms terms = { 0 };
1426
+
1427
+ if (!argc )
1428
+ usage_msg_opt (_ ("need a command" ), git_bisect_usage , options );
1429
+
1430
+ set_terms (& terms , "bad" , "good" );
1431
+ get_terms (& terms );
1432
+ if (check_and_set_terms (& terms , argv [0 ]))
1433
+ usage_msg_optf (_ ("unknown command: '%s'" ), git_bisect_usage ,
1434
+ options , argv [0 ]);
1435
+ res = bisect_state (& terms , argv , argc );
1436
+ free_terms (& terms );
1437
+ } else {
1438
+ argc -- ;
1439
+ argv ++ ;
1440
+ res = fn (argc , argv , prefix );
1441
+ }
1420
1442
1421
1443
/*
1422
1444
* Handle early success
0 commit comments