{"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-01-12T16:26:02Z","messageCount":5,"participants":["tboegi@web.de","Junio C Hamano"],"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"}]}