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

Re: git-apply: warn/fail on *changed* end of line (eol) *only*?

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 27, 2016, 17:27 UTC
Message-ID
<xmqq8tr1cmf9.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<xmqqvau7cqy1.fsf@gitster.mtv.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 18 quoted lines
> Imagine that the project wants LF line endings, i.e. it considers
> that a line with CRLF ending has an unwanted "whitespace" at the
> end.  Now, you start from this source file:
>
>     1 <CRLF>
>     3 <CRLF>
>     5 <CRLF>
>
> and a patch like this comes in:
>
>      1 <CRLF>
>     -3 <CRLF>
>     +three <CRLF>
>      5 <CRLF>
>
> You think that "3 <CRLF>" was replaced by "three <CRLF>", and the
> claim is "the 'previous' contents already had <CRLF> ending, so the
> change is not making things worse".

To see the problem with "check existing lines", it probably is easier to extend the above example to start from a file with one more line, like this:

    1 <CRLF>
    3 <CRLF>
    4 <LF>
    5 <CRLF>

and extend all the example patches to remove "4 <LF>" line as well, where they remove "3 <CRLF>", making the first example patch like so:

     1 <CRLF>
    -3 <CRLF>
    -4 <LF>
    +three <CRLF>
     5 <CRLF>

Now, if you take "three <CRLF>" to be replacing "3 <CRLF>", then you may feel that not warning on the CRLF would be the right thing, but there is no reason (other than the fact you, a human, understand what 'three' means) to choose "3 <CRLF>" over "4 <LF>" as the original. If you take "three <CRLF>" to be replacing "4 <LF>", you would need to warn.

A totally uninteresting special case is when the original is all <CRLF>, but in that case, as you already said in the original message, the project wants <CRLF> and you can configure it as such. Then <CR> in the line-end <CRLF> won't be mistaken as if it is a whitespace character <CR> at the end of a line terminated with <LF>.

Previous: Igor Djordjevic BugANext: Igor Djordjevic BugA
Message 5 of 6 in “git-apply: warn/fail on *changed* end of line (eol) *only*?”
  1. Igor Djordjevic BugADec 25, 2016
  2. Igor Djordjevic BugADec 25, 2016
  3. Junio C HamanoDec 26, 2016
  4. Igor Djordjevic BugADec 27, 2016
  5. Junio C HamanoDec 27, 2016
  6. Igor Djordjevic BugADec 27, 2016

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.