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

Re: [PATCH v2 2/2] File commited with CRLF should roundtrip diff and apply

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 17, 2017, 06:37 UTC
Message-ID
<xmqqk222itso.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170817060633.28491-1-tboegi@web.de>
tboegi@web.de writes:
Show 10 quoted lines
> Analyze the patch if there is a) any context line with CRLF,
> or b) if any line with CRLF is to be removed.
> Thanks to Junio C Hamano, his input became the base for the changes in t4124.
> One test case is split up into 3:
> - Detect the " a\r" line in the patch
> - Detect the "-a\r" line in the patch
> - Use LF in repo and CLRF in the worktree. (*)
>
> * This one proves that convert_to_git(&the_index,...) still needs to pass
> the &index, otherwise Git will crash.

I do not understand why you think it proves anything like that. Forget about "in repo" when you think about "git apply" without "--index/--cache". There is *NO* role the index should play in that mode.

"Otherwise Git will crash" is true, because convert_to_git() tries to dereference the istate it is given to see if there is CR in the blob that happens to be in the index at the path.

But step back and *think*. It only proves that convert_to_git() you have and/or the way read_old_data() you updated calls it after applying these two patches are still broken.

The "blob that happens to be in the index at the path" does *NOT* have anything to do with the file in the working tree that you are patching. Such an index entry may not exist (and the code would see that there is 0 CRs and 0 LFs---so what?), or it may have a blob full of CRLF, or it may have a blob full of CR not LF, or any random thing that has NO relation to the file you are patching. Why should that random blob (which may not even exist---we are discussing "git apply" without "--index/--cache" here) affect the outcome? If it does not affect the outcome, why should convert_to_git() even look at it?

It shouldn't be calling down to "has_cr_in_index(istate, path)" that is called from crlf_to_git() in the first place. The check for CR was done in the caller of convert_to_git(), i.e. read_old_data(), long before convert_to_git() is called, and the caller knows if it is (or it is not) dealing with data that needs crlf conversion at that point, based on the contents of the file being patched (which, again, does not have any relation to the blob that may or may not happen to be in the index).

Your updated caller is already telling convert_to_git() codepath when it needs CRLF and it refrains from peeking in the index with SAFE_CRLF_KEEP_CRLF flag. The bug still in the code after applying these two patches is that the other choice, i.e. SAFE_CRLF_FALSE, that is passed from read_old_data() to convert_to_git() does *not* prevent the latter from peeking into the in-core index.

And that is why "Otherwise Git will crash".
Previous: tboegi@web.deNext: tboegi@web.de
Message 18 of 36 in “core.autocrlf=true causes `git apply` to fail on patch generated with `git diff-index HEAD --patch`”
  1. Anthony SottileAug 1, 2017
  2. Torsten BögershausenAug 1, 2017
  3. Anthony SottileAug 1, 2017
  4. Torsten BögershausenAug 2, 2017
  5. 1/1 correct apply for files commited with CRLFtboegi@web.de, Aug 2, 2017
  6. Junio C HamanoAug 2, 2017
  7. Torsten BögershausenAug 4, 2017
  8. Junio C HamanoAug 4, 2017
  9. Junio C HamanoAug 4, 2017
  10. Junio C HamanoAug 2, 2017
  11. Torsten BögershausenAug 12, 2017
  12. Torsten BögershausenAug 12, 2017
  13. convert: Add SAFE_CRLF_KEEP_CRLFtboegi@web.de, Aug 12, 2017
  14. File commited with CRLF should roundtrip diff and applytboegi@web.de, Aug 12, 2017
  15. Junio C HamanoAug 14, 2017
  16. 1/2 convert: Add SAFE_CRLF_KEEP_CRLFtboegi@web.de, Aug 17, 2017
  17. 2/2 File commited with CRLF should roundtrip diff and applytboegi@web.de, Aug 17, 2017
  18. Junio C HamanoAug 17, 2017
  19. 1/2 convert: Add SAFE_CRLF_KEEP_CRLFtboegi@web.de, Aug 17, 2017
  20. 2/2 File commited with CRLF should roundtrip diff and applytboegi@web.de, Aug 17, 2017
  21. Junio C HamanoAug 17, 2017
  22. Junio C HamanoAug 17, 2017
  23. 1/2 convert: Add SAFE_CRLF_KEEP_CRLFtboegi@web.de, Aug 19, 2017
  24. 2/2 File commited with CRLF should roundtrip diff and applytboegi@web.de, Aug 19, 2017
  25. 1/2 convert: Add SAFE_CRLF_KEEP_CRLFtboegi@web.de, Aug 13, 2017
  26. 2/2 File commited with CRLF should roundtrip diff and applytboegi@web.de, Aug 13, 2017
  27. 3/2 apply: remove unused member apply_state.flagsJunio C Hamano, Aug 16, 2017
  28. Junio C HamanoAug 16, 2017
  29. 4/2 apply: only pay attention to CRLF in the preimageJunio C Hamano, Aug 16, 2017
  30. 5/2 apply: localize the CRLF business to read_old_data()Junio C Hamano, Aug 16, 2017
  31. 6/2 apply: clarify read_old_data() is about no-index caseJunio C Hamano, Aug 16, 2017
  32. Torsten BögershausenAug 17, 2017
  33. Junio C HamanoAug 17, 2017
  34. Junio C HamanoAug 17, 2017
  35. Torsten BögershausenAug 17, 2017
  36. Junio C HamanoAug 17, 2017

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.