Skip to content

Commit f126f6e

Browse files
peffgitster
authored andcommitted
diff-files: avoid negative exit value
If loading the index fails, we print an error and then return "-1" from the function. But since this is a builtin, we end up with exit(-1), which produces odd results since program exit codes are unsigned. Because of integer conversion, it usually becomes 255, which is at least still an error, but values above 128 are usually interpreted as signal death. Since we know the program is exiting immediately, we can just replace the error return with a die(). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 976b97e commit f126f6e

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

builtin/diff-files.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,10 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
8080
(rev.diffopt.output_format & DIFF_FORMAT_PATCH))
8181
diff_merges_set_dense_combined_if_unset(&rev);
8282

83-
if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {
84-
perror("repo_read_index_preload");
85-
result = -1;
86-
goto cleanup;
87-
}
83+
if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0)
84+
die_errno("repo_read_index_preload");
8885
result = run_diff_files(&rev, options);
8986
result = diff_result_code(&rev.diffopt, result);
90-
cleanup:
9187
release_revisions(&rev);
9288
return result;
9389
}

0 commit comments

Comments
 (0)