]> git.ipfire.org Git - thirdparty/git.git/commitdiff
bisect--helper: handle states directly
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 10 Nov 2022 16:36:44 +0000 (23:36 +0700)
committerTaylor Blau <me@ttaylorr.com>
Fri, 11 Nov 2022 22:06:00 +0000 (17:06 -0500)
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>
builtin/bisect--helper.c
git-bisect.sh

index 1ff2d4ea3fee612c281f8bb69585a240d635434a..29d5a26c648a2d4ba9b38c2e6cde895253f837f1 100644 (file)
@@ -1347,18 +1347,6 @@ static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *pref
        return res;
 }
 
-static int cmd_bisect__state(int argc, const char **argv, const char *prefix UNUSED)
-{
-       int res;
-       struct bisect_terms terms = { 0 };
-
-       set_terms(&terms, "bad", "good");
-       get_terms(&terms);
-       res = bisect_state(&terms, argv, argc);
-       free_terms(&terms);
-       return res;
-}
-
 static int cmd_bisect__log(int argc, const char **argv UNUSED, const char *prefix UNUSED)
 {
        if (argc)
@@ -1424,7 +1412,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
                OPT_SUBCOMMAND("terms", &fn, cmd_bisect__terms),
                OPT_SUBCOMMAND("start", &fn, cmd_bisect__start),
                OPT_SUBCOMMAND("next", &fn, cmd_bisect__next),
-               OPT_SUBCOMMAND("state", &fn, cmd_bisect__state),
                OPT_SUBCOMMAND("log", &fn, cmd_bisect__log),
                OPT_SUBCOMMAND("replay", &fn, cmd_bisect__replay),
                OPT_SUBCOMMAND("skip", &fn, cmd_bisect__skip),
@@ -1433,14 +1420,27 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
                OPT_SUBCOMMAND("run", &fn, cmd_bisect__run),
                OPT_END()
        };
-       argc = parse_options(argc, argv, prefix, options, git_bisect_usage, 0);
-
-       if (!fn)
-               usage_with_options(git_bisect_usage, options);
-       argc--;
-       argv++;
-
-       res = fn(argc, argv, prefix);
+       argc = parse_options(argc, argv, prefix, options, git_bisect_usage,
+                            PARSE_OPT_SUBCOMMAND_OPTIONAL);
+
+       if (!fn) {
+               struct bisect_terms terms = { 0 };
+
+               if (!argc)
+                       usage_msg_opt(_("need a command"), git_bisect_usage, options);
+
+               set_terms(&terms, "bad", "good");
+               get_terms(&terms);
+               if (check_and_set_terms(&terms, argv[0]))
+                       usage_msg_optf(_("unknown command: '%s'"), git_bisect_usage,
+                                      options, argv[0]);
+               res = bisect_state(&terms, argv, argc);
+               free_terms(&terms);
+       } else {
+               argc--;
+               argv++;
+               res = fn(argc, argv, prefix);
+       }
 
        /*
         * Handle early success
index dfce4b4f44e05d1074acc103e8b8c16f702a1411..9f6c8cc0934c9d2d202c7e0c6abbd9bea164c76d 100755 (executable)
@@ -57,8 +57,6 @@ case "$#" in
        case "$cmd" in
        help)
                git bisect -h ;;
-       bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD")
-               git bisect--helper state "$cmd" "$@" ;;
        log)
                git bisect--helper log || exit ;;
        *)