Skip to content

Commit b094b49

Browse files
committed
Merge branch 'skip-gettext-when-possible'
This topic branch allows us to skip the gettext initialization when the locale directory does not even exist. This saves 150ms out of 210ms for a simply `git version` call on Windows, and it most likely will help scripts that call out to `git.exe` hundreds of times. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents b14ab15 + a1d7637 commit b094b49

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ lib = lib
443443
# DESTDIR =
444444
pathsep = :
445445

446+
localedir_relative = $(patsubst $(prefix)/%,%,$(localedir))
446447
mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))
447448
infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))
448449
htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))
@@ -1598,6 +1599,7 @@ bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
15981599
mandir_relative_SQ = $(subst ','\'',$(mandir_relative))
15991600
infodir_relative_SQ = $(subst ','\'',$(infodir_relative))
16001601
localedir_SQ = $(subst ','\'',$(localedir))
1602+
localedir_relative_SQ = $(subst ','\'',$(localedir_relative))
16011603
gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
16021604
template_dir_SQ = $(subst ','\'',$(template_dir))
16031605
htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative))
@@ -2034,7 +2036,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
20342036

20352037
gettext.sp gettext.s gettext.o: GIT-PREFIX
20362038
gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
2037-
-DGIT_LOCALE_PATH='"$(localedir_SQ)"'
2039+
-DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"'
20382040

20392041
http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SPARSE_FLAGS += \
20402042
-DCURL_DISABLE_TYPECHECK

common-main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ int main(int argc, const char **argv)
3131
*/
3232
sanitize_stdfds();
3333

34-
git_setup_gettext();
35-
3634
git_extract_argv0_path(argv[0]);
3735

36+
git_setup_gettext();
37+
3838
restore_sigpipe_to_default();
3939

4040
return cmd_main(argc, argv);

gettext.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "gettext.h"
77
#include "strbuf.h"
88
#include "utf8.h"
9+
#include "cache.h"
10+
#include "exec_cmd.h"
911

1012
#ifndef NO_GETTEXT
1113
# include <locale.h>
@@ -160,14 +162,22 @@ static void init_gettext_charset(const char *domain)
160162
void git_setup_gettext(void)
161163
{
162164
const char *podir = getenv("GIT_TEXTDOMAINDIR");
165+
char *p = NULL;
163166

164167
if (!podir)
165168
podir = GIT_LOCALE_PATH;
166-
bindtextdomain("git", podir);
167-
setlocale(LC_MESSAGES, "");
168-
setlocale(LC_TIME, "");
169-
init_gettext_charset("git");
170-
textdomain("git");
169+
if (!is_absolute_path(podir))
170+
podir = p = system_path(podir);
171+
172+
if (is_directory(podir)) {
173+
bindtextdomain("git", podir);
174+
setlocale(LC_MESSAGES, "");
175+
setlocale(LC_TIME, "");
176+
init_gettext_charset("git");
177+
textdomain("git");
178+
}
179+
180+
free(p);
171181
}
172182

173183
/* return the number of columns of string 's' in current locale */

0 commit comments

Comments
 (0)