Skip to content

Commit 464ce0a

Browse files
sgnttaylorr
authored andcommitted
bisect--helper: move all subcommands into their own functions
In a later change, we will use OPT_SUBCOMMAND to parse sub-commands to avoid consuming non-option opts. Since OPT_SUBCOMMAND needs a function pointer to operate, let's move it now. Signed-off-by: Đoàn Trần Công Danh <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 58786d7 commit 464ce0a

File tree

1 file changed

+121
-34
lines changed

1 file changed

+121
-34
lines changed

builtin/bisect--helper.c

Lines changed: 121 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,117 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12771277
return res;
12781278
}
12791279

1280+
static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNUSED)
1281+
{
1282+
if (argc > 1)
1283+
return error(_("--bisect-reset requires either no argument or a commit"));
1284+
return bisect_reset(argc ? argv[0] : NULL);
1285+
}
1286+
1287+
static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNUSED)
1288+
{
1289+
int res;
1290+
struct bisect_terms terms = { 0 };
1291+
1292+
if (argc > 1)
1293+
return error(_("--bisect-terms requires 0 or 1 argument"));
1294+
res = bisect_terms(&terms, argc == 1 ? argv[0] : NULL);
1295+
free_terms(&terms);
1296+
return res;
1297+
}
1298+
1299+
static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNUSED)
1300+
{
1301+
int res;
1302+
struct bisect_terms terms = { 0 };
1303+
1304+
set_terms(&terms, "bad", "good");
1305+
res = bisect_start(&terms, argv, argc);
1306+
free_terms(&terms);
1307+
return res;
1308+
}
1309+
1310+
static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *prefix)
1311+
{
1312+
int res;
1313+
struct bisect_terms terms = { 0 };
1314+
1315+
if (argc)
1316+
return error(_("--bisect-next requires 0 arguments"));
1317+
get_terms(&terms);
1318+
res = bisect_next(&terms, prefix);
1319+
free_terms(&terms);
1320+
return res;
1321+
}
1322+
1323+
static int cmd_bisect__state(int argc, const char **argv, const char *prefix UNUSED)
1324+
{
1325+
int res;
1326+
struct bisect_terms terms = { 0 };
1327+
1328+
set_terms(&terms, "bad", "good");
1329+
get_terms(&terms);
1330+
res = bisect_state(&terms, argv, argc);
1331+
free_terms(&terms);
1332+
return res;
1333+
}
1334+
1335+
static int cmd_bisect__log(int argc, const char **argv UNUSED, const char *prefix UNUSED)
1336+
{
1337+
if (argc)
1338+
return error(_("--bisect-log requires 0 arguments"));
1339+
return bisect_log();
1340+
}
1341+
1342+
static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UNUSED)
1343+
{
1344+
int res;
1345+
struct bisect_terms terms = { 0 };
1346+
1347+
if (argc != 1)
1348+
return error(_("no logfile given"));
1349+
set_terms(&terms, "bad", "good");
1350+
res = bisect_replay(&terms, argv[0]);
1351+
free_terms(&terms);
1352+
return res;
1353+
}
1354+
1355+
static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUSED)
1356+
{
1357+
int res;
1358+
struct bisect_terms terms = { 0 };
1359+
1360+
set_terms(&terms, "bad", "good");
1361+
get_terms(&terms);
1362+
res = bisect_skip(&terms, argv, argc);
1363+
free_terms(&terms);
1364+
return res;
1365+
}
1366+
1367+
static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix UNUSED)
1368+
{
1369+
int res;
1370+
struct bisect_terms terms = { 0 };
1371+
1372+
get_terms(&terms);
1373+
res = bisect_visualize(&terms, argv, argc);
1374+
free_terms(&terms);
1375+
return res;
1376+
}
1377+
1378+
static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSED)
1379+
{
1380+
int res;
1381+
struct bisect_terms terms = { 0 };
1382+
1383+
if (!argc)
1384+
return error(_("bisect run failed: no command provided."));
1385+
get_terms(&terms);
1386+
res = bisect_run(&terms, argv, argc);
1387+
free_terms(&terms);
1388+
return res;
1389+
}
1390+
12801391
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
12811392
{
12821393
enum {
@@ -1316,8 +1427,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
13161427
N_("use <cmd>... to automatically bisect"), BISECT_RUN),
13171428
OPT_END()
13181429
};
1319-
struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL };
1320-
13211430
argc = parse_options(argc, argv, prefix, options,
13221431
git_bisect_helper_usage,
13231432
PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN_OPT);
@@ -1327,60 +1436,38 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
13271436

13281437
switch (cmdmode) {
13291438
case BISECT_RESET:
1330-
if (argc > 1)
1331-
return error(_("--bisect-reset requires either no argument or a commit"));
1332-
res = bisect_reset(argc ? argv[0] : NULL);
1439+
res = cmd_bisect__reset(argc, argv, prefix);
13331440
break;
13341441
case BISECT_TERMS:
1335-
if (argc > 1)
1336-
return error(_("--bisect-terms requires 0 or 1 argument"));
1337-
res = bisect_terms(&terms, argc == 1 ? argv[0] : NULL);
1442+
res = cmd_bisect__terms(argc, argv, prefix);
13381443
break;
13391444
case BISECT_START:
1340-
set_terms(&terms, "bad", "good");
1341-
res = bisect_start(&terms, argv, argc);
1445+
res = cmd_bisect__start(argc, argv, prefix);
13421446
break;
13431447
case BISECT_NEXT:
1344-
if (argc)
1345-
return error(_("--bisect-next requires 0 arguments"));
1346-
get_terms(&terms);
1347-
res = bisect_next(&terms, prefix);
1448+
res = cmd_bisect__next(argc, argv, prefix);
13481449
break;
13491450
case BISECT_STATE:
1350-
set_terms(&terms, "bad", "good");
1351-
get_terms(&terms);
1352-
res = bisect_state(&terms, argv, argc);
1451+
res = cmd_bisect__state(argc, argv, prefix);
13531452
break;
13541453
case BISECT_LOG:
1355-
if (argc)
1356-
return error(_("--bisect-log requires 0 arguments"));
1357-
res = bisect_log();
1454+
res = cmd_bisect__log(argc, argv, prefix);
13581455
break;
13591456
case BISECT_REPLAY:
1360-
if (argc != 1)
1361-
return error(_("no logfile given"));
1362-
set_terms(&terms, "bad", "good");
1363-
res = bisect_replay(&terms, argv[0]);
1457+
res = cmd_bisect__replay(argc, argv, prefix);
13641458
break;
13651459
case BISECT_SKIP:
1366-
set_terms(&terms, "bad", "good");
1367-
get_terms(&terms);
1368-
res = bisect_skip(&terms, argv, argc);
1460+
res = cmd_bisect__skip(argc, argv, prefix);
13691461
break;
13701462
case BISECT_VISUALIZE:
1371-
get_terms(&terms);
1372-
res = bisect_visualize(&terms, argv, argc);
1463+
res = cmd_bisect__visualize(argc, argv, prefix);
13731464
break;
13741465
case BISECT_RUN:
1375-
if (!argc)
1376-
return error(_("bisect run failed: no command provided."));
1377-
get_terms(&terms);
1378-
res = bisect_run(&terms, argv, argc);
1466+
res = cmd_bisect__run(argc, argv, prefix);
13791467
break;
13801468
default:
13811469
BUG("unknown subcommand %d", cmdmode);
13821470
}
1383-
free_terms(&terms);
13841471

13851472
/*
13861473
* Handle early success

0 commit comments

Comments
 (0)