Skip to content

Commit ce58b5d

Browse files
pranitbauva1997gitster
authored andcommitted
bisect: libify exit_if_skipped_commits to error_if_skipped* 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 7613ec5 commit ce58b5d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

bisect.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,11 @@ static void bisect_common(struct rev_info *revs)
661661
mark_edges_uninteresting(revs, NULL, 0);
662662
}
663663

664-
static void exit_if_skipped_commits(struct commit_list *tried,
664+
static enum bisect_error error_if_skipped_commits(struct commit_list *tried,
665665
const struct object_id *bad)
666666
{
667667
if (!tried)
668-
return;
668+
return BISECT_OK;
669669

670670
printf("There are only 'skip'ped commits left to test.\n"
671671
"The first %s commit could be any of:\n", term_bad);
@@ -676,7 +676,8 @@ static void exit_if_skipped_commits(struct commit_list *tried,
676676
if (bad)
677677
printf("%s\n", oid_to_hex(bad));
678678
printf(_("We cannot bisect more!\n"));
679-
exit(2);
679+
680+
return BISECT_ONLY_SKIPPED_LEFT;
680681
}
681682

682683
static int is_expected_rev(const struct object_id *oid)
@@ -950,6 +951,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int
950951
struct rev_info revs;
951952
struct commit_list *tried;
952953
int reaches = 0, all = 0, nr, steps;
954+
enum bisect_error res = BISECT_OK;
953955
struct object_id *bisect_rev;
954956
char *steps_msg;
955957

@@ -972,8 +974,9 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int
972974
* We should exit here only if the "bad"
973975
* commit is also a "skip" commit.
974976
*/
975-
exit_if_skipped_commits(tried, NULL);
976-
977+
res = error_if_skipped_commits(tried, NULL);
978+
if (res < 0)
979+
exit(-res);
977980
printf(_("%s was both %s and %s\n"),
978981
oid_to_hex(current_bad_oid),
979982
term_good,
@@ -990,7 +993,9 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int
990993
bisect_rev = &revs.commits->item->object.oid;
991994

992995
if (oideq(bisect_rev, current_bad_oid)) {
993-
exit_if_skipped_commits(tried, current_bad_oid);
996+
res = error_if_skipped_commits(tried, current_bad_oid);
997+
if (res)
998+
exit(-res);
994999
printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
9951000
term_bad);
9961001
show_diff_tree(r, prefix, revs.commits->item);

bisect.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ struct rev_list_info {
3737
* commit has been found (and possibly checked out) and it
3838
* should be tested.
3939
* BISECT_FAILED error code: default error code.
40+
* BISECT_ONLY_SKIPPED_LEFT error code: only skipped
41+
* commits left to be tested.
4042
*/
4143
enum bisect_error {
4244
BISECT_OK = 0,
43-
BISECT_FAILED = -1
45+
BISECT_FAILED = -1,
46+
BISECT_ONLY_SKIPPED_LEFT = -2
4447
};
4548

4649
enum bisect_error bisect_next_all(struct repository *r,

0 commit comments

Comments
 (0)