Skip to content

Commit df63421

Browse files
dschottaylorr
authored andcommitted
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 <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Đoàn Trần Công Danh <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 5512376 commit df63421

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

builtin/bisect--helper.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,18 +1347,6 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref
13471347
return res;
13481348
}
13491349

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-
13621350
static int cmd_bisect__log(int argc, const char **argv UNUSED, const char *prefix UNUSED)
13631351
{
13641352
if (argc)
@@ -1424,7 +1412,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
14241412
OPT_SUBCOMMAND("terms", &fn, cmd_bisect__terms),
14251413
OPT_SUBCOMMAND("start", &fn, cmd_bisect__start),
14261414
OPT_SUBCOMMAND("next", &fn, cmd_bisect__next),
1427-
OPT_SUBCOMMAND("state", &fn, cmd_bisect__state),
14281415
OPT_SUBCOMMAND("log", &fn, cmd_bisect__log),
14291416
OPT_SUBCOMMAND("replay", &fn, cmd_bisect__replay),
14301417
OPT_SUBCOMMAND("skip", &fn, cmd_bisect__skip),
@@ -1433,14 +1420,27 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
14331420
OPT_SUBCOMMAND("run", &fn, cmd_bisect__run),
14341421
OPT_END()
14351422
};
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+
}
14441444

14451445
/*
14461446
* Handle early success

git-bisect.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ case "$#" in
5757
case "$cmd" in
5858
help)
5959
git bisect -h ;;
60-
bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD")
61-
git bisect--helper state "$cmd" "$@" ;;
6260
log)
6361
git bisect--helper log || exit ;;
6462
*)

0 commit comments

Comments
 (0)