Re: [PATCH] Fix git-bisect when show-branch is configured to run with pager
- From
Christian Couder <christian.couder@gmail.com>
- Date
- Jul 28, 2021, 06:37 UTC
- Message-ID
- <CAP8UFD26AXTYPvSzBD1x6hSvK5SNbM0F5BPX5bLEbxUZa2dAUg@mail.gmail.com>
- In-Reply-To
- <xmqq7dhbehwl.fsf@gitster.g>
On Tue, Jul 27, 2021 at 8:26 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 8 quoted lines
> > Junio C Hamano <gitster@pobox.com> writes: > > > Also, in the longer term, I suspect that we probably should stop > > calling show-branch from this codepath and here is why. > > I wonder if it is just a simple matter of a few lines of code, like > this?
Yeah, I also think it's a good idea.
Show 5 quoted lines
> ---- >8 ------- >8 ------- >8 ------- >8 ------- >8 ---- > Subject: [PATCH] bisect: do not run show-branch just to show the current commit > > In scripted versions of "git bisect", we used "git show-branch" to > describe single commit in the bisect log and also to the interactive
s/single/ a single/
> user after checking out the next version to be tested.
[...]
Show 39 quoted lines
> diff --git a/bisect.c b/bisect.c
> index af2863d044..2b8b6546e9 100644
> --- a/bisect.c
> +++ b/bisect.c
> @@ -23,7 +23,6 @@ static struct oid_array skipped_revs;
> static struct object_id *current_bad_oid;
>
> static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
> -static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
>
> static const char *term_bad;
> static const char *term_good;
> @@ -729,6 +728,9 @@ static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int
> {
> char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
> enum bisect_error res = BISECT_OK;
> + struct commit *commit;
> + struct pretty_print_context pp = {0};
> + struct strbuf commit_msg = STRBUF_INIT;
>
> oid_to_hex_r(bisect_rev_hex, bisect_rev);
> update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
> @@ -748,13 +750,11 @@ static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int
> return -abs(res);
> }
>
> - argv_show_branch[1] = bisect_rev_hex;
> - res = run_command_v_opt(argv_show_branch, RUN_GIT_CMD);
> - /*
> - * Errors in `run_command()` itself, signaled by res < 0,
> - * and errors in the child process, signaled by res > 0
> - * can both be treated as regular BISECT_FAILURE (-1).
> - */
> + commit = lookup_commit_reference(the_repository, bisect_rev);
> + format_commit_message(commit, "[%H] %s%n", &commit_msg, &pp);
> + fputs(commit_msg.buf, stdout);
> + strbuf_release(&commit_msg);
> +
> return -abs(res);Nice! Now, the above line can be simplified to:
return BISECT_OK;
And the declaration of the `res` variable can be moved into the else clause where it is used.
> }