Skip to content

Commit 1fcc40c

Browse files
committed
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 <[email protected]>
1 parent ffcb4e9 commit 1fcc40c

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

bisect.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,6 @@ static int is_expected_rev(const struct object_id *oid)
727727
static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
728728
{
729729
char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
730-
enum bisect_error res = BISECT_OK;
731730
struct commit *commit;
732731
struct pretty_print_context pp = {0};
733732
struct strbuf commit_msg = STRBUF_INIT;
@@ -740,22 +739,21 @@ static enum bisect_error bisect_checkout(const struct object_id *bisect_rev, int
740739
update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0,
741740
UPDATE_REFS_DIE_ON_ERR);
742741
} 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))
745743
/*
746744
* Errors in `run_command()` itself, signaled by res < 0,
747745
* 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).
749747
*/
750-
return -abs(res);
748+
return BISECT_FAILED;
751749
}
752750

753751
commit = lookup_commit_reference(the_repository, bisect_rev);
754752
format_commit_message(commit, "[%H] %s%n", &commit_msg, &pp);
755753
fputs(commit_msg.buf, stdout);
756754
strbuf_release(&commit_msg);
757755

758-
return -abs(res);
756+
return BISECT_OK;
759757
}
760758

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

0 commit comments

Comments
 (0)