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

Re: cherry-pick -Xrenormalize fails with formerly CRLF files

From
EMEevee (Lexy Munroe) <eevee@veekun.com>
Date
Nov 29, 2016, 00:27 UTC
Message-ID
<76a7e155-f399-c9f8-c69e-8164e0735dfb@veekun.com>
In-Reply-To
<20161128155415.GA9966@tb-raspi>
On 11/28/2016 07:54 AM, Torsten Bögershausen wrote:
Show 17 quoted lines
> On Sun, Nov 27, 2016 at 10:19:35PM -0800, Eevee (Lexy Munroe) wrote:
>> I'm working with a repo that used to be all CRLF.  At some point it
>> was changed to all LF, with `text=auto` in .gitattributes for the
>> sake of Windows devs.  I'm on Linux and have never touched any
>> twiddles relating to line endings.  I'm trying to cherry-pick some
>> commits from before the switchover.
>>
>> Straightforward cherry-picking causes entire files at a time to
>> conflict, which I've seen before when switching from tabs to spaces.
>> So I tried -Xrenormalize and got:
>>
>>     fatal: CRLF would be replaced by LF in [path]
>>
>
> Which version of Git are you using, what does
> git --version
> say?

Oh, sorry. 2.10.2, but I also tried building next (c8190e7) with the same result.

Show 19 quoted lines
>> The error comes from check_safe_crlf, which warns if checksafe is
>> CRLF_SAFE_WARN and dies if it's (presumably) CRLF_SAFE_FAIL.  The
>> funny thing is that it's CRLF_SAFE_RENORMALIZE.
>>
>> I don't know what the semantics of this value are, but the caller
>> (crlf_to_git) explicitly checks for CRLF_SAFE_RENORMALIZE and
>> changes it to CRLF_SAFE_FALSE instead.  But that check only happens
>> if crlf_action is CRLF_AUTO*, and for me it's CRLF_TEXT_INPUT.
>>
>> I moved the check to happen regardless of the value of crlf_action,
>> and at least in this case, git appears to happily do the right
>> thing.  So I think this is a bug, but line endings are such a tangle
>> that I'm really not sure.  :)
>>
> I am not sure either.
> Could you send me the diff you made ?
> git diff
>
> I am happy to look into it, (in the amount of time I have).
It's pretty straightforward:
diff --git a/convert.c b/convert.c
index be91358..f9ff6a5 100644
--- a/convert.c
+++ b/convert.c
@@ -275,6 +275,8 @@ static int crlf_to_git(const char *path, const char 
*src, size_t len,
         /* Optimization: No CRLF? Nothing to convert, regardless. */
         convert_crlf_into_lf = !!stats.crlf;

+       if (checksafe == SAFE_CRLF_RENORMALIZE)
+               checksafe = SAFE_CRLF_FALSE;
         if (crlf_action == CRLF_AUTO || crlf_action == CRLF_AUTO_INPUT 
|| crlf_action == CRLF_AUTO_CRLF) {
                 if (convert_is_binary(len, &stats))
                         return 0;

(The new lines are copied from the block immediately following, just 
past where the context ends.)

>> The repository in question is ZDoom: https://github.com/rheit/zdoom
>> I'm trying to cherry-pick commits from the 3dfloors3 branch (e.g.,
>> 9fb2daf58e9d512170859302a1ac0ea9c2ec5993) onto a slightly outdated
>> master, 6384e81d0f135a2c292ac3e874f6fe26093f45b1.
>
> This is what I tried:
>
> ...
>
> The patch did not apply, but for different reasons.
>
> Could you send us, what exactly you did, to help me out ?

I did notice it works when there's a conflict, but I thought I 
specifically named a commit that applied cleanly.  Apparently not, 
sorry.  Try ddba3dd325054e71d48634cb19708cb7bcd8f20b:

eevee@perushian ~/dev-foreign/zdoom.git/src ⚘ git checkout -b 
git-renormalize-test 6384e81d0f135a2c292ac3e874f6fe26093f45b1
Switched to a new branch 'git-renormalize-test'
eevee@perushian ~/dev-foreign/zdoom.git/src ⚘ git cherry-pick 
-Xrenormalize ddba3dd325054e71d48634cb19708cb7bcd8f20b
fatal: CRLF would be replaced by LF in src/r_plane.cpp.
Previous: Torsten Bögershausen
Message 3 of 3 in “cherry-pick -Xrenormalize fails with formerly CRLF files”
  1. Eevee (Lexy Munroe)Nov 28, 2016
  2. Torsten BögershausenNov 28, 2016
  3. Eevee (Lexy Munroe)Nov 29, 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.