git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/1] gettext: always use UTF-8 on native Windows

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 3, 2019, 11:26 UTC
Message-ID
<nycvar.QRO.7.76.6.1907031321270.44@tvgsbejvaqbjf.bet>
In-Reply-To
<ff37a2646a848e3eca8d02a001844986a3fa366b.1561625060.git.gitgitgadget@gmail.com>
Hi,
On Thu, 27 Jun 2019, Karsten Blees via GitGitGadget wrote:
Show 15 quoted lines
> 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
Previous: Karsten Blees via GitGitGadgetNext: Junio C Hamano
Message 3 of 9 in “gettext(windows): always use UTF-8”
  1. 0/1 gettext(windows): always use UTF-8Johannes Schindelin via GitGitGadget, Jun 27, 2019
  2. 1/1 gettext: always use UTF-8 on native WindowsKarsten Blees via GitGitGadget, Jun 27, 2019
  3. Johannes SchindelinJul 3, 2019
  4. Junio C HamanoJul 3, 2019
  5. 0/1 gettext(windows): always use UTF-8Johannes Schindelin via GitGitGadget, Jul 3, 2019
  6. 1/1 gettext: always use UTF-8 on native WindowsKarsten Blees via GitGitGadget, Jul 3, 2019
  7. Ævar Arnfjörð BjarmasonJul 4, 2019
  8. Johannes SchindelinJul 8, 2019
  9. Junio C HamanoJul 8, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.