Skip to content

Commit 96acecc

Browse files
committed
gettext: avoid initialization if the locale dir is not present
The runtime of a simple `git.exe version` call on Windows is currently dominated by the gettext setup, adding a whopping ~150ms to the ~210ms total. Given that this cost is added to each and every git.exe invocation goes through common-main's invocation of git_setup_gettext(), and given that scripts have to call git.exe dozens, if not hundreds, of times, this is a substantial performance penalty. This is particularly pointless when considering that Git for Windows ships without localization (to keep the installer's size to a bearable ~34MB): all that time setting up gettext is for naught. So let's be smart about it and skip setting up gettext if the locale directory is not even present. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 90cdb5e commit 96acecc

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

gettext.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,13 @@ void git_setup_gettext(void)
169169
if (!is_absolute_path(podir))
170170
podir = p = system_path(podir);
171171

172-
bindtextdomain("git", podir);
173-
setlocale(LC_MESSAGES, "");
174-
setlocale(LC_TIME, "");
175-
init_gettext_charset("git");
176-
textdomain("git");
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+
}
177179

178180
free(p);
179181
}

0 commit comments

Comments
 (0)