6 #include "list-objects.h"
8 #include "sha1-lookup.h"
9 #include "run-command.h"
14 unsigned char (*sha1
)[20];
20 static struct sha1_array good_revs
;
21 static struct sha1_array skipped_revs
;
23 static const unsigned char *current_bad_sha1
;
31 static const char *argv_checkout
[] = {"checkout", "-q", NULL
, "--", NULL
};
32 static const char *argv_show_branch
[] = {"show-branch", NULL
, NULL
};
34 /* bits #0-15 in revision.h */
36 #define COUNTED (1u<<16)
39 * This is a truly stupid algorithm, but it's only
40 * used for bisection, and we just don't care enough.
42 * We care just barely enough to avoid recursing for
45 static int count_distance(struct commit_list
*entry
)
50 struct commit
*commit
= entry
->item
;
51 struct commit_list
*p
;
53 if (commit
->object
.flags
& (UNINTERESTING
| COUNTED
))
55 if (!(commit
->object
.flags
& TREESAME
))
57 commit
->object
.flags
|= COUNTED
;
63 nr
+= count_distance(p
);
72 static void clear_distance(struct commit_list
*list
)
75 struct commit
*commit
= list
->item
;
76 commit
->object
.flags
&= ~COUNTED
;
81 #define DEBUG_BISECT 0
83 static inline int weight(struct commit_list
*elem
)
85 return *((int*)(elem
->item
->util
));
88 static inline void weight_set(struct commit_list
*elem
, int weight
)
90 *((int*)(elem
->item
->util
)) = weight
;
93 static int count_interesting_parents(struct commit
*commit
)
95 struct commit_list
*p
;
98 for (count
= 0, p
= commit
->parents
; p
; p
= p
->next
) {
99 if (p
->item
->object
.flags
& UNINTERESTING
)
106 static inline int halfway(struct commit_list
*p
, int nr
)
109 * Don't short-cut something we are not going to return!
111 if (p
->item
->object
.flags
& TREESAME
)
116 * 2 and 3 are halfway of 5.
117 * 3 is halfway of 6 but 2 and 4 are not.
119 switch (2 * weight(p
) - nr
) {
120 case -1: case 0: case 1:
128 #define show_list(a,b,c,d) do { ; } while (0)
130 static void show_list(const char *debug
, int counted
, int nr
,
131 struct commit_list
*list
)
133 struct commit_list
*p
;
135 fprintf(stderr
, "%s (%d/%d)\n", debug
, counted
, nr
);
137 for (p
= list
; p
; p
= p
->next
) {
138 struct commit_list
*pp
;
139 struct commit
*commit
= p
->item
;
140 unsigned flags
= commit
->object
.flags
;
141 enum object_type type
;
143 char *buf
= read_sha1_file(commit
->object
.sha1
, &type
, &size
);
146 fprintf(stderr
, "%c%c%c ",
147 (flags
& TREESAME
) ? ' ' : 'T',
148 (flags
& UNINTERESTING
) ? 'U' : ' ',
149 (flags
& COUNTED
) ? 'C' : ' ');
151 fprintf(stderr
, "%3d", weight(p
));
153 fprintf(stderr
, "---");
154 fprintf(stderr
, " %.*s", 8, sha1_to_hex(commit
->object
.sha1
));
155 for (pp
= commit
->parents
; pp
; pp
= pp
->next
)
156 fprintf(stderr
, " %.*s", 8,
157 sha1_to_hex(pp
->item
->object
.sha1
));
159 sp
= strstr(buf
, "\n\n");
162 for (ep
= sp
; *ep
&& *ep
!= '\n'; ep
++)
164 fprintf(stderr
, " %.*s", (int)(ep
- sp
), sp
);
166 fprintf(stderr
, "\n");
169 #endif /* DEBUG_BISECT */
171 static struct commit_list
*best_bisection(struct commit_list
*list
, int nr
)
173 struct commit_list
*p
, *best
;
174 int best_distance
= -1;
177 for (p
= list
; p
; p
= p
->next
) {
179 unsigned flags
= p
->item
->object
.flags
;
181 if (flags
& TREESAME
)
183 distance
= weight(p
);
184 if (nr
- distance
< distance
)
185 distance
= nr
- distance
;
186 if (distance
> best_distance
) {
188 best_distance
= distance
;
196 struct commit
*commit
;
200 static int compare_commit_dist(const void *a_
, const void *b_
)
202 struct commit_dist
*a
, *b
;
204 a
= (struct commit_dist
*)a_
;
205 b
= (struct commit_dist
*)b_
;
206 if (a
->distance
!= b
->distance
)
207 return b
->distance
- a
->distance
; /* desc sort */
208 return hashcmp(a
->commit
->object
.sha1
, b
->commit
->object
.sha1
);
211 static struct commit_list
*best_bisection_sorted(struct commit_list
*list
, int nr
)
213 struct commit_list
*p
;
214 struct commit_dist
*array
= xcalloc(nr
, sizeof(*array
));
217 for (p
= list
, cnt
= 0; p
; p
= p
->next
) {
219 unsigned flags
= p
->item
->object
.flags
;
221 if (flags
& TREESAME
)
223 distance
= weight(p
);
224 if (nr
- distance
< distance
)
225 distance
= nr
- distance
;
226 array
[cnt
].commit
= p
->item
;
227 array
[cnt
].distance
= distance
;
230 qsort(array
, cnt
, sizeof(*array
), compare_commit_dist
);
231 for (p
= list
, i
= 0; i
< cnt
; i
++) {
232 struct name_decoration
*r
= xmalloc(sizeof(*r
) + 100);
233 struct object
*obj
= &(array
[i
].commit
->object
);
235 sprintf(r
->name
, "dist=%d", array
[i
].distance
);
236 r
->next
= add_decoration(&name_decoration
, obj
, r
);
237 p
->item
= array
[i
].commit
;
247 * zero or positive weight is the number of interesting commits it can
248 * reach, including itself. Especially, weight = 0 means it does not
249 * reach any tree-changing commits (e.g. just above uninteresting one
250 * but traversal is with pathspec).
252 * weight = -1 means it has one parent and its distance is yet to
255 * weight = -2 means it has more than one parent and its distance is
256 * unknown. After running count_distance() first, they will get zero
257 * or positive distance.
259 static struct commit_list
*do_find_bisection(struct commit_list
*list
,
260 int nr
, int *weights
,
264 struct commit_list
*p
;
268 for (n
= 0, p
= list
; p
; p
= p
->next
) {
269 struct commit
*commit
= p
->item
;
270 unsigned flags
= commit
->object
.flags
;
272 p
->item
->util
= &weights
[n
++];
273 switch (count_interesting_parents(commit
)) {
275 if (!(flags
& TREESAME
)) {
278 show_list("bisection 2 count one",
282 * otherwise, it is known not to reach any
283 * tree-changing commit and gets weight 0.
295 show_list("bisection 2 initialize", counted
, nr
, list
);
298 * If you have only one parent in the resulting set
299 * then you can reach one commit more than that parent
300 * can reach. So we do not have to run the expensive
301 * count_distance() for single strand of pearls.
303 * However, if you have more than one parents, you cannot
304 * just add their distance and one for yourself, since
305 * they usually reach the same ancestor and you would
306 * end up counting them twice that way.
308 * So we will first count distance of merges the usual
309 * way, and then fill the blanks using cheaper algorithm.
311 for (p
= list
; p
; p
= p
->next
) {
312 if (p
->item
->object
.flags
& UNINTERESTING
)
316 weight_set(p
, count_distance(p
));
317 clear_distance(list
);
319 /* Does it happen to be at exactly half-way? */
320 if (!find_all
&& halfway(p
, nr
))
325 show_list("bisection 2 count_distance", counted
, nr
, list
);
327 while (counted
< nr
) {
328 for (p
= list
; p
; p
= p
->next
) {
329 struct commit_list
*q
;
330 unsigned flags
= p
->item
->object
.flags
;
334 for (q
= p
->item
->parents
; q
; q
= q
->next
) {
335 if (q
->item
->object
.flags
& UNINTERESTING
)
344 * weight for p is unknown but q is known.
345 * add one for p itself if p is to be counted,
346 * otherwise inherit it from q directly.
348 if (!(flags
& TREESAME
)) {
349 weight_set(p
, weight(q
)+1);
351 show_list("bisection 2 count one",
355 weight_set(p
, weight(q
));
357 /* Does it happen to be at exactly half-way? */
358 if (!find_all
&& halfway(p
, nr
))
363 show_list("bisection 2 counted all", counted
, nr
, list
);
366 return best_bisection(list
, nr
);
368 return best_bisection_sorted(list
, nr
);
371 struct commit_list
*find_bisection(struct commit_list
*list
,
372 int *reaches
, int *all
,
376 struct commit_list
*p
, *best
, *next
, *last
;
379 show_list("bisection 2 entry", 0, 0, list
);
382 * Count the number of total and tree-changing items on the
383 * list, while reversing the list.
385 for (nr
= on_list
= 0, last
= NULL
, p
= list
;
388 unsigned flags
= p
->item
->object
.flags
;
391 if (flags
& UNINTERESTING
)
395 if (!(flags
& TREESAME
))
400 show_list("bisection 2 sorted", 0, nr
, list
);
403 weights
= xcalloc(on_list
, sizeof(*weights
));
405 /* Do the real work of finding bisection commit. */
406 best
= do_find_bisection(list
, nr
, weights
, find_all
);
410 *reaches
= weight(best
);
416 static void argv_array_push(struct argv_array
*array
, const char *string
)
418 ALLOC_GROW(array
->argv
, array
->argv_nr
+ 1, array
->argv_alloc
);
419 array
->argv
[array
->argv_nr
++] = string
;
422 static void argv_array_push_sha1(struct argv_array
*array
,
423 const unsigned char *sha1
,
426 struct strbuf buf
= STRBUF_INIT
;
427 strbuf_addf(&buf
, format
, sha1_to_hex(sha1
));
428 argv_array_push(array
, strbuf_detach(&buf
, NULL
));
431 static void sha1_array_push(struct sha1_array
*array
,
432 const unsigned char *sha1
)
434 ALLOC_GROW(array
->sha1
, array
->sha1_nr
+ 1, array
->sha1_alloc
);
435 hashcpy(array
->sha1
[array
->sha1_nr
++], sha1
);
438 static int register_ref(const char *refname
, const unsigned char *sha1
,
439 int flags
, void *cb_data
)
441 if (!strcmp(refname
, "bad")) {
442 current_bad_sha1
= sha1
;
443 } else if (!prefixcmp(refname
, "good-")) {
444 sha1_array_push(&good_revs
, sha1
);
445 } else if (!prefixcmp(refname
, "skip-")) {
446 sha1_array_push(&skipped_revs
, sha1
);
452 static int read_bisect_refs(void)
454 return for_each_ref_in("refs/bisect/", register_ref
, NULL
);
457 static void read_bisect_paths(struct argv_array
*array
)
459 struct strbuf str
= STRBUF_INIT
;
460 const char *filename
= git_path("BISECT_NAMES");
461 FILE *fp
= fopen(filename
, "r");
464 die_errno("Could not open file '%s'", filename
);
466 while (strbuf_getline(&str
, fp
, '\n') != EOF
) {
471 quoted
= strbuf_detach(&str
, NULL
);
472 res
= sq_dequote_to_argv(quoted
, &array
->argv
,
473 &array
->argv_nr
, &array
->argv_alloc
);
475 die("Badly quoted content in file '%s': %s",
479 strbuf_release(&str
);
483 static int array_cmp(const void *a
, const void *b
)
485 return hashcmp(a
, b
);
488 static void sort_sha1_array(struct sha1_array
*array
)
490 qsort(array
->sha1
, array
->sha1_nr
, sizeof(*array
->sha1
), array_cmp
);
495 static const unsigned char *sha1_access(size_t index
, void *table
)
497 unsigned char (*array
)[20] = table
;
501 static int lookup_sha1_array(struct sha1_array
*array
,
502 const unsigned char *sha1
)
505 sort_sha1_array(array
);
507 return sha1_pos(sha1
, array
->sha1
, array
->sha1_nr
, sha1_access
);
510 static char *join_sha1_array_hex(struct sha1_array
*array
, char delim
)
512 struct strbuf joined_hexs
= STRBUF_INIT
;
515 for (i
= 0; i
< array
->sha1_nr
; i
++) {
516 strbuf_addstr(&joined_hexs
, sha1_to_hex(array
->sha1
[i
]));
517 if (i
+ 1 < array
->sha1_nr
)
518 strbuf_addch(&joined_hexs
, delim
);
521 return strbuf_detach(&joined_hexs
, NULL
);
525 * In this function, passing a not NULL skipped_first is very special.
526 * It means that we want to know if the first commit in the list is
527 * skipped because we will want to test a commit away from it if it is
529 * So if the first commit is skipped, we cannot take the shortcut to
530 * just "return list" when we find the first non skipped commit, we
531 * have to return a fully filtered list.
533 * We use (*skipped_first == -1) to mean "it has been found that the
534 * first commit is not skipped". In this case *skipped_first is set back
535 * to 0 just before the function returns.
537 struct commit_list
*filter_skipped(struct commit_list
*list
,
538 struct commit_list
**tried
,
543 struct commit_list
*filtered
= NULL
, **f
= &filtered
;
552 if (!skipped_revs
.sha1_nr
)
556 struct commit_list
*next
= list
->next
;
558 if (0 <= lookup_sha1_array(&skipped_revs
,
559 list
->item
->object
.sha1
)) {
560 if (skipped_first
&& !*skipped_first
)
562 /* Move current to tried list */
567 if (!skipped_first
|| !*skipped_first
)
569 } else if (skipped_first
&& !*skipped_first
) {
570 /* This means we know it's not skipped */
573 /* Move current to filtered list */
582 if (skipped_first
&& *skipped_first
== -1)
588 #define PRN_MODULO 32768
591 * This is a pseudo random number generator based on "man 3 rand".
592 * It is not used properly because the seed is the argument and it
593 * is increased by one between each call, but that should not matter
594 * for this application.
596 int get_prn(int count
) {
597 count
= count
* 1103515245 + 12345;
598 return ((unsigned)(count
/65536) % PRN_MODULO
);
602 * Custom integer square root from
603 * http://en.wikipedia.org/wiki/Integer_square_root
605 static int sqrti(int val
)
613 float y
= (x
+ (float)val
/ x
) / 2;
614 d
= (y
> x
) ? y
- x
: x
- y
;
621 static struct commit_list
*skip_away(struct commit_list
*list
, int count
)
623 struct commit_list
*cur
, *previous
;
626 prn
= get_prn(count
);
627 index
= (count
* prn
/ PRN_MODULO
) * sqrti(prn
) / sqrti(PRN_MODULO
);
632 for (i
= 0; cur
; cur
= cur
->next
, i
++) {
634 if (hashcmp(cur
->item
->object
.sha1
, current_bad_sha1
))
646 static struct commit_list
*managed_skipped(struct commit_list
*list
,
647 struct commit_list
**tried
)
649 int count
, skipped_first
;
653 if (!skipped_revs
.sha1_nr
)
656 list
= filter_skipped(list
, tried
, 0, &count
, &skipped_first
);
661 return skip_away(list
, count
);
664 static void bisect_rev_setup(struct rev_info
*revs
, const char *prefix
,
665 const char *bad_format
, const char *good_format
,
668 struct argv_array rev_argv
= { NULL
, 0, 0 };
671 init_revisions(revs
, prefix
);
673 revs
->commit_format
= CMIT_FMT_UNSPECIFIED
;
675 /* rev_argv.argv[0] will be ignored by setup_revisions */
676 argv_array_push(&rev_argv
, xstrdup("bisect_rev_setup"));
677 argv_array_push_sha1(&rev_argv
, current_bad_sha1
, bad_format
);
678 for (i
= 0; i
< good_revs
.sha1_nr
; i
++)
679 argv_array_push_sha1(&rev_argv
, good_revs
.sha1
[i
],
681 argv_array_push(&rev_argv
, xstrdup("--"));
683 read_bisect_paths(&rev_argv
);
684 argv_array_push(&rev_argv
, NULL
);
686 setup_revisions(rev_argv
.argv_nr
, rev_argv
.argv
, revs
, NULL
);
689 static void bisect_common(struct rev_info
*revs
)
691 if (prepare_revision_walk(revs
))
692 die("revision walk setup failed");
693 if (revs
->tree_objects
)
694 mark_edges_uninteresting(revs
->commits
, revs
, NULL
);
697 static void exit_if_skipped_commits(struct commit_list
*tried
,
698 const unsigned char *bad
)
703 printf("There are only 'skip'ped commits left to test.\n"
704 "The first bad commit could be any of:\n");
705 print_commit_list(tried
, "%s\n", "%s\n");
707 printf("%s\n", sha1_to_hex(bad
));
708 printf("We cannot bisect more!\n");
712 static int is_expected_rev(const unsigned char *sha1
)
714 const char *filename
= git_path("BISECT_EXPECTED_REV");
716 struct strbuf str
= STRBUF_INIT
;
720 if (stat(filename
, &st
) || !S_ISREG(st
.st_mode
))
723 fp
= fopen(filename
, "r");
727 if (strbuf_getline(&str
, fp
, '\n') != EOF
)
728 res
= !strcmp(str
.buf
, sha1_to_hex(sha1
));
730 strbuf_release(&str
);
736 static void mark_expected_rev(char *bisect_rev_hex
)
738 int len
= strlen(bisect_rev_hex
);
739 const char *filename
= git_path("BISECT_EXPECTED_REV");
740 int fd
= open(filename
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600);
743 die_errno("could not create file '%s'", filename
);
745 bisect_rev_hex
[len
] = '\n';
746 write_or_die(fd
, bisect_rev_hex
, len
+ 1);
747 bisect_rev_hex
[len
] = '\0';
750 die("closing file %s: %s", filename
, strerror(errno
));
753 static int bisect_checkout(char *bisect_rev_hex
)
757 mark_expected_rev(bisect_rev_hex
);
759 argv_checkout
[2] = bisect_rev_hex
;
760 res
= run_command_v_opt(argv_checkout
, RUN_GIT_CMD
);
764 argv_show_branch
[1] = bisect_rev_hex
;
765 return run_command_v_opt(argv_show_branch
, RUN_GIT_CMD
);
768 static struct commit
*get_commit_reference(const unsigned char *sha1
)
770 struct commit
*r
= lookup_commit_reference(sha1
);
772 die("Not a valid commit name %s", sha1_to_hex(sha1
));
776 static struct commit
**get_bad_and_good_commits(int *rev_nr
)
778 int len
= 1 + good_revs
.sha1_nr
;
779 struct commit
**rev
= xmalloc(len
* sizeof(*rev
));
782 rev
[n
++] = get_commit_reference(current_bad_sha1
);
783 for (i
= 0; i
< good_revs
.sha1_nr
; i
++)
784 rev
[n
++] = get_commit_reference(good_revs
.sha1
[i
]);
790 static void handle_bad_merge_base(void)
792 if (is_expected_rev(current_bad_sha1
)) {
793 char *bad_hex
= sha1_to_hex(current_bad_sha1
);
794 char *good_hex
= join_sha1_array_hex(&good_revs
, ' ');
796 fprintf(stderr
, "The merge base %s is bad.\n"
797 "This means the bug has been fixed "
798 "between %s and [%s].\n",
799 bad_hex
, bad_hex
, good_hex
);
804 fprintf(stderr
, "Some good revs are not ancestor of the bad rev.\n"
805 "git bisect cannot work properly in this case.\n"
806 "Maybe you mistake good and bad revs?\n");
810 static void handle_skipped_merge_base(const unsigned char *mb
)
812 char *mb_hex
= sha1_to_hex(mb
);
813 char *bad_hex
= sha1_to_hex(current_bad_sha1
);
814 char *good_hex
= join_sha1_array_hex(&good_revs
, ' ');
816 fprintf(stderr
, "Warning: the merge base between %s and [%s] "
818 "So we cannot be sure the first bad commit is "
819 "between %s and %s.\n"
820 "We continue anyway.\n",
821 bad_hex
, good_hex
, mb_hex
, bad_hex
);
826 * "check_merge_bases" checks that merge bases are not "bad".
828 * - If one is "bad", it means the user assumed something wrong
829 * and we must exit with a non 0 error code.
830 * - If one is "good", that's good, we have nothing to do.
831 * - If one is "skipped", we can't know but we should warn.
832 * - If we don't know, we should check it out and ask the user to test.
834 static void check_merge_bases(void)
836 struct commit_list
*result
;
838 struct commit
**rev
= get_bad_and_good_commits(&rev_nr
);
840 result
= get_merge_bases_many(rev
[0], rev_nr
- 1, rev
+ 1, 0);
842 for (; result
; result
= result
->next
) {
843 const unsigned char *mb
= result
->item
->object
.sha1
;
844 if (!hashcmp(mb
, current_bad_sha1
)) {
845 handle_bad_merge_base();
846 } else if (0 <= lookup_sha1_array(&good_revs
, mb
)) {
848 } else if (0 <= lookup_sha1_array(&skipped_revs
, mb
)) {
849 handle_skipped_merge_base(mb
);
851 printf("Bisecting: a merge base must be tested\n");
852 exit(bisect_checkout(sha1_to_hex(mb
)));
857 free_commit_list(result
);
860 static int check_ancestors(const char *prefix
)
862 struct rev_info revs
;
863 struct object_array pending_copy
;
866 bisect_rev_setup(&revs
, prefix
, "^%s", "%s", 0);
868 /* Save pending objects, so they can be cleaned up later. */
869 memset(&pending_copy
, 0, sizeof(pending_copy
));
870 for (i
= 0; i
< revs
.pending
.nr
; i
++)
871 add_object_array(revs
.pending
.objects
[i
].item
,
872 revs
.pending
.objects
[i
].name
,
875 bisect_common(&revs
);
876 res
= (revs
.commits
!= NULL
);
878 /* Clean up objects used, as they will be reused. */
879 for (i
= 0; i
< pending_copy
.nr
; i
++) {
880 struct object
*o
= pending_copy
.objects
[i
].item
;
881 clear_commit_marks((struct commit
*)o
, ALL_REV_FLAGS
);
888 * "check_good_are_ancestors_of_bad" checks that all "good" revs are
889 * ancestor of the "bad" rev.
891 * If that's not the case, we need to check the merge bases.
892 * If a merge base must be tested by the user, its source code will be
893 * checked out to be tested by the user and we will exit.
895 static void check_good_are_ancestors_of_bad(const char *prefix
)
897 const char *filename
= git_path("BISECT_ANCESTORS_OK");
901 if (!current_bad_sha1
)
902 die("a bad revision is needed");
904 /* Check if file BISECT_ANCESTORS_OK exists. */
905 if (!stat(filename
, &st
) && S_ISREG(st
.st_mode
))
908 /* Bisecting with no good rev is ok. */
909 if (good_revs
.sha1_nr
== 0)
912 /* Check if all good revs are ancestor of the bad rev. */
913 if (check_ancestors(prefix
))
916 /* Create file BISECT_ANCESTORS_OK. */
917 fd
= open(filename
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600);
919 warning("could not create file '%s': %s",
920 filename
, strerror(errno
));
926 * This does "git diff-tree --pretty COMMIT" without one fork+exec.
928 static void show_diff_tree(const char *prefix
, struct commit
*commit
)
933 init_revisions(&opt
, prefix
);
934 git_config(git_diff_basic_config
, NULL
); /* no "diff" UI options */
938 /* This is what "--pretty" does */
939 opt
.verbose_header
= 1;
940 opt
.use_terminator
= 0;
941 opt
.commit_format
= CMIT_FMT_DEFAULT
;
944 if (!opt
.diffopt
.output_format
)
945 opt
.diffopt
.output_format
= DIFF_FORMAT_RAW
;
947 log_tree_commit(&opt
, commit
);
951 * We use the convention that exiting with an exit code 10 means that
952 * the bisection process finished successfully.
953 * In this case the calling shell script should exit 0.
955 int bisect_next_all(const char *prefix
)
957 struct rev_info revs
;
958 struct commit_list
*tried
;
959 int reaches
= 0, all
= 0, nr
;
960 const unsigned char *bisect_rev
;
961 char bisect_rev_hex
[41];
963 if (read_bisect_refs())
964 die("reading bisect refs failed");
966 check_good_are_ancestors_of_bad(prefix
);
968 bisect_rev_setup(&revs
, prefix
, "%s", "^%s", 1);
971 bisect_common(&revs
);
973 revs
.commits
= find_bisection(revs
.commits
, &reaches
, &all
,
974 !!skipped_revs
.sha1_nr
);
975 revs
.commits
= managed_skipped(revs
.commits
, &tried
);
979 * We should exit here only if the "bad"
980 * commit is also a "skip" commit.
982 exit_if_skipped_commits(tried
, NULL
);
984 printf("%s was both good and bad\n",
985 sha1_to_hex(current_bad_sha1
));
989 bisect_rev
= revs
.commits
->item
->object
.sha1
;
990 memcpy(bisect_rev_hex
, sha1_to_hex(bisect_rev
), 41);
992 if (!hashcmp(bisect_rev
, current_bad_sha1
)) {
993 exit_if_skipped_commits(tried
, current_bad_sha1
);
994 printf("%s is first bad commit\n", bisect_rev_hex
);
995 show_diff_tree(prefix
, revs
.commits
->item
);
996 /* This means the bisection process succeeded. */
1000 nr
= all
- reaches
- 1;
1001 printf("Bisecting: %d revisions left to test after this "
1002 "(roughly %d steps)\n", nr
, estimate_bisect_steps(all
));
1004 return bisect_checkout(bisect_rev_hex
);