Skip to content

Commit 60f335b

Browse files
committed
Merge branch 'jc/diff-populate-filespec-size-only-fix'
"git diff --quiet" relies on the size field in diff_filespec to be correctly populated, but diff_populate_filespec() helper function made an incorrect short-cut when asked only to populate the size field for paths that need to go through convert_to_git() (e.g. CRLF conversion). * jc/diff-populate-filespec-size-only-fix: diff: do not short-cut CHECK_SIZE_ONLY check in diff_populate_filespec()
2 parents 6c62101 + 12426e1 commit 60f335b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

diff.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2870,8 +2870,25 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
28702870
s->should_free = 1;
28712871
return 0;
28722872
}
2873-
if (size_only)
2873+
2874+
/*
2875+
* Even if the caller would be happy with getting
2876+
* only the size, we cannot return early at this
2877+
* point if the path requires us to run the content
2878+
* conversion.
2879+
*/
2880+
if (size_only && !would_convert_to_git(s->path))
28742881
return 0;
2882+
2883+
/*
2884+
* Note: this check uses xsize_t(st.st_size) that may
2885+
* not be the true size of the blob after it goes
2886+
* through convert_to_git(). This may not strictly be
2887+
* correct, but the whole point of big_file_threshold
2888+
* and is_binary check being that we want to avoid
2889+
* opening the file and inspecting the contents, this
2890+
* is probably fine.
2891+
*/
28752892
if ((flags & CHECK_BINARY) &&
28762893
s->size > big_file_threshold && s->is_binary == -1) {
28772894
s->is_binary = 1;

t/t4035-diff-quiet.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,13 @@ test_expect_success 'git diff --quiet ignores stat-change only entries' '
152152
test_expect_code 1 git diff --quiet
153153
'
154154

155+
test_expect_success 'git diff --quiet on a path that need conversion' '
156+
echo "crlf.txt text=auto" >.gitattributes &&
157+
printf "Hello\r\nWorld\r\n" >crlf.txt &&
158+
git add .gitattributes crlf.txt &&
159+
160+
printf "Hello\r\nWorld\n" >crlf.txt &&
161+
git diff --quiet crlf.txt
162+
'
163+
155164
test_done

0 commit comments

Comments
 (0)