Skip to content

Commit e8e3ce6

Browse files
pranitbauva1997gitster
authored andcommitted
bisect: libify bisect_checkout
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. Turn `exit()` to `return` calls in `bisect_checkout()`. Changes related to return values have no bad side effects on the code that calls `bisect_checkout()`. 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 ce58b5d commit e8e3ce6

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

bisect.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,10 @@ static int is_expected_rev(const struct object_id *oid)
704704
return res;
705705
}
706706

707-
static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
707+
static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
708708
{
709709
char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
710+
enum bisect_error res = BISECT_OK;
710711

711712
memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), the_hash_algo->hexsz + 1);
712713
update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
@@ -716,14 +717,24 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
716717
update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0,
717718
UPDATE_REFS_DIE_ON_ERR);
718719
} else {
719-
int res;
720720
res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);
721721
if (res)
722-
exit(res);
722+
/*
723+
* Errors in `run_command()` itself, signaled by res < 0,
724+
* and errors in the child process, signaled by res > 0
725+
* can both be treated as regular BISECT_FAILURE (-1).
726+
*/
727+
return -abs(res);
723728
}
724729

725730
argv_show_branch[1] = bisect_rev_hex;
726-
return run_command_v_opt(argv_show_branch, RUN_GIT_CMD);
731+
res = run_command_v_opt(argv_show_branch, RUN_GIT_CMD);
732+
/*
733+
* Errors in `run_command()` itself, signaled by res < 0,
734+
* and errors in the child process, signaled by res > 0
735+
* can both be treated as regular BISECT_FAILURE (-1).
736+
*/
737+
return -abs(res);
727738
}
728739

729740
static struct commit *get_commit_reference(struct repository *r,

0 commit comments

Comments
 (0)