{"thread":{"id":"64776","subject":"[PATCH v2 1/2] utf8.c: Prepare workaround for iconv under macOS 14/15","startedAt":"2026-01-11T19:51:52Z","lastAt":"2026-11-29T22:10:24Z","messageCount":37,"participants":["tboegi@web.de","Junio C Hamano","Johannes Sixt","Curtis Smith","Curtis Allen Smith","Phillip Wood","Torsten Bögershausen"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"533540","messageId":"20260111195149.716177-1-tboegi@web.de","threadId":"64776","inReplyTo":null,"subject":"[PATCH v2 1/2] utf8.c: Prepare workaround for iconv under macOS 14/15","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2026-01-11T19:51:49Z","receivedAt":"2026-01-11T19:51:52Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\nMacOS14 (Sonoma) has started to ship an iconv library with bugs.\nThe same bugs exists even in MacOS 15 (Sequoia)\n\nA bug report running the Git test suite says:\n\nthree tests of t3900 fail on macOS 26.1 for me:\n\n  not ok 17 - ISO-2022-JP should be shown in UTF-8 now\n  not ok 25 - ISO-2022-JP should be shown in UTF-8 now\n  not ok 38 - commit --fixup into ISO-2022-JP from UTF-8\n\nHere's the verbose output of the first one:\n\n----- snip! -----\nexpecting success of 3900.17 'ISO-2022-JP should be shown in UTF-8 now':\n                compare_with ISO-2022-JP \"$TEST_DIRECTORY\"/t3900/2-UTF-8.txt\n\n--- /Users/x/src/git/t/t3900/2-UTF-8.txt 2024-10-01 19:43:24.605230684 +0000\n+++ current     2025-12-08 21:52:45.786161909 +0000\n@@ -1,4 +1,4 @@\n はれひほふ\n\n しているのが、いるので。\n-濱浜ほれぷりぽれまびぐりろへ。\n+濱浜ほれぷりぽれまび$0$j$m$X!#\nnot ok 17 - ISO-2022-JP should be shown in UTF-8 now\n1..17\n----- snap! -----\n\ncompare_with runs git show to display a commit message, which in this\ncase here was encoded using ISO-2022-JP and is supposed to be reencoded\nto UTF-8, but git show only does that half-way -- the \"$0$j$m$X!#\" part\nis from the original ISO-2022-JP representation.\n\nThat botched conversion is done by utf8.c::reencode_string_iconv().  It\ncalls iconv(3) to do the actual work, initially with an output buffer of\nthe same size as the input.  If the output needs more space the function\nenlarges the buffer and calls iconv(3) again.\n\niconv(3) won't tell us how much space it needs, but it will report what\npart it already managed to convert, so we can increase the buffer and\ncontinue from there.  ISO-2022-JP has escape codes for switching between\ncharacter sets, so it's a stateful encoding.  I guess the iconv(3) on my\nmachine forgets the state at the end of part one and then messes up part\ntwo.\n\n[end of citation]\n\nWorking around the buggy iconv shipped with the OS can be done in\ntwo  ways:\na) Link Git against a different version of iconv\nb) Improve the handling when iconv needs a larger output buffer\n\na) is already done by default when either Fink [1] or MacPorts [2]\n   or Homebrew [3] is installed.\nb) is implemented here, in case that no fixed iconv is available:\n   When the output buffer is too short, increase it (as before)\n   and start from scratch (this is new).\n\nThis workound needs to be enabled with\n'#define ICONV_RESTART_RESET'\nand a makefile knob will be added in the next commit\n\nSuggested-by: René Scharfe <l.s.r@web.de>\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n\n[1] https://www.finkproject.org/\n[2] https://www.macports.org/\n[3] https://brew.sh/\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n utf8.c | 13 +++++++++++++\n 1 file changed, 13 insertions(+)\n\ndiff --git a/utf8.c b/utf8.c\nindex 35a0251939..96460cc414 100644\n--- a/utf8.c\n+++ b/utf8.c\n@@ -515,6 +515,19 @@ char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv,\n \t\t\tout = xrealloc(out, outalloc);\n \t\t\toutpos = out + sofar;\n \t\t\toutsz = outalloc - sofar - 1;\n+#ifdef ICONV_RESTART_RESET\n+\t\t\t/*\n+\t\t\t * If iconv(3) messes up piecemeal conversions\n+\t\t\t * then restore the original pointers, sizes,\n+\t\t\t * and converter state, then retry converting\n+\t\t\t * the full string using the reallocated buffer.\n+\t\t\t */\n+\t\t\tinsz += cp - (iconv_ibp)in; /* Restore insz */\n+\t\t\tcp = (iconv_ibp)in;         /* original start value */\n+\t\t\toutpos = out + bom_len;     /* original start value */\n+\t\t\toutsz = outalloc - bom_len - 1; /* new len */\n+\t\t\ticonv(conv, NULL, NULL, NULL, NULL); /* reset iconv machinery */\n+#endif\n \t\t}\n \t\telse {\n \t\t\t*outpos = '\\0';\n-- \n2.50.0.rc0.46.g7014b55638.dirty\n\n"},{"id":"533552","messageId":"xmqqwm1no29m.fsf@gitster.g","threadId":"64776","inReplyTo":"20260111195149.716177-1-tboegi@web.de","subject":"Re: [PATCH v2 1/2] utf8.c: Prepare workaround for iconv under macOS 14/15","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-01-12T04:58:45Z","receivedAt":"2026-01-12T04:58:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"tboegi@web.de writes:\n\n> From: Torsten Bögershausen <tboegi@web.de>\n>\n> MacOS14 (Sonoma) has started to ship an iconv library with bugs.\n> The same bugs exists even in MacOS 15 (Sequoia)\n>\n> A bug report running the Git test suite says:\n>\n> three tests of t3900 fail on macOS 26.1 for me:\n>\n>   not ok 17 - ISO-2022-JP should be shown in UTF-8 now\n>   not ok 25 - ISO-2022-JP should be shown in UTF-8 now\n>   not ok 38 - commit --fixup into ISO-2022-JP from UTF-8\n>\n> Here's the verbose output of the first one:\n>\n> ----- snip! -----\n\nDoesn't this tell \"git am\" that your log message ends here, and ...\n\n> expecting success of 3900.17 'ISO-2022-JP should be shown in UTF-8 now':\n>                 compare_with ISO-2022-JP \"$TEST_DIRECTORY\"/t3900/2-UTF-8.txt\n>\n> --- /Users/x/src/git/t/t3900/2-UTF-8.txt 2024-10-01 19:43:24.605230684 +0000\n> +++ current     2025-12-08 21:52:45.786161909 +0000\n\n... makes the tool to apply the patch to file \"current\"?\n\n> @@ -1,4 +1,4 @@\n>  はれひほふ\n>\n>  しているのが、いるので。\n> -濱浜ほれぷりぽれまびぐりろへ。\n> +濱浜ほれぷりぽれまび$0$j$m$X!#\n> not ok 17 - ISO-2022-JP should be shown in UTF-8 now\n> 1..17\n> ----- snap! -----\n\nIOW, indent the displayed material used as an example in the\nproposed log message.\n\n> compare_with runs git show to display a commit message, which in this\n> case here was encoded using ISO-2022-JP and is supposed to be reencoded\n> to UTF-8, but git show only does that half-way -- the \"$0$j$m$X!#\" part\n> is from the original ISO-2022-JP representation.\n>\n> That botched conversion is done by utf8.c::reencode_string_iconv().  It\n> calls iconv(3) to do the actual work, initially with an output buffer of\n> the same size as the input.  If the output needs more space the function\n> enlarges the buffer and calls iconv(3) again.\n>\n> iconv(3) won't tell us how much space it needs, but it will report what\n> part it already managed to convert, so we can increase the buffer and\n> continue from there.  ISO-2022-JP has escape codes for switching between\n> character sets, so it's a stateful encoding.  I guess the iconv(3) on my\n> machine forgets the state at the end of part one and then messes up part\n> two.\n>\n> [end of citation]\n>\n> Working around the buggy iconv shipped with the OS can be done in\n> two  ways:\n> a) Link Git against a different version of iconv\n> b) Improve the handling when iconv needs a larger output buffer\n>\n> a) is already done by default when either Fink [1] or MacPorts [2]\n>    or Homebrew [3] is installed.\n> b) is implemented here, in case that no fixed iconv is available:\n>    When the output buffer is too short, increase it (as before)\n>    and start from scratch (this is new).\n>\n> This workound needs to be enabled with\n> '#define ICONV_RESTART_RESET'\n> and a makefile knob will be added in the next commit\n>\n> Suggested-by: René Scharfe <l.s.r@web.de>\n> Signed-off-by: Torsten Bögershausen <tboegi@web.de>\n>\n> [1] https://www.finkproject.org/\n> [2] https://www.macports.org/\n> [3] https://brew.sh/\n>\n> Signed-off-by: Torsten Bögershausen <tboegi@web.de>\n> ---\n>  utf8.c | 13 +++++++++++++\n>  1 file changed, 13 insertions(+)\n>\n> diff --git a/utf8.c b/utf8.c\n> index 35a0251939..96460cc414 100644\n> --- a/utf8.c\n> +++ b/utf8.c\n> @@ -515,6 +515,19 @@ char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv,\n>  \t\t\tout = xrealloc(out, outalloc);\n>  \t\t\toutpos = out + sofar;\n>  \t\t\toutsz = outalloc - sofar - 1;\n> +#ifdef ICONV_RESTART_RESET\n> +\t\t\t/*\n> +\t\t\t * If iconv(3) messes up piecemeal conversions\n> +\t\t\t * then restore the original pointers, sizes,\n> +\t\t\t * and converter state, then retry converting\n> +\t\t\t * the full string using the reallocated buffer.\n> +\t\t\t */\n> +\t\t\tinsz += cp - (iconv_ibp)in; /* Restore insz */\n> +\t\t\tcp = (iconv_ibp)in;         /* original start value */\n> +\t\t\toutpos = out + bom_len;     /* original start value */\n> +\t\t\toutsz = outalloc - bom_len - 1; /* new len */\n> +\t\t\ticonv(conv, NULL, NULL, NULL, NULL); /* reset iconv machinery */\n> +#endif\n>  \t\t}\n>  \t\telse {\n>  \t\t\t*outpos = '\\0';\n"},{"id":"533655","messageId":"20260112162551.774037-1-tboegi@web.de","threadId":"64776","inReplyTo":"xmqqwm1no29m.fsf@gitster.g","subject":"[PATCH v3 1/2] utf8.c: Prepare workaround for iconv under macOS 14/15","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2026-01-12T16:25:51Z","receivedAt":"2026-01-12T16:25:56Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\nMacOS14 (Sonoma) has started to ship an iconv library with bugs.\nThe same bugs exists even in MacOS 15 (Sequoia)\n\nA bug report running the Git test suite says:\n\nthree tests of t3900 fail on macOS 26.1 for me:\n\n  not ok 17 - ISO-2022-JP should be shown in UTF-8 now\n  not ok 25 - ISO-2022-JP should be shown in UTF-8 now\n  not ok 38 - commit --fixup into ISO-2022-JP from UTF-8\n\nHere's the verbose output of the first one:\n\n=================\nexpecting success of 3900.17 'ISO-2022-JP should be shown in UTF-8 now':\n                compare_with ISO-2022-JP \"$TEST_DIRECTORY\"/t3900/2-UTF-8.txt\n\n --- /Users/x/src/git/t/t3900/2-UTF-8.txt 2024-10-01 19:43:24.605230684 +0000\n +++ current     2025-12-08 21:52:45.786161909 +0000\n@@ -1,5 +1,5 @@\n はれひほふ\n\n しているのが、いるので。\n -濱浜ほれぷりぽれまびぐりろへ。\n +濱浜ほれぷりぽれまび$0$j$m$X!#\nnot ok 17 - ISO-2022-JP should be shown in UTF-8 now\n1..17\n=================\n\ncompare_with runs git show to display a commit message, which in this\ncase here was encoded using ISO-2022-JP and is supposed to be reencoded\nto UTF-8, but git show only does that half-way -- the \"$0$j$m$X!#\" part\nis from the original ISO-2022-JP representation.\n\nThat botched conversion is done by utf8.c::reencode_string_iconv().  It\ncalls iconv(3) to do the actual work, initially with an output buffer of\nthe same size as the input.  If the output needs more space the function\nenlarges the buffer and calls iconv(3) again.\n\niconv(3) won't tell us how much space it needs, but it will report what\npart it already managed to convert, so we can increase the buffer and\ncontinue from there.  ISO-2022-JP has escape codes for switching between\ncharacter sets, so it's a stateful encoding.  I guess the iconv(3) on my\nmachine forgets the state at the end of part one and then messes up part\ntwo.\n\n[end of citation]\n\nWorking around the buggy iconv shipped with the OS can be done in\ntwo  ways:\na) Link Git against a different version of iconv\nb) Improve the handling when iconv needs a larger output buffer\n\na) is already done by default when either Fink [1] or MacPorts [2]\n   or Homebrew [3] is installed.\nb) is implemented here, in case that no fixed iconv is available:\n   When the output buffer is too short, increase it (as before)\n   and start from scratch (this is new).\n\nThis workound needs to be enabled with\n'#define ICONV_RESTART_RESET'\nand a makefile knob will be added in the next commit\n\nSuggested-by: René Scharfe <l.s.r@web.de>\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n\n[1] https://www.finkproject.org/\n[2] https://www.macports.org/\n[3] https://brew.sh/\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n utf8.c | 13 +++++++++++++\n 1 file changed, 13 insertions(+)\n\ndiff --git a/utf8.c b/utf8.c\nindex 35a0251939..96460cc414 100644\n--- a/utf8.c\n+++ b/utf8.c\n@@ -515,6 +515,19 @@ char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv,\n \t\t\tout = xrealloc(out, outalloc);\n \t\t\toutpos = out + sofar;\n \t\t\toutsz = outalloc - sofar - 1;\n+#ifdef ICONV_RESTART_RESET\n+\t\t\t/*\n+\t\t\t * If iconv(3) messes up piecemeal conversions\n+\t\t\t * then restore the original pointers, sizes,\n+\t\t\t * and converter state, then retry converting\n+\t\t\t * the full string using the reallocated buffer.\n+\t\t\t */\n+\t\t\tinsz += cp - (iconv_ibp)in; /* Restore insz */\n+\t\t\tcp = (iconv_ibp)in;         /* original start value */\n+\t\t\toutpos = out + bom_len;     /* original start value */\n+\t\t\toutsz = outalloc - bom_len - 1; /* new len */\n+\t\t\ticonv(conv, NULL, NULL, NULL, NULL); /* reset iconv machinery */\n+#endif\n \t\t}\n \t\telse {\n \t\t\t*outpos = '\\0';\n-- \n2.50.0.rc0.46.g7014b55638.dirty\n\n"},{"id":"533656","messageId":"20260112162547.774015-1-tboegi@web.de","threadId":"64776","inReplyTo":"xmqqwm1no29m.fsf@gitster.g","subject":"[PATCH v3 0/2] Workaround for iconv under macOS 14/15","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2026-01-12T16:25:47Z","receivedAt":"2026-01-12T16:25:59Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\nChanges since v1:\n  Re-fined commit message (thanks René)\n  Installed a fresh Fink. It lives under /opt/sw now (/sw in older versions)\n  However, people can choose other places, I did use the default.\n  Make more clear that libiconv from Homebrew, Macports or Fink can be used.\nChanges since v2:\n  Even more details in commit message, and now\n  git am works (Thanks Junio for the patience)\n\n\nTorsten Bögershausen (2):\n  utf8.c: Prepare workaround for iconv under macOS 14/15\n  utf8.c: Enable workaround for iconv under macOS 14/15\n\n Makefile         | 16 ++++++++++++++++\n config.mak.uname |  1 +\n utf8.c           | 13 +++++++++++++\n 3 files changed, 30 insertions(+)\n\n-- \n2.50.0.rc0.46.g7014b55638.dirty\n\n"},{"id":"533657","messageId":"20260112162553.774051-1-tboegi@web.de","threadId":"64776","inReplyTo":"xmqqwm1no29m.fsf@gitster.g","subject":"[PATCH v3 2/2] utf8.c: Enable workaround for iconv under macOS 14/15","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2026-01-12T16:25:53Z","receivedAt":"2026-01-12T16:26:02Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\nThe previous commit introduced a workaround in utf8.c to deal\nwith broken iconv implementations.\n\nIt is enabled when a MacOS version is used that has a buggy\niconv library and there is no external library provided\n(and linked against) from neither MacPorts nor Homebrew nor Fink.\nFor Homebrew, MacPorts and Fink we check if libiconv exist.\nIntroduce 2 new macros: HAS_GOOD_LIBICONV and NEEDS_GOOD_LIBICONV.\n\nFor Homebrew HAS_GOOD_LIBICONV is set when the libiconv directory\nexist.\nMacPorts can be installed with or without libiconv, so check if\nlibiconv.dylib exists (which is a softlink)\n\nFink compiles and installs libiconv by default.\nNote that a fresh installation of Fink now defaults to /opt/sw.\nOlder versions used /sw as default, so leave the check and setting\nof BASIC_CFLAGS and BASIC_LDFLAGS as is.\nFor the new default check for the existance of /opt/sw as well.\nAdd a check for /opt/sw/lib/libiconv.dylib which sets HAS_GOOD_LIBICONV\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n Makefile         | 16 ++++++++++++++++\n config.mak.uname |  1 +\n 2 files changed, 17 insertions(+)\n\ndiff --git a/Makefile b/Makefile\nindex b7eba509c6..8aa489f3b6 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1687,11 +1687,21 @@ ifeq ($(uname_S),Darwin)\n \t\t\tBASIC_CFLAGS += -I/sw/include\n \t\t\tBASIC_LDFLAGS += -L/sw/lib\n                 endif\n+                ifeq ($(shell test -d /opt/sw/lib && echo y),y)\n+\t\t\tBASIC_CFLAGS += -I/opt/sw/include\n+\t\t\tBASIC_LDFLAGS += -L/opt/sw/lib\n+\t\t\tifeq ($(shell test -e /opt/sw/lib/libiconv.dylib && echo y),y)\n+\t\t\t\tHAS_GOOD_LIBICONV = Yes\n+\t\t\tendif\n+                endif\n         endif\n         ifndef NO_DARWIN_PORTS\n                 ifeq ($(shell test -d /opt/local/lib && echo y),y)\n \t\t\tBASIC_CFLAGS += -I/opt/local/include\n \t\t\tBASIC_LDFLAGS += -L/opt/local/lib\n+\t\t\tifeq ($(shell test -e /opt/local/lib/libiconv.dylib && echo y),y)\n+\t\t\t\tHAS_GOOD_LIBICONV = Yes\n+\t\t\tendif\n                 endif\n         endif\n         ifndef NO_APPLE_COMMON_CRYPTO\n@@ -1714,6 +1724,7 @@ endif\n ifdef USE_HOMEBREW_LIBICONV\n ifeq ($(shell test -d $(HOMEBREW_PREFIX)/opt/libiconv && echo y),y)\n \tICONVDIR ?= $(HOMEBREW_PREFIX)/opt/libiconv\n+\tHAS_GOOD_LIBICONV = Yes\n endif\n endif\n endif\n@@ -1859,6 +1870,11 @@ ifndef NO_ICONV\n                 endif\n \t\tEXTLIBS += $(ICONV_LINK) -liconv\n         endif\n+        ifdef NEEDS_GOOD_LIBICONV\n+        ifndef HAS_GOOD_LIBICONV\n+                BASIC_CFLAGS += -DICONV_RESTART_RESET\n+        endif\n+        endif\n endif\n ifdef ICONV_OMITS_BOM\n \tBASIC_CFLAGS += -DICONV_OMITS_BOM\ndiff --git a/config.mak.uname b/config.mak.uname\nindex 38b35af366..3c35ae33a3 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -157,6 +157,7 @@ ifeq ($(uname_S),Darwin)\n         endif\n         ifeq ($(shell test \"$(DARWIN_MAJOR_VERSION)\" -ge 24 && echo 1),1)\n \t\tUSE_HOMEBREW_LIBICONV = UnfortunatelyYes\n+\t\tNEEDS_GOOD_LIBICONV = UnfortunatelyYes\n         endif\n \n \t# The builtin FSMonitor on MacOS builds upon Simple-IPC.  Both require\n-- \n2.50.0.rc0.46.g7014b55638.dirty\n\n"},{"id":"554788","messageId":"20261012175628.3692-1-tboegi@web.de","threadId":"64776","inReplyTo":"xmqqwm1no29m.fsf@gitster.g","subject":"[PATCH v3/RFC 0/1] read-cache: do not trust a size change when conversion","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2026-10-12T17:56:28Z","receivedAt":"2026-10-12T17:56:28Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\n- Pick up the patch from Curtis Allen Smith\n- Reduce the commit message and especially the code changes\n- All tests pass here.\n- The commit message feels still somewhat bumpy - better suggestions welcome.\n- The original series add a configuration switch - that is removed\n- I took ownwership of this patch and add a Signed-Off Curtis Allen Smith,\n  is this OK ?\n- All in all this is not the final version, trying to move things forward\n\nTorsten Bögershausen (1):\n  read-cache: do not trust a size change when conversion is active\n\n read-cache.c    | 25 ++++++++++++++++++++++++-\n t/t0020-crlf.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 69 insertions(+), 1 deletion(-)\n\n-- \n2.50.0.rc0.46.g7014b55638\n\n\n"},{"id":"554789","messageId":"20261012175638.3712-1-tboegi@web.de","threadId":"64776","inReplyTo":"xmqqwm1no29m.fsf@gitster.g","subject":"[PATCH v3/RFC 1/1] read-cache: do not trust a size change when conversion is active","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2026-10-12T17:56:38Z","receivedAt":"2026-10-12T17:56:38Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\n\"git status\" can report a file as modified while \"git diff\" and\n\"git add\", which both run the clean filter, agree its contents are\nunchanged:\n\n\tgit init t && cd t\n\tprintf '* text eol=lf\\n' >.gitattributes\n\tprintf 'one\\ntwo\\nthree\\n' >file.txt\n\tgit add . && git commit -m init\n\n\tprintf 'one\\r\\ntwo\\r\\nthree\\r\\n' >file.txt\n\n\tgit status --short      # ->  M file.txt\n\tgit diff                # -> empty\n\tgit add file.txt        # -> updates the index\n\nNote that \"clean filter\" here means the \"clean filter\" and CRLF conversion,\nand all converting of a file in the worktree into the index.\n\nProblems that have been found in real live:\n  Tools that rewrites unchanged files in native line endings e.g.\n    javadoc, code generators, formatters and some editors change\n    the size of every file it touches.\n  Editors that insist to replace 4 space with a TAB,\n    even if the file is changed manually forth and back -\n    Using a clean filter that changes the TAB back into space when\n    committing will cause the same confusion.\n\n`git status` and `git diff` disagree because ie_modified()\nin read-cache.c concludes that a file is modified\nas soon as the size has changed.\nThis had been true when Git was young, before the clean filter\nand CRLF conversion had been introduced.\n\nIntroduce size_change_is_conclusive() in read-cache.c, which calls\nwould_convert_to_git().\nThe content of the file in the worktree is now run through all filters\nand CRLF conversion whenever the size is different.\nAfter that, the new size (and mtime) is stored in the index\ntogether with the modified status.\n\nTechnical correctness vs performance considerations:\nInstead of running the chain of\n`git status` `git diff` (hm, nothing changed ?) `git add`\nwe now handle everything in `git status`, which may give a slower\nexecution time for this command.\nDifferent measurements came up with 20ms per file which are now\nspend in `git status` instead of `git add`.\n\nSigned-off-by: Curtis Allen Smith <curtis.allen.smith@gmail.com>\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n read-cache.c    | 25 ++++++++++++++++++++++++-\n t/t0020-crlf.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 69 insertions(+), 1 deletion(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex c4cf08a3a3..9aebe4c394 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -9,6 +9,7 @@\n \n #include \"git-compat-util.h\"\n #include \"config.h\"\n+#include \"convert.h\"\n #include \"date.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n@@ -438,6 +439,27 @@ int ie_match_stat(struct index_state *istate,\n \treturn changed;\n }\n \n+/*\n+ * A difference between the size of the file in the working tree and the\n+ * size recorded for it in the index proves that the contents changed\n+ * only as long as the two are byte-for-byte comparable.  That stops\n+ * being true as soon as the path is run through a clean filter:\n+ * rewriting a file with CRLF endings under \"text eol=lf\", for example,\n+ * changes its size in the working tree without changing the blob Git\n+ * would record for it.  For such a path the only way to tell is to read\n+ * the contents and convert them, which is what we already do when only\n+ * the mtime changed.\n+ */\n+static int size_change_is_conclusive(struct index_state *istate,\n+\t\t\t\t     const struct cache_entry *ce,\n+\t\t\t\t     struct stat *st)\n+{\n+\tif (!S_ISREG(st->st_mode))\n+\t\treturn 1;\n+\n+\treturn !would_convert_to_git(istate, ce->name);\n+}\n+\n int ie_modified(struct index_state *istate,\n \t\tconst struct cache_entry *ce,\n \t\tstruct stat *st, unsigned int options)\n@@ -480,7 +502,8 @@ int ie_modified(struct index_state *istate,\n \t     */\n \t    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&\n #endif\n-\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0))\n+\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0) &&\n+\t    size_change_is_conclusive(istate, ce, st))\n \t\treturn changed;\n \n \tchanged_fs = ce_modified_check_fs(istate, ce, st);\ndiff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh\nindex fd1cae09ed..88b728d509 100755\n--- a/t/t0020-crlf.sh\n+++ b/t/t0020-crlf.sh\n@@ -397,4 +397,49 @@ test_expect_success 'New CRLF file gets LF in repo' '\n \ttest_cmp alllf alllf2\n '\n \n+test_expect_success 'status does not report a CRLF-only rewrite as modified' '\n+\tgit init eol-status &&\n+\t(\n+\t\tcd eol-status &&\n+\t\techo \"* text eol=lf\" >.gitattributes &&\n+\t\tprintf \"one\\ntwo\\nthree\\n\" >file.txt &&\n+\t\tgit add .gitattributes file.txt &&\n+\t\tgit commit -m initial &&\n+\n+\t\t# a generator rewrites the file with CRLF, same content\n+\t\tprintf \"one\\r\\ntwo\\r\\nthree\\r\\n\" >file.txt &&\n+\t\tgit status --porcelain -uno >actual &&\n+\t\ttest_must_be_empty actual &&\n+\t\tgit diff --exit-code &&\n+\n+\t\t# a real change is still reported\n+\t\tprintf \"one\\r\\ntwo\\r\\nfour\\r\\n\" >file.txt &&\n+\t\tgit status --porcelain -uno >actual &&\n+\t\techo \" M file.txt\" >expect &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'status sizes a text file by its CRLF pairs, not its CRs' '\n+\tgit init eol-status-lone-cr &&\n+\t(\n+\t\tcd eol-status-lone-cr &&\n+\t\techo \"* text eol=lf\" >.gitattributes &&\n+\t\tprintf \"one\\rtwo\\nthree\\n\" >file.txt &&\n+\t\tgit add .gitattributes file.txt &&\n+\t\tgit commit -m initial &&\n+\n+\t\t# \"git add\" keeps the lone CR and drops the others\n+\t\tprintf \"one\\rtwo\\r\\nthree\\r\\n\" >file.txt &&\n+\t\tgit status --porcelain -uno >actual &&\n+\t\ttest_must_be_empty actual &&\n+\n+\t\t# the converted size matches the blob, the content does not\n+\t\tprintf \"one\\rtwo\\nthrEE\\r\\n\" >file.txt &&\n+\t\tgit status --porcelain -uno >actual &&\n+\t\techo \" M file.txt\" >expect &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n test_done\n-- \n2.50.0.rc0.46.g7014b55638\n\n\n"},{"id":"554796","messageId":"xmqqik3668ff.fsf@gitster.g","threadId":"64776","inReplyTo":"20261012175638.3712-1-tboegi@web.de","subject":"Re: [PATCH v3/RFC 1/1] read-cache: do not trust a size change when conversion is active","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-12T19:11:16Z","receivedAt":"2026-10-12T19:11:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"tboegi@web.de writes:\n\n> From: Torsten Bögershausen <tboegi@web.de>\n>\n> \"git status\" can report a file as modified while \"git diff\" and\n> \"git add\", which both run the clean filter, agree its contents are\n> unchanged:\n>\n> \tgit init t && cd t\n> \tprintf '* text eol=lf\\n' >.gitattributes\n> \tprintf 'one\\ntwo\\nthree\\n' >file.txt\n> \tgit add . && git commit -m init\n>\n> \tprintf 'one\\r\\ntwo\\r\\nthree\\r\\n' >file.txt\n>\n> \tgit status --short      # ->  M file.txt\n> \tgit diff                # -> empty\n> \tgit add file.txt        # -> updates the index\n>\n> Note that \"clean filter\" here means the \"clean filter\" and CRLF conversion,\n> and all converting of a file in the worktree into the index.\n>\n> Problems that have been found in real live:\n\n\"in real life\"?\n\n>   Tools that rewrites unchanged files in native line endings e.g.\n>     javadoc, code generators, formatters and some editors change\n>     the size of every file it touches.\n\nThat is not just size but contents are changed, no?\n\n>   Editors that insist to replace 4 space with a TAB,\n>     even if the file is changed manually forth and back -\n\n\"back and forth\"?\n\n>     Using a clean filter that changes the TAB back into space when\n>     committing will cause the same confusion.\n\nThis also changes size as a result of changing contents.\n\n> `git status` and `git diff` disagree because ie_modified()\n> in read-cache.c concludes that a file is modified\n> as soon as the size has changed.\n\n\"when size differs, without looking at the contents\"?\n\n> Signed-off-by: Curtis Allen Smith <curtis.allen.smith@gmail.com>\n> Signed-off-by: Torsten Bögershausen <tboegi@web.de>\n\nHow is the collaboration going here, Have you taken over the series,\nor are you two working together on the topic (or I take that your\nintention to CC Curtis is to work together starting with this\nversion)?\n\nI am wondering if we want co-authored-by or similar when we lose the\nRFC status.\n\n> ---\n>  read-cache.c    | 25 ++++++++++++++++++++++++-\n>  t/t0020-crlf.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 69 insertions(+), 1 deletion(-)\n>\n> diff --git a/read-cache.c b/read-cache.c\n> index c4cf08a3a3..9aebe4c394 100644\n> --- a/read-cache.c\n> +++ b/read-cache.c\n> @@ -9,6 +9,7 @@\n>  \n>  #include \"git-compat-util.h\"\n>  #include \"config.h\"\n> +#include \"convert.h\"\n>  #include \"date.h\"\n>  #include \"diff.h\"\n>  #include \"diffcore.h\"\n> @@ -438,6 +439,27 @@ int ie_match_stat(struct index_state *istate,\n>  \treturn changed;\n>  }\n>  \n> +/*\n> + * A difference between the size of the file in the working tree and the\n> + * size recorded for it in the index proves that the contents changed\n> + * only as long as the two are byte-for-byte comparable.  That stops\n\n\"compatable\" -> \"identical\"?\n\n> + * being true as soon as the path is run through a clean filter:\n> + * rewriting a file with CRLF endings under \"text eol=lf\", for example,\n> + * changes its size in the working tree without changing the blob Git\n> + * would record for it.  For such a path the only way to tell is to read\n> + * the contents and convert them, which is what we already do when only\n> + * the mtime changed.\n> + */\n> +static int size_change_is_conclusive(struct index_state *istate,\n> +\t\t\t\t     const struct cache_entry *ce,\n> +\t\t\t\t     struct stat *st)\n> +{\n> +\tif (!S_ISREG(st->st_mode))\n> +\t\treturn 1;\n> +\n> +\treturn !would_convert_to_git(istate, ce->name);\n> +}\n\nWooo, that is surprisingly simple.  Even attribute look-up is not\nfree.  How much overhead are we adding to the case where no clean\nfilter is involved, I wonder?\n\n\n"},{"id":"554821","messageId":"xmqqqzhu2xre.fsf@gitster.g","threadId":"64776","inReplyTo":"xmqqik3668ff.fsf@gitster.g","subject":"Re: [PATCH v3/RFC 1/1] read-cache: do not trust a size change when conversion is active","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-13T01:29:57Z","receivedAt":"2026-10-13T01:29:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> tboegi@web.de writes:\n>\n>> From: Torsten Bögershausen <tboegi@web.de>\n>> ...\n>> Signed-off-by: Curtis Allen Smith <curtis.allen.smith@gmail.com>\n>> Signed-off-by: Torsten Bögershausen <tboegi@web.de>\n>\n> How is the collaboration going here, Have you taken over the series,\n> or are you two working together on the topic (or I take that your\n> intention to CC Curtis is to work together starting with this\n> version)?\n>\n> I am wondering if we want co-authored-by or similar when we lose the\n> RFC status.\n\nIf you two are collaborating outside the mailing list, that would be\nfine and I would have no reason to complain.  But such collaboration\nis invisible to others, of course, so I would like to double-check\nthat you are not unilaterally taking over the topic.  Can you\nconfirm that you are working well together, or say something\nsimilar, before we proceed to other technical points?\n\nThis is a tangent, but it is the reason why my mailer settings\ndrop into the trash all incoming Git-related messages that are\naddressed only to me without CC'ing the list.  This forces me to\nresist the temptation to collude with selected others behind\nclosed doors.\n\nThanks.\n\n"},{"id":"554826","messageId":"3b36c428-6d67-45ef-9f6f-e78da33646ac@kdbg.org","threadId":"64776","inReplyTo":"20261012175638.3712-1-tboegi@web.de","subject":"Re: [PATCH v3/RFC 1/1] read-cache: do not trust a size change when conversion is active","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2026-10-13T05:34:24Z","receivedAt":"2026-10-13T05:34:24Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 12.10.26 um 19:56 schrieb tboegi@web.de:\n> @@ -438,6 +439,27 @@ int ie_match_stat(struct index_state *istate,\n>  \treturn changed;\n>  }\n>  \n> +/*\n> + * A difference between the size of the file in the working tree and the\n> + * size recorded for it in the index proves that the contents changed\n> + * only as long as the two are byte-for-byte comparable.  That stops\n> + * being true as soon as the path is run through a clean filter:\n\nI cannot agree with this reasoning. The index is a cache of the stat\ninformation. The size recorded in the index is only used as a clue\nwhether the file was changed or not. It does *not* record the size of\nthe data that the object database holds for the blob.\n\nIf your analysis found that, after the content was `git add`-ed, the\nsize in the index is *not* identical to the size taken from the\nfilesystem, then the problem is that an incorrect size was put into the\nindex, and not that the size between the blob data in the database and\nthe filesystem's file are different (and unusable).\n\n> + * rewriting a file with CRLF endings under \"text eol=lf\", for example,\n> + * changes its size in the working tree without changing the blob Git\n> + * would record for it.  For such a path the only way to tell is to read\n> + * the contents and convert them, which is what we already do when only\n> + * the mtime changed.\n> + */\n\n-- Hannes\n\n\n"},{"id":"554827","messageId":"CACnh8r+gBPJMF6kGdzpM8guEp_UiVh_P6qpvKi8uLCx6MFFoRQ@mail.gmail.com","threadId":"64776","inReplyTo":"xmqqqzhu2xre.fsf@gitster.g","subject":"Re: [PATCH v3/RFC 1/1] read-cache: do not trust a size change when conversion is active","fromName":"Curtis Smith","fromEmail":"curtis.allen.smith@gmail.com","sentAt":"2026-10-13T06:45:45Z","receivedAt":"2026-10-13T06:45:45Z","isPatch":true,"sender":{"key":"curtis.allen.smith@gmail.com","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> If you two are collaborating outside the mailing list, that would be\n> fine and I would have no reason to complain.  But such collaboration\n> is invisible to others, of course, so I would like to double-check\n> that you are not unilaterally taking over the topic.\n\nWe are not collaborating off the list, and Torsten did not ask me\nbefore sending v3.  v3 is my v1 patch 1 with the optimization taken\nout, but it keeps the size_change_is_conclusive() helper.  In my\nreply to you on Saturday I proposed the fix inlined into the\ncondition in ie_modified() instead, with no new function.\n\nI would like to keep the topic.  v4 follows in this thread: that\ninlined fix, my tests, a short log message, and Torsten credited with\nHelped-by.  Thanks, Torsten, for the review.\n\nFrom your earlier message:\n\n> Wooo, that is surprisingly simple.  Even attribute look-up is not\n> free.  How much overhead are we adding to the case where no clean\n> filter is involved, I wonder?\n\nThe lookup is the last test in the \"changed & DATA_CHANGED\"\ncondition, so it runs only for a path whose size changed.  A clean\ntree never reaches it.  With no conversion configured, \"git status\"\non 10000 files with a size change takes 26ms on stock git and 24ms\nwith the fix.  The full numbers are below the \"---\" in v4.\n\nOn Mon, Oct 12, 2026 at 7:29 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n> > tboegi@web.de writes:\n> >\n> >> From: Torsten Bögershausen <tboegi@web.de>\n> >> ...\n> >> Signed-off-by: Curtis Allen Smith <curtis.allen.smith@gmail.com>\n> >> Signed-off-by: Torsten Bögershausen <tboegi@web.de>\n> >\n> > How is the collaboration going here, Have you taken over the series,\n> > or are you two working together on the topic (or I take that your\n> > intention to CC Curtis is to work together starting with this\n> > version)?\n> >\n> > I am wondering if we want co-authored-by or similar when we lose the\n> > RFC status.\n>\n> If you two are collaborating outside the mailing list, that would be\n> fine and I would have no reason to complain.  But such collaboration\n> is invisible to others, of course, so I would like to double-check\n> that you are not unilaterally taking over the topic.  Can you\n> confirm that you are working well together, or say something\n> similar, before we proceed to other technical points?\n>\n> This is a tangent, but it is the reason why my mailer settings\n> drop into the trash all incoming Git-related messages that are\n> addressed only to me without CC'ing the list.  This forces me to\n> resist the temptation to collude with selected others behind\n> closed doors.\n>\n> Thanks.\n\n"},{"id":"554828","messageId":"CACnh8r+=nRvCbJYj7=M9BiK=ac94xLOVPhcKbPNpjnfr50U_ZA@mail.gmail.com","threadId":"64776","inReplyTo":"3b36c428-6d67-45ef-9f6f-e78da33646ac@kdbg.org","subject":"Re: [PATCH v3/RFC 1/1] read-cache: do not trust a size change when conversion is active","fromName":"Curtis Smith","fromEmail":"curtis.allen.smith@gmail.com","sentAt":"2026-10-13T06:48:22Z","receivedAt":"2026-10-13T06:48:22Z","isPatch":true,"sender":{"key":"curtis.allen.smith@gmail.com","avatar":null},"body":"Johannes Sixt <j6t@kdbg.org> writes:\n\n> I cannot agree with this reasoning. The index is a cache of the stat\n> information. The size recorded in the index is only used as a clue\n> whether the file was changed or not. It does *not* record the size of\n> the data that the object database holds for the blob.\n\nAgreed, and that comment is worded badly.  The size in the index is\ncorrect here: it is the size of the LF file as it was checked out or\nadded.  The tool then rewrites the file with CRLF endings, so the\nsize on disk really does change.\n\nThe problem is what ie_modified() concludes from that.  A size change\nproves that the bytes in the working tree changed.  Without\nconversion, that means the content Git would record changed too.\nWith conversion it does not: the CRLF file converts to the same\nblob, which is why \"git diff\" shows nothing.\n\nv4 has no such comment, and its log message says it this way.\n\nOn Mon, Oct 12, 2026 at 11:34 PM Johannes Sixt <j6t@kdbg.org> wrote:\n>\n> Am 12.10.26 um 19:56 schrieb tboegi@web.de:\n> > @@ -438,6 +439,27 @@ int ie_match_stat(struct index_state *istate,\n> >       return changed;\n> >  }\n> >\n> > +/*\n> > + * A difference between the size of the file in the working tree and the\n> > + * size recorded for it in the index proves that the contents changed\n> > + * only as long as the two are byte-for-byte comparable.  That stops\n> > + * being true as soon as the path is run through a clean filter:\n>\n> I cannot agree with this reasoning. The index is a cache of the stat\n> information. The size recorded in the index is only used as a clue\n> whether the file was changed or not. It does *not* record the size of\n> the data that the object database holds for the blob.\n>\n> If your analysis found that, after the content was `git add`-ed, the\n> size in the index is *not* identical to the size taken from the\n> filesystem, then the problem is that an incorrect size was put into the\n> index, and not that the size between the blob data in the database and\n> the filesystem's file are different (and unusable).\n>\n> > + * rewriting a file with CRLF endings under \"text eol=lf\", for example,\n> > + * changes its size in the working tree without changing the blob Git\n> > + * would record for it.  For such a path the only way to tell is to read\n> > + * the contents and convert them, which is what we already do when only\n> > + * the mtime changed.\n> > + */\n>\n> -- Hannes\n>\n\n"},{"id":"554829","messageId":"20261013065915.879-1-curtis.allen.smith@gmail.com","threadId":"64776","inReplyTo":"20261012175638.3712-1-tboegi@web.de","subject":"[PATCH v4] read-cache: do not trust a size change when conversion is active","fromName":"Curtis Allen Smith","fromEmail":"curtis.allen.smith@gmail.com","sentAt":"2026-10-13T06:58:28Z","receivedAt":"2026-10-13T06:58:28Z","isPatch":true,"sender":{"key":"curtis.allen.smith@gmail.com","avatar":null},"body":"\"git status\" can report a file as modified while \"git diff\" and\n\"git add\" agree that its contents are unchanged:\n\n\tgit init t && cd t\n\tprintf '* text eol=lf\\n' >.gitattributes\n\tprintf 'one\\ntwo\\nthree\\n' >file.txt\n\tgit add . && git commit -m init\n\n\tprintf 'one\\r\\ntwo\\r\\nthree\\r\\n' >file.txt\n\n\tgit status --short      # ->  M file.txt\n\tgit diff                # -> empty\n\tgit add file.txt        # -> nothing to commit\n\nie_modified() takes a change in the file's size since the index\nentry was last refreshed as proof that the file is modified, without\nlooking at the contents.  A size change proves only that the bytes in\nthe working tree changed.  When the path is subject to conversion\n(the \"text\" and \"eol\" attributes, core.autocrlf, a clean filter),\ndifferent bytes can convert to the same blob, as the CRLF rewrite\nabove does.\n\nFor such a path, fall through to ce_modified_check_fs(), as is\nalready done when only the mtime changed.  Paths without conversion\nreturn early as before.\n\nHelped-by: Torsten Bögershausen <tboegi@web.de>\nSigned-off-by: Curtis Allen Smith <curtis.allen.smith@gmail.com>\n---\nChanges since v3:\n - The fix is inlined into the condition in ie_modified(), with no\n   helper function.\n - Shorter log message, using Junio's wording; the \"real life\"\n   examples are gone.\n\nCost, i9-14900K under WSL2, warm cache, fastest of 5 runs of\n\"git status -uno\", stock 6de20f6 against this patch:\n\n\t10000 files x 2.6 KB, no conversion       stock      v4\n\t  clean tree                               5 ms     5 ms\n\t  10000 files with a size change          26 ms    24 ms\n\n\t10000 files x 2.6 KB, \"* text=auto eol=lf\"\n\t  clean tree                               5 ms     5 ms\n\t  10000 genuinely modified                25 ms   137 ms\n\t  10000 CRLF-rewritten, 1st run           21 ms   143 ms\n\t  the same, every run after               21 ms     5 ms\n\n\t200 files x 1 MB, \"* text=auto eol=lf\"\n\t  clean tree                               3 ms     3 ms\n\t  200 genuinely modified                   3 ms   498 ms\n\t  200 CRLF-rewritten, 1st run              3 ms   584 ms\n\t  the same, every run after                3 ms     3 ms\n\nThe attribute lookup happens only for a path whose size changed, so a\nclean tree pays nothing, and a tree without conversion pays one\nlookup per size-changed path (the first block).  A converted path\nwhose size changed is now read, converted and hashed, which is what\nalready happens when only its mtime changes.  Stock git keeps\nreporting the CRLF-rewritten files as modified on every run.\n\nA follow-up that skips the conversion and the hash when the length\nalready rules out a match is ready if wanted.  It takes the\n\"genuinely modified\" rows to 57 ms and 25 ms.\n\n read-cache.c    |  4 +++-\n t/t0020-crlf.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 48 insertions(+), 1 deletion(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex c4cf08a3a..70f4787de 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -9,6 +9,7 @@\n \n #include \"git-compat-util.h\"\n #include \"config.h\"\n+#include \"convert.h\"\n #include \"date.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n@@ -480,7 +481,8 @@ int ie_modified(struct index_state *istate,\n \t     */\n \t    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&\n #endif\n-\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0))\n+\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0) &&\n+\t    !(S_ISREG(st->st_mode) && would_convert_to_git(istate, ce->name)))\n \t\treturn changed;\n \n \tchanged_fs = ce_modified_check_fs(istate, ce, st);\ndiff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh\nindex fd1cae09e..b76c678ce 100755\n--- a/t/t0020-crlf.sh\n+++ b/t/t0020-crlf.sh\n@@ -397,4 +397,49 @@ test_expect_success 'New CRLF file gets LF in repo' '\n \ttest_cmp alllf alllf2\n '\n \n+test_expect_success 'status does not report a CRLF-only rewrite as modified' '\n+\tgit init eol-status &&\n+\t(\n+\t\tcd eol-status &&\n+\t\techo \"* text eol=lf\" >.gitattributes &&\n+\t\tprintf \"one\\ntwo\\nthree\\n\" >file.txt &&\n+\t\tgit add .gitattributes file.txt &&\n+\t\tgit commit -m initial &&\n+\n+\t\t# a generator rewrites the file with CRLF, same content\n+\t\tprintf \"one\\r\\ntwo\\r\\nthree\\r\\n\" >file.txt &&\n+\t\tgit status --porcelain -uno >actual &&\n+\t\ttest_must_be_empty actual &&\n+\t\tgit diff --exit-code &&\n+\n+\t\t# a real change is still reported\n+\t\tprintf \"one\\r\\ntwo\\r\\nfour\\r\\n\" >file.txt &&\n+\t\tgit status --porcelain -uno >actual &&\n+\t\techo \" M file.txt\" >expect &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'status sees through a CRLF rewrite of a file with a lone CR' '\n+\tgit init eol-status-lone-cr &&\n+\t(\n+\t\tcd eol-status-lone-cr &&\n+\t\techo \"* text eol=lf\" >.gitattributes &&\n+\t\tprintf \"one\\rtwo\\nthree\\n\" >file.txt &&\n+\t\tgit add .gitattributes file.txt &&\n+\t\tgit commit -m initial &&\n+\n+\t\t# \"git add\" keeps the lone CR and drops the others\n+\t\tprintf \"one\\rtwo\\r\\nthree\\r\\n\" >file.txt &&\n+\t\tgit status --porcelain -uno >actual &&\n+\t\ttest_must_be_empty actual &&\n+\n+\t\t# the converted length matches the blob, the content does not\n+\t\tprintf \"one\\rtwo\\nthrEE\\r\\n\" >file.txt &&\n+\t\tgit status --porcelain -uno >actual &&\n+\t\techo \" M file.txt\" >expect &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n test_done\n-- \n2.53.0\n\n\n"},{"id":"554840","messageId":"ede6ef41-df6f-4912-be31-1c4a5c0a550e@gmail.com","threadId":"64776","inReplyTo":"20261013065915.879-1-curtis.allen.smith@gmail.com","subject":"Re: [PATCH v4] read-cache: do not trust a size change when conversion is active","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2026-10-13T09:44:05Z","receivedAt":"2026-10-13T09:44:05Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Curtis\n\nOn 13/10/2026 07:58, Curtis Allen Smith wrote:\n> \"git status\" can report a file as modified while \"git diff\" and\n> \"git add\" agree that its contents are unchanged:\n> > \tgit init t && cd t\n> \tprintf '* text eol=lf\\n' >.gitattributes\n> \tprintf 'one\\ntwo\\nthree\\n' >file.txt\n> \tgit add . && git commit -m init\n> > \tprintf 'one\\r\\ntwo\\r\\nthree\\r\\n' >file.txt\n> > \tgit status --short      # ->  M file.txt\n> \tgit diff                # -> empty\n> \tgit add file.txt        # -> nothing to commit\n> > ie_modified() takes a change in the file's size since the index\n> entry was last refreshed as proof that the file is modified, without\n> looking at the contents.  A size change proves only that the bytes in\n> the working tree changed.  When the path is subject to conversion\n> (the \"text\" and \"eol\" attributes, core.autocrlf, a clean filter),\n> different bytes can convert to the same blob, as the CRLF rewrite\n> above does.\n> > For such a path, fall through to ce_modified_check_fs(), as is\n> already done when only the mtime changed.  Paths without conversion\n> return early as before.\n\nThe commit message talks about \"git status\" but presumably this change affects the output of \"git diff-files\" and \"git diff-index\" as well. Does this change improve the performance of \"git diff\" because it no-longer tries to diff two blobs that are identical after conversion or is the existing implementation smart enough to avoid that already?\n\n> A follow-up that skips the conversion and the hash when the length\n> already rules out a match is ready if wanted.  It takes the\n> \"genuinely modified\" rows to 57 ms and 25 ms.\n\nWhat does that entail? A file that consists of blank lines can double or halve its length going from '\\n' to '\\r\\n' and vice-versa. Is that range narrow enough to avoid converting a significant number of \"real\" changes?\n\nLooking at t0020-crlf.sh none of the existing tests use a separate repository, so maybe we could avoid that overhead here as well.\n\nThanks\n\nPhillip\n\n>   read-cache.c    |  4 +++-\n>   t/t0020-crlf.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++\n>   2 files changed, 48 insertions(+), 1 deletion(-)\n> > diff --git a/read-cache.c b/read-cache.c\n> index c4cf08a3a..70f4787de 100644\n> --- a/read-cache.c\n> +++ b/read-cache.c\n> @@ -9,6 +9,7 @@\n>   >   #include \"git-compat-util.h\"\n>   #include \"config.h\"\n> +#include \"convert.h\"\n>   #include \"date.h\"\n>   #include \"diff.h\"\n>   #include \"diffcore.h\"\n> @@ -480,7 +481,8 @@ int ie_modified(struct index_state *istate,\n>   \t     */\n>   \t    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&\n>   #endif\n> -\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0))\n> +\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0) &&\n> +\t    !(S_ISREG(st->st_mode) && would_convert_to_git(istate, ce->name)))\n>   \t\treturn changed;\n>   >   \tchanged_fs = ce_modified_check_fs(istate, ce, st);\n> diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh\n> index fd1cae09e..b76c678ce 100755\n> --- a/t/t0020-crlf.sh\n> +++ b/t/t0020-crlf.sh\n> @@ -397,4 +397,49 @@ test_expect_success 'New CRLF file gets LF in repo' '\n>   \ttest_cmp alllf alllf2\n>   '\n>   > +test_expect_success 'status does not report a CRLF-only rewrite as modified' '\n> +\tgit init eol-status &&\n> +\t(\n> +\t\tcd eol-status &&\n> +\t\techo \"* text eol=lf\" >.gitattributes &&\n> +\t\tprintf \"one\\ntwo\\nthree\\n\" >file.txt &&\n> +\t\tgit add .gitattributes file.txt &&\n> +\t\tgit commit -m initial &&\n> +\n> +\t\t# a generator rewrites the file with CRLF, same content\n> +\t\tprintf \"one\\r\\ntwo\\r\\nthree\\r\\n\" >file.txt &&\n> +\t\tgit status --porcelain -uno >actual &&\n> +\t\ttest_must_be_empty actual &&\n> +\t\tgit diff --exit-code &&\n> +\n> +\t\t# a real change is still reported\n> +\t\tprintf \"one\\r\\ntwo\\r\\nfour\\r\\n\" >file.txt &&\n> +\t\tgit status --porcelain -uno >actual &&\n> +\t\techo \" M file.txt\" >expect &&\n> +\t\ttest_cmp expect actual\n> +\t)\n> +'\n> +\n> +test_expect_success 'status sees through a CRLF rewrite of a file with a lone CR' '\n> +\tgit init eol-status-lone-cr &&\n> +\t(\n> +\t\tcd eol-status-lone-cr &&\n> +\t\techo \"* text eol=lf\" >.gitattributes &&\n> +\t\tprintf \"one\\rtwo\\nthree\\n\" >file.txt &&\n> +\t\tgit add .gitattributes file.txt &&\n> +\t\tgit commit -m initial &&\n> +\n> +\t\t# \"git add\" keeps the lone CR and drops the others\n> +\t\tprintf \"one\\rtwo\\r\\nthree\\r\\n\" >file.txt &&\n> +\t\tgit status --porcelain -uno >actual &&\n> +\t\ttest_must_be_empty actual &&\n> +\n> +\t\t# the converted length matches the blob, the content does not\n> +\t\tprintf \"one\\rtwo\\nthrEE\\r\\n\" >file.txt &&\n> +\t\tgit status --porcelain -uno >actual &&\n> +\t\techo \" M file.txt\" >expect &&\n> +\t\ttest_cmp expect actual\n> +\t)\n> +'\n> +\n>   test_done\n\n\n"},{"id":"554889","messageId":"CACnh8rL8gzJ24O905Es=6-TLhfP7ufVnpeREs0vvtBYPawWuOw@mail.gmail.com","threadId":"64776","inReplyTo":"ede6ef41-df6f-4912-be31-1c4a5c0a550e@gmail.com","subject":"Re: [PATCH v4] read-cache: do not trust a size change when conversion is active","fromName":"Curtis Smith","fromEmail":"curtis.allen.smith@gmail.com","sentAt":"2026-10-13T17:57:13Z","receivedAt":"2026-10-13T17:57:13Z","isPatch":true,"sender":{"key":"curtis.allen.smith@gmail.com","avatar":null},"body":"Hi Phillip,\n\nThanks for looking at this.\n\nOn 13/10/2026, Phillip Wood wrote:\n> The commit message talks about \"git status\" but presumably this change\n> affects the output of \"git diff-files\" and \"git diff-index\" as well.\n\nYou are right that the message is too narrow, though the mechanism is\nnot quite that.  ie_modified() is reached from refresh_cache_ent(),\nand from ls-files, mv and submodule.c; that is all four callers.\nrun_diff_files() and run_diff_index() go through\nmatch_stat_with_submodule(), which calls ie_match_stat() and never\nie_modified().  So diff-files and diff-index are not changed directly.\n\nWhat changes is the index refresh.  Stock git can never clear the\nstat-dirty mark on such a path: refresh_cache_ent() calls\nie_modified(), ie_modified() returns early on the size change, and the\nentry is left alone, so the next refresh repeats the whole thing.\nWith the patch the refresh resolves the path and writes the new stat\ndata, and everything downstream of a refreshed index settles.  On the\nexample in the commit message, stock 6de20f6 against the patch:\n\n                                      stock              patched\n  git update-index --refresh          exit 1,            exit 0,\n                                      \"file.txt:         no output\n                                       needs update\"\n  git ls-files -m (after a refresh)   file.txt           no output\n  git status --porcelain -uno          M file.txt        no output\n  git diff-files --name-only          file.txt           file.txt\n  git diff-files --name-only,\n    after anything that refreshes\n    and writes the index              file.txt           no output\n  git diff-index --name-only HEAD,\n    likewise                          file.txt           no output\n\n\"git diff\" is one of the commands that refreshes, so in practice a\nsecond \"git diff-files\" in the same tree does change.\n\nSo the plumbing answer is: diff-files run against an unrefreshed index\nis unchanged, and that is correct, since its contract is to report\nwhat differs by stat.  But stock git leaves these paths permanently\nstat-dirty, so the report never settles no matter how many times you\nrefresh.  The patch is what lets it settle.  \"git update-index\n--refresh\", which is the usual way a script asks \"is the working tree\nclean\", is the plainest case: today it fails on a file that git itself\nagrees is unmodified.\n\nThe visible cost of that is in the commands that refresh the index\nbefore they will run.  require_clean_work_tree() calls\nrefresh_index(), so with one CRLF-rewritten file in the tree, stock\ngit refuses:\n\n    $ git rebase HEAD~1\n    error: cannot rebase: You have unstaged changes.\n    error: Please commit or stash them.\n\nand then will not let you take its advice:\n\n    $ git add file.txt && git commit -m x\n    On branch master\n    nothing to commit, working tree clean\n\nThe \"git add\" repairs the stat data as a side effect, so a second\n\"git rebase\" does work; there is just no way for the user to know\nthat.  With the patch the first one runs.  \"git pull --rebase\"\nwithout --autostash is the same, since it calls\nrequire_clean_work_tree() as well.  A merging \"git pull\" does not,\nand is unaffected.\n\n> Does this change improve the performance of \"git diff\" because it\n> no-longer tries to diff two blobs that are identical after conversion\n> or is the existing implementation smart enough to avoid that already?\n\nNot for a single \"git diff\": diff-files flags the path on the stat\ndifference, the diff machinery reads the file, converts it, finds the\nresult identical to the blob and emits nothing.  That read and\nconversion is the only way to know, and it happens in stock git today.\nThe patch neither adds nor removes it.\n\nThe saving is on the runs after the first.  Once a refresh has\nrecorded the stat data, the path matches on stat and is never opened\nagain.  Stock git reads and converts it on every single run, forever.\nThat is the \"steady state\" row in the numbers below the --- in v4:\n21 ms against 5 ms for 10000 files, and it is the same effect.\n\nI will say this in the commit message.  Replacing the last paragraph:\n\n  -For such a path, fall through to ce_modified_check_fs(), as is\n  -already done when only the mtime changed.  Paths without conversion\n  -return early as before.\n  +For such a path, fall through to ce_modified_check_fs(), as is\n  +already done when only the mtime changed.  Paths without conversion\n  +return early as before.\n  +\n  +ie_modified() runs when the index is refreshed, so this reaches\n  +every command that refreshes it: \"git update-index --refresh\" now\n  +succeeds instead of reporting \"needs update\", \"git ls-files -m\"\n  +and \"git status\" stop reporting the path, and \"git rebase\" and\n  +\"git pull --rebase\" no longer refuse to run.  \"git diff\" itself is\n  +unchanged; it already reads and converts the file and prints\n  +nothing.\n\nHappy to make that longer or shorter.\n\n> > A follow-up that skips the conversion and the hash when the length\n> > already rules out a match is ready if wanted.\n>\n> What does that entail? A file that consists of blank lines can double\n> or halve its length going from '\\n' to '\\r\\n' and vice-versa. Is that\n> range narrow enough to avoid converting a significant number of \"real\"\n> changes?\n\nIt is not a range test, so the blank-line file is fine.  When the\nend-of-line conversion is the only one that applies (no clean filter,\nno \"ident\", no working-tree-encoding), \"git add\" either leaves the\nfile alone or turns every CRLF into LF.  The converted length is\ntherefore exactly one of two values: the raw length, or the raw length\nminus the number of CRLF pairs.  A memchr scan for CR gets that count.\nIf neither value is the size of the blob, the file is modified, and it\nis neither converted nor hashed.  \"text=auto\" strips every CR rather\nthan CRLF pairs only, but it refuses to convert a file containing a\nlone CR, so those two values still cover it.\n\nYour example comes out right.  N blank lines is N bytes with LF and 2N\nwith CRLF.  Rewritten to CRLF the raw length is 2N and the CRLF count\nis N, so the two candidates are 2N and N.  The blob is N, that\nmatches, and the file goes on to be converted and hashed as before.\nThe length test never reports such a file as modified; it only\ndeclines to short-circuit.\n\nYour underlying question still stands, though, so let me answer it\nwith the losing cases in the table and not just the winning one.\nMeasured on an i9-14900K under WSL2, warm cache, fastest of 5 runs of\n\"git status -uno\":\n\n  10000 files x 2.6 KB, \"* text=auto eol=lf\" stock     v4  v4+opt\n    length-changing edit                     20 ms 136 ms   57 ms\n    same-length edit                        133 ms 135 ms  146 ms\n    CRLF-rewritten, 1st run                  20 ms 139 ms  160 ms\n\n  200 files x 1 MB, same attributes\n    length-changing edit                      2 ms 506 ms   24 ms\n    same-length edit                        509 ms 511 ms  516 ms\n    CRLF-rewritten, 1st run                   3 ms 605 ms  623 ms\n\nThe length-changing rows are the ones the scan decides: an edit that\nadds or removes a character cannot produce the blob's length, so the\nfile is neither converted nor hashed.\n\nTwo cases it does not help, and I would rather say so than let one\nrow speak for the patch.  The CRLF rewrite this series is about has,\nby definition, a converted length equal to the blob's size, so the\nscan there is pure overhead: 139 ms against 160 ms.  And a\nsame-length edit does not change the size at all, so it goes down the\nmtime path that stock git already walks; the scan adds about 8\npercent to a path that exists today, 133 ms against 146 ms.  Those\nrows are also the clearest evidence that the fix by itself adds\nnothing to that path: 133 ms against 135 ms.\n\nWhich brings me to whether the follow-up is wanted at all.  Those\ncorpora are deliberately extreme; they exist to make the effect\nmeasurable.  On a tree with a realistic number of modified files the\nfix does not show up:\n\n  10000 files x 2.6 KB, \"* text=auto eol=lf\" stock     v4  v4+opt\n    clean tree                                5 ms    4 ms     5 ms\n    1 file edited                             5 ms    5 ms     5 ms\n    10 files edited                           4 ms    4 ms     4 ms\n    100 files edited                          5 ms    8 ms     5 ms\n    1000 files edited                         6 ms   20 ms    10 ms\n    10000 files edited                       20 ms  136 ms    57 ms\n\n  the same tree, n files CRLF-rewritten, 1st run\n    1 file                                    6 ms    8 ms     7 ms\n    10 files                                  8 ms    8 ms     8 ms\n    100 files                                 8 ms    9 ms     9 ms\n    1000 files                                9 ms   18 ms    13 ms\n\nThe cost is proportional to the bytes in the files you actually\nchanged: roughly 12 microseconds per modified 2.6 KB file, and about\n2.5 ms per modified 1 MB file.  It takes on the order of a thousand\nmodified converted paths before it is worth measuring at all.\n\nSo I would rather leave the follow-up out for now.  Nothing in the\nfix depends on it; it is correct on its own, and this only changes\nwhat it costs.  The fix is one condition and an #include, and it is\nfree in every case anyone is likely to hit; 124 more lines to speed\nup trees far larger than the one in the bug report is a poor trade\nunless someone is actually hitting it.  If the fix's cost does bother\npeople, say so and I will send it.\n\n> Looking at t0020-crlf.sh none of the existing tests use a separate\n> repository, so maybe we could avoid that overhead here as well.\n\nAgreed, and both tests now run in t0020's own repository.  One wrinkle\nworth noting: \"* text eol=lf\" makes the existing allcrlf and mixed\nfiles modified, so the attribute is scoped to the file under test.\nBoth tests pass with the patch and fail on stock 6de20f6, as before.\n\nFor what it is worth, the overhead was not measurable: t0020 takes\n0.41s either way.  The change is for consistency with the rest of the\nfile.\n\nThat will be in v5.\n\nThanks,\nCurtis\n\n"},{"id":"554891","messageId":"20261013180116.GA26647@tb-raspi4","threadId":"64776","inReplyTo":"20261013065915.879-1-curtis.allen.smith@gmail.com","subject":"Re: [PATCH v4] read-cache: do not trust a size change when conversion is active","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2026-10-13T18:01:16Z","receivedAt":"2026-10-13T18:01:16Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On Tue, Oct 13, 2026 at 12:58:28AM -0600, Curtis Allen Smith wrote:\n\nThanks for the fast and good answers everybody.\nAs a comment: no, I didn't intend to tak over the series -\njust want to move things forward.\nAnd the Helped-By is of course ok.\n\nI don't know if we need more explanations why this change\nis needed (after so long time), but here is my undestanding:\n\nWhen we run\n\n\ngit init t && cd t\nprintf 'one\\ntwo\\nthree\\n' >file.txt\ngit add . && git commit -m init\n\nfollowed by\n\nprintf 'two\\ntwo\\nthree\\n' >file.txt\n\nthen Git will notice that the actual  mtime as a result of lstat()\nis different from what is recorded in the index.\nAs a result, git needs to re-hash the content to conclude if the\ncontent has changed.\nHowever, in order to avoid the expensive hashing,\nGit concludes that when the size of a file has changed\nthen the content -must- be different - files having a different size\nare never identical.\nThis did work well until the .gitattributes feature was introduced.\nNow, in the example below, a file having a different size -can-\nresult in the same blob once it is commited.\nTherefore this patch does need to check if attributes\n(for input conversions) are defined.\nIf not, take the shortcut and conclude that the file is modified.\nBut if, take the long way, which is what happens when only mtime\n(and possibly other elements from struct st are changed.\n\nAnd now the new size, mtime (and the rest)\nwill be recorded in the index. So it is a one-time cost.\n\nDoes this make sense ?\n\n\n> \"git status\" can report a file as modified while \"git diff\" and\n> \"git add\" agree that its contents are unchanged:\n> \n> \tgit init t && cd t\n> \tprintf '* text eol=lf\\n' >.gitattributes\n> \tprintf 'one\\ntwo\\nthree\\n' >file.txt\n> \tgit add . && git commit -m init\n> \n> \tprintf 'one\\r\\ntwo\\r\\nthree\\r\\n' >file.txt\n> \n> \tgit status --short      # ->  M file.txt\n> \tgit diff                # -> empty\n> \tgit add file.txt        # -> nothing to commit\n> \n> ie_modified() takes a change in the file's size since the index\n> entry was last refreshed as proof that the file is modified, without\n> looking at the contents.  A size change proves only that the bytes in\n> the working tree changed.  When the path is subject to conversion\n> (the \"text\" and \"eol\" attributes, core.autocrlf, a clean filter),\n> different bytes can convert to the same blob, as the CRLF rewrite\n> above does.\n> \n> For such a path, fall through to ce_modified_check_fs(), as is\n> already done when only the mtime changed.  Paths without conversion\n> return early as before.\n> \n> Helped-by: Torsten Bögershausen <tboegi@web.de>\n> Signed-off-by: Curtis Allen Smith <curtis.allen.smith@gmail.com>\n> ---\n> Changes since v3:\n>  - The fix is inlined into the condition in ie_modified(), with no\n>    helper function.\n>  - Shorter log message, using Junio's wording; the \"real life\"\n>    examples are gone.\n> \n> Cost, i9-14900K under WSL2, warm cache, fastest of 5 runs of\n> \"git status -uno\", stock 6de20f6 against this patch:\n> \n> \t10000 files x 2.6 KB, no conversion       stock      v4\n> \t  clean tree                               5 ms     5 ms\n> \t  10000 files with a size change          26 ms    24 ms\n> \n> \t10000 files x 2.6 KB, \"* text=auto eol=lf\"\n> \t  clean tree                               5 ms     5 ms\n> \t  10000 genuinely modified                25 ms   137 ms\n> \t  10000 CRLF-rewritten, 1st run           21 ms   143 ms\n> \t  the same, every run after               21 ms     5 ms\n> \n> \t200 files x 1 MB, \"* text=auto eol=lf\"\n> \t  clean tree                               3 ms     3 ms\n> \t  200 genuinely modified                   3 ms   498 ms\n> \t  200 CRLF-rewritten, 1st run              3 ms   584 ms\n> \t  the same, every run after                3 ms     3 ms\n> \n> The attribute lookup happens only for a path whose size changed, so a\n> clean tree pays nothing, and a tree without conversion pays one\n> lookup per size-changed path (the first block).  A converted path\n> whose size changed is now read, converted and hashed, which is what\n> already happens when only its mtime changes.  Stock git keeps\n> reporting the CRLF-rewritten files as modified on every run.\n> \n> A follow-up that skips the conversion and the hash when the length\n> already rules out a match is ready if wanted.  It takes the\n> \"genuinely modified\" rows to 57 ms and 25 ms.\n\n[snip]\n\n"},{"id":"554892","messageId":"20261013180206.610-1-curtis.allen.smith@gmail.com","threadId":"64776","inReplyTo":"20261013065915.879-1-curtis.allen.smith@gmail.com","subject":"[PATCH v5] read-cache: do not trust a size change when conversion is active","fromName":"Curtis Allen Smith","fromEmail":"curtis.allen.smith@gmail.com","sentAt":"2026-10-13T18:02:04Z","receivedAt":"2026-10-13T18:02:04Z","isPatch":true,"sender":{"key":"curtis.allen.smith@gmail.com","avatar":null},"body":"\"git status\" can report a file as modified while \"git diff\" and\n\"git add\" agree that its contents are unchanged:\n\n\tgit init t && cd t\n\tprintf '* text eol=lf\\n' >.gitattributes\n\tprintf 'one\\ntwo\\nthree\\n' >file.txt\n\tgit add . && git commit -m init\n\n\tprintf 'one\\r\\ntwo\\r\\nthree\\r\\n' >file.txt\n\n\tgit status --short      # ->  M file.txt\n\tgit diff                # -> empty\n\tgit add file.txt        # -> nothing to commit\n\nie_modified() takes a change in the file's size since the index\nentry was last refreshed as proof that the file is modified, without\nlooking at the contents.  A size change proves only that the bytes in\nthe working tree changed.  When the path is subject to conversion\n(the \"text\" and \"eol\" attributes, core.autocrlf, a clean filter),\ndifferent bytes can convert to the same blob, as the CRLF rewrite\nabove does.\n\nFor such a path, fall through to ce_modified_check_fs(), as is\nalready done when only the mtime changed.  Paths without conversion\nreturn early as before.\n\nie_modified() runs when the index is refreshed, so this reaches\nevery command that refreshes it: \"git update-index --refresh\" now\nsucceeds instead of reporting \"needs update\", \"git ls-files -m\" and\n\"git status\" stop reporting the path, and \"git rebase\" and\n\"git pull --rebase\" no longer refuse to run.  \"git diff\" itself is\nunchanged; it already reads and converts the file and prints\nnothing.\n\nHelped-by: Torsten Bögershausen <tboegi@web.de>\nSigned-off-by: Curtis Allen Smith <curtis.allen.smith@gmail.com>\n---\nChanges since v4:\n - The two t0020 tests run in the test script's own repository rather\n   than creating one; the attribute is scoped to the file under test\n   so the existing allcrlf and mixed files are untouched.\n - The log message says which commands the index refresh reaches.\n\nCost, i9-14900K under WSL2, warm cache, fastest of 5 runs of\n\"git status -uno\" (the first-run rows, of 3), stock 6de20f6 against\nthis patch:\n\n\t10000 files x 2.6 KB, \"* text=auto eol=lf\" stock      v5\n\t  clean tree                                5 ms     5 ms\n\t  10 files edited                           5 ms     5 ms\n\t  100 files edited                          5 ms     7 ms\n\t  1000 files edited                         6 ms    20 ms\n\t  10000 files edited                       23 ms   138 ms\n\t  10000 same-length edits                 138 ms   133 ms\n\t  10000 CRLF-rewritten, 1st run            22 ms   114 ms\n\t    the same, every run after              21 ms     5 ms\n\n\t200 files x 1 MB, same attributes\n\t  clean tree                                3 ms     2 ms\n\t  200 files edited                          3 ms   514 ms\n\t  200 same-length edits                   523 ms   513 ms\n\t  200 CRLF-rewritten, 1st run               3 ms   436 ms\n\t    the same, every run after               3 ms     2 ms\n\n\t10000 files x 2.6 KB, no conversion\n\t  clean tree                                5 ms     5 ms\n\t  10000 files with a size change           21 ms    22 ms\n\nThe attribute lookup is the last test in the condition, so it happens\nonly for a path whose size changed: a clean tree pays nothing, and a\ntree without conversion pays one lookup per size-changed path (the\nlast block).  What the patch adds is proportional to the bytes in the\nfiles actually changed, roughly 12 microseconds per modified 2.6 KB\nfile, so it takes on the order of a thousand modified converted paths\nbefore it is measurable at all.  The same-length rows go down the\npre-existing mtime path and are unaffected by this patch.  Stock git\nkeeps reporting the CRLF-rewritten files as modified on every run.\n\nA follow-up that skips the conversion and the hash when the length\nalready rules out a match is written and tested, but on these numbers\nI do not think it earns its size.  It is there if anyone wants it.\n read-cache.c    |  4 +++-\n t/t0020-crlf.sh | 39 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 42 insertions(+), 1 deletion(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex c4cf08a3a..70f4787de 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -9,6 +9,7 @@\n \n #include \"git-compat-util.h\"\n #include \"config.h\"\n+#include \"convert.h\"\n #include \"date.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n@@ -480,7 +481,8 @@ int ie_modified(struct index_state *istate,\n \t     */\n \t    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&\n #endif\n-\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0))\n+\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0) &&\n+\t    !(S_ISREG(st->st_mode) && would_convert_to_git(istate, ce->name)))\n \t\treturn changed;\n \n \tchanged_fs = ce_modified_check_fs(istate, ce, st);\ndiff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh\nindex fd1cae09e..9c8d07cfc 100755\n--- a/t/t0020-crlf.sh\n+++ b/t/t0020-crlf.sh\n@@ -397,4 +397,43 @@ test_expect_success 'New CRLF file gets LF in repo' '\n \ttest_cmp alllf alllf2\n '\n \n+test_expect_success 'status does not report a CRLF-only rewrite as modified' '\n+\ttest_when_finished \"git reset --hard autocrlf-checkpoint\" &&\n+\techo \"eol.txt text eol=lf\" >.gitattributes &&\n+\tprintf \"one\\ntwo\\nthree\\n\" >eol.txt &&\n+\tgit add .gitattributes eol.txt &&\n+\tgit commit -m \"eol.txt\" &&\n+\n+\t# a generator rewrites the file with CRLF, same content\n+\tprintf \"one\\r\\ntwo\\r\\nthree\\r\\n\" >eol.txt &&\n+\tgit status --porcelain -uno >actual &&\n+\ttest_must_be_empty actual &&\n+\tgit diff --exit-code &&\n+\n+\t# a real change is still reported\n+\tprintf \"one\\r\\ntwo\\r\\nfour\\r\\n\" >eol.txt &&\n+\tgit status --porcelain -uno >actual &&\n+\techo \" M eol.txt\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'status sees through a CRLF rewrite of a file with a lone CR' '\n+\ttest_when_finished \"git reset --hard autocrlf-checkpoint\" &&\n+\techo \"cr.txt text eol=lf\" >.gitattributes &&\n+\tprintf \"one\\rtwo\\nthree\\n\" >cr.txt &&\n+\tgit add .gitattributes cr.txt &&\n+\tgit commit -m \"cr.txt\" &&\n+\n+\t# \"git add\" keeps the lone CR and drops the others\n+\tprintf \"one\\rtwo\\r\\nthree\\r\\n\" >cr.txt &&\n+\tgit status --porcelain -uno >actual &&\n+\ttest_must_be_empty actual &&\n+\n+\t# the converted length matches the blob, the content does not\n+\tprintf \"one\\rtwo\\nthrEE\\r\\n\" >cr.txt &&\n+\tgit status --porcelain -uno >actual &&\n+\techo \" M cr.txt\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.53.0\n\n\n"},{"id":"554909","messageId":"xmqq1p9twdhh.fsf@gitster.g","threadId":"64776","inReplyTo":"20261013180206.610-1-curtis.allen.smith@gmail.com","subject":"Re: [PATCH v5] read-cache: do not trust a size change when conversion is active","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-13T20:29:46Z","receivedAt":"2026-10-13T20:29:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Curtis Allen Smith <curtis.allen.smith@gmail.com> writes:\n\n> \tgit status --short      # ->  M file.txt\n> \tgit diff                # -> empty\n> \tgit add file.txt        # -> nothing to commit\n\nI do not think \"git add\" would ever say nothing to commit.\n\n\tgit commit file.txt\n\nmay say \"nothing added to commit\" when there is no modification made\nto file.txt to indicate that there is no change worth comitting.\n\nThere are code paths that make performance trade-offs (see the\nintroductory part of Documentation/technical/racy-git.adoc for\nexamples) and are designed to tolerate false positives from\nie_modified(), filtering them out themselves.  I am somewhat\nhesitant to butcher code paths at this low level to make\nunconditional changes that reduce false positives without thinking\nthings through.  For example, we may want to disable this new code\nwhen the 'CE_MATCH_RACY_IS_DIRTY' bit is set.  But the goal\nnevertheless should be to avoid surfacing these false positives,\nwhich are deliberately allowed as performance trade-offs, to code\npaths like 'git status' that do not further filter them out (as you\ndemonstrated above).\n\nThere may be other cases where this patch unknowingly breaks\ncarefully made performance trade-offs.\n\n> diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh\n> index fd1cae09e..9c8d07cfc 100755\n> --- a/t/t0020-crlf.sh\n> +++ b/t/t0020-crlf.sh\n> @@ -397,4 +397,43 @@ test_expect_success 'New CRLF file gets LF in repo' '\n>  \ttest_cmp alllf alllf2\n>  '\n>  \n> +test_expect_success 'status does not report a CRLF-only rewrite as modified' '\n> +\ttest_when_finished \"git reset --hard autocrlf-checkpoint\" &&\n> +\techo \"eol.txt text eol=lf\" >.gitattributes &&\n> +\tprintf \"one\\ntwo\\nthree\\n\" >eol.txt &&\n> +\tgit add .gitattributes eol.txt &&\n> +\tgit commit -m \"eol.txt\" &&\n> +\n> +\t# a generator rewrites the file with CRLF, same content\n> +\tprintf \"one\\r\\ntwo\\r\\nthree\\r\\n\" >eol.txt &&\n> +\tgit status --porcelain -uno >actual &&\n> +\ttest_must_be_empty actual &&\n> +\tgit diff --exit-code &&\n> +\n> +\t# a real change is still reported\n> +\tprintf \"one\\r\\ntwo\\r\\nfour\\r\\n\" >eol.txt &&\n> +\tgit status --porcelain -uno >actual &&\n> +\techo \" M eol.txt\" >expect &&\n> +\ttest_cmp expect actual\n> +'\n>\n> +test_expect_success 'status sees through a CRLF rewrite of a file with a lone CR' '\n> +\ttest_when_finished \"git reset --hard autocrlf-checkpoint\" &&\n> +\techo \"cr.txt text eol=lf\" >.gitattributes &&\n> +\tprintf \"one\\rtwo\\nthree\\n\" >cr.txt &&\n> +\tgit add .gitattributes cr.txt &&\n> +\tgit commit -m \"cr.txt\" &&\n> +\n> +\t# \"git add\" keeps the lone CR and drops the others\n> +\tprintf \"one\\rtwo\\r\\nthree\\r\\n\" >cr.txt &&\n> +\tgit status --porcelain -uno >actual &&\n> +\ttest_must_be_empty actual &&\n> +\n> +\t# the converted length matches the blob, the content does not\n> +\tprintf \"one\\rtwo\\nthrEE\\r\\n\" >cr.txt &&\n> +\tgit status --porcelain -uno >actual &&\n> +\techo \" M cr.txt\" >expect &&\n> +\ttest_cmp expect actual\n> +'\n\nTests like these may run fast enough to trigger \"oops, we may be in\nthe racy-git situation so make the comparison differently from the\nnormal code paths (usually spends extra cycles to compare the\ncontents)\", which may hide existing problems, so these tests need to\nbe extra careful.\n\n> +\n>  test_done\n\nThanks.\n\n"},{"id":"555345","messageId":"20261018111851.GA27528@tb-raspi4","threadId":"64776","inReplyTo":"xmqq1p9twdhh.fsf@gitster.g","subject":"Re: [PATCH v5] read-cache: do not trust a size change when conversion is active","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2026-10-18T11:18:51Z","receivedAt":"2026-10-18T11:18:51Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On Tue, Oct 13, 2026 at 01:29:46PM -0700, Junio C Hamano wrote:\n> Curtis Allen Smith <curtis.allen.smith@gmail.com> writes:\n> \n> > \tgit status --short      # ->  M file.txt\n> > \tgit diff                # -> empty\n> > \tgit add file.txt        # -> nothing to commit\n> \n> I do not think \"git add\" would ever say nothing to commit.\n> \n> \tgit commit file.txt\n> \n> may say \"nothing added to commit\" when there is no modification made\n> to file.txt to indicate that there is no change worth comitting.\n> \n> There are code paths that make performance trade-offs (see the\n> introductory part of Documentation/technical/racy-git.adoc for\n> examples) and are designed to tolerate false positives from\n> ie_modified(), filtering them out themselves.  I am somewhat\n> hesitant to butcher code paths at this low level to make\n> unconditional changes that reduce false positives without thinking\n> things through.  For example, we may want to disable this new code\n> when the 'CE_MATCH_RACY_IS_DIRTY' bit is set.  But the goal\n> nevertheless should be to avoid surfacing these false positives,\n> which are deliberately allowed as performance trade-offs, to code\n> paths like 'git status' that do not further filter them out (as you\n> demonstrated above).\n> \n> There may be other cases where this patch unknowingly breaks\n> carefully made performance trade-offs.\n\n\nLooking at CE_MATCH_RACY_IS_DIRTY it seems as if the call\nto would_convert_to_git()may be better done in ie_match_stat() ?\n\n\nBeside that I was able to test it with a real live repo,\nwhere a clean filter replaces a TAB with 4 spaces: Now\ngit status no longer claims the file to be modified\n(and refuses to stash or other operations))\n\n[snip]\n\n"},{"id":"555377","messageId":"xmqqqzhm8c7e.fsf@gitster.g","threadId":"64776","inReplyTo":"20261018111851.GA27528@tb-raspi4","subject":"Re: [PATCH v5] read-cache: do not trust a size change when conversion is active","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-19T05:57:09Z","receivedAt":"2026-10-19T05:57:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Torsten Bögershausen <tboegi@web.de> writes:\n\n> Looking at CE_MATCH_RACY_IS_DIRTY it seems as if the call\n> to would_convert_to_git()may be better done in ie_match_stat() ?\n\nIt would be a better fit than the patch being discussed, even though\nI do not know if that is the best spot.\n\n> Beside that I was able to test it with a real live repo,\n> where a clean filter replaces a TAB with 4 spaces: Now\n> git status no longer claims the file to be modified\n> (and refuses to stash or other operations))\n\nThe issue I was raising in the message you are responding to was not\nabout correctness but about avoiding unnecessary cycles.\n\nIf you rip out the lstat()-based optimization altogether and rewrite\nthe code to always compare the contents, status would not say the\nfile is modified in the same case, either.  \"Now it behaves\ndifferently\" is not something we need to boast about.  Having the\ncode behave the way we want is a mere baseline requirement, and\nby v5 we hopefully have passed that point long ago.\n\n"},{"id":"555623","messageId":"20261020205644.GB6367@tb-raspi4","threadId":"64776","inReplyTo":"20261013180206.610-1-curtis.allen.smith@gmail.com","subject":"Re: [PATCH v5] read-cache: do not trust a size change when conversion is active","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2026-10-20T20:56:44Z","receivedAt":"2026-10-20T20:56:44Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On Tue, Oct 13, 2026 at 12:02:04PM -0600, Curtis Allen Smith wrote:\n[snip]\n\n> diff --git a/read-cache.c b/read-cache.c\n> index c4cf08a3a..70f4787de 100644\n> --- a/read-cache.c\n> +++ b/read-cache.c\n> @@ -9,6 +9,7 @@\n>  \n>  #include \"git-compat-util.h\"\n>  #include \"config.h\"\n> +#include \"convert.h\"\n>  #include \"date.h\"\n>  #include \"diff.h\"\n>  #include \"diffcore.h\"\n> @@ -480,7 +481,8 @@ int ie_modified(struct index_state *istate,\n>  \t     */\n>  \t    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&\n>  #endif\n> -\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0))\n> +\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0) &&\n> +\t    !(S_ISREG(st->st_mode) && would_convert_to_git(istate, ce->name)))\n>  \t\treturn changed;\n>  \n>  \tchanged_fs = ce_modified_check_fs(istate, ce, st);\n\nAfter some more code reading: I think that, if the (to be commited) content\nis unchanged and would_convert_to_git() return 0, we will do another\ncheck further down:\n\nce_modified_check_fs() will call ce_compare_data() which does the filter\ninvokation and concludes that nothing has changed.\nThe thing is that a changed file size of a regular file does not mean\nthat the filtered file has changed. And removing this shortcut\ngives the following code (with all test cases passed)\n\n\n#ifdef GIT_WINDOWS_NATIVE\n            /*                                                                                                                                     * Work around Git for Windows v2.27.0 fixing a bug where symlinks'                                                                    * target path lengths were not read at all, and instead recorded                                                                      * as 4096: now, all symlinks would appear as modified.                                                                                *                                                                                                                                     * So let's just special-case symlinks with a target path length                                                                       * (i.e. `sd_size`) of 4096 and force them to be re-checked.                                                                           */\n            (ce->ce_stat_data.sd_size != MAX_PATH) &&\n#endif\n            (S_ISGITLINK(ce->ce_mode)))\n                return changed;\n\n        changed_fs = ce_modified_check_fs(istate, ce, st);\n        if (changed_fs)\n                return changed | changed_fs;\n        return 0;\n}\n\n"},{"id":"556394","messageId":"20261026192514.15844-1-tboegi@web.de","threadId":"64776","inReplyTo":"xmqqwm1no29m.fsf@gitster.g","subject":"[PATCH/RFC 0/1] More cs/read-cache-conversion-size","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2026-10-26T19:25:14Z","receivedAt":"2026-10-26T19:25:14Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\nAdd an addition on top off\ncs/read-cache-conversion-size\nIt turns out that we can optimize even more here.\n\n\nTorsten Bögershausen (1):\n  read-cache: optimize  file size change when conversion is active\n\n read-cache.c | 19 ++++++++-----------\n 1 file changed, 8 insertions(+), 11 deletions(-)\n\n-- \n2.53.0.154.g7c02d39fc2\n\n\n"},{"id":"556395","messageId":"20261026192519.15860-1-tboegi@web.de","threadId":"64776","inReplyTo":"xmqqwm1no29m.fsf@gitster.g","subject":"[PATCH/RFC 1/1] read-cache: optimize file size change when conversion is active","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2026-10-26T19:25:19Z","receivedAt":"2026-10-26T19:25:19Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\nCommit\n\"read-cache: do not trust a size change when conversion is active\"\n\ncorrected the case when the file size in the worktree has changed.\nInput filters may convert worktree files with different sizes into the\nsame blob.\n\nOptimize the new code:\nThe call to would_convert_to_git() can be skipped since the same check\nis done in ce_compare_data()  for regular files, which is called from\nce_modified_check_fs().\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n read-cache.c | 19 ++++++++-----------\n 1 file changed, 8 insertions(+), 11 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex 70f4787de9..3497997bda 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -9,7 +9,6 @@\n \n #include \"git-compat-util.h\"\n #include \"config.h\"\n-#include \"convert.h\"\n #include \"date.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n@@ -456,13 +455,12 @@ int ie_modified(struct index_state *istate,\n \t\treturn changed;\n \n \t/*\n-\t * Immediately after read-tree or update-index --cacheinfo,\n-\t * the length field is zero, as we have never even read the\n-\t * lstat(2) information once, and we cannot trust DATA_CHANGED\n-\t * returned by ie_match_stat() which in turn was returned by\n-\t * ce_match_stat_basic() to signal that the filesize of the\n-\t * blob changed.  We have to actually go to the filesystem to\n-\t * see if the contents match, and if so, should answer \"unchanged\".\n+\t * When the length field of a regular file is zero or changed,\n+\t * this does not necessarily mean a changed blob in the index.\n+\t * All input filters (CRLF line endings, clean filter..)\n+\t * need to be applied followed by a hash and oideq().\n+\t * This is done in ce_modified_check_fs() below,\n+\t * which calls ce_compare_data().\n \t *\n \t * The logic does not apply to gitlinks, as ce_match_stat_basic()\n \t * already has checked the actual HEAD from the filesystem in the\n@@ -479,10 +477,9 @@ int ie_modified(struct index_state *istate,\n \t     * So let's just special-case symlinks with a target path length\n \t     * (i.e. `sd_size`) of 4096 and force them to be re-checked.\n \t     */\n-\t    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&\n+\t    (ce->ce_stat_data.sd_size != MAX_PATH) &&\n #endif\n-\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0) &&\n-\t    !(S_ISREG(st->st_mode) && would_convert_to_git(istate, ce->name)))\n+\t    (S_ISGITLINK(ce->ce_mode)))\n \t\treturn changed;\n \n \tchanged_fs = ce_modified_check_fs(istate, ce, st);\n-- \n2.53.0.154.g7c02d39fc2\n\n\n"},{"id":"559549","messageId":"20261127194233.10069-1-tboegi@web.de","threadId":"64776","inReplyTo":"xmqqwm1no29m.fsf@gitster.g","subject":"[PATCH/RESEND v6 0/2] read-cache: do not trust a size change when conversion is active","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2026-11-27T19:42:33Z","receivedAt":"2026-11-27T19:42:33Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\nThis patch series was stalled, it seems.\nAs agreed in the coooking thread:\nLets try to move things forward, here comes my simplified summary:\n\nWhen `git status` is run, git runs a lstat() on all files that are\ntracked.\nWhen all relevant fields of \"struct stat\" are the same\nas recorded in the index, the file is unchanged.\n\na) If mtime is changed, git must check if the file contents give\n   the same blob (hash value) in the index.\nb) If mtime is close to mtime of the index file itself,\n   we can not trust ctime and the check is done as well (racy)\nc) And there is a \"shortcut\":\n   When a file has a different size on disk compared to what is recorded\n   in the index, it -must- have a different content.\n   However, ever since line ending conversions (CRLF -> LF) and input filters\n   had been introduced, this assumption is no longer true.\n   The file on disk must be converted\n   (into the content that the next commit will have in the next commit)\n   and re-hashed.\n   And this is what the patch series is about.\n   The short cut (different size -> different content)\n   is removed for regular files.\n   It is kept for for links, they don't undergo a conversion.\n\nPatch 1 does the basic work and adds test cases.\nPatch 2 optimizes and updates the comments in read-cache.c\n\nComments welcome.\n\nCurtis Allen Smith (1):\n  read-cache: do not trust a size change when conversion is active\n\nTorsten Bögershausen (1):\n  read-cache: optimize file size change when conversion is active\n\n read-cache.c    | 17 ++++++++---------\n t/t0020-crlf.sh | 39 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 47 insertions(+), 9 deletions(-)\n\n-- \n2.56.0.236.g7e34d8174d\n\n\n"},{"id":"559550","messageId":"20261127194241.10085-1-tboegi@web.de","threadId":"64776","inReplyTo":"xmqqwm1no29m.fsf@gitster.g","subject":"[PATCH/RESEND v6 1/2] read-cache: do not trust a size change when conversion is active","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2026-11-27T19:42:41Z","receivedAt":"2026-11-27T19:42:41Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Curtis Allen Smith <curtis.allen.smith@gmail.com>\n\n\"git status\" can report a file as modified while \"git diff\" and\n\"git add\" agree that its contents are unchanged:\n\n\tgit init t && cd t\n\tprintf '* text eol=lf\\n' >.gitattributes\n\tprintf 'one\\ntwo\\nthree\\n' >file.txt\n\tgit add . && git commit -m init\n\n\tprintf 'one\\r\\ntwo\\r\\nthree\\r\\n' >file.txt\n\n\tgit status --short      # ->  M file.txt\n\tgit diff                # -> empty\n\tgit add file.txt        # -> nothing to commit\n\nie_modified() takes a change in the file's size since the index\nentry was last refreshed as proof that the file is modified, without\nlooking at the contents.  A size change proves only that the bytes in\nthe working tree changed.  When the path is subject to conversion\n(the \"text\" and \"eol\" attributes, core.autocrlf, a clean filter),\ndifferent bytes can convert to the same blob, as the CRLF rewrite\nabove does.\n\nFor such a path, fall through to ce_modified_check_fs(), as is\nalready done when only the mtime changed.  Paths without conversion\nreturn early as before.\n\nie_modified() runs when the index is refreshed, so this reaches\nevery command that refreshes it: \"git update-index --refresh\" now\nsucceeds instead of reporting \"needs update\", \"git ls-files -m\" and\n\"git status\" stop reporting the path, and \"git rebase\" and\n\"git pull --rebase\" no longer refuse to run.  \"git diff\" itself is\nunchanged; it already reads and converts the file and prints\nnothing.\n\nHelped-by: Torsten Bögershausen <tboegi@web.de>\nSigned-off-by: Curtis Allen Smith <curtis.allen.smith@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n read-cache.c    |  4 +++-\n t/t0020-crlf.sh | 39 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 42 insertions(+), 1 deletion(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex c4cf08a3a3..70f4787de9 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -9,6 +9,7 @@\n \n #include \"git-compat-util.h\"\n #include \"config.h\"\n+#include \"convert.h\"\n #include \"date.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n@@ -480,7 +481,8 @@ int ie_modified(struct index_state *istate,\n \t     */\n \t    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&\n #endif\n-\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0))\n+\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0) &&\n+\t    !(S_ISREG(st->st_mode) && would_convert_to_git(istate, ce->name)))\n \t\treturn changed;\n \n \tchanged_fs = ce_modified_check_fs(istate, ce, st);\ndiff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh\nindex fd1cae09ed..9c8d07cfc4 100755\n--- a/t/t0020-crlf.sh\n+++ b/t/t0020-crlf.sh\n@@ -397,4 +397,43 @@ test_expect_success 'New CRLF file gets LF in repo' '\n \ttest_cmp alllf alllf2\n '\n \n+test_expect_success 'status does not report a CRLF-only rewrite as modified' '\n+\ttest_when_finished \"git reset --hard autocrlf-checkpoint\" &&\n+\techo \"eol.txt text eol=lf\" >.gitattributes &&\n+\tprintf \"one\\ntwo\\nthree\\n\" >eol.txt &&\n+\tgit add .gitattributes eol.txt &&\n+\tgit commit -m \"eol.txt\" &&\n+\n+\t# a generator rewrites the file with CRLF, same content\n+\tprintf \"one\\r\\ntwo\\r\\nthree\\r\\n\" >eol.txt &&\n+\tgit status --porcelain -uno >actual &&\n+\ttest_must_be_empty actual &&\n+\tgit diff --exit-code &&\n+\n+\t# a real change is still reported\n+\tprintf \"one\\r\\ntwo\\r\\nfour\\r\\n\" >eol.txt &&\n+\tgit status --porcelain -uno >actual &&\n+\techo \" M eol.txt\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'status sees through a CRLF rewrite of a file with a lone CR' '\n+\ttest_when_finished \"git reset --hard autocrlf-checkpoint\" &&\n+\techo \"cr.txt text eol=lf\" >.gitattributes &&\n+\tprintf \"one\\rtwo\\nthree\\n\" >cr.txt &&\n+\tgit add .gitattributes cr.txt &&\n+\tgit commit -m \"cr.txt\" &&\n+\n+\t# \"git add\" keeps the lone CR and drops the others\n+\tprintf \"one\\rtwo\\r\\nthree\\r\\n\" >cr.txt &&\n+\tgit status --porcelain -uno >actual &&\n+\ttest_must_be_empty actual &&\n+\n+\t# the converted length matches the blob, the content does not\n+\tprintf \"one\\rtwo\\nthrEE\\r\\n\" >cr.txt &&\n+\tgit status --porcelain -uno >actual &&\n+\techo \" M cr.txt\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.56.0.236.g7e34d8174d\n\n\n"},{"id":"559551","messageId":"20261127194245.10104-1-tboegi@web.de","threadId":"64776","inReplyTo":"xmqqwm1no29m.fsf@gitster.g","subject":"[PATCH/RESEND v6 2/2] read-cache: optimize file size change when conversion is active","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2026-11-27T19:42:45Z","receivedAt":"2026-11-27T19:42:45Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\nCommit\n\"read-cache: do not trust a size change when conversion is active\"\ncorrected the case when the file size in the worktree has changed.\nInput filters may convert worktree files with different sizes into the\nsame blob.\n\nOptimize the new code:\nThe call to would_convert_to_git() can be skipped since the same check\nis done in ce_compare_data()  for regular files, which is called from\nce_modified_check_fs().\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n read-cache.c | 19 ++++++++-----------\n 1 file changed, 8 insertions(+), 11 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex 70f4787de9..3497997bda 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -9,7 +9,6 @@\n \n #include \"git-compat-util.h\"\n #include \"config.h\"\n-#include \"convert.h\"\n #include \"date.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n@@ -456,13 +455,12 @@ int ie_modified(struct index_state *istate,\n \t\treturn changed;\n \n \t/*\n-\t * Immediately after read-tree or update-index --cacheinfo,\n-\t * the length field is zero, as we have never even read the\n-\t * lstat(2) information once, and we cannot trust DATA_CHANGED\n-\t * returned by ie_match_stat() which in turn was returned by\n-\t * ce_match_stat_basic() to signal that the filesize of the\n-\t * blob changed.  We have to actually go to the filesystem to\n-\t * see if the contents match, and if so, should answer \"unchanged\".\n+\t * When the length field of a regular file is zero or changed,\n+\t * this does not necessarily mean a changed blob in the index.\n+\t * All input filters (CRLF line endings, clean filter..)\n+\t * need to be applied followed by a hash and oideq().\n+\t * This is done in ce_modified_check_fs() below,\n+\t * which calls ce_compare_data().\n \t *\n \t * The logic does not apply to gitlinks, as ce_match_stat_basic()\n \t * already has checked the actual HEAD from the filesystem in the\n@@ -479,10 +477,9 @@ int ie_modified(struct index_state *istate,\n \t     * So let's just special-case symlinks with a target path length\n \t     * (i.e. `sd_size`) of 4096 and force them to be re-checked.\n \t     */\n-\t    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&\n+\t    (ce->ce_stat_data.sd_size != MAX_PATH) &&\n #endif\n-\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0) &&\n-\t    !(S_ISREG(st->st_mode) && would_convert_to_git(istate, ce->name)))\n+\t    (S_ISGITLINK(ce->ce_mode)))\n \t\treturn changed;\n \n \tchanged_fs = ce_modified_check_fs(istate, ce, st);\n-- \n2.56.0.236.g7e34d8174d\n\n\n"},{"id":"559574","messageId":"xmqq8q2dzlae.fsf@gitster.g","threadId":"64776","inReplyTo":"20261127194241.10085-1-tboegi@web.de","subject":"Re: [PATCH/RESEND v6 1/2] read-cache: do not trust a size change when conversion is active","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-28T03:28:57Z","receivedAt":"2026-11-28T03:28:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"tboegi@web.de writes:\n\n> Helped-by: Torsten Bögershausen <tboegi@web.de>\n> Signed-off-by: Curtis Allen Smith <curtis.allen.smith@gmail.com>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> Signed-off-by: Torsten Bögershausen <tboegi@web.de>\n> ---\n\nI would have pretended that the patch was relayed directly from the list\nmessage by omitting my sign-off from the list if I were you, but I\npresume that the above accurately records the chain of custody by\nstating that you did not pick up Curtis's message from the list but\npicked up the copy I queued to my tree (and later got timed out).  What\nwe see above is not wrong, but I do not know if the distinction matters.\n\n>  read-cache.c    |  4 +++-\n>  t/t0020-crlf.sh | 39 +++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 42 insertions(+), 1 deletion(-)\n>\n> diff --git a/read-cache.c b/read-cache.c\n> index c4cf08a3a3..70f4787de9 100644\n> --- a/read-cache.c\n> +++ b/read-cache.c\n> @@ -9,6 +9,7 @@\n>  \n>  #include \"git-compat-util.h\"\n>  #include \"config.h\"\n> +#include \"convert.h\"\n>  #include \"date.h\"\n>  #include \"diff.h\"\n>  #include \"diffcore.h\"\n> @@ -480,7 +481,8 @@ int ie_modified(struct index_state *istate,\n>  \t     */\n>  \t    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&\n>  #endif\n> -\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0))\n> +\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0) &&\n> +\t    !(S_ISREG(st->st_mode) && would_convert_to_git(istate, ce->name)))\n>  \t\treturn changed;\n>  \n>  \tchanged_fs = ce_modified_check_fs(istate, ce, st);\n\nKeeping this check in ie_modified() rather than ie_match_stat() is the\nright call, I think.  Because preload_index() calls ie_match_stat() from\nworker threads with CE_MATCH_RACY_IS_DIRTY, attribute lookups must not\nrun there.\n\nIn contrast, none of the callers of ie_modified() (refresh_cache_ent(),\nbuiltin/ls-files.c, builtin/mv.c, and is_staging_gitmodules_ok() in\nsubmodule.c) pass CE_MATCH_RACY_IS_DIRTY.\n\nWhen a regular file's size changes and would_convert_to_git() returns\ntrue (covering clean filters, working-tree-encoding, CRLF conversion,\nand ident), ie_modified() falls through to ce_modified_check_fs(), which\ncalls ce_compare_data() and index_fd() to convert and hash the file.  If\nthe resulting object name matches the index entry, ie_modified() returns\n0 and refresh_cache_ent() calls fill_stat_cache_info() to update the\ncached stat data, so subsequent runs match on lstat(2) alone.\n\nFiles without conversion still take the fast early return on size\nmismatch.  OK.\n\nIt might be worth adding a bit to the comment above this conditional in\nie_modified() to explain why DATA_CHANGED is ignored when conversion is\nactive on a regular file, since the existing comment only mentions a\nzero '.sd_size' after read-tree or update-index.\n\nThanks.\n\n"},{"id":"559576","messageId":"xmqqzeuty698.fsf@gitster.g","threadId":"64776","inReplyTo":"20261127194245.10104-1-tboegi@web.de","subject":"Re: [PATCH/RESEND v6 2/2] read-cache: optimize file size change when conversion is active","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-28T03:38:59Z","receivedAt":"2026-11-28T03:38:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"tboegi@web.de writes:\n\n> From: Torsten Bögershausen <tboegi@web.de>\n>\n> Commit\n> \"read-cache: do not trust a size change when conversion is active\"\n> corrected the case when the file size in the worktree has changed.\n> Input filters may convert worktree files with different sizes into the\n> same blob.\n>\n> Optimize the new code:\n> The call to would_convert_to_git() can be skipped since the same check\n> is done in ce_compare_data()  for regular files, which is called from\n> ce_modified_check_fs().\n\nThat is a new and unusual way to write a proposed commit log message for\nour project.  Is this an LLM experiment gone wrong, or something?\n\nThe claim \"the same check is done in ce_compare_data(), hence\nwould_compare_to_git() is unnecessary\" seems to be mistaken.  Unless you\nmeant to name a different function, that is.\n\n> @@ -456,13 +455,12 @@ int ie_modified(struct index_state *istate,\n>  \t\treturn changed;\n>  \n>  \t/*\n> -\t * Immediately after read-tree or update-index --cacheinfo,\n> -\t * the length field is zero, as we have never even read the\n> -\t * lstat(2) information once, and we cannot trust DATA_CHANGED\n> -\t * returned by ie_match_stat() which in turn was returned by\n> -\t * ce_match_stat_basic() to signal that the filesize of the\n> -\t * blob changed.  We have to actually go to the filesystem to\n> -\t * see if the contents match, and if so, should answer \"unchanged\".\n> +\t * When the length field of a regular file is zero or changed,\n> +\t * this does not necessarily mean a changed blob in the index.\n> +\t * All input filters (CRLF line endings, clean filter..)\n> +\t * need to be applied followed by a hash and oideq().\n> +\t * This is done in ce_modified_check_fs() below,\n> +\t * which calls ce_compare_data().\n>  \t *\n>  \t * The logic does not apply to gitlinks, as ce_match_stat_basic()\n>  \t * already has checked the actual HEAD from the filesystem in the\n> @@ -479,10 +477,9 @@ int ie_modified(struct index_state *istate,\n>  \t     * So let's just special-case symlinks with a target path length\n>  \t     * (i.e. `sd_size`) of 4096 and force them to be re-checked.\n>  \t     */\n> -\t    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&\n> +\t    (ce->ce_stat_data.sd_size != MAX_PATH) &&\n>  #endif\n> -\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0) &&\n> -\t    !(S_ISREG(st->st_mode) && would_convert_to_git(istate, ce->name)))\n> +\t    (S_ISGITLINK(ce->ce_mode)))\n>  \t\treturn changed;\n\nDoesn't this actually have the opposite effect of an optimization?  I\nsuspect that it also breaks symlink handling.\n\nFor a file without conversion active, replacing the check\n(ce->ce_stat_data.sd_size != 0) and the would_convert_to_git() check\nwith S_ISGITLINK(ce->ce_mode) disables the size-mismatch fast path\naltogether.\n\nImagine a repository with 'core.autocrlf' set to false and no attributes\nset on a regular file that grows or shrinks on disk.  Because\nS_ISGITLINK(ce->ce_mode) is false for regular files, ie_modified() no\nlonger returns changed early on DATA_CHANGED.  Instead, it falls through\nto ce_modified_check_fs(), which calls ce_compare_data() and then\nobject-file.c:index_fd().\n\nWhile ce_compare_data() opens the file and passes the file descriptor to\nindex_fd(), which does call would_convert_to_git(), it does not use that\nresult to skip reading from the file descriptor or hashing when no\nconversion applies.  Rather, index_fd() either reads or maps the file in\nindex_core() or streams every byte through hash_stream() in order to\ncompute the object name.  That is in addition to open the file descriptor\nfor the path that we already know has changed, if we paid attention to\nwhat would_convert_to_git() says.\n\nWouldn't it be a serious regression to save a cheap gitattributes lookup\non converted files at the cost of reading and hashing every\nsize-modified non-converted file on disk?\n\nOr am I misreading the code and we actually won't compare the data?\n\nRemoving !S_ISLNK(st->st_mode) and (ce->ce_stat_data.sd_size !=\nMAX_PATH) makes the conditional false for every symlink on all\nplatforms, since S_ISGITLINK(ce->ce_mode) is false for symlinks too.\nEvery size-changed symlink now falls through to ce_compare_link(), which\nruns strbuf_readlink() and reads the blob from the object database.\n\nDoesn't it make the GIT_WINDOWS_NATIVE MAX_PATH workaround dead for\nsymlinks while applying the '.sd_size != MAX_PATH' check to gitlinks\ninstead?\n\nI think [1/2] alone was probably OK (I am not as familiar with the\ndetails on that part of the code as you are, so my review is not worth\nall that much), but I do not know about this step.\n\nThanks.\n\n"},{"id":"559578","messageId":"xmqqqzg5y4v7.fsf@gitster.g","threadId":"64776","inReplyTo":"20261127194233.10069-1-tboegi@web.de","subject":"Re: [PATCH/RESEND v6 0/2] read-cache: do not trust a size change when conversion is active","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-28T04:09:00Z","receivedAt":"2026-11-28T04:09:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"tboegi@web.de writes:\n\n> From: Torsten Bögershausen <tboegi@web.de>\n>\n> This patch series was stalled, it seems.\n> As agreed in the coooking thread:\n> Lets try to move things forward, here comes my simplified summary:\n\nThanks.  These colon-at-the-end-of-line smells a bit funny.\n\nThe cover letter being a reply to an earlier discussion is good, but\ncan you make these patch messages [1/2] and [2/2] response to this cover\nletter, not the same message that the cover letter is responding to?\nOtherwise the threading is broken.\n\n\n"},{"id":"559589","messageId":"20261128073840.GA23645@tb-raspi4","threadId":"64776","inReplyTo":"xmqq8q2dzlae.fsf@gitster.g","subject":"Re: [PATCH/RESEND v6 1/2] read-cache: do not trust a size change when conversion is active","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2026-11-28T07:38:40Z","receivedAt":"2026-11-28T07:38:40Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On Fri, Nov 27, 2026 at 07:28:57PM -0800, Junio C Hamano wrote:\n> tboegi@web.de writes:\n> \n> > Helped-by: Torsten Bögershausen <tboegi@web.de>\n> > Signed-off-by: Curtis Allen Smith <curtis.allen.smith@gmail.com>\n> > Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> > Signed-off-by: Torsten Bögershausen <tboegi@web.de>\n> > ---\n> \n> I would have pretended that the patch was relayed directly from the list\n> message by omitting my sign-off from the list if I were you, but I\n> presume that the above accurately records the chain of custody by\n> stating that you did not pick up Curtis's message from the list but\n> picked up the copy I queued to my tree (and later got timed out).  What\n> we see above is not wrong, but I do not know if the distinction matters.\n> \n\nAs a side note: There was no LLM involved, just an overloaded\nHI (Human Inteligence).\nI think that I digged into the code, but the outcome was not ideal.\n\nIt looks as I will take over the patch series - as discussed earlier.\nHaving said that,\nA single patch combining the current 2 changes makes much more sense.\n\nWhile probably the resulting code is in a good shape,\nI take the challange to come up with a good commit message.\n\nThanks for the review, Junio.\n\n\n\n\n\n"},{"id":"559636","messageId":"20261129152805.758456-1-tboegi@web.de","threadId":"64776","inReplyTo":"xmqqwm1no29m.fsf@gitster.g","subject":"[PATCH v7 1/1] read-cache: do not trust a size change when conversion is active","fromName":"","fromEmail":"tboegi@web.de","sentAt":"2026-11-29T15:28:05Z","receivedAt":"2026-11-29T15:28:05Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"From: Torsten Bögershausen <tboegi@web.de>\n\n\"git status\" can report a file as modified while \"git diff\" and\n\"git add\" agree that its contents are unchanged:\n\n  git init t && cd t\n  printf '* text eol=lf\\n' >.gitattributes\n  printf 'one\\ntwo\\nthree\\n' >file.txt\n  git add . && git commit -m init\n  git ls-files --debug file.txt | grep size # size: 14 flags: 0\n\n  printf 'one\\r\\ntwo\\r\\nthree\\r\\n' >file.txt\n  git ls-files --debug file.txt | grep size # size: 14 flags: 0\n\n  git status --short      # ->  M file.txt\n  git ls-files --debug file.txt | grep size # size: 14 (*)\n\n  git diff                # -> empty\n  git add file.txt        # -> nothing to commit\n  git ls-files --debug file.txt  | grep size #  size: 17 flags: 0\n\nThe problem is that `git status` assumes that a file is modified when\nthe size on disk is different from what is recorded in the index.\n\nThis assumption was valid when Git was created in 2005.\nIt is no longer valid since core.autocrlf and the 'crlf' attributes\nhad been introduced in 2007, followed by clean and other input filters.\n\nToday different different file contents and/or file length may result\nin the same content in the index using `git add`, when all input\nconversions are run.\n(*) With this change: size: 17\n\nThis change removes the 'shortcut' in read-cache/ie_modified():\nwhen a regular file has a different size compared to what is\nrecorded in the index then the file is modified.\nWhen the path is subject to conversion\n(the \"text\" and \"eol\" attributes, core.autocrlf, a clean filter),\ndifferent bytes can convert to the same blob, as the CRLF rewrite\nabove does.\n\nNow `git update-index --refresh` succeeds instead of reporting\n\"needs update\", `git ls-files -m` and `git status`\nno longer report the file as modified.\n`git rebase` and `git pull --rebase` no longer refuse to run.\n`git diff` itself is unchanged; it already reads and converts the\nfile and prints nothing.\n\nThe analyses of the problem, the new tests in t0020-crlf.sh\nand the first versions of a fix was done by Curtis Allen Smith.\n\nHelped-by: Curtis Allen Smith <curtis.allen.smith@gmail.com>\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\nNext version of a patch - only 1 commit, achiving the final code\nin one go.\nThe commit message and comments may need improvements,\nas well as the comments. In short: A review is appreciated.\nAnd yes, there is no artifical i involved.\nAnd no, the \"racy git\" code path is not involved or changed.\n\nread-cache.c    | 26 ++++++++++++--------------\n t/t0020-crlf.sh | 39 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 51 insertions(+), 14 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex 595497d14c..2757bbb6ff 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -593,20 +593,18 @@ int ie_modified(struct index_state *istate,\n \t\treturn changed;\n \n \t/*\n-\t * Immediately after read-tree or update-index --cacheinfo,\n-\t * the length field is zero, as we have never even read the\n-\t * lstat(2) information once, and we cannot trust DATA_CHANGED\n-\t * returned by ie_match_stat() which in turn was returned by\n-\t * ce_match_stat_basic() to signal that the filesize of the\n-\t * blob changed.  We have to actually go to the filesystem to\n-\t * see if the contents match, and if so, should answer \"unchanged\".\n+\t * gitlinks do not go through any conversion, see below.\n+\t * When the size if different, the content is different.\n+\t *\n+\t * When the length field of a regular file is zero or changed,\n+\t * this does not always mean a changed blob in the index.\n+\t * All input filters (CRLF line endings, clean filter..)\n+\t * need to be applied followed by a hash and oideq().\n+\t * This is done in ce_modified_check_fs() below,\n+\t * which calls ce_compare_data().\n \t *\n-\t * The logic does not apply to gitlinks, as ce_match_stat_basic()\n-\t * already has checked the actual HEAD from the filesystem in the\n-\t * subproject.  If ie_match_stat() already said it is different,\n-\t * then we know it is.\n \t */\n-\tif ((changed & DATA_CHANGED) &&\n+\tif ((S_ISGITLINK(ce->ce_mode) &&\n #ifdef GIT_WINDOWS_NATIVE\n \t    /*\n \t     * Work around Git for Windows v2.27.0 fixing a bug where symlinks'\n@@ -616,9 +614,9 @@ int ie_modified(struct index_state *istate,\n \t     * So let's just special-case symlinks with a target path length\n \t     * (i.e. `sd_size`) of 4096 and force them to be re-checked.\n \t     */\n-\t    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&\n+\t    (ce->ce_stat_data.sd_size != MAX_PATH) &&\n #endif\n-\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0))\n+\t    (changed & DATA_CHANGED)))\n \t\treturn changed;\n \n \tchanged_fs = ce_modified_check_fs(istate, ce, st);\ndiff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh\nindex fd1cae09ed..9c8d07cfc4 100755\n--- a/t/t0020-crlf.sh\n+++ b/t/t0020-crlf.sh\n@@ -397,4 +397,43 @@ test_expect_success 'New CRLF file gets LF in repo' '\n \ttest_cmp alllf alllf2\n '\n \n+test_expect_success 'status does not report a CRLF-only rewrite as modified' '\n+\ttest_when_finished \"git reset --hard autocrlf-checkpoint\" &&\n+\techo \"eol.txt text eol=lf\" >.gitattributes &&\n+\tprintf \"one\\ntwo\\nthree\\n\" >eol.txt &&\n+\tgit add .gitattributes eol.txt &&\n+\tgit commit -m \"eol.txt\" &&\n+\n+\t# a generator rewrites the file with CRLF, same content\n+\tprintf \"one\\r\\ntwo\\r\\nthree\\r\\n\" >eol.txt &&\n+\tgit status --porcelain -uno >actual &&\n+\ttest_must_be_empty actual &&\n+\tgit diff --exit-code &&\n+\n+\t# a real change is still reported\n+\tprintf \"one\\r\\ntwo\\r\\nfour\\r\\n\" >eol.txt &&\n+\tgit status --porcelain -uno >actual &&\n+\techo \" M eol.txt\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'status sees through a CRLF rewrite of a file with a lone CR' '\n+\ttest_when_finished \"git reset --hard autocrlf-checkpoint\" &&\n+\techo \"cr.txt text eol=lf\" >.gitattributes &&\n+\tprintf \"one\\rtwo\\nthree\\n\" >cr.txt &&\n+\tgit add .gitattributes cr.txt &&\n+\tgit commit -m \"cr.txt\" &&\n+\n+\t# \"git add\" keeps the lone CR and drops the others\n+\tprintf \"one\\rtwo\\r\\nthree\\r\\n\" >cr.txt &&\n+\tgit status --porcelain -uno >actual &&\n+\ttest_must_be_empty actual &&\n+\n+\t# the converted length matches the blob, the content does not\n+\tprintf \"one\\rtwo\\nthrEE\\r\\n\" >cr.txt &&\n+\tgit status --porcelain -uno >actual &&\n+\techo \" M cr.txt\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.56.1.713.geb3bf631d6\n\n\n"},{"id":"559642","messageId":"xmqqqzg3ilci.fsf@gitster.g","threadId":"64776","inReplyTo":"20261128073840.GA23645@tb-raspi4","subject":"Re: [PATCH/RESEND v6 1/2] read-cache: do not trust a size change when conversion is active","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-29T17:44:13Z","receivedAt":"2026-11-29T17:44:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Torsten Bögershausen <tboegi@web.de> writes:\n\n> On Fri, Nov 27, 2026 at 07:28:57PM -0800, Junio C Hamano wrote:\n>> tboegi@web.de writes:\n>> \n>> > Helped-by: Torsten Bögershausen <tboegi@web.de>\n>> > Signed-off-by: Curtis Allen Smith <curtis.allen.smith@gmail.com>\n>> > Signed-off-by: Junio C Hamano <gitster@pobox.com>\n>> > Signed-off-by: Torsten Bögershausen <tboegi@web.de>\n>> > ---\n>> \n>> I would have pretended that the patch was relayed directly from the list\n>> message by omitting my sign-off from the list if I were you, but I\n>> presume that the above accurately records the chain of custody by\n>> stating that you did not pick up Curtis's message from the list but\n>> picked up the copy I queued to my tree (and later got timed out).  What\n>> we see above is not wrong, but I do not know if the distinction matters.\n>> \n>\n> As a side note: There was no LLM involved, just an overloaded\n> HI (Human Inteligence).\n\nI understand that this [1/2] step were simply relayed without rewriting\nwhat Curtis originally sent.  I did not think it was your LLM, but I do\nnot know how Cutris came up with the log message.\n\n> While probably the resulting code is in a good shape,\n> I take the challange to come up with a good commit message.\n>\n> Thanks for the review, Junio.\n\nThanks.  I may have already said, but I am reasonably happy with [1/2].\n\n"},{"id":"559652","messageId":"xmqq1p83flbg.fsf@gitster.g","threadId":"64776","inReplyTo":"20261129152805.758456-1-tboegi@web.de","subject":"Re: [PATCH v7 1/1] read-cache: do not trust a size change when conversion is active","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-29T20:13:07Z","receivedAt":"2026-11-29T20:13:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"tboegi@web.de writes:\n\n>   git status --short      # ->  M file.txt\n>   git ls-files --debug file.txt | grep size # size: 14 (*)\n>\n>   git diff                # -> empty\n>   git add file.txt        # -> nothing to commit\n\nAs pointed out earlier, 'git add' does not say \"nothing to commit\".\nRunning 'git commit file.txt' after 'git add file.txt' (or 'git\nstatus' after 'git add file.txt') is what reports \"nothing to\ncommit\".\n\n> Today different different file contents and/or file length may result\n> in the same content in the index using `git add`, when all input\n> conversions are run.\n> (*) With this change: size: 17\n\nThere is a doubled word (\"different different\"), and this log\nmessage uses markdown backticks around commands, which we tend to\navoid in plain-text commit logs.  Also, placing the \"(*)\" note\nbetween prose paragraphs breaks the flow; folding that note right\nbelow the transcript (or showing the refreshed size directly in a\nshort post-patch snippet) would read more smoothly.\n\n> This change removes the 'shortcut' in read-cache/ie_modified():\n> when a regular file has a different size compared to what is\n> recorded in the index then the file is modified.\n> When the path is subject to conversion\n> (the \"text\" and \"eol\" attributes, core.autocrlf, a clean filter),\n> different bytes can convert to the same blob, as the CRLF rewrite\n> above does.\n\nThis paragraph describes checking only paths subject to conversion,\nbut the diff itself removes the shortcut unconditionally for all\nregular files and symlinks, which may be a serious regression I\nalready pointed out in the review of [2/2] in an earlier round.\n\nIn style, the log message also uses reporting prose (\"This change\nremoves...\", \"Now ...\") instead of ending with an imperative command\ntelling the codebase what to change.\n\n> read-cache.c    | 26 ++++++++++++--------------\n>  t/t0020-crlf.sh | 39 +++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 51 insertions(+), 14 deletions(-)\n>\n> diff --git a/read-cache.c b/read-cache.c\n> index 595497d14c..2757bbb6ff 100644\n> --- a/read-cache.c\n> +++ b/read-cache.c\n> @@ -593,20 +593,18 @@ int ie_modified(struct index_state *istate,\n>  \t\treturn changed;\n>  \n>  \t/*\n> -\t * Immediately after read-tree or update-index --cacheinfo,\n> -\t * the length field is zero, as we have never even read the\n> -\t * lstat(2) information once, and we cannot trust DATA_CHANGED\n> -\t * returned by ie_match_stat() which in turn was returned by\n> -\t * ce_match_stat_basic() to signal that the filesize of the\n> -\t * blob changed.  We have to actually go to the filesystem to\n> -\t * see if the contents match, and if so, should answer \"unchanged\".\n> +\t * gitlinks do not go through any conversion, see below.\n> +\t * When the size if different, the content is different.\n\n\"if\" -> \"is\".\n\nI do not think gitlinks compare file sizes at all.\n\nIn ce_match_stat_basic(), gitlinks enter a dedicated S_IFGITLINK\nbranch that ignores '.st_size' and sets DATA_CHANGED only when\nce_compare_gitlink() detects that the subproject's HEAD differs from\nthe recorded object ID.  Keeping the original explanation for\ngitlinks and symlinks alongside the new note for converted regular\nfiles would be much clearer.\n\n> +\t *\n> +\t * When the length field of a regular file is zero or changed,\n> +\t * this does not always mean a changed blob in the index.\n> +\t * All input filters (CRLF line endings, clean filter..)\n> +\t * need to be applied followed by a hash and oideq().\n> +\t * This is done in ce_modified_check_fs() below,\n> +\t * which calls ce_compare_data().\n>  \t *\n\nThis becomes a stray empty comment line.\n\n> -\t * The logic does not apply to gitlinks, as ce_match_stat_basic()\n> -\t * already has checked the actual HEAD from the filesystem in the\n> -\t * subproject.  If ie_match_stat() already said it is different,\n> -\t * then we know it is.\n>  \t */\n\n\n> -\tif ((changed & DATA_CHANGED) &&\n> +\tif ((S_ISGITLINK(ce->ce_mode) &&\n>  #ifdef GIT_WINDOWS_NATIVE\n>  \t    /*\n>  \t     * Work around Git for Windows v2.27.0 fixing a bug where symlinks'\n> @@ -616,9 +614,9 @@ int ie_modified(struct index_state *istate,\n>  \t     * So let's just special-case symlinks with a target path length\n>  \t     * (i.e. `sd_size`) of 4096 and force them to be re-checked.\n>  \t     */\n> -\t    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&\n> +\t    (ce->ce_stat_data.sd_size != MAX_PATH) &&\n>  #endif\n> -\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0))\n> +\t    (changed & DATA_CHANGED)))\n>  \t\treturn changed;\n\nSquashing v6 1/2 and 2/2 into one commit carried forward the two bugs\nthat was already flagged against v6 [PATCH 2/2], doesn't it?\n\nKeeping the check in ie_modified() rather than ie_match_stat() is\nthe right design so that preload_index() worker threads never run\nattribute lookups, I think.\n\nBy dropping would_convert_to_git() and the non-zero check on\n'.sd_size', you remove the size-change fast path even when no\nconversion is active.  Imagine a repository has 'core.autocrlf' set\nto false (or marks a large binary file with '-text' in\n.gitattributes).  The user modifies that file so its size changes.\n\nWhen 'git status' runs refresh_index(), ie_modified() now sees that\nS_ISGITLINK() is false and unconditionally falls through to\nce_modified_check_fs(), which calls ce_compare_data() and\nindex_fd().  Although index_fd() calls would_convert_to_git() and\nnotices that there is no need for conversion, it is too late.  It\ndoes not know that it is only called to see if there is a change,\nand the fact that the caller knows that the last-known size is\ndifferent from what is on the disk, and it does not know its work to\nread (or mmap), stream, and hash the entire file is wasted.\n\nRemoving \"!S_ISLNK(st->st_mode) ||\" and using the remaining\n'.sd_size != MAX_PATH' check on S_ISGITLINK() breaks both symlinks\nand the GIT_WINDOWS_NATIVE workaround.  Because S_ISGITLINK() is\nalways false for symlinks, the Windows MAX_PATH workaround is dead\nfor symlinks and instead applies a symlink length check to gitlinks.\nMeanwhile, every size-changed symlink on all platforms now falls\nthrough to ce_compare_link(), reading the symlink target and the\nobject database blob even though symlinks never undergo input\nconversion.\n\n\n\n> diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh\n> index fd1cae09ed..9c8d07cfc4 100755\n> --- a/t/t0020-crlf.sh\n> +++ b/t/t0020-crlf.sh\n> @@ -397,4 +397,43 @@ test_expect_success 'New CRLF file gets LF in repo' '\n>  \ttest_cmp alllf alllf2\n>  '\n>  \n> +test_expect_success 'status does not report a CRLF-only rewrite as modified' '\n> +\ttest_when_finished \"git reset --hard autocrlf-checkpoint\" &&\n> +\techo \"eol.txt text eol=lf\" >.gitattributes &&\n> +\tprintf \"one\\ntwo\\nthree\\n\" >eol.txt &&\n> +\tgit add .gitattributes eol.txt &&\n> +\tgit commit -m \"eol.txt\" &&\n> +\n> +\t# a generator rewrites the file with CRLF, same content\n> +\tprintf \"one\\r\\ntwo\\r\\nthree\\r\\n\" >eol.txt &&\n> +\tgit status --porcelain -uno >actual &&\n> +\ttest_must_be_empty actual &&\n> +\tgit diff --exit-code &&\n> +\n> +\t# a real change is still reported\n> +\tprintf \"one\\r\\ntwo\\r\\nfour\\r\\n\" >eol.txt &&\n> +\tgit status --porcelain -uno >actual &&\n> +\techo \" M eol.txt\" >expect &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'status sees through a CRLF rewrite of a file with a lone CR' '\n> +\ttest_when_finished \"git reset --hard autocrlf-checkpoint\" &&\n> +\techo \"cr.txt text eol=lf\" >.gitattributes &&\n> +\tprintf \"one\\rtwo\\nthree\\n\" >cr.txt &&\n> +\tgit add .gitattributes cr.txt &&\n> +\tgit commit -m \"cr.txt\" &&\n> +\n> +\t# \"git add\" keeps the lone CR and drops the others\n> +\tprintf \"one\\rtwo\\r\\nthree\\r\\n\" >cr.txt &&\n> +\tgit status --porcelain -uno >actual &&\n> +\ttest_must_be_empty actual &&\n> +\n> +\t# the converted length matches the blob, the content does not\n> +\tprintf \"one\\rtwo\\nthrEE\\r\\n\" >cr.txt &&\n> +\tgit status --porcelain -uno >actual &&\n> +\techo \" M cr.txt\" >expect &&\n> +\ttest_cmp expect actual\n> +'\n\nBoth new tests in t/t0020-crlf.sh are nicely scoped to their own\npaths and clean up cleanly against autocrlf-checkpoint, covering\nboth the plain CRLF rewrite and the lone-CR case where converted\nsize equals the original blob size.\n\n"},{"id":"559653","messageId":"xmqqo6b7e6hf.fsf@gitster.g","threadId":"64776","inReplyTo":"20261129152805.758456-1-tboegi@web.de","subject":"Re: [PATCH v7 1/1] read-cache: do not trust a size change when conversion is active","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-29T20:18:52Z","receivedAt":"2026-11-29T20:18:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"tboegi@web.de writes:\n\n>   git status --short      # ->  M file.txt\n>   git ls-files --debug file.txt | grep size # size: 14 (*)\n>\n>   git diff                # -> empty\n>   git add file.txt        # -> nothing to commit\n\nAs pointed out earlier, 'git add' does not say \"nothing to commit\".\nRunning 'git commit file.txt' after 'git add file.txt' (or 'git\nstatus' after 'git add file.txt') is what reports \"nothing to\ncommit\".\n\n> Today different different file contents and/or file length may result\n> in the same content in the index using `git add`, when all input\n> conversions are run.\n> (*) With this change: size: 17\n\nThere is a doubled word (\"different different\"), and this log\nmessage uses Markdown backticks around commands, which we tend to\navoid in plain-text commit logs.  Also, placing the \"(*)\" note\nbetween prose paragraphs breaks the flow; folding that note right\nbelow the transcript (or showing the refreshed size directly in a\nshort post-patch snippet) would read more smoothly.\n\n> This change removes the 'shortcut' in read-cache/ie_modified():\n> when a regular file has a different size compared to what is\n> recorded in the index then the file is modified.\n> When the path is subject to conversion\n> (the \"text\" and \"eol\" attributes, core.autocrlf, a clean filter),\n> different bytes can convert to the same blob, as the CRLF rewrite\n> above does.\n\nThis paragraph describes checking only paths subject to conversion,\nbut the patch seems to remove the shortcut unconditionally for all\nregular files and symlinks, which may be a serious regression I\nalready pointed out in the review of [2/2] in an earlier round.\n\nThe proposed log message also uses reporting prose (\"This change\nremoves...\", \"Now ...\") instead of ending with an imperative command\ntelling the codebase what to change.\n\n> read-cache.c    | 26 ++++++++++++--------------\n>  t/t0020-crlf.sh | 39 +++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 51 insertions(+), 14 deletions(-)\n>\n> diff --git a/read-cache.c b/read-cache.c\n> index 595497d14c..2757bbb6ff 100644\n> --- a/read-cache.c\n> +++ b/read-cache.c\n> @@ -593,20 +593,18 @@ int ie_modified(struct index_state *istate,\n>  \t\treturn changed;\n>  \n>  \t/*\n> -\t * Immediately after read-tree or update-index --cacheinfo,\n> -\t * the length field is zero, as we have never even read the\n> -\t * lstat(2) information once, and we cannot trust DATA_CHANGED\n> -\t * returned by ie_match_stat() which in turn was returned by\n> -\t * ce_match_stat_basic() to signal that the filesize of the\n> -\t * blob changed.  We have to actually go to the filesystem to\n> -\t * see if the contents match, and if so, should answer \"unchanged\".\n> +\t * gitlinks do not go through any conversion, see below.\n> +\t * When the size if different, the content is different.\n\n\"if\" -> \"is\".\n\nI do not think gitlinks compare file sizes at all.\n\nIn ce_match_stat_basic(), gitlinks enter a dedicated S_IFGITLINK\nbranch that ignores '.st_size' and sets DATA_CHANGED only when\nce_compare_gitlink() detects that the subproject's HEAD differs from\nthe recorded object ID.  Keeping the original explanation for\ngitlinks and symlinks alongside the new note for converted regular\nfiles would be much clearer.\n\n> +\t *\n> +\t * When the length field of a regular file is zero or changed,\n> +\t * this does not always mean a changed blob in the index.\n> +\t * All input filters (CRLF line endings, clean filter..)\n> +\t * need to be applied followed by a hash and oideq().\n> +\t * This is done in ce_modified_check_fs() below,\n> +\t * which calls ce_compare_data().\n>  \t *\n\nThis becomes a stray empty comment line.\n\n> -\t * The logic does not apply to gitlinks, as ce_match_stat_basic()\n> -\t * already has checked the actual HEAD from the filesystem in the\n> -\t * subproject.  If ie_match_stat() already said it is different,\n> -\t * then we know it is.\n>  \t */\n\n\n> -\tif ((changed & DATA_CHANGED) &&\n> +\tif ((S_ISGITLINK(ce->ce_mode) &&\n>  #ifdef GIT_WINDOWS_NATIVE\n>  \t    /*\n>  \t     * Work around Git for Windows v2.27.0 fixing a bug where symlinks'\n> @@ -616,9 +614,9 @@ int ie_modified(struct index_state *istate,\n>  \t     * So let's just special-case symlinks with a target path length\n>  \t     * (i.e. `sd_size`) of 4096 and force them to be re-checked.\n>  \t     */\n> -\t    (!S_ISLNK(st->st_mode) || ce->ce_stat_data.sd_size != MAX_PATH) &&\n> +\t    (ce->ce_stat_data.sd_size != MAX_PATH) &&\n>  #endif\n> -\t    (S_ISGITLINK(ce->ce_mode) || ce->ce_stat_data.sd_size != 0))\n> +\t    (changed & DATA_CHANGED)))\n>  \t\treturn changed;\n\nSquashing v6 1/2 and 2/2 into one commit carried forward the two\nbugs that was already flagged against v6 [PATCH 2/2], didn't it?\n\nKeeping the check in ie_modified() rather than ie_match_stat() is\nthe right design so that preload_index() worker threads never run\nattribute lookups, I think.\n\nBy dropping would_convert_to_git() and the non-zero check on\n'.sd_size', you remove the size-change fast path even when no\nconversion is active.  Imagine a repository has 'core.autocrlf' set\nto false (or marks a large binary file with '-text' in\n.gitattributes).  The user modifies that file so its size changes.\n\nWhen 'git status' runs refresh_index(), ie_modified() now sees that\nS_ISGITLINK() is false and unconditionally falls through to\nce_modified_check_fs(), which calls ce_compare_data() and\nindex_fd().  Although index_fd() calls would_convert_to_git() and\nnotices that there is no need for conversion, it is too late.  It\ndoes not know that it is only called to see if there is a change, or\nthe fact that the caller knows that the last-known size is different\nfrom what is on the disk, and it does not know its work to read (or\nmmap), stream, and hash the entire file will be wasted because without\nconversion, what is on disk and what is in the index are definitely\ndifferent once we know their sizes are different.\n\nAlso, I think it breaks both symlinks and the GIT_WINDOWS_NATIVE\nworkaround to remove \"!S_ISLNK(st->st_mode) ||\" and to use the\nremaining '.sd_size != MAX_PATH' check on S_ISGITLINK().\n\nBecause S_ISGITLINK() is always false for symlinks, the Windows\nMAX_PATH workaround is dead for symlinks and instead applies a\nsymlink length check to gitlinks.  Meanwhile, every size-changed\nsymlink on all platforms now falls through to ce_compare_link(),\nreading the symlink target and the object database blob even though\nsymlinks never undergo input conversion.\n\n> diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh\n> index fd1cae09ed..9c8d07cfc4 100755\n> --- a/t/t0020-crlf.sh\n> +++ b/t/t0020-crlf.sh\n> @@ -397,4 +397,43 @@ test_expect_success 'New CRLF file gets LF in repo' '\n>  \ttest_cmp alllf alllf2\n>  '\n>  \n> +test_expect_success 'status does not report a CRLF-only rewrite as modified' '\n> +\ttest_when_finished \"git reset --hard autocrlf-checkpoint\" &&\n> +\techo \"eol.txt text eol=lf\" >.gitattributes &&\n> +\tprintf \"one\\ntwo\\nthree\\n\" >eol.txt &&\n> +\tgit add .gitattributes eol.txt &&\n> +\tgit commit -m \"eol.txt\" &&\n> +\n> +\t# a generator rewrites the file with CRLF, same content\n> +\tprintf \"one\\r\\ntwo\\r\\nthree\\r\\n\" >eol.txt &&\n> +\tgit status --porcelain -uno >actual &&\n> +\ttest_must_be_empty actual &&\n> +\tgit diff --exit-code &&\n> +\n> +\t# a real change is still reported\n> +\tprintf \"one\\r\\ntwo\\r\\nfour\\r\\n\" >eol.txt &&\n> +\tgit status --porcelain -uno >actual &&\n> +\techo \" M eol.txt\" >expect &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'status sees through a CRLF rewrite of a file with a lone CR' '\n> +\ttest_when_finished \"git reset --hard autocrlf-checkpoint\" &&\n> +\techo \"cr.txt text eol=lf\" >.gitattributes &&\n> +\tprintf \"one\\rtwo\\nthree\\n\" >cr.txt &&\n> +\tgit add .gitattributes cr.txt &&\n> +\tgit commit -m \"cr.txt\" &&\n> +\n> +\t# \"git add\" keeps the lone CR and drops the others\n> +\tprintf \"one\\rtwo\\r\\nthree\\r\\n\" >cr.txt &&\n> +\tgit status --porcelain -uno >actual &&\n> +\ttest_must_be_empty actual &&\n> +\n> +\t# the converted length matches the blob, the content does not\n> +\tprintf \"one\\rtwo\\nthrEE\\r\\n\" >cr.txt &&\n> +\tgit status --porcelain -uno >actual &&\n> +\techo \" M cr.txt\" >expect &&\n> +\ttest_cmp expect actual\n> +'\n\nBoth new tests in t/t0020-crlf.sh are nicely scoped to their own\npaths and clean up cleanly against autocrlf-checkpoint, covering\nboth the plain CRLF rewrite and the lone-CR case where converted\nsize equals the original blob size.\n\n"},{"id":"559654","messageId":"xmqqh5gze245.fsf@gitster.g","threadId":"64776","inReplyTo":"xmqq1p83flbg.fsf@gitster.g","subject":"Re: [PATCH v7 1/1] read-cache: do not trust a size change when conversion is active","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-29T21:53:14Z","receivedAt":"2026-11-29T21:53:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> This paragraph describes checking only paths subject to conversion,\n> but the diff itself removes the shortcut unconditionally for all\n> ...\n\nSorry for a doubled message.  This one was sent by mistake before\ncompleting proofreading.  Please ignore.\n\n\n"},{"id":"559658","messageId":"20261129220550.GA7899@tb-raspi4","threadId":"64776","inReplyTo":"xmqqo6b7e6hf.fsf@gitster.g","subject":"Re: [PATCH v7 1/1] read-cache: do not trust a size change when conversion is active","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2026-11-29T22:05:50Z","receivedAt":"2026-11-29T22:05:50Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On Sun, Nov 29, 2026 at 12:18:52PM -0800, Junio C Hamano wrote:\n> tboegi@web.de writes:\n[]\n\nAfter re-re-reading everything:\nI think that it is best to ignore the v7 completely.\n\nAnd please drop 2/2 from v6 as well, this one:\ncommit bfe0ed02a57e9691927377509df6371cfe7f0713\n  Author: Torsten Bögershausen <tboegi@web.de>\n  Date:   Fri Nov 27 20:42:45 2026 +0100\n\nThe only thing we need is this one.\nPlease correct me, if I am wrong:\n  commit ad71f84572aa21e58abcc089c9794ad2034abe80\n  Author: Curtis Allen Smith <curtis.allen.smith@gmail.com>\n  Date:   Fri Nov 27 20:42:41 2026 +0100\n\nAnd sorry for the noise.\n\n"},{"id":"559659","messageId":"xmqqse0jcmr3.fsf@gitster.g","threadId":"64776","inReplyTo":"20261129220550.GA7899@tb-raspi4","subject":"Re: [PATCH v7 1/1] read-cache: do not trust a size change when conversion is active","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-29T22:10:24Z","receivedAt":"2026-11-29T22:10:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Torsten Bögershausen <tboegi@web.de> writes:\n\n> The only thing we need is this one.\n> Please correct me, if I am wrong:\n>   commit ad71f84572aa21e58abcc089c9794ad2034abe80\n>   Author: Curtis Allen Smith <curtis.allen.smith@gmail.com>\n>   Date:   Fri Nov 27 20:42:41 2026 +0100\n\nThanks.  I think that is the best way forward, and matches the\nmaterial I am preparing to push out.\n\n\n"}]}