Skip to content

Commit 04393ae

Browse files
peffgitster
authored andcommitted
diff-files: move misplaced cleanup label
Commit 0139c58 (revisions API users: add "goto cleanup" for release_revisions(), 2022-04-13) converted an early return in cmd_diff_files() into a goto. But it put the cleanup label too early: if read_cache_preload() returns an error, we'll set result to "-1", but then jump to calling run_diff_files(), overwriting our result. We should jump past the call to run_diff_files(). Likewise, we should go past diff_result_code(), which is expecting to see a code from an actual diff, not a negative error code. In practice, I suspect this bug cannot actually be triggered, because read_cache_preload() does not seem to ever return an error. Its return value (eventually) comes from do_read_index(), which gives the number of cache entries found, and calls die() on error. Still, it makes sense to fix the inadvertent change from 0139c58 first, and we can look into the overall error handling of read_cache() separately (which is present in many other callsites). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 54c8a7c commit 04393ae

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

builtin/diff-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
8080
result = -1;
8181
goto cleanup;
8282
}
83-
cleanup:
8483
result = run_diff_files(&rev, options);
8584
result = diff_result_code(&rev.diffopt, result);
85+
cleanup:
8686
release_revisions(&rev);
8787
return result;
8888
}

0 commit comments

Comments
 (0)