From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Alex Riesen" <raa.lkml@gmail.com>,
"Johannes Sixt" <j.sixt@viscovery.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH] git-sh-i18n: detect and avoid broken gettext(1) implementation
Date: Fri, 20 Jan 2012 12:49:35 +0000 [thread overview]
Message-ID: <1327063775-28420-1-git-send-email-avarab@gmail.com> (raw)
In-Reply-To: <CALxABCZWBtgX736Acoy-CCAz8RJb0EKnHf+7g72dOdVS+BOhSw@mail.gmail.com>
Even though we can load gettext.sh the gettext(1) and eval_gettext
functions it provides might be completely broken. This reportedly
happens on some Cygwin installations where we can load gettext.sh, but
gettext and eval_gettext both return exit code 127 and no output.
The reason we're trying to load gettext.sh (or the equivalent Solaris
implementation) at all is so we don't have to provide our own fallback
implementation if the OS already has one installed, but because we
didn't test whether it actually worked under GNU gettext we might end
up with broken functions.
Change the detection in git-sh-i18n so that it tests that the output
of "gettext test" produces "test", on Solaris we already test that
"gettext -h" produces "-h", so we were already guarded against the
same sort of failure there.
Reported-by: Alex Riesen <raa.lkml@gmail.com>
---
Here's a minimal patch to git-sh-i18n that should make things work on
Cygwin and any other platforms with broken gettext functions while
also using the OS-provided functions if they work.
I've added a new t0201-gettext-fallbacks-broken-gettext.sh test that
tests this. This required a small change in lib-gettext.sh so I
wouldn't load test-lib.sh twice.
Note that there's already a t0201* test in the repo. Maybe we want to
increment all the gettext test numbers by one to make room for it?
As an aside I'm really not a big fan of having hardcoded numbers in
the test files like this. We don't care about the order of execution
here.
git-sh-i18n.sh | 2 +-
t/lib-gettext.sh | 7 +++++-
t/t0201-gettext-fallbacks-broken-gettext.sh | 28 +++++++++++++++++++++++++++
3 files changed, 35 insertions(+), 2 deletions(-)
create mode 100755 t/t0201-gettext-fallbacks-broken-gettext.sh
diff --git a/git-sh-i18n.sh b/git-sh-i18n.sh
index b4575fb..26a57b0 100644
--- a/git-sh-i18n.sh
+++ b/git-sh-i18n.sh
@@ -18,7 +18,7 @@ export TEXTDOMAINDIR
if test -z "$GIT_GETTEXT_POISON"
then
- if test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" && type gettext.sh >/dev/null 2>&1
+ if test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" && type gettext.sh >/dev/null 2>&1 && test "$(gettext test 2>&1)" = "test"
then
# This is GNU libintl's gettext.sh, we don't need to do anything
# else than setting up the environment and loading gettext.sh
diff --git a/t/lib-gettext.sh b/t/lib-gettext.sh
index 0f76f6c..2c5b758 100644
--- a/t/lib-gettext.sh
+++ b/t/lib-gettext.sh
@@ -3,7 +3,12 @@
# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
#
-. ./test-lib.sh
+if test -z "$TEST_DIRECTORY"
+then
+ # In case the test loaded test-lib.sh by itself to do some tests
+ # prior to loading us.
+ . ./test-lib.sh
+fi
GIT_TEXTDOMAINDIR="$GIT_BUILD_DIR/po/build/locale"
GIT_PO_PATH="$GIT_BUILD_DIR/po"
diff --git a/t/t0201-gettext-fallbacks-broken-gettext.sh b/t/t0201-gettext-fallbacks-broken-gettext.sh
new file mode 100755
index 0000000..92b95ae
--- /dev/null
+++ b/t/t0201-gettext-fallbacks-broken-gettext.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+#
+# Copyright (c) 2012 Ævar Arnfjörð Bjarmason
+#
+
+test_description='Gettext Shell fallbacks with broken gettext'
+
+. ./test-lib.sh
+
+test_expect_success 'set up a fake broken gettext(1)' '
+ cat >gettext <<-\EOF &&
+ #!/bin/sh
+ exit 1
+ EOF
+ chmod +x gettext &&
+ ! ./gettext
+'
+
+PATH=.:$PATH
+. "$TEST_DIRECTORY"/lib-gettext.sh
+
+test_expect_success C_LOCALE_OUTPUT '$GIT_INTERNAL_GETTEXT_SH_SCHEME" is fallthrough with broken gettext(1)' '
+ echo fallthrough >expect &&
+ echo $GIT_INTERNAL_GETTEXT_SH_SCHEME >actual &&
+ test_cmp expect actual
+'
+
+test_done
--
1.7.7.3
next prev parent reply other threads:[~2012-01-20 12:49 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-17 13:42 [PATCH] i18n: disable i18n for shell scripts if NO_GETTEXT defined Alex Riesen
2012-01-17 19:08 ` Junio C Hamano
2012-01-18 14:25 ` Alex Riesen
2012-01-18 19:54 ` Alex Riesen
2012-01-19 0:12 ` Jonathan Nieder
2012-01-19 9:15 ` Alex Riesen
2012-01-18 15:22 ` Ævar Arnfjörð Bjarmason
2012-01-18 18:57 ` Alex Riesen
2012-01-18 23:18 ` Ævar Arnfjörð Bjarmason
2012-01-19 0:15 ` Jonathan Nieder
2012-01-19 0:17 ` Junio C Hamano
2012-01-19 7:13 ` Johannes Sixt
2012-01-19 18:30 ` Junio C Hamano
2012-01-20 9:50 ` Ævar Arnfjörð Bjarmason
2012-01-20 10:40 ` Alex Riesen
2012-01-20 12:49 ` Ævar Arnfjörð Bjarmason [this message]
2012-01-20 14:02 ` [PATCH] git-sh-i18n: detect and avoid broken gettext(1) implementation Alex Riesen
2012-01-20 20:00 ` Junio C Hamano
2012-01-20 20:13 ` Alex Riesen
2012-01-20 20:21 ` Junio C Hamano
2012-01-20 20:24 ` Alex Riesen
2012-01-20 20:26 ` Junio C Hamano
2012-01-20 20:33 ` Alex Riesen
2012-01-20 19:35 ` [PATCH] i18n: disable i18n for shell scripts if NO_GETTEXT defined Junio C Hamano
2012-01-20 19:45 ` Alex Riesen
2012-01-19 9:24 ` Alex Riesen
2012-01-19 9:13 ` Alex Riesen
2012-01-19 19:52 ` [PATCH] add a Makefile switch to avoid gettext translation in shell scripts Alex Riesen
2012-01-23 22:01 ` Junio C Hamano
2012-01-23 22:02 ` [PATCH 1/2] git-sh-i18n: restructure the logic to compute gettext.sh scheme Junio C Hamano
2012-01-23 22:04 ` [PATCH 2/2] add a Makefile switch to avoid gettext translation in shell scripts Junio C Hamano
2012-01-23 22:12 ` Jonathan Nieder
2012-01-23 22:23 ` Junio C Hamano
2012-01-23 22:40 ` Jonathan Nieder
2012-01-24 0:31 ` [PATCH/RFC 3/2] i18n: do not use gettext.sh by default when NO_GETTEXT is set Jonathan Nieder
2012-01-24 20:06 ` Alex Riesen
2012-01-24 0:39 ` [PATCH 2/2] add a Makefile switch to avoid gettext translation in shell scripts Ævar Arnfjörð Bjarmason
2012-01-24 19:59 ` Alex Riesen
2012-01-24 20:00 ` Alex Riesen
2012-01-24 20:13 ` Junio C Hamano
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=1327063775-28420-1-git-send-email-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
--cc=raa.lkml@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 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 NNTP newsgroup(s).