@matheusbsbs / matheus-bagliano / commits / be5fe2000d
Fork 0

cmd_bisect__helper: defer parsing no-checkout flag

cmd_bisect__helper() is intended as a temporary shim layer serving as an interface for git-bisect.sh. This function and git-bisect.sh should eventually be replaced by a C implementation, cmd_bisect(), serving as an entrypoint for all "git bisect ..." shell commands: cmd_bisect() will only parse the first token following "git bisect", and dispatch the remaining args to the appropriate function ["bisect_start()", "bisect_next()", etc.]. Thus, cmd_bisect__helper() should not be responsible for parsing flags like --no-checkout. Instead, let the --no-checkout flag remain in the argv array, so it may be evaluated alongside the other options already parsed by bisect_start(). Signed-off-by: Aaron Lipman <alipman88@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Aaron Lipman committed Aug 7, 2020 at 17:58 UTC be5fe2000df5c1110d8086e4704e1a90a64f7387
4 files changed +10 -13
bisect.c
+2 -1
@@ -989,7 +989,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
989 * If no_checkout is non-zero, the bisection process does not
990 * checkout the trial commit but instead simply updates BISECT_HEAD.
991 */
992 -enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int no_checkout)
992 +enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
993 {
994 struct rev_info revs;
995 struct commit_list *tried;
@@ -997,6 +997,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int
997 enum bisect_error res = BISECT_OK;
998 struct object_id *bisect_rev;
999 char *steps_msg;
1000 + int no_checkout = ref_exists("BISECT_HEAD");
1001 int first_parent_only = 0; /* TODO: pass --first-parent flag from git bisect start */
1002
1003 read_bisect_terms(&term_bad, &term_good);
bisect.h
+1 -3
@@ -58,9 +58,7 @@ enum bisect_error {
58 BISECT_INTERNAL_SUCCESS_MERGE_BASE = -11
59 };
60
61 -enum bisect_error bisect_next_all(struct repository *r,
62 - const char *prefix,
63 - int no_checkout);
61 +enum bisect_error bisect_next_all(struct repository *r, const char *prefix);
62
63 int estimate_bisect_steps(int all);
64
builtin/bisect--helper.c
+6 -8
@@ -19,7 +19,7 @@ static GIT_PATH_FUNC(git_path_head_name, "head-name")
19 static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
20
21 static const char * const git_bisect_helper_usage[] = {
22 - N_("git bisect--helper --next-all [--no-checkout]"),
22 + N_("git bisect--helper --next-all"),
23 N_("git bisect--helper --write-terms <bad_term> <good_term>"),
24 N_("git bisect--helper --bisect-clean-state"),
25 N_("git bisect--helper --bisect-reset [<commit>]"),
@@ -421,9 +421,9 @@ finish:
421 return res;
422 }
423
424 -static int bisect_start(struct bisect_terms *terms, int no_checkout,
425 - const char **argv, int argc)
424 +static int bisect_start(struct bisect_terms *terms, const char **argv, int argc)
425 {
426 + int no_checkout = 0;
427 int i, has_double_dash = 0, must_write_terms = 0, bad_seen = 0;
428 int flags, pathspec_pos, res = 0;
429 struct string_list revs = STRING_LIST_INIT_DUP;
@@ -632,7 +632,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
632 BISECT_TERMS,
633 BISECT_START
634 } cmdmode = 0;
635 - int no_checkout = 0, res = 0, nolog = 0;
635 + int res = 0, nolog = 0;
636 struct option options[] = {
637 OPT_CMDMODE(0, "next-all", &cmdmode,
638 N_("perform 'git bisect next'"), NEXT_ALL),
@@ -654,8 +654,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
654 N_("print out the bisect terms"), BISECT_TERMS),
655 OPT_CMDMODE(0, "bisect-start", &cmdmode,
656 N_("start the bisect session"), BISECT_START),
657 - OPT_BOOL(0, "no-checkout", &no_checkout,
658 - N_("update BISECT_HEAD instead of checking out the current commit")),
657 OPT_BOOL(0, "no-log", &nolog,
658 N_("no log for BISECT_WRITE")),
659 OPT_END()
@@ -671,7 +669,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
669
670 switch (cmdmode) {
671 case NEXT_ALL:
674 - res = bisect_next_all(the_repository, prefix, no_checkout);
672 + res = bisect_next_all(the_repository, prefix);
673 break;
674 case WRITE_TERMS:
675 if (argc != 2)
@@ -713,7 +711,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
711 break;
712 case BISECT_START:
713 set_terms(&terms, "bad", "good");
716 - res = bisect_start(&terms, no_checkout, argv, argc);
714 + res = bisect_start(&terms, argv, argc);
715 break;
716 default:
717 return error("BUG: unknown subcommand '%d'", cmdmode);
git-bisect.sh
+1 -1
@@ -153,7 +153,7 @@ bisect_next() {
153 git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit
154
155 # Perform all bisection computation, display and checkout
156 - git bisect--helper --next-all $(test -f "$GIT_DIR/BISECT_HEAD" && echo --no-checkout)
156 + git bisect--helper --next-all
157 res=$?
158
159 # Check if we should exit because bisection is finished