bisect--helper: handle states directly

In preparation for making `git bisect` a real built-in, let's prepare the `bisect--helper` built-in to handle `git bisect--helper good` and `git bisect--helper bad`, i.e. eliminate the need of `state` subcommand. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Johannes Schindelin committed Nov 10, 2022 at 23:36 UTC df63421be927c689bbd9384d503768c0515063c4
2 files changed +21 -23
builtin/bisect--helper.c
+21 -21
@@ -1347,18 +1347,6 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref
1347 return res;
1348 }
1349
1350 -static int cmd_bisect__state(int argc, const char **argv, const char *prefix UNUSED)
1351 -{
1352 - int res;
1353 - struct bisect_terms terms = { 0 };
1354 -
1355 - set_terms(&terms, "bad", "good");
1356 - get_terms(&terms);
1357 - res = bisect_state(&terms, argv, argc);
1358 - free_terms(&terms);
1359 - return res;
1360 -}
1361 -
1350 static int cmd_bisect__log(int argc, const char **argv UNUSED, const char *prefix UNUSED)
1351 {
1352 if (argc)
@@ -1424,7 +1412,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1412 OPT_SUBCOMMAND("terms", &fn, cmd_bisect__terms),
1413 OPT_SUBCOMMAND("start", &fn, cmd_bisect__start),
1414 OPT_SUBCOMMAND("next", &fn, cmd_bisect__next),
1427 - OPT_SUBCOMMAND("state", &fn, cmd_bisect__state),
1415 OPT_SUBCOMMAND("log", &fn, cmd_bisect__log),
1416 OPT_SUBCOMMAND("replay", &fn, cmd_bisect__replay),
1417 OPT_SUBCOMMAND("skip", &fn, cmd_bisect__skip),
@@ -1433,14 +1420,27 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1420 OPT_SUBCOMMAND("run", &fn, cmd_bisect__run),
1421 OPT_END()
1422 };
1436 - argc = parse_options(argc, argv, prefix, options, git_bisect_usage, 0);
1437 -
1438 - if (!fn)
1439 - usage_with_options(git_bisect_usage, options);
1440 - argc--;
1441 - argv++;
1442 -
1443 - res = fn(argc, argv, prefix);
1423 + argc = parse_options(argc, argv, prefix, options, git_bisect_usage,
1424 + PARSE_OPT_SUBCOMMAND_OPTIONAL);
1425 +
1426 + if (!fn) {
1427 + struct bisect_terms terms = { 0 };
1428 +
1429 + if (!argc)
1430 + usage_msg_opt(_("need a command"), git_bisect_usage, options);
1431 +
1432 + set_terms(&terms, "bad", "good");
1433 + get_terms(&terms);
1434 + if (check_and_set_terms(&terms, argv[0]))
1435 + usage_msg_optf(_("unknown command: '%s'"), git_bisect_usage,
1436 + options, argv[0]);
1437 + res = bisect_state(&terms, argv, argc);
1438 + free_terms(&terms);
1439 + } else {
1440 + argc--;
1441 + argv++;
1442 + res = fn(argc, argv, prefix);
1443 + }
1444
1445 /*
1446 * Handle early success
git-bisect.sh
-2
@@ -57,8 +57,6 @@ case "$#" in
57 case "$cmd" in
58 help)
59 git bisect -h ;;
60 - bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD")
61 - git bisect--helper state "$cmd" "$@" ;;
60 log)
61 git bisect--helper log || exit ;;
62 *)