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

Re: [TESTCASE] Failing 'git am' when core.autocrlf=true

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Aug 23, 2007, 19:23 UTC
Message-ID
<alpine.LFD.0.999.0708231153150.30176@woody.linux-foundation.org>
In-Reply-To
<alpine.LFD.0.999.0708230956190.30176@woody.linux-foundation.org>
On Thu, 23 Aug 2007, Linus Torvalds wrote:
> 
> Junio - it fixes the test for me, but quite frankly, I don't see why 
> write-tree would *ever* change any non-tree index entries. But it does. I 
> think there's another bug somewhere, or I'm missing something.

Looking more carefully at the index file before and after, the _only_ difference really is the ce_size field for "foo".

In the fixed one, ce_size remains at 5 (which is correct: the file contents are "bar\n\r"), in the broken case it gets zeroed by git-write-tree for some reason.

And the reason is really interesting: it only happens if the index file has the same date as the entry in the index, in which case we end up doign the "careful" check in ce_smudge_racily_clean_entry() and there the "ce_modified_check_fs()" will end up re-reading the file, and if we don't have the right CRLF behaviour, we will now return DATA_CHANGED.

So the call-chain for this is:
	cmd_write_tree ->
	  write_tree ->
	    write_index ->
	      ce_smudge_racily_clean_entry -> 
		ce_modified_check_fs ->
		  ce_compare_data ->
		    index_fd ->
		      convert_to_git ->
			** wrong answer unless auto_crlf is set **
		and now "ce_smudge_racily_clean_entry()" will do
			ce->ce_size = htonl(0);
and the one-liner fix I sent out is actually the right fix.

This was harder to find than it should have been, because it actually depends on the datestamp of the index file matching the datestamp of the file in question!

		Linus
Previous: Linus TorvaldsNext: Junio C Hamano
Message 6 of 8 in “[TESTCASE] Failing 'git am' when core.autocrlf=true”
  1. Marius Storm-OlsenAug 23, 2007
  2. Linus TorvaldsAug 23, 2007
  3. Marius Storm-OlsenAug 23, 2007
  4. Junio C HamanoAug 23, 2007
  5. Linus TorvaldsAug 23, 2007
  6. Linus TorvaldsAug 23, 2007
  7. Junio C HamanoAug 23, 2007
  8. Marius Storm-OlsenAug 23, 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.