提交 12426e11 编写于 作者: J Junio C Hamano

diff: do not short-cut CHECK_SIZE_ONLY check in diff_populate_filespec()

Callers of diff_populate_filespec() can choose to ask only for the
size of the blob without grabbing the blob data, and the function,
after running lstat() when the filespec points at a working tree
file, returns by copying the value in size field of the stat
structure into the size field of the filespec when this is the case.

However, this short-cut cannot be taken if the contents from the
path needs to go through convert_to_git(), whose resulting real blob
data may be different from what is in the working tree file.

As "git diff --quiet" compares the .size fields of filespec
structures to skip content comparison, this bug manifests as a
false "there are differences" for a file that needs eol conversion,
for example.
Reported-by: NMike Crowe <mac@mcrowe.com>
Helped-by: NTorsten Bögershausen <tboegi@web.de>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 0b65a8db
......@@ -2783,8 +2783,25 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
s->should_free = 1;
return 0;
}
if (size_only)
/*
* Even if the caller would be happy with getting
* only the size, we cannot return early at this
* point if the path requires us to run the content
* conversion.
*/
if (size_only && !would_convert_to_git(s->path))
return 0;
/*
* Note: this check uses xsize_t(st.st_size) that may
* not be the true size of the blob after it goes
* through convert_to_git(). This may not strictly be
* correct, but the whole point of big_file_threshold
* and is_binary check being that we want to avoid
* opening the file and inspecting the contents, this
* is probably fine.
*/
if ((flags & CHECK_BINARY) &&
s->size > big_file_threshold && s->is_binary == -1) {
s->is_binary = 1;
......
......@@ -152,4 +152,13 @@ test_expect_success 'git diff --quiet ignores stat-change only entries' '
test_expect_code 1 git diff --quiet
'
test_expect_success 'git diff --quiet on a path that need conversion' '
echo "crlf.txt text=auto" >.gitattributes &&
printf "Hello\r\nWorld\r\n" >crlf.txt &&
git add .gitattributes crlf.txt &&
printf "Hello\r\nWorld\n" >crlf.txt &&
git diff --quiet crlf.txt
'
test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册