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 <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>
Pranit Bauva committed
Feb 3, 2021 at 22:54 UTC
e4c7b33747dccc6600bc528b51e91c11b474eb04
2 files changed
+45
-17
builtin/bisect--helper.c
+44
-1
@@ -30,6 +30,7 @@ static const char * const git_bisect_helper_usage[] = {
30
N_("git bisect--helper --bisect-state (bad|new) [<rev>]"),
31
N_("git bisect--helper --bisect-state (good|old) [<rev>...]"),
32
N_("git bisect--helper --bisect-replay <filename>"),
33
+ N_("git bisect--helper --bisect-skip [(<rev>|<range>)...]"),
34
NULL
35
};
36
@@ -992,6 +993,41 @@ static enum bisect_error bisect_replay(struct bisect_terms *terms, const char *f
993
return bisect_auto_next(terms, NULL);
994
}
995
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
+
1031
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1032
{
1033
enum {
@@ -1004,7 +1040,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1040
BISECT_NEXT,
1041
BISECT_STATE,
1042
BISECT_LOG,
1007
- BISECT_REPLAY
1043
+ BISECT_REPLAY,
1044
+ BISECT_SKIP
1045
} cmdmode = 0;
1046
int res = 0, nolog = 0;
1047
struct option options[] = {
@@ -1026,6 +1063,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1063
N_("list the bisection steps so far"), BISECT_LOG),
1064
OPT_CMDMODE(0, "bisect-replay", &cmdmode,
1065
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),
1068
OPT_BOOL(0, "no-log", &nolog,
1069
N_("no log for BISECT_WRITE")),
1070
OPT_END()
@@ -1088,6 +1127,10 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1127
set_terms(&terms, "bad", "good");
1128
res = bisect_replay(&terms, argv[0]);
1129
break;
1130
+ case BISECT_SKIP:
1131
+ set_terms(&terms, "bad", "good");
1132
+ res = bisect_skip(&terms, argv, argc);
1133
+ break;
1134
default:
1135
BUG("unknown subcommand %d", cmdmode);
1136
}
git-bisect.sh
+1
-16
@@ -39,21 +39,6 @@ _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
39
TERM_BAD=bad
40
TERM_GOOD=good
41
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
-
42
bisect_visualize() {
43
git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit
44
@@ -162,7 +147,7 @@ case "$#" in
147
bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD")
148
git bisect--helper --bisect-state "$cmd" "$@" ;;
149
skip)
165
- bisect_skip "$@" ;;
150
+ git bisect--helper --bisect-skip "$@" || exit;;
151
next)
152
# Not sure we want "next" at the UI level anymore.
153
git bisect--helper --bisect-next "$@" || exit ;;