{"thread":{"id":"39227","subject":"[PATCH v5] blame: CRLF in the working tree and LF in the repo","startedAt":"2015-05-03T16:38:01Z","lastAt":"2015-05-03T16:38:01Z","messageCount":1,"participants":["Torsten Bögershausen"],"isPatch":true,"patchVersion":5,"patchTotal":null},"messages":[{"id":"260467","messageId":"55464EE9.3090201@web.de","threadId":"39227","inReplyTo":null,"subject":"[PATCH v5] blame: CRLF in the working tree and LF in the repo","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2015-05-03T16:38:01Z","receivedAt":"2015-05-03T16:38:01Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"A typical setup under Windows is to set core.eol to CRLF, and text\nfiles are marked as \"text\" in .gitattributes, or core.autocrlf is\nset to true.\n\nAfter 4d4813a5 \"git blame\" no longer works as expected for such a\nset-up.  Every line is annotated as \"Not Committed Yet\", even though\nthe working directory is clean.  This is because the commit removed\nthe conversion in blame.c for all files, with or without CRLF in the\nrepo.\n\nHaving files with CRLF in the repo and core.autocrlf=input is a\ntemporary situation, and the files, if committed as is, will be\nnormalized in the repo, which _will_ be a notable change.  Blaming\nthem with \"Not Committed Yet\" is the right result.  Revert commit\n4d4813a5 which was a misguided attempt to \"solve\" a non-problem.\n\nAdd two test cases in t8003 to verify the correct CRLF conversion.\n\nSuggested-By: Stepan Kasal <kasal@ucw.cz>\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\nChanges against pu:\n- fixed typo typical\n- Add the 2 test cases suggested originally be Stepan,\n  mention them in the commit msg and say\n  \"Suggested-By\" instead of \"Reported-By\"\n- This should be in line with Junios suggestion not to introduce\n  additional (and somewhat unrelated) TC's\n\n builtin/blame.c               |  1 +\n t/t8003-blame-corner-cases.sh | 18 +++++++++++++++---\n 2 files changed, 16 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 06484c2..8d70623 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -2348,6 +2348,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,\n \t\tif (strbuf_read(&buf, 0, 0) < 0)\n \t\t\tdie_errno(\"failed to read from stdin\");\n \t}\n+\tconvert_to_git(path, buf.buf, buf.len, &buf, 0);\n \torigin->file.ptr = buf.buf;\n \torigin->file.size = buf.len;\n \tpretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);\ndiff --git a/t/t8003-blame-corner-cases.sh b/t/t8003-blame-corner-cases.sh\nindex 32895e5..16f1442 100755\n--- a/t/t8003-blame-corner-cases.sh\n+++ b/t/t8003-blame-corner-cases.sh\n@@ -191,12 +191,24 @@ test_expect_success 'indent of line numbers, ten lines' '\n \ttest $(grep -c \"  \" actual) = 9\n '\n \n-test_expect_success 'blaming files with CRLF newlines' '\n+test_expect_success 'setup file with CRLF newlines' '\n \tgit config core.autocrlf false &&\n-\tprintf \"testcase\\r\\n\" >crlffile &&\n+\tprintf \"testcase\\n\" >crlffile &&\n \tgit add crlffile &&\n \tgit commit -m testcase &&\n-\tgit -c core.autocrlf=input blame crlffile >actual &&\n+\tprintf \"testcase\\r\\n\" >crlffile\n+'\n+\n+test_expect_success 'blame file with CRLF core.autocrlf true' '\n+\tgit config core.autocrlf true &&\n+\tgit blame crlffile >actual &&\n+\tgrep \"A U Thor\" actual\n+'\n+\n+test_expect_success 'blame file with CRLF attributes text' '\n+\tgit config core.autocrlf false &&\n+\techo \"crlffile text\" >.gitattributes &&\n+\tgit blame crlffile >actual &&\n \tgrep \"A U Thor\" actual\n '\n \n-- \n2.2.0.rc1.790.ge19fcd2\n"}]}