git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] cc5e1bf992 (gettext: avoid initialization if the locale dir is not present, 2018-04-21) changed the way the gettext initialization is done skipping most of it for performance reasons if the locale directories wouldn't exist.
@ 2019-08-07  9:53 Carlo Marcelo Arenas Belón
  2019-08-07 10:18 ` Carlo Arenas
  0 siblings, 1 reply; 2+ messages in thread
From: Carlo Marcelo Arenas Belón @ 2019-08-07  9:53 UTC (permalink / raw)
  To: git; +Cc: Johannes.Schindelin, avarab

in environments where the build running wasn't installed and wasn't
using NO_GETTEXT the initialization of charset will be skipped, breaking
is_utf_locale()

Split the init function on two, so the initialization of charset could
be done before a decision to abort was made and therefore keeping most
of the performance improvement.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
 gettext.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/gettext.c b/gettext.c
index d4021d690c..3ecf456f74 100644
--- a/gettext.c
+++ b/gettext.c
@@ -69,7 +69,14 @@ static int test_vsnprintf(const char *fmt, ...)
 	return ret;
 }
 
-static void init_gettext_charset(const char *domain)
+static void init_gettext_charset(void)
+{
+	const char *current = setlocale(LC_CTYPE, "");
+	charset = locale_charset();
+	setlocale(LC_CTYPE, current);
+}
+
+static void bind_gettext_charset(const char *domain)
 {
 	/*
 	   This trick arranges for messages to be emitted in the user's
@@ -150,7 +157,7 @@ static void init_gettext_charset(const char *domain)
 	   2. E.g. "Content-Type: text/plain; charset=UTF-8\n" in po/is.po
 	*/
 	setlocale(LC_CTYPE, "");
-	charset = locale_charset();
+	/* charset was already initialized in init_gettext_charset() */
 	bind_textdomain_codeset(domain, charset);
 	/* the string is taken from v0.99.6~1 */
 	if (test_vsnprintf("%.*s", 13, "David_K\345gedal") < 0)
@@ -166,6 +173,7 @@ void git_setup_gettext(void)
 		podir = p = system_path(GIT_LOCALE_PATH);
 
 	use_gettext_poison(); /* getenv() reentrancy paranoia */
+	init_gettext_charset();
 
 	if (!is_directory(podir)) {
 		free(p);
@@ -175,7 +183,7 @@ void git_setup_gettext(void)
 	bindtextdomain("git", podir);
 	setlocale(LC_MESSAGES, "");
 	setlocale(LC_TIME, "");
-	init_gettext_charset("git");
+	bind_gettext_charset("git");
 	textdomain("git");
 
 	free(p);
-- 
2.23.0.rc1


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

end of thread, other threads:[~2019-08-07 10:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-07  9:53 [PATCH] cc5e1bf992 (gettext: avoid initialization if the locale dir is not present, 2018-04-21) changed the way the gettext initialization is done skipping most of it for performance reasons if the locale directories wouldn't exist Carlo Marcelo Arenas Belón
2019-08-07 10:18 ` Carlo Arenas

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).