path: root/compat/mingw.c
diff options
authorMatthias Aßhauer <>2020-04-08 17:58:49 (GMT)
committerJunio C Hamano <>2020-04-08 19:15:50 (GMT)
commita748f3f3dc0adff1d8a83dfc098ed819658998d0 (patch)
tree8f916fdb495b2d2e40c4741ef18d6a32d87f6c77 /compat/mingw.c
parent274b9cc25322d9ee79aa8e6d4e86f0ffe5ced925 (diff)
mingw: use modern strftime implementation if possible
Microsoft introduced a new "Universal C Runtime Library" (UCRT) with Visual Studio 2015. The UCRT comes with a new strftime() implementation that supports more date formats. We link git against the older "Microsoft Visual C Runtime Library" (MSVCRT), so to use the UCRT strftime() we need to load it from ucrtbase.dll using DECLARE_PROC_ADDR()/INIT_PROC_ADDR(). Most supported Windows systems should have recieved the UCRT via Windows update, but in some cases only MSVCRT might be available. In that case we fall back to using that implementation. With this change, it is possible to use e.g. the `%g` and `%V` date format specifiers, e.g. git show -s --format=%cd --date=format:‘%g.%V’ HEAD Without this change, the user would see this error message on Windows: fatal: invalid strftime format: '‘%g.%V’' This fixes Signed-off-by: Matthias Aßhauer <> Signed-off-by: Johannes Schindelin <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'compat/mingw.c')
1 files changed, 10 insertions, 1 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index d14065d..2136744 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -964,7 +964,16 @@ revert_attrs:
size_t mingw_strftime(char *s, size_t max,
const char *format, const struct tm *tm)
- size_t ret = strftime(s, max, format, tm);
+ /* a pointer to the original strftime in case we can't find the UCRT version */
+ static size_t (*fallback)(char *, size_t, const char *, const struct tm *) = strftime;
+ size_t ret;
+ DECLARE_PROC_ADDR(ucrtbase.dll, size_t, strftime, char *, size_t,
+ const char *, const struct tm *);
+ if (INIT_PROC_ADDR(strftime))
+ ret = strftime(s, max, format, tm);
+ else
+ ret = fallback(s, max, format, tm);
if (!ret && errno == EINVAL)
die("invalid strftime format: '%s'", format);