Skip to content

Commit 2946f7f

Browse files
pranitbauva1997gitster
authored andcommitted
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 <[email protected]> Mentored-by: Johannes Schindelin <[email protected]> Signed-off-by: Pranit Bauva <[email protected]> Signed-off-by: Tanushree Tumane <[email protected]> Signed-off-by: Miriam Rubio <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f9b21d3 commit 2946f7f

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

bisect.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ static struct commit **get_bad_and_good_commits(struct repository *r,
761761
return rev;
762762
}
763763

764-
static void handle_bad_merge_base(void)
764+
static enum bisect_error handle_bad_merge_base(void)
765765
{
766766
if (is_expected_rev(current_bad_oid)) {
767767
char *bad_hex = oid_to_hex(current_bad_oid);
@@ -782,14 +782,14 @@ static void handle_bad_merge_base(void)
782782
"between %s and [%s].\n"),
783783
bad_hex, term_bad, term_good, bad_hex, good_hex);
784784
}
785-
exit(3);
785+
return BISECT_MERGE_BASE_CHECK;
786786
}
787787

788788
fprintf(stderr, _("Some %s revs are not ancestors of the %s rev.\n"
789789
"git bisect cannot work properly in this case.\n"
790790
"Maybe you mistook %s and %s revs?\n"),
791791
term_good, term_bad, term_good, term_bad);
792-
exit(1);
792+
return BISECT_FAILED;
793793
}
794794

795795
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
830830
for (; result; result = result->next) {
831831
const struct object_id *mb = &result->item->object.oid;
832832
if (oideq(mb, current_bad_oid)) {
833-
handle_bad_merge_base();
833+
res = handle_bad_merge_base();
834+
break;
834835
} else if (0 <= oid_array_lookup(&good_revs, mb)) {
835836
continue;
836837
} else if (0 <= oid_array_lookup(&skipped_revs, mb)) {

bisect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ enum bisect_error {
4848
BISECT_OK = 0,
4949
BISECT_FAILED = -1,
5050
BISECT_ONLY_SKIPPED_LEFT = -2,
51+
BISECT_MERGE_BASE_CHECK = -3,
5152
BISECT_INTERNAL_SUCCESS_MERGE_BASE = -11
5253
};
5354

0 commit comments

Comments
 (0)