Skip to content

Commit e22278c

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7a8e389 commit e22278c

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

bisect.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "quote.h"
88
#include "sha1-lookup.h"
99
#include "run-command.h"
10+
#include "log-tree.h"
1011
#include "bisect.h"
1112

1213
struct sha1_array {
@@ -27,7 +28,6 @@ struct argv_array {
2728
int argv_alloc;
2829
};
2930

30-
static const char *argv_diff_tree[] = {"diff-tree", "--pretty", NULL, NULL};
3131
static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
3232
static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
3333

@@ -815,6 +815,31 @@ static void check_good_are_ancestors_of_bad(const char *prefix)
815815
close(fd);
816816
}
817817

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+
818843
/*
819844
* We use the convention that exiting with an exit code 10 means that
820845
* the bisection process finished successfully.
@@ -860,8 +885,7 @@ int bisect_next_all(const char *prefix)
860885
if (!hashcmp(bisect_rev, current_bad_sha1)) {
861886
exit_if_skipped_commits(tried, current_bad_sha1);
862887
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);
865889
/* This means the bisection process succeeded. */
866890
exit(10);
867891
}

0 commit comments

Comments
 (0)