Skip to content

Commit 09535f0

Browse files
pranitbauva1997gitster
authored andcommitted
bisect--helper: reimplement bisect_autostart shell function in C
Reimplement the `bisect_autostart()` shell function in C and add the C implementation from `bisect_next()` which was previously left uncovered. Add `--bisect-autostart` subcommand to be called from git-bisect.sh. Using `--bisect-autostart` subcommand is a temporary measure to port the shell function to C so as to use the existing test suite. As more functions are ported, this subcommand will be retired and bisect_autostart() will be called directly by `bisect_state()`. Change behavior of shell script that returned success when user aborted the bisection. 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 7b4de74 commit 09535f0

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

builtin/bisect--helper.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static const char * const git_bisect_helper_usage[] = {
2929
N_("git bisect--helper --bisect-terms [--term-good | --term-old | --term-bad | --term-new]"),
3030
N_("git bisect--helper --bisect-start [--term-{old,good}=<term> --term-{new,bad}=<term>]"
3131
" [--no-checkout] [--first-parent] [<bad> [<good>...]] [--] [<paths>...]"),
32+
N_("git bisect--helper --bisect-autostart"),
3233
NULL
3334
};
3435

@@ -653,6 +654,38 @@ static int bisect_start(struct bisect_terms *terms, const char **argv, int argc)
653654
return res;
654655
}
655656

657+
static inline int file_is_not_empty(const char *path)
658+
{
659+
return !is_empty_or_missing_file(path);
660+
}
661+
662+
static int bisect_autostart(struct bisect_terms *terms)
663+
{
664+
int res;
665+
const char *yesno;
666+
667+
if (file_is_not_empty(git_path_bisect_start()))
668+
return 0;
669+
670+
fprintf_ln(stderr, _("You need to start by \"git bisect "
671+
"start\"\n"));
672+
673+
if (!isatty(STDIN_FILENO))
674+
return -1;
675+
676+
/*
677+
* TRANSLATORS: Make sure to include [Y] and [n] in your
678+
* translation. The program will only accept English input
679+
* at this point.
680+
*/
681+
yesno = git_prompt(_("Do you want me to do it for you "
682+
"[Y/n]? "), PROMPT_ECHO);
683+
res = tolower(*yesno) == 'n' ?
684+
-1 : bisect_start(terms, empty_strvec, 0);
685+
686+
return res;
687+
}
688+
656689
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
657690
{
658691
enum {
@@ -665,7 +698,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
665698
CHECK_AND_SET_TERMS,
666699
BISECT_NEXT_CHECK,
667700
BISECT_TERMS,
668-
BISECT_START
701+
BISECT_START,
702+
BISECT_AUTOSTART,
669703
} cmdmode = 0;
670704
int res = 0, nolog = 0;
671705
struct option options[] = {
@@ -689,6 +723,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
689723
N_("print out the bisect terms"), BISECT_TERMS),
690724
OPT_CMDMODE(0, "bisect-start", &cmdmode,
691725
N_("start the bisect session"), BISECT_START),
726+
OPT_CMDMODE(0, "bisect-autostart", &cmdmode,
727+
N_("start the bisection if it has not yet been started"), BISECT_AUTOSTART),
692728
OPT_BOOL(0, "no-log", &nolog,
693729
N_("no log for BISECT_WRITE")),
694730
OPT_END()
@@ -748,6 +784,12 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
748784
set_terms(&terms, "bad", "good");
749785
res = bisect_start(&terms, argv, argc);
750786
break;
787+
case BISECT_AUTOSTART:
788+
if (argc)
789+
return error(_("--bisect-autostart does not accept arguments"));
790+
set_terms(&terms, "bad", "good");
791+
res = bisect_autostart(&terms);
792+
break;
751793
default:
752794
BUG("unknown subcommand %d", cmdmode);
753795
}

git-bisect.sh

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,6 @@ bisect_head()
4949
fi
5050
}
5151

52-
bisect_autostart() {
53-
test -s "$GIT_DIR/BISECT_START" || {
54-
gettextln "You need to start by \"git bisect start\"" >&2
55-
if test -t 0
56-
then
57-
# TRANSLATORS: Make sure to include [Y] and [n] in your
58-
# translation. The program will only accept English input
59-
# at this point.
60-
gettext "Do you want me to do it for you [Y/n]? " >&2
61-
read yesno
62-
case "$yesno" in
63-
[Nn]*)
64-
exit ;;
65-
esac
66-
bisect_start
67-
else
68-
exit 1
69-
fi
70-
}
71-
}
72-
7352
bisect_start() {
7453
git bisect--helper --bisect-start $@ || exit
7554

@@ -108,7 +87,7 @@ bisect_skip() {
10887
}
10988

11089
bisect_state() {
111-
bisect_autostart
90+
git bisect--helper --bisect-autostart || exit
11291
state=$1
11392
git bisect--helper --check-and-set-terms $state $TERM_GOOD $TERM_BAD || exit
11493
get_terms
@@ -149,7 +128,7 @@ bisect_auto_next() {
149128

150129
bisect_next() {
151130
case "$#" in 0) ;; *) usage ;; esac
152-
bisect_autostart
131+
git bisect--helper --bisect-autostart || exit
153132
git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit
154133

155134
# Perform all bisection computation, display and checkout

0 commit comments

Comments
 (0)