Skip to content

Commit 39aade4

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 21fa111 + 605b908 commit 39aade4

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
@@ -452,6 +452,7 @@ lib = lib
452452
# DESTDIR =
453453
pathsep = :
454454

455+
localedir_relative = $(patsubst $(prefix)/%,%,$(localedir))
455456
mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))
456457
infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))
457458
htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))
@@ -1619,6 +1620,7 @@ bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
16191620
mandir_relative_SQ = $(subst ','\'',$(mandir_relative))
16201621
infodir_relative_SQ = $(subst ','\'',$(infodir_relative))
16211622
localedir_SQ = $(subst ','\'',$(localedir))
1623+
localedir_relative_SQ = $(subst ','\'',$(localedir_relative))
16221624
gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
16231625
template_dir_SQ = $(subst ','\'',$(template_dir))
16241626
htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative))
@@ -2055,7 +2057,7 @@ attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
20552057

20562058
gettext.sp gettext.s gettext.o: GIT-PREFIX
20572059
gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
2058-
-DGIT_LOCALE_PATH='"$(localedir_SQ)"'
2060+
-DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"'
20592061

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