]> git.ipfire.org Git - thirdparty/git.git/commitdiff
bisect--helper: reimplement `bisect_skip` shell function in C
authorPranit Bauva <pranit.bauva@gmail.com>
Wed, 3 Feb 2021 21:54:37 +0000 (22:54 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Feb 2021 22:52:09 +0000 (14:52 -0800)
Reimplement the `bisect_skip()` shell function in C and also add
`bisect-skip` subcommand to `git bisect--helper` to call it from
git-bisect.sh

Using `--bisect-skip` subcommand is a temporary measure to port shell
function to C so as to use the existing test suite.

Mentored-by: Lars Schneider <larsxschneider@gmail.com>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
Signed-off-by: Tanushree Tumane <tanushreetumane@gmail.com>
Signed-off-by: Miriam Rubio <mirucam@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/bisect--helper.c
git-bisect.sh

index 31eba522ffeed7c2504b7afb0f70d6ea75524715..7ad9b4d55b4d10a90e0c765e63394dbac4688b6e 100644 (file)
@@ -30,6 +30,7 @@ static const char * const git_bisect_helper_usage[] = {
        N_("git bisect--helper --bisect-state (bad|new) [<rev>]"),
        N_("git bisect--helper --bisect-state (good|old) [<rev>...]"),
        N_("git bisect--helper --bisect-replay <filename>"),
+       N_("git bisect--helper --bisect-skip [(<rev>|<range>)...]"),
        NULL
 };
 
@@ -992,6 +993,41 @@ static enum bisect_error bisect_replay(struct bisect_terms *terms, const char *f
        return bisect_auto_next(terms, NULL);
 }
 
+static enum bisect_error bisect_skip(struct bisect_terms *terms, const char **argv, int argc)
+{
+       int i;
+       enum bisect_error res;
+       struct strvec argv_state = STRVEC_INIT;
+
+       strvec_push(&argv_state, "skip");
+
+       for (i = 0; i < argc; i++) {
+               const char *dotdot = strstr(argv[i], "..");
+
+               if (dotdot) {
+                       struct rev_info revs;
+                       struct commit *commit;
+
+                       init_revisions(&revs, NULL);
+                       setup_revisions(2, argv + i - 1, &revs, NULL);
+
+                       if (prepare_revision_walk(&revs))
+                               die(_("revision walk setup failed\n"));
+                       while ((commit = get_revision(&revs)) != NULL)
+                               strvec_push(&argv_state,
+                                               oid_to_hex(&commit->object.oid));
+
+                       reset_revision_walk();
+               } else {
+                       strvec_push(&argv_state, argv[i]);
+               }
+       }
+       res = bisect_state(terms, argv_state.v, argv_state.nr);
+
+       strvec_clear(&argv_state);
+       return res;
+}
+
 int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
 {
        enum {
@@ -1004,7 +1040,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
                BISECT_NEXT,
                BISECT_STATE,
                BISECT_LOG,
-               BISECT_REPLAY
+               BISECT_REPLAY,
+               BISECT_SKIP
        } cmdmode = 0;
        int res = 0, nolog = 0;
        struct option options[] = {
@@ -1026,6 +1063,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
                         N_("list the bisection steps so far"), BISECT_LOG),
                OPT_CMDMODE(0, "bisect-replay", &cmdmode,
                         N_("replay the bisection process from the given file"), BISECT_REPLAY),
+               OPT_CMDMODE(0, "bisect-skip", &cmdmode,
+                        N_("skip some commits for checkout"), BISECT_SKIP),
                OPT_BOOL(0, "no-log", &nolog,
                         N_("no log for BISECT_WRITE")),
                OPT_END()
@@ -1088,6 +1127,10 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
                set_terms(&terms, "bad", "good");
                res = bisect_replay(&terms, argv[0]);
                break;
+       case BISECT_SKIP:
+               set_terms(&terms, "bad", "good");
+               res = bisect_skip(&terms, argv, argc);
+               break;
        default:
                BUG("unknown subcommand %d", cmdmode);
        }
index e834154e2975d84dd6c9e8627f1535a99145f2cf..6a7afaea8da09fa3fb3670d1a688421fbf152747 100755 (executable)
@@ -39,21 +39,6 @@ _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
 TERM_BAD=bad
 TERM_GOOD=good
 
-bisect_skip() {
-       all=''
-       for arg in "$@"
-       do
-               case "$arg" in
-               *..*)
-                       revs=$(git rev-list "$arg") || die "$(eval_gettext "Bad rev input: \$arg")" ;;
-               *)
-                       revs=$(git rev-parse --sq-quote "$arg") ;;
-               esac
-               all="$all $revs"
-       done
-       eval git bisect--helper --bisect-state 'skip' $all
-}
-
 bisect_visualize() {
        git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit
 
@@ -162,7 +147,7 @@ case "$#" in
        bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD")
                git bisect--helper --bisect-state "$cmd" "$@" ;;
        skip)
-               bisect_skip "$@" ;;
+               git bisect--helper --bisect-skip "$@" || exit;;
        next)
                # Not sure we want "next" at the UI level anymore.
                git bisect--helper --bisect-next "$@" || exit ;;