Skip to content

Commit 8198993

Browse files
nafmogitster
authored andcommitted
bisect: report the found commit with "show"
When "git bisect" finds the first bad commit and shows it to the user, it calls "git diff-tree" to do so, whose output is meant to be stable and deliberately ignores end-user customizations. As the output is supposed to be consumed by humans, replace this with a call to "git show". This command honors configuration options (such as "log.date" and "log.mailmap") and other UI improvements (renames are detected). Pass some hard-coded options to "git show" to make the output similar to the one we are replacing, such as showing a patch summary only. Reported-by: Michael Osipov <[email protected]> Signed-off-By: Peter Krefting <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f7582d commit 8198993

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

bisect.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -946,23 +946,32 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r,
946946
}
947947

948948
/*
949-
* This does "git diff-tree --pretty COMMIT" without one fork+exec.
949+
* Display a commit summary to the user.
950950
*/
951-
static void show_diff_tree(struct repository *r,
952-
const char *prefix,
953-
struct commit *commit)
951+
static void show_commit(struct commit *commit)
954952
{
955-
const char *argv[] = {
956-
"diff-tree", "--pretty", "--stat", "--summary", "--cc", NULL
957-
};
958-
struct rev_info opt;
959-
960-
git_config(git_diff_ui_config, NULL);
961-
repo_init_revisions(r, &opt, prefix);
953+
struct child_process show = CHILD_PROCESS_INIT;
962954

963-
setup_revisions(ARRAY_SIZE(argv) - 1, argv, &opt, NULL);
964-
log_tree_commit(&opt, commit);
965-
release_revisions(&opt);
955+
/*
956+
* Call git show with --no-pager, as it would otherwise
957+
* paginate the "git show" output only, not the output
958+
* from bisect_next_all(); this can be fixed by moving
959+
* it into a --format parameter, but that would override
960+
* the user's default options for "git show", which we
961+
* are trying to honour.
962+
*/
963+
strvec_pushl(&show.args,
964+
"--no-pager",
965+
"show",
966+
"--stat",
967+
"--summary",
968+
"--no-abbrev-commit",
969+
"--diff-merges=first-parent",
970+
oid_to_hex(&commit->object.oid), NULL);
971+
show.git_cmd = 1;
972+
if (run_command(&show))
973+
die(_("unable to start 'show' for object '%s'"),
974+
oid_to_hex(&commit->object.oid));
966975
}
967976

968977
/*
@@ -1079,7 +1088,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
10791088
printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
10801089
term_bad);
10811090

1082-
show_diff_tree(r, prefix, revs.commits->item);
1091+
show_commit(revs.commits->item);
10831092
/*
10841093
* This means the bisection process succeeded.
10851094
* Using BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND (-10)

0 commit comments

Comments
 (0)