blame: CRLF in the working tree and LF in the repo

A typical setup under Windows is to set core.eol to CRLF, and text files are marked as "text" in .gitattributes, or core.autocrlf is set to true. After 4d4813a5 "git blame" no longer works as expected for such a set-up. Every line is annotated as "Not Committed Yet", even though the working directory is clean. This is because the commit removed the conversion in blame.c for all files, with or without CRLF in the repo. Having files with CRLF in the repo and core.autocrlf=input is a temporary situation, and the files, if committed as is, will be normalized in the repo, which _will_ be a notable change. Blaming them with "Not Committed Yet" is the right result. Revert commit 4d4813a5 which was a misguided attempt to "solve" a non-problem. Add two test cases in t8003 to verify the correct CRLF conversion. Suggested-By: Stepan Kasal <kasal@ucw.cz> Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Torsten Bögershausen committed May 3, 2015 at 18:38 UTC 4bf256d67a85bed1e175ecc2706322eafe4489ca
2 files changed +16 -3
builtin/blame.c
+1
@@ -2106,6 +2106,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
2106 if (strbuf_read(&buf, 0, 0) < 0)
2107 die_errno("failed to read from stdin");
2108 }
2109 + convert_to_git(path, buf.buf, buf.len, &buf, 0);
2110 origin->file.ptr = buf.buf;
2111 origin->file.size = buf.len;
2112 pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);
t/t8003-blame-corner-cases.sh
+15 -3
@@ -191,12 +191,24 @@ test_expect_success 'indent of line numbers, ten lines' '
191 test $(grep -c " " actual) = 9
192 '
193
194 -test_expect_success 'blaming files with CRLF newlines' '
194 +test_expect_success 'setup file with CRLF newlines' '
195 git config core.autocrlf false &&
196 - printf "testcase\r\n" >crlffile &&
196 + printf "testcase\n" >crlffile &&
197 git add crlffile &&
198 git commit -m testcase &&
199 - git -c core.autocrlf=input blame crlffile >actual &&
199 + printf "testcase\r\n" >crlffile
200 +'
201 +
202 +test_expect_success 'blame file with CRLF core.autocrlf true' '
203 + git config core.autocrlf true &&
204 + git blame crlffile >actual &&
205 + grep "A U Thor" actual
206 +'
207 +
208 +test_expect_success 'blame file with CRLF attributes text' '
209 + git config core.autocrlf false &&
210 + echo "crlffile text" >.gitattributes &&
211 + git blame crlffile >actual &&
212 grep "A U Thor" actual
213 '
214