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

Re: [PATCH] merge-file: consider core.crlf when writing merge markers

From
Beat Bolli <dev+git@drbeat.li>
Date
Nov 24, 2015, 22:43 UTC
Message-ID
<5654E7FD.2060000@drbeat.li>
In-Reply-To
<alpine.DEB.1.00.1511240844380.1686@s15462909.onlinehome-server.info>
On 24.11.15 09:21, Johannes Schindelin wrote:
Show 44 quoted lines
> Hi Beat,
> 
> On Mon, 23 Nov 2015, Beat Bolli wrote:
> 
>> When merging files in repos with core.eol = crlf, git merge-file inserts
>> just a LF at the end of the merge markers. Files with mixed line endings
>> cause trouble in Windows editors and e.g. contrib/git-jump, where an
>> unmerged file in a run of "git jump merge" is reported as simply "binary
>> file matches".
> 
> Wow, what a beautiful contribution!
> 
> I wonder how difficult it would be to make this work with gitattributes,
> i.e. when .gitattributes' `eol` setting disagrees with core.eol.
> 
> I imagine that we could use convert.c to do all the hard work, e.g. by
> adding a function
> 
> 	const char *eol_for_path(const char *path, const char *contents)
> 	{
> 		enum eol eol;
> 		struct conv_attrs ca;
> 		struct text_stat stats;
> 
> 		convert_attrs(&ca, path);
> 		eol = output_eol(ca.crlf_action);
> 		if (eol != EOL_CRLF)
> 			eol = EOL_LF;
> 		else if (!*contents || (crlf_action != CRLF_AUTO &&
> 				crlf_action != CRLF_GUESS)
> 			eol = EOL_CRLF;
> 		else {
> 			ca.crlf_action = input_crlf_action(ca.crlf_action,
> 					ca.eol_attr);
> 			if (crlf_action == CRLF_GUESS && stats.cr > stats.crlf)
> 				eol = core_eol;
> 			else if (stats.crlf)
> 				eol = EOL_CRLF;
> 			else
> 				eol = EOL_LF;
> 		}
> 
> 		return eol == EOL_CRLF ? "\r\n" : "\n";
> 	}
Hi Johannes,

I have implemented this according to your algorithm. Now, I have to set core.autocrlf to true for making the new test pass. Setting core.eol no longer has an effect on the merge markers. Is this expected? (I haven't set any attributes)

Clearly I don't have much experience with gitattributes and how they interact with the core config settings :-\

Regards, Beat

Previous: Johannes SchindelinNext: Beat Bolli
Message 3 of 5 in “merge-file: consider core.crlf when writing merge markers”
  1. merge-file: consider core.crlf when writing merge markersBeat Bolli, Nov 23, 2015
  2. Johannes SchindelinNov 24, 2015
  3. Beat BolliNov 24, 2015
  4. Beat BolliNov 24, 2015
  5. Johannes SchindelinNov 25, 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.