Skip to content

Commit 1c22d05

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 554ca5b + 0f77025 commit 1c22d05

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
@@ -482,6 +482,7 @@ lib = lib
482482
# DESTDIR =
483483
pathsep = :
484484

485+
localedir_relative = $(patsubst $(prefix)/%,%,$(localedir))
485486
mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))
486487
infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))
487488
htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))
@@ -1714,6 +1715,7 @@ bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
17141715
mandir_relative_SQ = $(subst ','\'',$(mandir_relative))
17151716
infodir_relative_SQ = $(subst ','\'',$(infodir_relative))
17161717
localedir_SQ = $(subst ','\'',$(localedir))
1718+
localedir_relative_SQ = $(subst ','\'',$(localedir_relative))
17171719
gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
17181720
template_dir_SQ = $(subst ','\'',$(template_dir))
17191721
htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative))
@@ -2149,7 +2151,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
21492151

21502152
gettext.sp gettext.s gettext.o: GIT-PREFIX
21512153
gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
2152-
-DGIT_LOCALE_PATH='"$(localedir_SQ)"'
2154+
-DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"'
21532155

21542156
http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SPARSE_FLAGS += \
21552157
-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)