{"thread":{"id":"51600","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.","startedAt":"2019-08-07T09:53:26Z","lastAt":"2019-08-07T10:18:40Z","messageCount":2,"participants":["Carlo Marcelo Arenas Belón","Carlo Arenas"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"380061","messageId":"20190807095322.8988-1-carenas@gmail.com","threadId":"51600","inReplyTo":null,"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.","fromName":"Carlo Marcelo Arenas Belón","fromEmail":"carenas@gmail.com","sentAt":"2019-08-07T09:53:22Z","receivedAt":"2019-08-07T09:53:26Z","isPatch":true,"sender":{"key":"carenas@gmail.com","avatar":"https://avatars.githubusercontent.com/u/76036?v=4"},"body":"in environments where the build running wasn't installed and wasn't\nusing NO_GETTEXT the initialization of charset will be skipped, breaking\nis_utf_locale()\n\nSplit the init function on two, so the initialization of charset could\nbe done before a decision to abort was made and therefore keeping most\nof the performance improvement.\n\nSigned-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>\n---\n gettext.c | 14 +++++++++++---\n 1 file changed, 11 insertions(+), 3 deletions(-)\n\ndiff --git a/gettext.c b/gettext.c\nindex d4021d690c..3ecf456f74 100644\n--- a/gettext.c\n+++ b/gettext.c\n@@ -69,7 +69,14 @@ static int test_vsnprintf(const char *fmt, ...)\n \treturn ret;\n }\n \n-static void init_gettext_charset(const char *domain)\n+static void init_gettext_charset(void)\n+{\n+\tconst char *current = setlocale(LC_CTYPE, \"\");\n+\tcharset = locale_charset();\n+\tsetlocale(LC_CTYPE, current);\n+}\n+\n+static void bind_gettext_charset(const char *domain)\n {\n \t/*\n \t   This trick arranges for messages to be emitted in the user's\n@@ -150,7 +157,7 @@ static void init_gettext_charset(const char *domain)\n \t   2. E.g. \"Content-Type: text/plain; charset=UTF-8\\n\" in po/is.po\n \t*/\n \tsetlocale(LC_CTYPE, \"\");\n-\tcharset = locale_charset();\n+\t/* charset was already initialized in init_gettext_charset() */\n \tbind_textdomain_codeset(domain, charset);\n \t/* the string is taken from v0.99.6~1 */\n \tif (test_vsnprintf(\"%.*s\", 13, \"David_K\\345gedal\") < 0)\n@@ -166,6 +173,7 @@ void git_setup_gettext(void)\n \t\tpodir = p = system_path(GIT_LOCALE_PATH);\n \n \tuse_gettext_poison(); /* getenv() reentrancy paranoia */\n+\tinit_gettext_charset();\n \n \tif (!is_directory(podir)) {\n \t\tfree(p);\n@@ -175,7 +183,7 @@ void git_setup_gettext(void)\n \tbindtextdomain(\"git\", podir);\n \tsetlocale(LC_MESSAGES, \"\");\n \tsetlocale(LC_TIME, \"\");\n-\tinit_gettext_charset(\"git\");\n+\tbind_gettext_charset(\"git\");\n \ttextdomain(\"git\");\n \n \tfree(p);\n-- \n2.23.0.rc1\n\n"},{"id":"380062","messageId":"CAPUEspgoPizN5mnBJjeUVdmTtsJ4NCrd-gMWcqaghoBqG7Sp+A@mail.gmail.com","threadId":"51600","inReplyTo":"20190807095322.8988-1-carenas@gmail.com","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.","fromName":"Carlo Arenas","fromEmail":"carenas@gmail.com","sentAt":"2019-08-07T10:18:26Z","receivedAt":"2019-08-07T10:18:40Z","isPatch":true,"sender":{"key":"carenas@gmail.com","avatar":"https://avatars.githubusercontent.com/u/76036?v=4"},"body":"Subject was meant to be \"gettext: fix is_utf8_locale() when not using\nNO_GETTEXT\" and affects mainly PCRE by using UTF-8 flag even when the\nlocale was ISO.\n\nsomehow it doesn't break any tests though, but PCRE strongly advices\nagainst doing both UTF and chartables and we might end up doing that\nmore often, because of this.\n\nCarlo\n\nPS. apologize for the badly formatted patch, don't think this needs to\nbe fixed in maint, eventhough the patch is based on it with the most\nlikely to be affected being developers (or automated tests)\n"}]}