{"thread":{"id":"19562","subject":"[PATCH] bisect: display first bad commit without forking a new process","startedAt":"2009-05-28T21:21:16Z","lastAt":"2009-05-28T21:21:16Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"114967","messageId":"20090528212117.3989.88194.chriscool@tuxfamily.org","threadId":"19562","inReplyTo":null,"subject":"[PATCH] bisect: display first bad commit without forking a new process","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-05-28T21:21:16Z","receivedAt":"2009-05-28T21:21:16Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Previously \"git diff-tree --pretty COMMIT\" was run using\n\"run_command_v_opt\" to display information about the first bad\ncommit.\n\nThe goal of this patch is to avoid a \"fork\" and an \"exec\" call\nwhen displaying that information.\n\nTo do that, we manually setup revision information as\n\"git diff-tree --pretty\" would do it, and then use the\n\"log_tree_commit\" function.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n bisect.c |   30 +++++++++++++++++++++++++++---\n 1 files changed, 27 insertions(+), 3 deletions(-)\n\n\tThe only change is that \"struct rev_info opt\" is not\n\tstatic anymore. \n\ndiff --git a/bisect.c b/bisect.c\nindex c43c120..edd3cfb 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -7,6 +7,7 @@\n #include \"quote.h\"\n #include \"sha1-lookup.h\"\n #include \"run-command.h\"\n+#include \"log-tree.h\"\n #include \"bisect.h\"\n \n struct sha1_array {\n@@ -27,7 +28,6 @@ struct argv_array {\n \tint argv_alloc;\n };\n \n-static const char *argv_diff_tree[] = {\"diff-tree\", \"--pretty\", NULL, NULL};\n static const char *argv_checkout[] = {\"checkout\", \"-q\", NULL, \"--\", NULL};\n static const char *argv_show_branch[] = {\"show-branch\", NULL, NULL};\n \n@@ -816,6 +816,31 @@ static void check_good_are_ancestors_of_bad(const char *prefix)\n }\n \n /*\n+ * This does \"git diff-tree --pretty COMMIT\" without one fork+exec.\n+ */\n+static void show_diff_tree(const char *prefix, struct commit *commit)\n+{\n+\tstruct rev_info opt;\n+\n+\t/* diff-tree init */\n+\tinit_revisions(&opt, prefix);\n+\tgit_config(git_diff_basic_config, NULL); /* no \"diff\" UI options */\n+\topt.abbrev = 0;\n+\topt.diff = 1;\n+\n+\t/* This is what \"--pretty\" does */\n+\topt.verbose_header = 1;\n+\topt.use_terminator = 0;\n+\topt.commit_format = CMIT_FMT_DEFAULT;\n+\n+\t/* diff-tree init */\n+\tif (!opt.diffopt.output_format)\n+\t\topt.diffopt.output_format = DIFF_FORMAT_RAW;\n+\n+\tlog_tree_commit(&opt, commit);\n+}\n+\n+/*\n  * We use the convention that exiting with an exit code 10 means that\n  * the bisection process finished successfully.\n  * In this case the calling shell script should exit 0.\n@@ -860,8 +885,7 @@ int bisect_next_all(const char *prefix)\n \tif (!hashcmp(bisect_rev, current_bad_sha1)) {\n \t\texit_if_skipped_commits(tried, current_bad_sha1);\n \t\tprintf(\"%s is first bad commit\\n\", bisect_rev_hex);\n-\t\targv_diff_tree[2] = bisect_rev_hex;\n-\t\trun_command_v_opt(argv_diff_tree, RUN_GIT_CMD);\n+\t\tshow_diff_tree(prefix, revs.commits->item);\n \t\t/* This means the bisection process succeeded. */\n \t\texit(10);\n \t}\n-- \n1.6.3.GIT\n"}]}