@matheusbsbs / matheus-bagliano / commits / ce58b5d8b1
Fork 0

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 <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 ce58b5d8b128568e9b4f37703377cbc22eaf00f5
2 files changed +15 -7
bisect.c
+11 -6
@@ -661,11 +661,11 @@ static void bisect_common(struct rev_info *revs)
661 mark_edges_uninteresting(revs, NULL, 0);
662 }
663
664 -static void exit_if_skipped_commits(struct commit_list *tried,
664 +static enum bisect_error error_if_skipped_commits(struct commit_list *tried,
665 const struct object_id *bad)
666 {
667 if (!tried)
668 - return;
668 + return BISECT_OK;
669
670 printf("There are only 'skip'ped commits left to test.\n"
671 "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,
676 if (bad)
677 printf("%s\n", oid_to_hex(bad));
678 printf(_("We cannot bisect more!\n"));
679 - exit(2);
679 +
680 + return BISECT_ONLY_SKIPPED_LEFT;
681 }
682
683 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
951 struct rev_info revs;
952 struct commit_list *tried;
953 int reaches = 0, all = 0, nr, steps;
954 + enum bisect_error res = BISECT_OK;
955 struct object_id *bisect_rev;
956 char *steps_msg;
957
@@ -972,8 +974,9 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int
974 * We should exit here only if the "bad"
975 * commit is also a "skip" commit.
976 */
975 - exit_if_skipped_commits(tried, NULL);
976 -
977 + res = error_if_skipped_commits(tried, NULL);
978 + if (res < 0)
979 + exit(-res);
980 printf(_("%s was both %s and %s\n"),
981 oid_to_hex(current_bad_oid),
982 term_good,
@@ -990,7 +993,9 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int
993 bisect_rev = &revs.commits->item->object.oid;
994
995 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);
999 printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
1000 term_bad);
1001 show_diff_tree(r, prefix, revs.commits->item);
bisect.h
+4 -1
@@ -37,10 +37,13 @@ struct rev_list_info {
37 * commit has been found (and possibly checked out) and it
38 * should be tested.
39 * BISECT_FAILED error code: default error code.
40 + * BISECT_ONLY_SKIPPED_LEFT error code: only skipped
41 + * commits left to be tested.
42 */
43 enum bisect_error {
44 BISECT_OK = 0,
43 - BISECT_FAILED = -1
45 + BISECT_FAILED = -1,
46 + BISECT_ONLY_SKIPPED_LEFT = -2
47 };
48
49 enum bisect_error bisect_next_all(struct repository *r,