From ffcb4e94d309db2889dac1d3dcbd0f4b2a0f6390 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 27 Jul 2021 11:22:18 -0700 Subject: 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 a 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 "[] " 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 --- bisect.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'bisect.c') 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); } -- cgit v1.2.3 From 1fcc40cd1dbfbdf6879a7b60a3a0250e46dc5c60 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 28 Jul 2021 10:07:02 -0700 Subject: bisect: simplify return code from bisect_checkout() The function was designed to return only BISECT_OK (0) or BISECT_FAILED (-1) and no other values, but there were two issues: - The comment misspelled BISECT_FAILED as BISECT_FAILURE, even though the logic it described (i.e. any non-zero return should be reported as a single BISECT_FAILED) was correct. - It took the return value from run_command_v_opt(), and assumed it was either -1 or 1 upon error, which is not the case; it can relay errors from wait_or_whine(), which can report exit status of the child process. Translate any error return from run_command_v_opt() to BISECT_FAILED, and simplify the resulting code by losing the 'res' variable that is no longer needed. Signed-off-by: Junio C Hamano --- bisect.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'bisect.c') diff --git a/bisect.c b/bisect.c index 2b8b6546e9..888949fba6 100644 --- a/bisect.c +++ b/bisect.c @@ -727,7 +727,6 @@ static int is_expected_rev(const struct object_id *oid) static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int no_checkout) { 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; @@ -740,14 +739,13 @@ static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR); } else { - res = run_command_v_opt(argv_checkout, RUN_GIT_CMD); - if (res) + if (run_command_v_opt(argv_checkout, 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). + * can both be treated as regular BISECT_FAILED (-1). */ - return -abs(res); + return BISECT_FAILED; } commit = lookup_commit_reference(the_repository, bisect_rev); @@ -755,7 +753,7 @@ static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int fputs(commit_msg.buf, stdout); strbuf_release(&commit_msg); - return -abs(res); + return BISECT_OK; } static struct commit *get_commit_reference(struct repository *r, -- cgit v1.2.3