git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Surprising interaction of "binary" and "eol" gitattributes

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Mar 6, 2015, 17:51 UTC
Message-ID
<54F9E907.4040703@alum.mit.edu>
In-Reply-To
<54F9422D.2020800@web.de>
On 03/06/2015 06:59 AM, Torsten Bögershausen wrote:
Show 77 quoted lines
> On 03/05/2015 11:08 PM, Junio C Hamano wrote:
>> Michael Haggerty <mhagger@alum.mit.edu> writes:
>>
>>> I would expect that the following .gitattributes file
>>>
>>>      *       eol=crlf
>>>      *.png   -text
>>>
>>> would leave EOL translation turned off for PNG files. In other words, I
>>> would expect that explicitly setting "-text" would take precedence over
>>> the fact that setting "eol" implies that a file should be considered to
>>> be "text".
>>>
>>> I would even more strongly expect
>>>
>>>      *       eol=crlf
>>>      *.png   binary
>>>
>>> to turn off EOL translation for PNG files.
>>>
>>> But in fact, in both of the above cases, EOL translation is turned *on*
>>> for PNG files.
>>>
>>> I propose that "-text" should override any setting for "eol" (which
>>> would of course fix both problems, since "binary" is equivalent to
>>> "-diff -merge -text"). What do people think?
>> Hmm, is there really something that needs a new proposal and
>> opinions?
>>
>> The way I read the flow in convert.c is:
>>
>>      convert_to_git() uses input_crlf_action() to figure out what
>>      crlf_to_git() conversion is necessary.
>>
>>      input_crlf_action() looks at text_attr and says CRLF_BINARY when
>>      it is CRLF_BINARY without looking at eol_attr at all.
>>
>>      text_attr above is ca.crlf_action in convert_to_git().
>>
>>      The whole ca.* comes from convert_attrs() inspecting attributes
>>      on the incoming path.
>>
>>      convert_attrs() inspects "eol" and "text" attributes, among
>>      others, and sets crlf_action by calling git_path_check_crlf().
>>
>>      git_path_check_crlf() looks at the 'text' attribute; if it is
>>      set to false, it returns CRLF_BINARY.
>>
>>      crlf_to_git() when given crlf_action==CRLF_BINARY is a no-op.
>>
>> So, with the above attributes where anything is eol=crlf by default
>> and in addition *.png is binary (which contains -text), we shouldn't
>> get any crlf munging.  Am I reading/following the code incorrectly?
>>
>> Puzzled....
>> -- 
> 
> I need to admit that I can't reproduce it here,
> the following should trigger it, but all test cases pass
> 
> 
> diff --git a/t/t0027-auto-crlf.sh b/t/t0027-auto-crlf.sh
> 
> index 452320d..22f031d 100755
> --- a/t/t0027-auto-crlf.sh
> +++ b/t/t0027-auto-crlf.sh
> @@ -37,7 +37,8 @@ create_gitattributes () {
>                 echo "*.txt text" >.gitattributes
>                 ;;
>                 -text)
> -               echo "*.txt -text" >.gitattributes
> +               echo "* eol=crlf" >.gitattributes
> +               echo "*.txt -text" >>.gitattributes
>                 ;;
>                 crlf)
>                 echo "*.txt eol=crlf" >.gitattributes
> 

Oops, I misunderstood an internal bug report. In seems that it is the following scenario that is incorrect:

    *.png text=auto eol=crlf
when applied to a binary file.

I'm currently studying documentation and writing tests to figure out the exact current behavior. But honestly, this end-of-line conversion stuff is bewildering, so it might take a while.

Sorry for the half-cocked bug report. I'll report back when I know more.
Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
Previous: Torsten BögershausenNext: Torsten Bögershausen
Message 5 of 17 in “Surprising interaction of "binary" and "eol" gitattributes”
  1. Michael HaggertyMar 5, 2015
  2. Torsten BögershausenMar 5, 2015
  3. Junio C HamanoMar 5, 2015
  4. Torsten BögershausenMar 6, 2015
  5. Michael HaggertyMar 6, 2015
  6. Torsten BögershausenMar 6, 2015
  7. Michael HaggertyMar 10, 2015
  8. Junio C HamanoMar 10, 2015
  9. Michael HaggertyMar 10, 2015
  10. Junio C HamanoMar 10, 2015
  11. Torsten BögershausenMar 11, 2015
  12. Junio C HamanoMar 11, 2015
  13. Johannes SixtMar 11, 2015
  14. Junio C HamanoMar 11, 2015
  15. Junio C HamanoMar 11, 2015
  16. Torsten BögershausenMar 10, 2015
  17. Michael HaggertyMar 10, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.