bisect: libify `handle_bad_merge_base` and its dependents
Since we want to get rid of git-bisect.sh, it would be necessary to convert those exit() calls to return statements so that errors can be reported. Emulate try catch in C by converting `exit(<positive-value>)` to `return <negative-value>`. Follow POSIX conventions to return <negative-value> to indicate error. Update all callers to handle the error returns. Mentored-by: Christian Couder <chriscool@tuxfamily.org> Mentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com> Signed-off-by: Tanushree Tumane <tanushreetumane@gmail.com> Signed-off-by: Miriam Rubio <mirucam@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pranit Bauva committed
Feb 17, 2020 at 09:40 UTC
9ec598e0d55ff263e47d95e7d4decef1eb1b6ac6
2 files changed
+6
-4
bisect.c
+5
-4
@@ -761,7 +761,7 @@ static struct commit **get_bad_and_good_commits(struct repository *r,
761
return rev;
762
}
763
764
-static void handle_bad_merge_base(void)
764
+static enum bisect_error handle_bad_merge_base(void)
765
{
766
if (is_expected_rev(current_bad_oid)) {
767
char *bad_hex = oid_to_hex(current_bad_oid);
@@ -782,14 +782,14 @@ static void handle_bad_merge_base(void)
782
"between %s and [%s].\n"),
783
bad_hex, term_bad, term_good, bad_hex, good_hex);
784
}
785
- exit(3);
785
+ return BISECT_MERGE_BASE_CHECK;
786
}
787
788
fprintf(stderr, _("Some %s revs are not ancestors of the %s rev.\n"
789
"git bisect cannot work properly in this case.\n"
790
"Maybe you mistook %s and %s revs?\n"),
791
term_good, term_bad, term_good, term_bad);
792
- exit(1);
792
+ return BISECT_FAILED;
793
}
794
795
static void handle_skipped_merge_base(const struct object_id *mb)
@@ -830,7 +830,8 @@ static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int
830
for (; result; result = result->next) {
831
const struct object_id *mb = &result->item->object.oid;
832
if (oideq(mb, current_bad_oid)) {
833
- handle_bad_merge_base();
833
+ res = handle_bad_merge_base();
834
+ break;
835
} else if (0 <= oid_array_lookup(&good_revs, mb)) {
836
continue;
837
} else if (0 <= oid_array_lookup(&skipped_revs, mb)) {
bisect.h
+1
@@ -48,6 +48,7 @@ enum bisect_error {
48
BISECT_OK = 0,
49
BISECT_FAILED = -1,
50
BISECT_ONLY_SKIPPED_LEFT = -2,
51
+ BISECT_MERGE_BASE_CHECK = -3,
52
BISECT_INTERNAL_SUCCESS_MERGE_BASE = -11
53
};
54