From: Pranit Bauva via GitGitGadget Date: Sun, 24 Feb 2019 10:11:19 GMT Subject: [PATCH 05/26] bisect.c: libify `bisect_checkout` and its dependants Message-ID: <45c00ddf64982448361c461964e4ad77a328be74.1551003074.git.gitgitgadget@gmail.com> In-Reply-To: From: Pranit Bauva 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()` to `return `. Follow POSIX conventions to return to indicate error. Turn `exit()` to `return` calls in `bisect_checkout()`. Handle this return in dependant methods - `check_merge_bases()`. Mentored-by: Christian Couder Mentored-by: Johannes Schindelin Signed-off-by: Pranit Bauva Signed-off-by: Tanushree Tumane --- bisect.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bisect.c b/bisect.c index bb926f09d0..1f2f3201a3 100644 --- a/bisect.c +++ b/bisect.c @@ -710,7 +710,7 @@ static int is_expected_rev(const struct object_id *oid) static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout) { char bisect_rev_hex[GIT_MAX_HEXSZ + 1]; - + int res = 0; memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1); update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR); @@ -719,14 +719,14 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout) update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR); } else { - int res; res = run_command_v_opt(argv_checkout, RUN_GIT_CMD); if (res) - exit(res); + return res > 0 ? -res : res; } argv_show_branch[1] = bisect_rev_hex; - return run_command_v_opt(argv_show_branch, RUN_GIT_CMD); + res = run_command_v_opt(argv_show_branch, RUN_GIT_CMD); + return res > 0 ? -res : res; } static struct commit *get_commit_reference(const struct object_id *oid) @@ -822,7 +822,7 @@ static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout) handle_skipped_merge_base(mb); } else { printf(_("Bisecting: a merge base must be tested\n")); - exit(bisect_checkout(mb, no_checkout)); + exit(-bisect_checkout(mb, no_checkout)); } } -- gitgitgadget