Commit 5762922
committed
gettext: derive charset from the environment when gettext is uninitialized
is_utf8_locale() drives, among other things, whether `git grep -P -i`
applies Unicode case-folding (grep.c sets PCRE2_UTF | PCRE2_UCP only when
this returns true). It consults the static `charset` that
git_setup_gettext() fills in via locale_charset(). That setup, however,
bails out early when the locale directory cannot be found, leaving
`charset` NULL. Because is_encoding_utf8(NULL) answers "yes", is_utf8_locale()
then reports a UTF-8 locale unconditionally, even under LC_ALL=C, and
`git grep -P -i` case-folds non-ASCII bytes when it must not.
I ran into this while running the test suite with BusyBox' ash as the
POSIX shell: in that leg the locale directory is not located, so t7816's
"LC_ALL='C' git grep -P -i" cases that assert no Unicode folding (the
matches_pcre2=0 rows) instead matched and their test_must_fail invocations
failed. The MSYS2 Bash leg, where the locale directory is found and
locale_charset() returns "C", was unaffected.
The NO_GETTEXT build already protects against a NULL `charset` by deriving
it from LC_ALL/LC_CTYPE/LANG. Apply that same fallback whenever `charset`
is NULL rather than only in NO_GETTEXT builds, so a gettext-enabled build
that could not initialize gettext still honors the locale from the
environment.
Assisted-by: Opus 4.8
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>1 parent 15117b2 commit 5762922
1 file changed
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
145 | 151 | | |
146 | 152 | | |
147 | 153 | | |
| |||
154 | 160 | | |
155 | 161 | | |
156 | 162 | | |
157 | | - | |
158 | 163 | | |
159 | 164 | | |
0 commit comments