git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Fix git-bisect when show-branch is configured to run with pager

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 27, 2021, 18:22 UTC
Message-ID
<xmqq7dhbehwl.fsf@gitster.g>
In-Reply-To
<xmqq4kcgkjhk.fsf@gitster.g>
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?

---- >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 user after checking out the next version to be tested.

The former use of "git show-branch" was lost when the helper function that wrote bisect log entries was rewritten at 0f30233a (bisect--helper: `bisect_write` shell function in C, 2019-01-02) in C

But we've kept the latter ever since 0871984d (bisect: make "git bisect" use new "--next-all" bisect-helper function, 2009-05-09) started using the faithful C-rewrite introduced at ef24c7ca (bisect--helper: add "--next-exit" to output bisect results, 2009-04-19).

Showing "[<full hex>] <subject>" is simple enough with our helper pretty.c::format_commit_message() and spawning show-branch is an overkill. Let's lose one external process.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 bisect.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
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);
 }
 
-- 
2.32.0-555-g350b5add0b
Previous: Junio C HamanoNext: Christian Couder
Message 4 of 10 in “Fix git-bisect when show-branch is configured to run with pager”
  1. Fix git-bisect when show-branch is configured to run with pagerOded S via GitGitGadget, Jul 26, 2021
  2. Christian CouderJul 26, 2021
  3. Junio C HamanoJul 26, 2021
  4. Junio C HamanoJul 27, 2021
  5. Christian CouderJul 28, 2021
  6. Junio C HamanoJul 28, 2021
  7. Re* [PATCH] Fix git-bisect when show-branch is configured to run with pagerJunio C Hamano, Jul 28, 2021
  8. Christian CouderJul 29, 2021
  9. bisect: disable pager while invoking show-branchOded S via GitGitGadget, Jul 27, 2021
  10. Junio C HamanoJul 27, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.