bisect: display first bad commit without forking a new process
Previously "git diff-tree --pretty COMMIT" was run using "run_command_v_opt" to display information about the first bad commit. The goal of this patch is to avoid a "fork" and an "exec" call when displaying that information. To do that, we manually setup revision information as "git diff-tree --pretty" would do it, and then use the "log_tree_commit" function. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
May 28, 2009 at 23:21 UTC
e22278c0a0784d4285f0e3173794caad4e542658
1 file changed
+27
-3
bisect.c
+27
-3
@@ -7,6 +7,7 @@
7
#include "quote.h"
8
#include "sha1-lookup.h"
9
#include "run-command.h"
10
+#include "log-tree.h"
11
#include "bisect.h"
12
13
struct sha1_array {
@@ -27,7 +28,6 @@ struct argv_array {
28
int argv_alloc;
29
};
30
30
-static const char *argv_diff_tree[] = {"diff-tree", "--pretty", NULL, NULL};
31
static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
32
static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
33
@@ -815,6 +815,31 @@ static void check_good_are_ancestors_of_bad(const char *prefix)
815
close(fd);
816
}
817
818
+/*
819
+ * This does "git diff-tree --pretty COMMIT" without one fork+exec.
820
+ */
821
+static void show_diff_tree(const char *prefix, struct commit *commit)
822
+{
823
+ struct rev_info opt;
824
+
825
+ /* diff-tree init */
826
+ init_revisions(&opt, prefix);
827
+ git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
828
+ opt.abbrev = 0;
829
+ opt.diff = 1;
830
+
831
+ /* This is what "--pretty" does */
832
+ opt.verbose_header = 1;
833
+ opt.use_terminator = 0;
834
+ opt.commit_format = CMIT_FMT_DEFAULT;
835
+
836
+ /* diff-tree init */
837
+ if (!opt.diffopt.output_format)
838
+ opt.diffopt.output_format = DIFF_FORMAT_RAW;
839
+
840
+ log_tree_commit(&opt, commit);
841
+}
842
+
843
/*
844
* We use the convention that exiting with an exit code 10 means that
845
* the bisection process finished successfully.
@@ -860,8 +885,7 @@ int bisect_next_all(const char *prefix)
885
if (!hashcmp(bisect_rev, current_bad_sha1)) {
886
exit_if_skipped_commits(tried, current_bad_sha1);
887
printf("%s is first bad commit\n", bisect_rev_hex);
863
- argv_diff_tree[2] = bisect_rev_hex;
864
- run_command_v_opt(argv_diff_tree, RUN_GIT_CMD);
888
+ show_diff_tree(prefix, revs.commits->item);
889
/* This means the bisection process succeeded. */
890
exit(10);
891
}