Hi,

On Thu, 27 Jun 2019, Karsten Blees via GitGitGadget wrote:

> diff --git a/gettext.c b/gettext.c
> index d4021d690c..d8423e5c41 100644
> --- a/gettext.c
> +++ b/gettext.c
> @@ -12,7 +12,9 @@
>  #ifndef NO_GETTEXT
>  #    include <locale.h>
>  #    include <libintl.h>
> -#    ifdef HAVE_LIBCHARSET_H
> +#    ifdef GIT_WINDOWS_NATIVE
> +#            define locale_charset() "UTF-8"
> +#    elif defined HAVE_LIBCHARSET_H
>  #            include <libcharset.h>
>  #    else
>  #            include <langinfo.h>

Sadly, this has a really unfortunate interaction with ab/no-kwset: the
latter patch series contains test cases that rely on being able to
use `LC_ALL=C` to prevent Git from assuming UTF-8 encoding.

I have this tentative patch queued up on Git for Windows' `shears/pu`
branch (i.e. the ever-green branch that continuously rebases all of Git
for Windows' patch thicket on top of `pu`):
https://github.com/git-for-windows/git/commit/e561446d

For you convenience:

-- snip --
diff --git a/gettext.c b/gettext.c
index 7da80db453c4..35d2c1218db2 100644
--- a/gettext.c
+++ b/gettext.c
@@ -13,7 +13,23 @@
 #      include <locale.h>
 #      include <libintl.h>
 #      ifdef GIT_WINDOWS_NATIVE
-#              define locale_charset() "UTF-8"
+
+static const char *locale_charset(void)
+{
+       const char *env = getenv("LC_ALL"), *dot;
+
+       if (!env || !*env)
+               env = getenv("LC_CTYPE");
+       if (!env || !*env)
+               env = getenv("LANG");
+
+       if (!env)
+               return "UTF-8";
+
+       dot = strchr(env, '.');
+       return !dot ? env : dot + 1;
+}
+
 #      elif defined HAVE_LIBCHARSET_H
 #              include <libcharset.h>
 #      else
-- snap --

Junio, please hold off from advancing `kb/windows-force-utf8` until this
is resolved.

Also: does that diff look okay? Or would you rather want to avoid having
that function defined in that #if...#endif block?

Ciao,
Dscho

Reply via email to