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

Re: [PATCH] Fix crlf attribute handling to match documentation

From
Junio C Hamano <junkio@cox.net>
Date
May 19, 2007, 00:02 UTC
Message-ID
<7v646p4r50.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<200705181333.32719.andyparkins@gmail.com>
Andy Parkins <andyparkins@gmail.com> writes:
Show 12 quoted lines
> gitattributes.txt says, of the crlf attribute:
>
>  Set::
>     Setting the `crlf` attribute on a path is meant to mark
>     the path as a "text" file.  'core.autocrlf' conversion
>     takes place without guessing the content type by
>     inspection.
>
> That is to say that the crlf attribute does not force the file to have
> CRLF line endings, instead it removes the autocrlf guesswork and forces
> the file to be treated as text.  Then, whatever line ending is defined
> by the autocrlf setting is applied.

Thanks; I looked at the patch (although I am still _physically_ at work ;-). I think your code is correct but the explanation is slightly misleading.

Show 5 quoted lines
> However, that is not what convert.c was doing.  The conversion to CRLF
> was being skipped in crlf_to_worktree() when the following condition was
> true:
>
>  action == CRLF_GUESS && auto_crlf <= 0

The check you modified in the first hunk is not the above '<=' comparison but is this:

	(action == CRLF_GUESS && !auto_crlf)

and "core.autocrlf = input" makes "auto_crlf = -1", so when action is not GUESS, or even when action is GUESS, if the config is set to "input", the if() statement you patched in the first hunk should not trigger. The above description is different from what the code was doing.

The logic (in crlf_to_git, which is the input codepath) should be:
	* if action is BINARY, do nothing (obviously -- and the
          code gets this right).
	* if action is GUESS, do nothing if config says false
          (we want 'input' and 'true' to apply the munging after
          guessing).
	* if action is TEXT or INPUT, do not guess but do CRLF
          only on platforms that need it -- which means where
          auto_crlf is -1 (input) or 1 (true).  Otherwise do not
          do the conversion.

The original code gets the third case incorrectly, and your patch fixes it by returning early in that case as well.

The output codepath is the same. Regardless of action (GUESS/TEXT/INPUT), we will not do anything if config says 'false' or 'input', so removing the check with "action == GUESS" is the right thing.

Previous: Junio C HamanoNext: Andy Parkins
Message 3 of 4 in “Fix crlf attribute handling to match documentation”
  1. Fix crlf attribute handling to match documentationAndy Parkins, May 18, 2007
  2. Junio C HamanoMay 18, 2007
  3. Junio C HamanoMay 19, 2007
  4. Andy ParkinsMay 19, 2007

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.