Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'js/i18n-windows'

* js/i18n-windows:
  Windows: teach getenv to do a case-sensitive search
  mingw.c: move definition of mingw_getenv down
  sh-i18n--envsubst: do not crash when no arguments are given
  • Loading branch information...
commit 1fd7ef2e8f6b8b67f4d3be7b9ab5bbd9d8f639ec 2 parents 1692d0c + df599e9
Junio C Hamano gitster authored

Showing 2 changed files with 33 additions and 15 deletions. Show diff stats Hide diff stats

  1. +32 15 compat/mingw.c
  2. +1 0  sh-i18n--envsubst.c
47 compat/mingw.c
@@ -178,7 +178,7 @@ static int ask_yes_no_if_possible(const char *format, ...)
178 178 vsnprintf(question, sizeof(question), format, args);
179 179 va_end(args);
180 180
181   - if ((retry_hook[0] = getenv("GIT_ASK_YESNO"))) {
  181 + if ((retry_hook[0] = mingw_getenv("GIT_ASK_YESNO"))) {
182 182 retry_hook[1] = question;
183 183 return !run_command_v_opt(retry_hook, 0);
184 184 }
@@ -599,19 +599,6 @@ char *mingw_getcwd(char *pointer, int len)
599 599 return ret;
600 600 }
601 601
602   -#undef getenv
603   -char *mingw_getenv(const char *name)
604   -{
605   - char *result = getenv(name);
606   - if (!result && !strcmp(name, "TMPDIR")) {
607   - /* on Windows it is TMP and TEMP */
608   - result = getenv("TMP");
609   - if (!result)
610   - result = getenv("TEMP");
611   - }
612   - return result;
613   -}
614   -
615 602 /*
616 603 * See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx
617 604 * (Parsing C++ Command-Line Arguments)
@@ -711,7 +698,7 @@ static const char *parse_interpreter(const char *cmd)
711 698 */
712 699 static char **get_path_split(void)
713 700 {
714   - char *p, **path, *envpath = getenv("PATH");
  701 + char *p, **path, *envpath = mingw_getenv("PATH");
715 702 int i, n = 0;
716 703
717 704 if (!envpath || !*envpath)
@@ -1128,6 +1115,36 @@ char **make_augmented_environ(const char *const *vars)
1128 1115 return env;
1129 1116 }
1130 1117
  1118 +#undef getenv
  1119 +
  1120 +/*
  1121 + * The system's getenv looks up the name in a case-insensitive manner.
  1122 + * This version tries a case-sensitive lookup and falls back to
  1123 + * case-insensitive if nothing was found. This is necessary because,
  1124 + * as a prominent example, CMD sets 'Path', but not 'PATH'.
  1125 + * Warning: not thread-safe.
  1126 + */
  1127 +static char *getenv_cs(const char *name)
  1128 +{
  1129 + size_t len = strlen(name);
  1130 + int i = lookup_env(environ, name, len);
  1131 + if (i >= 0)
  1132 + return environ[i] + len + 1; /* skip past name and '=' */
  1133 + return getenv(name);
  1134 +}
  1135 +
  1136 +char *mingw_getenv(const char *name)
  1137 +{
  1138 + char *result = getenv_cs(name);
  1139 + if (!result && !strcmp(name, "TMPDIR")) {
  1140 + /* on Windows it is TMP and TEMP */
  1141 + result = getenv_cs("TMP");
  1142 + if (!result)
  1143 + result = getenv_cs("TEMP");
  1144 + }
  1145 + return result;
  1146 +}
  1147 +
1131 1148 /*
1132 1149 * Note, this isn't a complete replacement for getaddrinfo. It assumes
1133 1150 * that service contains a numerical port, or that it is null. It
1  sh-i18n--envsubst.c
@@ -73,6 +73,7 @@ main (int argc, char *argv[])
73 73 {
74 74 case 1:
75 75 error ("we won't substitute all variables on stdin for you");
  76 + break;
76 77 /*
77 78 all_variables = 1;
78 79 subst_from_stdin ();

0 comments on commit 1fd7ef2

Please sign in to comment.
Something went wrong with that request. Please try again.