{"thread":{"id":"65428","subject":"[PATCH] mingw: use strftime() directly in UCRT builds","startedAt":"2026-04-03T09:56:25Z","lastAt":"2026-04-03T09:56:25Z","messageCount":1,"participants":["Johannes Schindelin via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"540845","messageId":"pull.2079.git.1775210183103.gitgitgadget@gmail.com","threadId":"65428","inReplyTo":null,"subject":"[PATCH] mingw: use strftime() directly in UCRT builds","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-04-03T09:56:23Z","receivedAt":"2026-04-03T09:56:25Z","isPatch":true,"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nThe `mingw_strftime()` wrapper exists to work around msvcrt.dll's\nincomplete `strftime()` implementation by dynamically loading the\nversion from ucrtbase.dll at runtime via `LoadLibrary()` +\n`GetProcAddress()`. When the binary is already linked against UCRT\n(i.e. when building in the UCRT64 environment), the linked-in\n`strftime()` is the ucrtbase.dll version, making the dynamic loading\nneedless churn: It's calling the very same code.\n\nSimply guard both the declaration and implementation so that the\nunnecessary work-around is skipped in UCRT builds.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n    mingw: use strftime() directly in UCRT builds\n    \n    Since the MSYS2 project deprecated the MINGW64 environment\n    [https://www.msys2.org/news/#2026-03-15-deprecating-the-mingw64-environment]\n    on which Git for Windows relies, we have to prepare quite swiftly for a\n    future where we switch to the UCRT64 environment instead. This patch is\n    the only fall-out of that that concerns the Git source code.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2079%2Fdscho%2Fmingw-use-strftime-directly-in-UCRT-builds-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2079/dscho/mingw-use-strftime-directly-in-UCRT-builds-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2079\n\n compat/mingw.c | 4 ++++\n 1 file changed, 4 insertions(+)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex c667a2dcda..338ec3535e 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1394,6 +1394,9 @@ revert_attrs:\n size_t mingw_strftime(char *s, size_t max,\n \t\t      const char *format, const struct tm *tm)\n {\n+#ifdef _UCRT\n+\tsize_t ret = strftime(s, max, format, tm);\n+#else\n \t/* a pointer to the original strftime in case we can't find the UCRT version */\n \tstatic size_t (*fallback)(char *, size_t, const char *, const struct tm *) = strftime;\n \tsize_t ret;\n@@ -1404,6 +1407,7 @@ size_t mingw_strftime(char *s, size_t max,\n \t\tret = strftime(s, max, format, tm);\n \telse\n \t\tret = fallback(s, max, format, tm);\n+#endif\n \n \tif (!ret && errno == EINVAL)\n \t\tdie(\"invalid strftime format: '%s'\", format);\n\nbase-commit: 6e8d538aab8fe4dd07ba9fb87b5c7edcfa5706ad\n-- \ngitgitgadget\n"}]}