Skip to content

Commit e4c7b33

Browse files
pranitbauva1997gitster
authored andcommitted
bisect--helper: reimplement bisect_skip shell function in C
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 <[email protected]> Mentored-by: Christian Couder <[email protected]> Mentored-by: Johannes Schindelin <[email protected]> Signed-off-by: Pranit Bauva <[email protected]> Signed-off-by: Tanushree Tumane <[email protected]> Signed-off-by: Miriam Rubio <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9feea34 commit e4c7b33

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

builtin/bisect--helper.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static const char * const git_bisect_helper_usage[] = {
3030
N_("git bisect--helper --bisect-state (bad|new) [<rev>]"),
3131
N_("git bisect--helper --bisect-state (good|old) [<rev>...]"),
3232
N_("git bisect--helper --bisect-replay <filename>"),
33+
N_("git bisect--helper --bisect-skip [(<rev>|<range>)...]"),
3334
NULL
3435
};
3536

@@ -992,6 +993,41 @@ static enum bisect_error bisect_replay(struct bisect_terms *terms, const char *f
992993
return bisect_auto_next(terms, NULL);
993994
}
994995

996+
static enum bisect_error bisect_skip(struct bisect_terms *terms, const char **argv, int argc)
997+
{
998+
int i;
999+
enum bisect_error res;
1000+
struct strvec argv_state = STRVEC_INIT;
1001+
1002+
strvec_push(&argv_state, "skip");
1003+
1004+
for (i = 0; i < argc; i++) {
1005+
const char *dotdot = strstr(argv[i], "..");
1006+
1007+
if (dotdot) {
1008+
struct rev_info revs;
1009+
struct commit *commit;
1010+
1011+
init_revisions(&revs, NULL);
1012+
setup_revisions(2, argv + i - 1, &revs, NULL);
1013+
1014+
if (prepare_revision_walk(&revs))
1015+
die(_("revision walk setup failed\n"));
1016+
while ((commit = get_revision(&revs)) != NULL)
1017+
strvec_push(&argv_state,
1018+
oid_to_hex(&commit->object.oid));
1019+
1020+
reset_revision_walk();
1021+
} else {
1022+
strvec_push(&argv_state, argv[i]);
1023+
}
1024+
}
1025+
res = bisect_state(terms, argv_state.v, argv_state.nr);
1026+
1027+
strvec_clear(&argv_state);
1028+
return res;
1029+
}
1030+
9951031
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
9961032
{
9971033
enum {
@@ -1004,7 +1040,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
10041040
BISECT_NEXT,
10051041
BISECT_STATE,
10061042
BISECT_LOG,
1007-
BISECT_REPLAY
1043+
BISECT_REPLAY,
1044+
BISECT_SKIP
10081045
} cmdmode = 0;
10091046
int res = 0, nolog = 0;
10101047
struct option options[] = {
@@ -1026,6 +1063,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
10261063
N_("list the bisection steps so far"), BISECT_LOG),
10271064
OPT_CMDMODE(0, "bisect-replay", &cmdmode,
10281065
N_("replay the bisection process from the given file"), BISECT_REPLAY),
1066+
OPT_CMDMODE(0, "bisect-skip", &cmdmode,
1067+
N_("skip some commits for checkout"), BISECT_SKIP),
10291068
OPT_BOOL(0, "no-log", &nolog,
10301069
N_("no log for BISECT_WRITE")),
10311070
OPT_END()
@@ -1088,6 +1127,10 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
10881127
set_terms(&terms, "bad", "good");
10891128
res = bisect_replay(&terms, argv[0]);
10901129
break;
1130+
case BISECT_SKIP:
1131+
set_terms(&terms, "bad", "good");
1132+
res = bisect_skip(&terms, argv, argc);
1133+
break;
10911134
default:
10921135
BUG("unknown subcommand %d", cmdmode);
10931136
}

git-bisect.sh

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,6 @@ _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
3939
TERM_BAD=bad
4040
TERM_GOOD=good
4141

42-
bisect_skip() {
43-
all=''
44-
for arg in "$@"
45-
do
46-
case "$arg" in
47-
*..*)
48-
revs=$(git rev-list "$arg") || die "$(eval_gettext "Bad rev input: \$arg")" ;;
49-
*)
50-
revs=$(git rev-parse --sq-quote "$arg") ;;
51-
esac
52-
all="$all $revs"
53-
done
54-
eval git bisect--helper --bisect-state 'skip' $all
55-
}
56-
5742
bisect_visualize() {
5843
git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit
5944

@@ -162,7 +147,7 @@ case "$#" in
162147
bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD")
163148
git bisect--helper --bisect-state "$cmd" "$@" ;;
164149
skip)
165-
bisect_skip "$@" ;;
150+
git bisect--helper --bisect-skip "$@" || exit;;
166151
next)
167152
# Not sure we want "next" at the UI level anymore.
168153
git bisect--helper --bisect-next "$@" || exit ;;

0 commit comments

Comments
 (0)