811
* "check_merge_bases" checks that merge bases are not "bad" (or "new").
812
*
813
* - If one is "bad" (or "new"), it means the user assumed something wrong
814
- * and we must exit with a non 0 error code.
814
+ * and we must return error with a non 0 error code.
815
* - If one is "good" (or "old"), that's good, we have nothing to do.
816
* - If one is "skipped", we can't know but we should warn.
817
* - If we don't know, we should check it out and ask the user to test.
818
+ * - If a merge base must be tested, on success return
819
+ * BISECT_INTERNAL_SUCCESS_MERGE_BASE (-11) a special condition
820
+ * for early success, this will be converted back to 0 in
821
+ * check_good_are_ancestors_of_bad().
822
*/
819
-static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)
823
+static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)
824
{
825
+ enum bisect_error res = BISECT_OK;
826
struct commit_list *result;
827
828
result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1);
837
handle_skipped_merge_base(mb);
838
} else {
839
printf(_("Bisecting: a merge base must be tested\n"));
835
- exit(bisect_checkout(mb, no_checkout));
840
+ res = bisect_checkout(mb, no_checkout);
841
+ if (!res)
842
+ /* indicate early success */
843
+ res = BISECT_INTERNAL_SUCCESS_MERGE_BASE;
844
+ break;
845
}
846
}
847
848
free_commit_list(result);
849
+ return res;
850
}
851
852
static int check_ancestors(struct repository *r, int rev_nr,
881
char *filename = git_pathdup("BISECT_ANCESTORS_OK");
882
struct stat st;
883
int fd, rev_nr;
884
+ enum bisect_error res = BISECT_OK;
885
struct commit **rev;
886
887
if (!current_bad_oid)
896
goto done;
897
898
/* Check if all good revs are ancestor of the bad rev. */
899
+
900
rev = get_bad_and_good_commits(r, &rev_nr);
901
if (check_ancestors(r, rev_nr, rev, prefix))
890
- check_merge_bases(rev_nr, rev, no_checkout);
902
+ res = check_merge_bases(rev_nr, rev, no_checkout);
903
free(rev);
904
+ if (res)
905
+ exit(res == BISECT_INTERNAL_SUCCESS_MERGE_BASE ? BISECT_OK : -res);
906
907
/* Create file BISECT_ANCESTORS_OK. */
908
fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);