On Wed, Feb 25, 2015 at 02:52:26PM -0800, Junio C Hamano wrote: > This is now in 'master', but I wonder if people are getting > compilation errors because of this change. I do.
I usually compile with NO_GETTEXT, but if I stop doing so, I see the problem, too. > I really do not like a conditional inclusion of system header files > inside any *.c file, but here is a minimum emergency fix-up I am > running with today. It should go to somewhere in git-compat-util.h. Perhaps it would be less risky to stick get_preferred_languages() into gettext.c, like the patch below. Then we do not have to worry about locale.h introducing other disruptive includes. The function is not technically about gettext, but it seems reasonable to me to stuff all of the i18n code together. Another variant of this would for gettext.c to provide a git_setlocale that just wraps setlocale (and does nothing when NO_GETTEXT is given). 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) { /* -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html