git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] mingw: use modern strftime implementation if possible
@ 2020-04-08 17:58 Johannes Schindelin via GitGitGadget
  2020-04-08 19:14 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2020-04-08 17:58 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin, Matthias Aßhauer

From: =?UTF-8?q?Matthias=20A=C3=9Fhauer?= <mha1993@live.de>

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 https://github.com/git-for-windows/git/issues/2495

Signed-off-by: Matthias Aßhauer <mha1993@live.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
    Use a modern strftime() on Windows when available
    
    This is another contribution that came in via Git for Windows.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-753%2Fdscho%2Fmingw-modern-strftime-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-753/dscho/mingw-modern-strftime-v1
Pull-Request: https://github.com/git/git/pull/753

 compat/mingw.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index d14065d60ec..2136744af35 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -964,7 +964,16 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)
 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);

base-commit: 9fadedd637b312089337d73c3ed8447e9f0aa775
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mingw: use modern strftime implementation if possible
  2020-04-08 17:58 [PATCH] mingw: use modern strftime implementation if possible Johannes Schindelin via GitGitGadget
@ 2020-04-08 19:14 ` Junio C Hamano
  2020-04-10 14:39   ` Johannes Schindelin
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2020-04-08 19:14 UTC (permalink / raw)
  To: Johannes Schindelin via GitGitGadget
  Cc: git, Johannes Schindelin, Matthias Aßhauer

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> From: =?UTF-8?q?Matthias=20A=C3=9Fhauer?= <mha1993@live.de>
>
> 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 https://github.com/git-for-windows/git/issues/2495
>
> Signed-off-by: Matthias Aßhauer <mha1993@live.de>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>     Use a modern strftime() on Windows when available
>     
>     This is another contribution that came in via Git for Windows.

Sure.  It would be very surprising if contribution to compat/mingw.c
came in via Git on Macintosh ;-)

Will apply, together with the other one.  Thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mingw: use modern strftime implementation if possible
  2020-04-08 19:14 ` Junio C Hamano
@ 2020-04-10 14:39   ` Johannes Schindelin
  0 siblings, 0 replies; 3+ messages in thread
From: Johannes Schindelin @ 2020-04-10 14:39 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Johannes Schindelin via GitGitGadget, git, Matthias Aßhauer

[-- Attachment #1: Type: text/plain, Size: 1738 bytes --]

Hi Junio,

On Wed, 8 Apr 2020, Junio C Hamano wrote:

> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
> > From: =?UTF-8?q?Matthias=20A=C3=9Fhauer?= <mha1993@live.de>
> >
> > 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 https://github.com/git-for-windows/git/issues/2495
> >
> > Signed-off-by: Matthias Aßhauer <mha1993@live.de>
> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> > ---
> >     Use a modern strftime() on Windows when available
> >
> >     This is another contribution that came in via Git for Windows.
>
> Sure.  It would be very surprising if contribution to compat/mingw.c
> came in via Git on Macintosh ;-)

What I mean to say with this is that the patches have seen some real-life
testing.

> Will apply, together with the other one.  Thanks.

Thanks,
Dscho

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-10 14:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-08 17:58 [PATCH] mingw: use modern strftime implementation if possible Johannes Schindelin via GitGitGadget
2020-04-08 19:14 ` Junio C Hamano
2020-04-10 14:39   ` Johannes Schindelin

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).