1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-04-19 17:43:53 +02:00

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>
This commit is contained in:
Pranit Bauva 2021-02-03 22:54:37 +01:00 committed by Junio C Hamano
parent 9feea34810
commit e4c7b33747
2 changed files with 45 additions and 17 deletions

View 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);
}

View File

@ -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 ;;