@matheusbsbs / matheus-bagliano / commits / 09535f056b
Fork 0

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 <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 Sep 24, 2020 at 14:33 UTC 09535f056b08445e28c4881064b8435fb434d760
2 files changed +45 -24
builtin/bisect--helper.c
+43 -1
@@ -29,6 +29,7 @@ static const char * const git_bisect_helper_usage[] = {
29 N_("git bisect--helper --bisect-terms [--term-good | --term-old | --term-bad | --term-new]"),
30 N_("git bisect--helper --bisect-start [--term-{old,good}=<term> --term-{new,bad}=<term>]"
31 " [--no-checkout] [--first-parent] [<bad> [<good>...]] [--] [<paths>...]"),
32 + N_("git bisect--helper --bisect-autostart"),
33 NULL
34 };
35
@@ -653,6 +654,38 @@ finish:
654 return res;
655 }
656
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 +
689 int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
690 {
691 enum {
@@ -665,7 +698,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
698 CHECK_AND_SET_TERMS,
699 BISECT_NEXT_CHECK,
700 BISECT_TERMS,
668 - BISECT_START
701 + BISECT_START,
702 + BISECT_AUTOSTART,
703 } cmdmode = 0;
704 int res = 0, nolog = 0;
705 struct option options[] = {
@@ -689,6 +723,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
723 N_("print out the bisect terms"), BISECT_TERMS),
724 OPT_CMDMODE(0, "bisect-start", &cmdmode,
725 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),
728 OPT_BOOL(0, "no-log", &nolog,
729 N_("no log for BISECT_WRITE")),
730 OPT_END()
@@ -748,6 +784,12 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
784 set_terms(&terms, "bad", "good");
785 res = bisect_start(&terms, argv, argc);
786 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;
793 default:
794 BUG("unknown subcommand %d", cmdmode);
795 }
git-bisect.sh
+2 -23
@@ -49,27 +49,6 @@ bisect_head()
49 fi
50 }
51
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 -
52 bisect_start() {
53 git bisect--helper --bisect-start $@ || exit
54
@@ -108,7 +87,7 @@ bisect_skip() {
87 }
88
89 bisect_state() {
111 - bisect_autostart
90 + git bisect--helper --bisect-autostart || exit
91 state=$1
92 git bisect--helper --check-and-set-terms $state $TERM_GOOD $TERM_BAD || exit
93 get_terms
@@ -149,7 +128,7 @@ bisect_auto_next() {
128
129 bisect_next() {
130 case "$#" in 0) ;; *) usage ;; esac
152 - bisect_autostart
131 + git bisect--helper --bisect-autostart || exit
132 git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit
133
134 # Perform all bisection computation, display and checkout