git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Ephrim Khong <dr.khong@gmail.com>
Subject: [PATCH v2] blame: correctly handle files regardless of autocrlf.
Date: Sat, 26 Apr 2014 23:10:40 +0000	[thread overview]
Message-ID: <1398553840-279066-1-git-send-email-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20140425150726.GA234593@vauxhall.crustytoothpaste.net>

If a file contained CRLF line endings in a repository with
core.autocrlf=input, then blame always marked lines as "Not Committed Yet",
even if they were unmodified.  Don't attempt to convert the line endings
when creating the fake commit so that blame works correctly regardless of
the autocrlf setting.

Reported-by: Ephrim Khong <dr.khong@gmail.com>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
> On Tue, Apr 22, 2014 at 04:12:42PM -0700, Junio C Hamano wrote:
> >  I have a feeling that a fix for this should be fairly isolated and
> >  trivial (it should be just the matter of paying attention to the
> >  crlf settings when synthesizing the fake commit)---perhaps somebody
> >  can squash in a fix to this?
>
> Last time I looked at this, I couldn't come up with an obvious fix for
> the problem, or I would have included one.  I'll try to have another go
> at it this weekend.

This was actually a very helpful hint, Junio.  Thanks for the push in
the right direction.

This includes the suggestion by Torsten Bögershausen to use the git -c
for the blame command.

 builtin/blame.c               | 1 -
 t/t8003-blame-corner-cases.sh | 9 +++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index 88cb799..eef3e86 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2088,7 +2088,6 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
 		if (strbuf_read(&buf, 0, 0) < 0)
 			die_errno("failed to read from stdin");
 	}
-	convert_to_git(path, buf.buf, buf.len, &buf, 0);
 	origin->file.ptr = buf.buf;
 	origin->file.size = buf.len;
 	pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);
diff --git a/t/t8003-blame-corner-cases.sh b/t/t8003-blame-corner-cases.sh
index e7cac1d..2a3469b 100755
--- a/t/t8003-blame-corner-cases.sh
+++ b/t/t8003-blame-corner-cases.sh
@@ -191,4 +191,13 @@ test_expect_success 'indent of line numbers, ten lines' '
 	test $(grep -c "  " actual) = 9
 '
 
+test_expect_success 'blaming files with CRLF newlines' '
+	git config core.autocrlf false &&
+	printf "testcase\r\n" >crlffile &&
+	git add crlffile &&
+	git commit -m testcase &&
+	git -c core.autocrlf=input blame crlffile >actual &&
+	grep "A U Thor" actual
+'
+
 test_done
-- 
2.0.0.rc0

      reply	other threads:[~2014-04-26 23:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-22 23:12 What's cooking in git.git (Apr 2014, #07; Tue, 22) Junio C Hamano
2014-04-23  4:43 ` Jiang Xin
2014-04-25 15:07 ` brian m. carlson
2014-04-26 23:10   ` brian m. carlson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1398553840-279066-1-git-send-email-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=dr.khong@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).