From: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
To: git@vger.kernel.org
Cc: jltobler@gmail.com, lucasseikioshiro@gmail.com,
K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Subject: [GSoC Patch 1/2] gettext: fall back to env-derived charset when unset
Date: Fri, 21 Aug 2026 19:23:44 +0530 [thread overview]
Message-ID: <20260821135410.429698-2-jayatheerthkulkarni2005@gmail.com> (raw)
In-Reply-To: <20260821135410.429698-1-jayatheerthkulkarni2005@gmail.com>
`is_utf8_locale()` relies on the static `charset` variable, which is
normally initialized by `init_gettext_charset()`. That initialization
only happens when `git_setup_gettext()` successfully locates the locale
directory.
When running directly from the source tree without `make install`, or in
other environments where the locale directory is unavailable,
`git_setup_gettext()` returns early, leaving `charset` unset (NULL).
Because `is_encoding_utf8(NULL)` defaults to 1, `is_utf8_locale()` would
mistakenly report a UTF-8 locale even in non-UTF-8 environments (e.g.
under `LC_ALL=C`).
The fallback that derives the charset from `LC_ALL`, `LC_CTYPE`, or
`LANG` was previously compiled only under `NO_GETTEXT`. That left
gettext-enabled builds without a fallback when `charset` remains
uninitialized.
Make the fallback conditional on `charset` being unset rather than on
`NO_GETTEXT`. This ensures `is_utf8_locale()` accurately inspects the
environment-derived charset regardless of whether gettext support is
enabled.
Mentored-by: Justin Tobler <jltobler@gmail.com>
Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
---
gettext.c | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/gettext.c b/gettext.c
index 8d08a61f84..5376a0de0f 100644
--- a/gettext.c
+++ b/gettext.c
@@ -141,19 +141,23 @@ int gettext_width(const char *s)
int is_utf8_locale(void)
{
-#ifdef NO_GETTEXT
- if (!charset) {
- const char *env = getenv("LC_ALL");
- if (!env || !*env)
- env = getenv("LC_CTYPE");
- if (!env || !*env)
- env = getenv("LANG");
- if (!env)
- env = "";
- if (strchr(env, '.'))
- env = strchr(env, '.') + 1;
- charset = xstrdup(env);
+ const char *c = charset;
+
+ if (!c) {
+ static char fallback_charset[64];
+ if (!*fallback_charset) {
+ const char *env = getenv("LC_ALL");
+ if (!env || !*env)
+ env = getenv("LC_CTYPE");
+ if (!env || !*env)
+ env = getenv("LANG");
+ if (!env)
+ env = "";
+ if (strchr(env, '.'))
+ env = strchr(env, '.') + 1;
+ strlcpy(fallback_charset, env, sizeof(fallback_charset));
+ }
+ c = fallback_charset;
}
-#endif
- return is_encoding_utf8(charset);
+ return is_encoding_utf8(c);
}
--
2.55.GIT
next prev parent reply other threads:[~2026-08-21 13:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 13:53 [GSoC Patch 0/2] add unicode support to git repo structure K Jayatheerth
2026-08-21 13:53 ` K Jayatheerth [this message]
2026-08-21 13:53 ` [GSoC Patch 2/2] repo: add Unicode support for `repo structure` output K Jayatheerth
2026-08-21 16:59 ` [GSoC Patch 0/2] add unicode support to git repo structure Junio C Hamano
2026-08-23 13:19 ` Oswald Buddenhagen
2026-08-23 15:01 ` Junio C Hamano
2026-08-23 17:06 ` Tuomas Ahola
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260821135410.429698-2-jayatheerthkulkarni2005@gmail.com \
--to=jayatheerthkulkarni2005@gmail.com \
--cc=git@vger.kernel.org \
--cc=jltobler@gmail.com \
--cc=lucasseikioshiro@gmail.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.