Making gettext poison second citizen makes it easy to forget to run
the test suite with it. This is step one to running test suite with
gettext poison by default.

The runtime cost should be small. "gcc -O2" inlines _() and
use_gettext_poison(). But even if it does not, performance should not
be impacted as _() calls are usually not on critical path. If some of
them are, we better fix there as gettext() may or may not be cheap
anyway.

A new target is added to run test with poisoned gettext: test-poison

Signed-off-by: Nguyễn Thái Ngọc Duy <pclo...@gmail.com>
---
 I don't know the story behind this compile-time switch. The series [1]
 that introduces it does not say much.

 This at least makes it easier for me to run poison tests instead of
 building another binary, if I remember it. Next step could be make
 "make test" run both normal and poison modes, but I'm not sure how to
 do it nicely yet.

 [1] http://thread.gmane.org/gmane.comp.version-control.git/167307/focus=167438

 Makefile  | 12 +++---------
 gettext.c | 10 ----------
 gettext.h | 12 +++++++-----
 po/README | 13 ++++---------
 4 files changed, 14 insertions(+), 33 deletions(-)

diff --git a/Makefile b/Makefile
index 6b0c961..8255fb9 100644
--- a/Makefile
+++ b/Makefile
@@ -258,11 +258,6 @@ all::
 # Define HAVE_DEV_TTY if your system can open /dev/tty to interact with the
 # user.
 #
-# Define GETTEXT_POISON if you are debugging the choice of strings marked
-# for translation.  In a GETTEXT_POISON build, you can turn all strings marked
-# for translation into gibberish by setting the GIT_GETTEXT_POISON variable
-# (to any value) in your environment.
-#
 # Define JSMIN to point to JavaScript minifier that functions as
 # a filter to have gitweb.js minified.
 #
@@ -1594,9 +1589,6 @@ endif
 ifdef NO_SYMLINK_HEAD
        BASIC_CFLAGS += -DNO_SYMLINK_HEAD
 endif
-ifdef GETTEXT_POISON
-       BASIC_CFLAGS += -DGETTEXT_POISON
-endif
 ifdef NO_GETTEXT
        BASIC_CFLAGS += -DNO_GETTEXT
        USE_GETTEXT_SCHEME ?= fallthrough
@@ -2497,7 +2489,6 @@ ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
        @echo GIT_TEST_CMP_USE_COPIED_CONTEXT=YesPlease >>$@
 endif
        @echo NO_GETTEXT=\''$(subst ','\'',$(subst ','\'',$(NO_GETTEXT)))'\' 
>>$@
-       @echo GETTEXT_POISON=\''$(subst ','\'',$(subst 
','\'',$(GETTEXT_POISON)))'\' >>$@
 ifdef GIT_PERF_REPEAT_COUNT
        @echo GIT_PERF_REPEAT_COUNT=\''$(subst ','\'',$(subst 
','\'',$(GIT_PERF_REPEAT_COUNT)))'\' >>$@
 endif
@@ -2545,6 +2536,9 @@ export NO_SVN_TESTS
 test: all
        $(MAKE) -C t/ all
 
+poison-test: all
+       $(MAKE) POISON_GETTEXT=YesPlease -C t/ all
+
 perf: all
        $(MAKE) -C t/perf/ all
 
diff --git a/gettext.c b/gettext.c
index f75bca7..6aa822c 100644
--- a/gettext.c
+++ b/gettext.c
@@ -16,16 +16,6 @@
 #      endif
 #endif
 
-#ifdef GETTEXT_POISON
-int use_gettext_poison(void)
-{
-       static int poison_requested = -1;
-       if (poison_requested == -1)
-               poison_requested = getenv("GIT_GETTEXT_POISON") ? 1 : 0;
-       return poison_requested;
-}
-#endif
-
 #ifndef NO_GETTEXT
 static void init_gettext_charset(const char *domain)
 {
diff --git a/gettext.h b/gettext.h
index 57ba8bb..a77554f 100644
--- a/gettext.h
+++ b/gettext.h
@@ -36,11 +36,13 @@ static inline void git_setup_gettext(void)
 }
 #endif
 
-#ifdef GETTEXT_POISON
-extern int use_gettext_poison(void);
-#else
-#define use_gettext_poison() 0
-#endif
+static inline int use_gettext_poison(void)
+{
+       static int poison_requested = -1;
+       if (poison_requested == -1)
+               poison_requested = getenv("GIT_GETTEXT_POISON") ? 1 : 0;
+       return poison_requested;
+}
 
 static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
 {
diff --git a/po/README b/po/README
index c1520e8..e25752b 100644
--- a/po/README
+++ b/po/README
@@ -270,16 +270,11 @@ something in the test suite might still depend on the US 
English
 version of the strings, e.g. to grep some error message or other
 output.
 
-To smoke out issues like these Git can be compiled with gettext poison
-support, at the top-level:
+To smoke out issues like these you should run the test suite with
+gettext poison support, which emits gibberish on every call to
+gettext:
 
-    make GETTEXT_POISON=YesPlease
-
-That'll give you a git which emits gibberish on every call to
-gettext. It's obviously not meant to be installed, but you should run
-the test suite with it:
-
-    cd t && prove -j 9 ./t[0-9]*.sh
+    cd t && GETTEXT_POISON=YesPlease prove -j 9 ./t[0-9]*.sh
 
 If tests break with it you should inspect them manually and see if
 what you're translating is sane, i.e. that you're not translating
-- 
1.7.12.rc2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to