Merge branch 'js/runtime-prefix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2018 06:59:34 +0000 (15:59 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2018 06:59:34 +0000 (15:59 +0900)
* js/runtime-prefix:
Avoid multiple PREFIX definitions
git_setup_gettext: plug memory leak
gettext: avoid initialization if the locale dir is not present

Makefile
exec-cmd.c
gettext.c
sideband.c
index 4541788e50c4faa424c6df717dfcc6bc78fa570b..ad880d1fc57212fc6b47aeea792a58129b61238e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2284,7 +2284,7 @@ exec-cmd.sp exec-cmd.s exec-cmd.o: EXTRA_CPPFLAGS = \
        '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
        '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
        '-DBINDIR="$(bindir_relative_SQ)"' \
-       '-DPREFIX="$(prefix_SQ)"'
+       '-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"'
 
 builtin/init-db.sp builtin/init-db.s builtin/init-db.o: GIT-PREFIX
 builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
index 3b0a039083a8d377325983272e4aa38ee1b5674c..02d31ee89711da7a4d5a483c6339909c05a15e08 100644 (file)
@@ -48,7 +48,7 @@ static const char *system_prefix(void)
            !(prefix = strip_path_suffix(executable_dirname, GIT_EXEC_PATH)) &&
            !(prefix = strip_path_suffix(executable_dirname, BINDIR)) &&
            !(prefix = strip_path_suffix(executable_dirname, "git"))) {
-               prefix = PREFIX;
+               prefix = FALLBACK_RUNTIME_PREFIX;
                trace_printf("RUNTIME_PREFIX requested, "
                                "but prefix computation failed.  "
                                "Using static fallback '%s'.\n", prefix);
@@ -243,7 +243,7 @@ void git_resolve_executable_dir(const char *argv0)
  */
 static const char *system_prefix(void)
 {
-       return PREFIX;
+       return FALLBACK_RUNTIME_PREFIX;
 }
 
 /*
index baba28343c311594e048d62e190ded09e49ed5b0..7272771c8e445da194ea608443d8bc9c891b6b33 100644 (file)
--- a/gettext.c
+++ b/gettext.c
@@ -159,15 +159,23 @@ static void init_gettext_charset(const char *domain)
 void git_setup_gettext(void)
 {
        const char *podir = getenv(GIT_TEXT_DOMAIN_DIR_ENVIRONMENT);
+       char *p = NULL;
 
        if (!podir)
-               podir = system_path(GIT_LOCALE_PATH);
+               podir = p = system_path(GIT_LOCALE_PATH);
+
+       if (!is_directory(podir)) {
+               free(p);
+               return;
+       }
 
        bindtextdomain("git", podir);
        setlocale(LC_MESSAGES, "");
        setlocale(LC_TIME, "");
        init_gettext_charset("git");
        textdomain("git");
+
+       free(p);
 }
 
 /* return the number of columns of string 's' in current locale */
index 6d7f943e4384fa90001fbb73cc5b63e2c0cfa639..325bf0e974ab9bd8c2c5b5483fbb619ac425531b 100644 (file)
@@ -13,7 +13,7 @@
  * the remote died unexpectedly.  A flush() concludes the stream.
  */
 
-#define PREFIX "remote: "
+#define DISPLAY_PREFIX "remote: "
 
 #define ANSI_SUFFIX "\033[K"
 #define DUMB_SUFFIX "        "
@@ -49,7 +49,7 @@ int recv_sideband(const char *me, int in_stream, int out)
                switch (band) {
                case 3:
                        strbuf_addf(&outbuf, "%s%s%s", outbuf.len ? "\n" : "",
-                                   PREFIX, buf + 1);
+                                   DISPLAY_PREFIX, buf + 1);
                        retval = SIDEBAND_REMOTE_ERROR;
                        break;
                case 2:
@@ -67,7 +67,7 @@ int recv_sideband(const char *me, int in_stream, int out)
                                int linelen = brk - b;
 
                                if (!outbuf.len)
-                                       strbuf_addstr(&outbuf, PREFIX);
+                                       strbuf_addstr(&outbuf, DISPLAY_PREFIX);
                                if (linelen > 0) {
                                        strbuf_addf(&outbuf, "%.*s%s%c",
                                                    linelen, b, suffix, *brk);
@@ -81,8 +81,8 @@ int recv_sideband(const char *me, int in_stream, int out)
                        }
 
                        if (*b)
-                               strbuf_addf(&outbuf, "%s%s",
-                                           outbuf.len ? "" : PREFIX, b);
+                               strbuf_addf(&outbuf, "%s%s", outbuf.len ?
+                                           "" : DISPLAY_PREFIX, b);
                        break;
                case 1:
                        write_or_die(out, buf + 1, len);