{"thread":{"id":"53189","subject":"[PATCH] mingw: use modern strftime implementation if possible","startedAt":"2020-04-08T17:58:56Z","lastAt":"2020-04-10T14:39:31Z","messageCount":3,"participants":["Johannes Schindelin via GitGitGadget","Junio C Hamano","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"395076","messageId":"pull.753.git.git.1586368729890.gitgitgadget@gmail.com","threadId":"53189","inReplyTo":null,"subject":"[PATCH] mingw: use modern strftime implementation if possible","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-04-08T17:58:49Z","receivedAt":"2020-04-08T17:58:56Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: =?UTF-8?q?Matthias=20A=C3=9Fhauer?= <mha1993@live.de>\n\nMicrosoft introduced a new \"Universal C Runtime Library\" (UCRT) with\nVisual Studio 2015. The UCRT comes with a new strftime() implementation\nthat supports more date formats. We link git against the older\n\"Microsoft Visual C Runtime Library\" (MSVCRT), so to use the UCRT\nstrftime() we need to load it from ucrtbase.dll using\nDECLARE_PROC_ADDR()/INIT_PROC_ADDR().\n\nMost supported Windows systems should have recieved the UCRT via Windows\nupdate, but in some cases only MSVCRT might be available. In that case\nwe fall back to using that implementation.\n\nWith this change, it is possible to use e.g. the `%g` and `%V` date\nformat specifiers, e.g.\n\n\tgit show -s --format=%cd --date=format:‘%g.%V’ HEAD\n\nWithout this change, the user would see this error message on Windows:\n\n\tfatal: invalid strftime format: '‘%g.%V’'\n\nThis fixes https://github.com/git-for-windows/git/issues/2495\n\nSigned-off-by: Matthias Aßhauer <mha1993@live.de>\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n    Use a modern strftime() on Windows when available\n    \n    This is another contribution that came in via Git for Windows.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-753%2Fdscho%2Fmingw-modern-strftime-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-753/dscho/mingw-modern-strftime-v1\nPull-Request: https://github.com/git/git/pull/753\n\n compat/mingw.c | 11 ++++++++++-\n 1 file changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex d14065d60ec..2136744af35 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -964,7 +964,16 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)\n size_t mingw_strftime(char *s, size_t max,\n \t\t      const char *format, const struct tm *tm)\n {\n-\tsize_t ret = strftime(s, max, format, tm);\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+\tDECLARE_PROC_ADDR(ucrtbase.dll, size_t, strftime, char *, size_t,\n+\t\tconst char *, const struct tm *);\n+\n+\tif (INIT_PROC_ADDR(strftime))\n+\t\tret = strftime(s, max, format, tm);\n+\telse\n+\t\tret = fallback(s, max, format, tm);\n \n \tif (!ret && errno == EINVAL)\n \t\tdie(\"invalid strftime format: '%s'\", format);\n\nbase-commit: 9fadedd637b312089337d73c3ed8447e9f0aa775\n-- \ngitgitgadget\n"},{"id":"395088","messageId":"xmqqblo1pz7b.fsf@gitster.c.googlers.com","threadId":"53189","inReplyTo":"pull.753.git.git.1586368729890.gitgitgadget@gmail.com","subject":"Re: [PATCH] mingw: use modern strftime implementation if possible","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-04-08T19:14:16Z","receivedAt":"2020-04-08T19:14:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> From: =?UTF-8?q?Matthias=20A=C3=9Fhauer?= <mha1993@live.de>\n>\n> Microsoft introduced a new \"Universal C Runtime Library\" (UCRT) with\n> Visual Studio 2015. The UCRT comes with a new strftime() implementation\n> that supports more date formats. We link git against the older\n> \"Microsoft Visual C Runtime Library\" (MSVCRT), so to use the UCRT\n> strftime() we need to load it from ucrtbase.dll using\n> DECLARE_PROC_ADDR()/INIT_PROC_ADDR().\n>\n> Most supported Windows systems should have recieved the UCRT via Windows\n> update, but in some cases only MSVCRT might be available. In that case\n> we fall back to using that implementation.\n>\n> With this change, it is possible to use e.g. the `%g` and `%V` date\n> format specifiers, e.g.\n>\n> \tgit show -s --format=%cd --date=format:‘%g.%V’ HEAD\n>\n> Without this change, the user would see this error message on Windows:\n>\n> \tfatal: invalid strftime format: '‘%g.%V’'\n>\n> This fixes https://github.com/git-for-windows/git/issues/2495\n>\n> Signed-off-by: Matthias Aßhauer <mha1993@live.de>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>     Use a modern strftime() on Windows when available\n>     \n>     This is another contribution that came in via Git for Windows.\n\nSure.  It would be very surprising if contribution to compat/mingw.c\ncame in via Git on Macintosh ;-)\n\nWill apply, together with the other one.  Thanks.\n\n"},{"id":"395190","messageId":"nycvar.QRO.7.76.6.2004101638420.46@tvgsbejvaqbjf.bet","threadId":"53189","inReplyTo":"xmqqblo1pz7b.fsf@gitster.c.googlers.com","subject":"Re: [PATCH] mingw: use modern strftime implementation if possible","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2020-04-10T14:39:25Z","receivedAt":"2020-04-10T14:39:31Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Wed, 8 Apr 2020, Junio C Hamano wrote:\n\n> \"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\n> writes:\n>\n> > From: =?UTF-8?q?Matthias=20A=C3=9Fhauer?= <mha1993@live.de>\n> >\n> > Microsoft introduced a new \"Universal C Runtime Library\" (UCRT) with\n> > Visual Studio 2015. The UCRT comes with a new strftime() implementation\n> > that supports more date formats. We link git against the older\n> > \"Microsoft Visual C Runtime Library\" (MSVCRT), so to use the UCRT\n> > strftime() we need to load it from ucrtbase.dll using\n> > DECLARE_PROC_ADDR()/INIT_PROC_ADDR().\n> >\n> > Most supported Windows systems should have recieved the UCRT via Windows\n> > update, but in some cases only MSVCRT might be available. In that case\n> > we fall back to using that implementation.\n> >\n> > With this change, it is possible to use e.g. the `%g` and `%V` date\n> > format specifiers, e.g.\n> >\n> > \tgit show -s --format=%cd --date=format:‘%g.%V’ HEAD\n> >\n> > Without this change, the user would see this error message on Windows:\n> >\n> > \tfatal: invalid strftime format: '‘%g.%V’'\n> >\n> > This fixes https://github.com/git-for-windows/git/issues/2495\n> >\n> > Signed-off-by: Matthias Aßhauer <mha1993@live.de>\n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n> >     Use a modern strftime() on Windows when available\n> >\n> >     This is another contribution that came in via Git for Windows.\n>\n> Sure.  It would be very surprising if contribution to compat/mingw.c\n> came in via Git on Macintosh ;-)\n\nWhat I mean to say with this is that the patches have seen some real-life\ntesting.\n\n> Will apply, together with the other one.  Thanks.\n\nThanks,\nDscho\n"}]}