{"thread":{"id":"61324","subject":"[PATCH v4] bisect: report the found commit with \"show\"","startedAt":"2024-04-15T20:42:13Z","lastAt":"2024-04-15T20:42:13Z","messageCount":1,"participants":["Peter Krefting"],"isPatch":true,"patchVersion":4,"patchTotal":null},"messages":[{"id":"492964","messageId":"234e8039-0000-d2c9-f3d7-9b5c3202f878@softwolves.pp.se","threadId":"61324","inReplyTo":null,"subject":"[PATCH v4] bisect: report the found commit with \"show\"","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2024-04-15T20:42:00Z","receivedAt":"2024-04-15T20:42:13Z","isPatch":true,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"When \"git bisect\" finds the first bad commit and shows it to the user,\nit calls \"git diff-tree\" to do so, whose output is meant to be stable\nand deliberately ignores end-user customizations.\n\nAs the output is supposed to be consumed by humans, replace this with\na call to \"git show\". This command honors configuration options (such\nas \"log.date\" and \"log.mailmap\") and other UI improvements (renames\nare detected).\n\nPass some hard-coded options to \"git show\" to make the output similar\nto the one we are replacing, such as showing a patch summary only.\n\nReported-by: Michael Osipov <michael.osipov@innomotics.com>\nSigned-off-By: Peter Krefting <peter@softwolves.pp.se>\nCc: Junio C Hamano <gitster@pobox.com>\nCc: Jeff King <peff@peff.net>\nCc: Christian Couder <christian.couder@gmail.com>\nCc: Eric Sunshine <sunshine@sunshineco.com>\n---\n  bisect.c | 40 +++++++++++++++++++++++++---------------\n  1 file changed, 25 insertions(+), 15 deletions(-)\n\nThis version code style issues in v3.\n\ndiff --git a/bisect.c b/bisect.c\nindex 8487f8cd1b..dd768ce3f0 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -959,23 +959,33 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r,\n  }\n\n  /*\n- * This does \"git diff-tree --pretty COMMIT\" without one fork+exec.\n+ * Display a commit summary to the user.\n   */\n-static void show_diff_tree(struct repository *r,\n-\t\t\t   const char *prefix,\n-\t\t\t   struct commit *commit)\n+static void show_commit(struct commit *commit)\n  {\n-\tconst char *argv[] = {\n-\t\t\"diff-tree\", \"--pretty\", \"--stat\", \"--summary\", \"--cc\", NULL\n-\t};\n-\tstruct rev_info opt;\n+\tstruct child_process show = CHILD_PROCESS_INIT;\n\n-\tgit_config(git_diff_ui_config, NULL);\n-\trepo_init_revisions(r, &opt, prefix);\n-\n-\tsetup_revisions(ARRAY_SIZE(argv) - 1, argv, &opt, NULL);\n-\tlog_tree_commit(&opt, commit);\n-\trelease_revisions(&opt);\n+\t/*\n+\t * Call git show with --no-pager, as it would otherwise\n+\t * paginate the \"git show\" output only, not the output\n+\t * from bisect_next_all(); this can be fixed by moving\n+\t * it into a --format parameter, but that would override\n+\t * the user's default options for \"git show\", which we\n+\t * are trying to honour.\n+\t */\n+\tstrvec_pushl(&show.args,\n+\t             \"--no-pager\",\n+\t             \"show\",\n+\t             \"--stat\",\n+\t             \"--summary\",\n+\t             \"--no-abbrev-commit\",\n+\t             \"--diff-merges=first-parent\",\n+\t             oid_to_hex(&commit->object.oid),\n+\t             NULL);\n+\tshow.git_cmd = 1;\n+\tif (run_command(&show))\n+\t\tdie(_(\"unable to start 'show' for object '%s'\"),\n+\t\t    oid_to_hex(&commit->object.oid));\n  }\n\n  /*\n@@ -1092,7 +1102,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)\n  \t\tprintf(\"%s is the first %s commit\\n\", oid_to_hex(bisect_rev),\n  \t\t\tterm_bad);\n\n-\t\tshow_diff_tree(r, prefix, revs.commits->item);\n+\t\tshow_commit(revs.commits->item);\n  \t\t/*\n  \t\t * This means the bisection process succeeded.\n  \t\t * Using BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND (-10)\n-- \n2.39.2\n\n"}]}