mirror of
https://github.com/git/git.git
synced 2024-11-30 21:44:02 +08:00
1ff750b128
Change the GIT_TEST_GETTEXT_POISON variable from being "non-empty?" to
being a more standard boolean variable.
Since it needed to be checked in both C code and shellscript (via test
-n) it was one of the remaining shellscript-like variables. Now that
we have "env--helper" we can change that.
There's a couple of tricky edge cases that arise because we're using
git_env_bool() early, and the config-reading "env--helper".
If GIT_TEST_GETTEXT_POISON is set to an invalid value die_bad_number()
will die, but to do so it would usually call gettext(). Let's detect
the special case of GIT_TEST_GETTEXT_POISON and always emit that
message in the C locale, lest we infinitely loop.
As seen in the updated tests in t0017-env-helper.sh there's also a
caveat related to "env--helper" needing to read the config for trace2
purposes.
Since the C_LOCALE_OUTPUT prerequisite is lazy and relies on
"env--helper" we could get invalid results if we failed to read the
config (e.g. because we'd loop on includes) when combined with
e.g. "test_i18ngrep" wanting to check with "env--helper" if
GIT_TEST_GETTEXT_POISON was true or not.
I'm crossing my fingers and hoping that a test similar to the one I
removed in the earlier "config tests: simplify include cycle test"
change in this series won't happen again, and testing for this
explicitly in "env--helper"'s own tests.
This change breaks existing uses of
e.g. GIT_TEST_GETTEXT_POISON=YesPlease, which we've documented in
po/README and other places. As noted in [1] we might want to consider
also accepting "YesPlease" in "env--helper" as a special-case.
But as the lack of uproar over 6cdccfce1e
("i18n: make GETTEXT_POISON
a runtime option", 2018-11-08) demonstrates the audience for this
option is a really narrow set of git developers, who shouldn't have
much trouble modifying their test scripts, so I think it's better to
deal with that minor headache now and make all the relevant GIT_TEST_*
variables boolean in the same way than carry the "YesPlease"
special-case forward.
1. https://public-inbox.org/git/xmqqtvckm3h8.fsf@gitster-ct.c.googlers.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
112 lines
2.4 KiB
Bash
112 lines
2.4 KiB
Bash
# This shell library is Git's interface to gettext.sh. See po/README
|
|
# for usage instructions.
|
|
#
|
|
# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
|
|
#
|
|
|
|
# Export the TEXTDOMAIN* data that we need for Git
|
|
TEXTDOMAIN=git
|
|
export TEXTDOMAIN
|
|
if test -z "$GIT_TEXTDOMAINDIR"
|
|
then
|
|
TEXTDOMAINDIR="@@LOCALEDIR@@"
|
|
else
|
|
TEXTDOMAINDIR="$GIT_TEXTDOMAINDIR"
|
|
fi
|
|
export TEXTDOMAINDIR
|
|
|
|
# First decide what scheme to use...
|
|
GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
|
|
if test -n "$GIT_TEST_GETTEXT_POISON" &&
|
|
git env--helper --type=bool --default=0 --exit-code \
|
|
GIT_TEST_GETTEXT_POISON
|
|
then
|
|
GIT_INTERNAL_GETTEXT_SH_SCHEME=poison
|
|
elif test -n "@@USE_GETTEXT_SCHEME@@"
|
|
then
|
|
GIT_INTERNAL_GETTEXT_SH_SCHEME="@@USE_GETTEXT_SCHEME@@"
|
|
elif test -n "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"
|
|
then
|
|
: no probing necessary
|
|
elif type gettext.sh >/dev/null 2>&1
|
|
then
|
|
# GNU libintl's gettext.sh
|
|
GIT_INTERNAL_GETTEXT_SH_SCHEME=gnu
|
|
elif test "$(gettext -h 2>&1)" = "-h"
|
|
then
|
|
# gettext binary exists but no gettext.sh. likely to be a gettext
|
|
# binary on a Solaris or something that is not GNU libintl and
|
|
# lack eval_gettext.
|
|
GIT_INTERNAL_GETTEXT_SH_SCHEME=gettext_without_eval_gettext
|
|
fi
|
|
export GIT_INTERNAL_GETTEXT_SH_SCHEME
|
|
|
|
# ... and then follow that decision.
|
|
case "$GIT_INTERNAL_GETTEXT_SH_SCHEME" in
|
|
gnu)
|
|
# Use libintl's gettext.sh, or fall back to English if we can't.
|
|
. gettext.sh
|
|
;;
|
|
gettext_without_eval_gettext)
|
|
# Solaris has a gettext(1) but no eval_gettext(1)
|
|
eval_gettext () {
|
|
gettext "$1" | (
|
|
export PATH $(git sh-i18n--envsubst --variables "$1");
|
|
git sh-i18n--envsubst "$1"
|
|
)
|
|
}
|
|
|
|
eval_ngettext () {
|
|
ngettext "$1" "$2" "$3" | (
|
|
export PATH $(git sh-i18n--envsubst --variables "$2");
|
|
git sh-i18n--envsubst "$2"
|
|
)
|
|
}
|
|
;;
|
|
poison)
|
|
# Emit garbage so that tests that incorrectly rely on translatable
|
|
# strings will fail.
|
|
gettext () {
|
|
printf "%s" "# GETTEXT POISON #"
|
|
}
|
|
|
|
eval_gettext () {
|
|
printf "%s" "# GETTEXT POISON #"
|
|
}
|
|
|
|
eval_ngettext () {
|
|
printf "%s" "# GETTEXT POISON #"
|
|
}
|
|
;;
|
|
*)
|
|
gettext () {
|
|
printf "%s" "$1"
|
|
}
|
|
|
|
eval_gettext () {
|
|
printf "%s" "$1" | (
|
|
export PATH $(git sh-i18n--envsubst --variables "$1");
|
|
git sh-i18n--envsubst "$1"
|
|
)
|
|
}
|
|
|
|
eval_ngettext () {
|
|
(test "$3" = 1 && printf "%s" "$1" || printf "%s" "$2") | (
|
|
export PATH $(git sh-i18n--envsubst --variables "$2");
|
|
git sh-i18n--envsubst "$2"
|
|
)
|
|
}
|
|
;;
|
|
esac
|
|
|
|
# Git-specific wrapper functions
|
|
gettextln () {
|
|
gettext "$1"
|
|
echo
|
|
}
|
|
|
|
eval_gettextln () {
|
|
eval_gettext "$1"
|
|
echo
|
|
}
|