bisect: simplify return code from bisect_checkout()
The function was designed to return only BISECT_OK (0) or BISECT_FAILED (-1) and no other values, but there were two issues: - The comment misspelled BISECT_FAILED as BISECT_FAILURE, even though the logic it described (i.e. any non-zero return should be reported as a single BISECT_FAILED) was correct. - It took the return value from run_command_v_opt(), and assumed it was either -1 or 1 upon error, which is not the case; it can relay errors from wait_or_whine(), which can report exit status of the child process. Translate any error return from run_command_v_opt() to BISECT_FAILED, and simplify the resulting code by losing the 'res' variable that is no longer needed. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jul 28, 2021 at 10:07 UTC
1fcc40cd1dbfbdf6879a7b60a3a0250e46dc5c60
1 file changed
+4
-6
bisect.c
+4
-6
@@ -727,7 +727,6 @@ static int is_expected_rev(const struct object_id *oid)
727
static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
728
{
729
char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
730
- enum bisect_error res = BISECT_OK;
730
struct commit *commit;
731
struct pretty_print_context pp = {0};
732
struct strbuf commit_msg = STRBUF_INIT;
@@ -740,14 +739,13 @@ static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int
739
update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0,
740
UPDATE_REFS_DIE_ON_ERR);
741
} else {
743
- res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);
744
- if (res)
742
+ if (run_command_v_opt(argv_checkout, RUN_GIT_CMD))
743
/*
744
* Errors in `run_command()` itself, signaled by res < 0,
745
* and errors in the child process, signaled by res > 0
748
- * can both be treated as regular BISECT_FAILURE (-1).
746
+ * can both be treated as regular BISECT_FAILED (-1).
747
*/
750
- return -abs(res);
748
+ return BISECT_FAILED;
749
}
750
751
commit = lookup_commit_reference(the_repository, bisect_rev);
@@ -755,7 +753,7 @@ static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int
753
fputs(commit_msg.buf, stdout);
754
strbuf_release(&commit_msg);
755
758
- return -abs(res);
756
+ return BISECT_OK;
757
}
758
759
static struct commit *get_commit_reference(struct repository *r,