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 <michael.osipov@innomotics.com> Signed-off-By: Peter Krefting <peter@softwolves.pp.se> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Peter Krefting committed Apr 13, 2024 at 21:14 UTC 8198993c817b6c3b42f91c7345469c113c6eeabc
1 file changed +24 -15
bisect.c
+24 -15
@@ -946,23 +946,32 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r,
946 }
947
948 /*
949 - * This does "git diff-tree --pretty COMMIT" without one fork+exec.
949 + * Display a commit summary to the user.
950 */
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)
952 {
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;
954
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));
975 }
976
977 /*
@@ -1079,7 +1088,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
1088 printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
1089 term_bad);
1090
1082 - show_diff_tree(r, prefix, revs.commits->item);
1091 + show_commit(revs.commits->item);
1092 /*
1093 * This means the bisection process succeeded.
1094 * Using BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND (-10)