perl: use mock i18n functions under NO_GETTEXT=Y
Change the logic of the i18n functions I added in 5e9637c6297 (i18n: add infrastructure for translating Git with gettext, 2011-11-18) to use pass-through functions when NO_GETTEXT is defined. This speeds up the compilation time of commands that use this library when NO_GETTEXT=Y is in effect. Loading it and POSIX.pm is around 20ms on my machine, whereas it takes 2ms to just instantiate perl itself. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
May 5, 2021 at 14:21 UTC
256c2dc42c812e4868532b88155f60f0a269c821
2 files changed
+13
Makefile
+3
@@ -1986,6 +1986,7 @@ ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
1986
ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES))
1987
1988
DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
1989
+NO_GETTEXT_SQ = $(subst ','\'',$(NO_GETTEXT))
1990
bindir_SQ = $(subst ','\'',$(bindir))
1991
bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
1992
mandir_SQ = $(subst ','\'',$(mandir))
@@ -2276,6 +2277,7 @@ PERL_DEFINES += $(PERLLIB_EXTRA_SQ)
2277
PERL_DEFINES += $(perllibdir_SQ)
2278
PERL_DEFINES += $(RUNTIME_PREFIX)
2279
PERL_DEFINES += $(NO_PERL_CPAN_FALLBACKS)
2280
+PERL_DEFINES += $(NO_GETTEXT)
2281
2282
# Support Perl runtime prefix. In this mode, a different header is installed
2283
# into Perl scripts.
@@ -2680,6 +2682,7 @@ endif
2682
perl/build/lib/%.pm: perl/%.pm GIT-PERL-DEFINES
2683
$(QUIET_GEN)mkdir -p $(dir $@) && \
2684
sed -e 's|@@LOCALEDIR@@|$(perl_localedir_SQ)|g' \
2685
+ -e 's|@@NO_GETTEXT@@|$(NO_GETTEXT_SQ)|g' \
2686
-e 's|@@NO_PERL_CPAN_FALLBACKS@@|$(NO_PERL_CPAN_FALLBACKS_SQ)|g' \
2687
< $< > $@
2688
perl/Git/I18N.pm
+10
@@ -16,9 +16,19 @@ BEGIN {
16
our @EXPORT = qw(__ __n N__);
17
our @EXPORT_OK = @EXPORT;
18
19
+# See Git::LoadCPAN's NO_PERL_CPAN_FALLBACKS_STR for a description of
20
+# this "'@@' [...] '@@'" pattern.
21
+use constant NO_GETTEXT_STR => '@@' . 'NO_GETTEXT' . '@@';
22
+use constant NO_GETTEXT => (
23
+ q[@@NO_GETTEXT@@] ne ''
24
+ and
25
+ q[@@NO_GETTEXT@@] ne NO_GETTEXT_STR
26
+);
27
+
28
sub __bootstrap_locale_messages {
29
our $TEXTDOMAIN = 'git';
30
our $TEXTDOMAINDIR ||= $ENV{GIT_TEXTDOMAINDIR} || '@@LOCALEDIR@@';
31
+ die "NO_GETTEXT=" . NO_GETTEXT_STR if NO_GETTEXT;
32
33
require POSIX;
34
POSIX->import(qw(setlocale));