git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: "Carlo Marcelo Arenas Belón" <carenas@gmail.com>
To: git@vger.kernel.org
Cc: Johannes.Schindelin@gmx.de, avarab@gmail.com
Subject: [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.
Date: Wed,  7 Aug 2019 02:53:22 -0700	[thread overview]
Message-ID: <20190807095322.8988-1-carenas@gmail.com> (raw)

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


             reply	other threads:[~2019-08-07  9:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-07  9:53 Carlo Marcelo Arenas Belón [this message]
2019-08-07 10:18 ` Carlo Arenas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190807095322.8988-1-carenas@gmail.com \
    --to=carenas@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --subject='Re: [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.' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this 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).