convert: tighten the safe autocrlf handling
commit86ff70a0f0d3917205e1aa82dba08db92d357cc0
authorTorsten Bögershausen <tboegi@web.de>
Sun, 26 Nov 2017 12:20:52 +0000 (26 13:20 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Nov 2017 01:17:24 +0000 (27 10:17 +0900)
tree3eab13624f6909418328dbc8c12f5275eb436912
parentfc849d8d6b90e5c1e0c37bc0d60dd92b2fe7347f
convert: tighten the safe autocrlf handling

When a text file had been commited with CRLF and the file is commited
again, the CRLF are kept if .gitattributs has "text=auto".
This is done by analyzing the content of the blob stored in the index:
If a '\r' is found, Git assumes that the blob was commited with CRLF.

The simple search for a '\r' does not always work as expected:
A file is encoded in UTF-16 with CRLF and commited. Git treats it as binary.
Now the content is converted into UTF-8. At the next commit Git treats the
file as text, the CRLF should be converted into LF, but isn't.

Replace has_cr_in_index() with has_crlf_in_index(). When no '\r' is found,
0 is returned directly, this is the most common case.
If a '\r' is found, the content is analyzed more deeply.

Reported-By: Ashish Negi <ashishnegi33@gmail.com>
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
convert.c
t/t0027-auto-crlf.sh