[Openmp-commits] [clang] [clang-tools-extra] [flang] [lldb] [llvm] [openmp] [pstl] Finally formalise our defacto line-ending policy (PR #86318)
via Openmp-commits
openmp-commits at lists.llvm.org
Tue Oct 22 03:54:45 PDT 2024
ldrumm wrote:
>> It's my understanding that text=auto does not override core.autocrlf. As far as I can tell from the documentation it honours the user's configuration for core.eol in combination with core.autocrlf - from git config --help:
> This doesn't match my experience.
I think this is due to a subtly of config. Setting `core.autocrlf` to `false` doesn't actually do anything since it's the default. In that case git is still in "no opinion" mode - which means it stores the input line endings and does no conversion.
However, once `eol=auto` is set in a `.gitattributes`, it forces git to use the configured eol config:
```c
static int text_eol_is_crlf(void)
{
if (auto_crlf == AUTO_CRLF_TRUE)
return 1;
else if (auto_crlf == AUTO_CRLF_INPUT)
return 0;
if (core_eol == EOL_CRLF)
return 1;
if (core_eol == EOL_UNSET && EOL_NATIVE == EOL_CRLF)
return 1;
return 0;
}
static enum eol output_eol(enum convert_crlf_action crlf_action)
{
switch (crlf_action) {
case CRLF_BINARY:
return EOL_UNSET;
case CRLF_TEXT_CRLF:
return EOL_CRLF;
case CRLF_TEXT_INPUT:
return EOL_LF;
case CRLF_UNDEFINED:
case CRLF_AUTO_CRLF:
return EOL_CRLF;
case CRLF_AUTO_INPUT:
return EOL_LF;
case CRLF_TEXT:
case CRLF_AUTO:
/* fall through */
return text_eol_is_crlf() ? EOL_CRLF : EOL_LF;
}
warning(_("illegal crlf_action %d"), (int)crlf_action);
return core_eol;
}
```
`output_eol` is the git function that decides to write out a file with CRLF or LF endings
Notice that now we hit the `CRLF_AUTO` case so it's `text_eol_is_crlf() ? EOL_CRLF : EOL_LF;`
`text_eol_is_crlf()` checks against `core.autocrlf`. Since you've stated that it's `false`, then it then it checks `core.eol`.
So if I've read that correctly, `core.autocrlf=false` is a red herring and you should really set `core.eol=lf` if you want git to use `lf` on windows.
> Would we get there by setting the wildcard rule in .gitattrubtes to * text eof=lf, or something along those lines?
This patch is about respecting local config, which is the exact opposite of that suggestion. It would be a way to solve the line-ending issue by fiat, not by co-operation, so I'm against it on principle. To be clear I very much don't like CRLF, but I also very much don't like it when someone forces me to use wrong-handed tools. Windows users would be forced to use wrong handed tools if we force line-endings one way or another
https://github.com/llvm/llvm-project/pull/86318
More information about the Openmp-commits
mailing list