Skip to content

Commit 50cbb49

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 e68bcdc + 0b4e3d1 commit 50cbb49

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
@@ -474,6 +474,7 @@ lib = lib
474474
# DESTDIR =
475475
pathsep = :
476476

477+
localedir_relative = $(patsubst $(prefix)/%,%,$(localedir))
477478
mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))
478479
infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))
479480
htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))
@@ -1677,6 +1678,7 @@ bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
16771678
mandir_relative_SQ = $(subst ','\'',$(mandir_relative))
16781679
infodir_relative_SQ = $(subst ','\'',$(infodir_relative))
16791680
localedir_SQ = $(subst ','\'',$(localedir))
1681+
localedir_relative_SQ = $(subst ','\'',$(localedir_relative))
16801682
gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
16811683
template_dir_SQ = $(subst ','\'',$(template_dir))
16821684
htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative))
@@ -2113,7 +2115,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
21132115

21142116
gettext.sp gettext.s gettext.o: GIT-PREFIX
21152117
gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
2116-
-DGIT_LOCALE_PATH='"$(localedir_SQ)"'
2118+
-DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"'
21172119

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

common-main.c

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

35+
git_extract_argv0_path(argv[0]);
36+
3537
git_setup_gettext();
3638

3739
attr_start();
3840

39-
git_extract_argv0_path(argv[0]);
40-
4141
restore_sigpipe_to_default();
4242

4343
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)