On Thu, Feb 26, 2015 at 2:07 PM, Jeff King [off-list ref] wrote:
Here it is, with the commit message and the missing hunk. This works for
me both with and without NO_GETTEXT defined.
This compiles here though a warning is spit:
In file included from cache.h:8:0,
from userdiff.c:1:
gettext.h:92:1: warning: function declaration isn't a prototype
[-Wstrict-prototypes]
const char *get_preferred_languages();
^
so I guess I can still add a
Tested-by: Stefan Beller <redacted>
quoted hunk ↗ jump to hunk
-- >8 --
Subject: [PATCH] gettext.c: move get_preferred_languages() from http.c
Calling setlocale(LC_MESSAGES, ...) directly from http.c,
without including <locale.h>, was causing compilation
warnings. Move the helper function to gettext.c that
already includes the header and where locale-related issues
are handled.
Signed-off-by: Jeff King <redacted>
---
gettext.c | 25 +++++++++++++++++++++++++
gettext.h | 2 ++
http.c | 27 +--------------------------
3 files changed, 28 insertions(+), 26 deletions(-)
diff --git a/gettext.c b/gettext.c
index 8b2da46..7378ba2 100644
--- a/gettext.c
+++ b/gettext.c
@@ -18,6 +18,31 @@
# endif
#endif
+/*
+ * Guess the user's preferred languages from the value in LANGUAGE environment
+ * variable and LC_MESSAGES locale category if NO_GETTEXT is not defined.
+ *
+ * The result can be a colon-separated list like "ko:ja:en".
+ */
+const char *get_preferred_languages(void)
+{
+ const char *retval;
+
+ retval = getenv("LANGUAGE");
+ if (retval && *retval)
+ return retval;
+
+#ifndef NO_GETTEXT
+ retval = setlocale(LC_MESSAGES, NULL);
+ if (retval && *retval &&
+ strcmp(retval, "C") &&
+ strcmp(retval, "POSIX"))
+ return retval;
+#endif
+
+ return NULL;
+}
+
#ifdef GETTEXT_POISON
int use_gettext_poison(void)
{diff --git a/gettext.h b/gettext.h
index dc1722d..5d8d2df 100644
--- a/gettext.h
+++ b/gettext.h
@@ -89,4 +89,6 @@ const char *Q_(const char *msgid, const char *plu, unsigned long n)
#define N_(msgid) (msgid)
#endif
+const char *get_preferred_languages();
+
#endif
diff --git a/http.c b/http.c
index 0153fb0..9c825af 100644
--- a/http.c
+++ b/http.c
@@ -8,6 +8,7 @@
#include "credential.h"
#include "version.h"
#include "pkt-line.h"
+#include "gettext.h"
int active_requests;
int http_is_verbose;
@@ -1002,32 +1003,6 @@ static void extract_content_type(struct strbuf *raw, struct strbuf *type,
strbuf_addstr(charset, "ISO-8859-1");
}
-
-/*
- * Guess the user's preferred languages from the value in LANGUAGE environment
- * variable and LC_MESSAGES locale category if NO_GETTEXT is not defined.
- *
- * The result can be a colon-separated list like "ko:ja:en".
- */
-static const char *get_preferred_languages(void)
-{
- const char *retval;
-
- retval = getenv("LANGUAGE");
- if (retval && *retval)
- return retval;
-
-#ifndef NO_GETTEXT
- retval = setlocale(LC_MESSAGES, NULL);
- if (retval && *retval &&
- strcmp(retval, "C") &&
- strcmp(retval, "POSIX"))
- return retval;
-#endif
-
- return NULL;
-}
-
static void write_accept_language(struct strbuf *buf)
{
/*
--2.3.0.449.g1690e78