Commit 3bac68ff05ae1a87975b8850b554830b4dea27d3

Iliyas Jorio 2022-02-09T18:54:34

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>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
 	}