diff_file: Apply suggestions from code review Skip new_file_size non-zero test, custom error message if file changed in workdir Co-authored-by: Edward Thomson <ethomson@github.com>
diff --git a/src/diff_file.c b/src/diff_file.c
index 0a5ded7..9804a94 100644
--- a/src/diff_file.c
+++ b/src/diff_file.c
@@ -335,12 +335,12 @@ static int diff_file_content_load_workdir_file(
error = git_futils_filesize(&new_file_size, fd);
- if (error < 0 || !new_file_size)
+ if (error < 0)
goto cleanup;
/* if file size doesn't match cached value, abort */
- if (fc->file->size && fc->file->size != new_file_size)
- {
+ if (fc->file->size && fc->file->size != new_file_size) {
+ git_error_set(GIT_ERROR_FILESYSTEM, "file changed before we could read it");
error = -1;
goto cleanup;
}