Skip to content

Commit 06bc4b7

Browse files
j6tgitster
authored andcommitted
mingw.c: move definition of mingw_getenv down
We want to use static lookup_env() in a subsequent change. At first sight, this change looks innocent. But it is not due to the #undef getenv. There is one caller of getenv between the old location and the new location whose behavior could change. But as can be seen from the defintion of mingw_getenv, the behavior for this caller does not change substantially. To ensure consistent behavior in the future, change all getenv callers in mingw.c to use mingw_getenv. With this patch, this is not a big deal, yet, but with the subsequent change, where we teach getenv to do a case-sensitive lookup, the behavior of all call sites is changed. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8c92516 commit 06bc4b7

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

compat/mingw.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static int ask_yes_no_if_possible(const char *format, ...)
178178
vsnprintf(question, sizeof(question), format, args);
179179
va_end(args);
180180

181-
if ((retry_hook[0] = getenv("GIT_ASK_YESNO"))) {
181+
if ((retry_hook[0] = mingw_getenv("GIT_ASK_YESNO"))) {
182182
retry_hook[1] = question;
183183
return !run_command_v_opt(retry_hook, 0);
184184
}
@@ -599,19 +599,6 @@ char *mingw_getcwd(char *pointer, int len)
599599
return ret;
600600
}
601601

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-
615602
/*
616603
* See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx
617604
* (Parsing C++ Command-Line Arguments)
@@ -711,7 +698,7 @@ static const char *parse_interpreter(const char *cmd)
711698
*/
712699
static char **get_path_split(void)
713700
{
714-
char *p, **path, *envpath = getenv("PATH");
701+
char *p, **path, *envpath = mingw_getenv("PATH");
715702
int i, n = 0;
716703

717704
if (!envpath || !*envpath)
@@ -1128,6 +1115,19 @@ char **make_augmented_environ(const char *const *vars)
11281115
return env;
11291116
}
11301117

1118+
#undef getenv
1119+
char *mingw_getenv(const char *name)
1120+
{
1121+
char *result = getenv(name);
1122+
if (!result && !strcmp(name, "TMPDIR")) {
1123+
/* on Windows it is TMP and TEMP */
1124+
result = getenv("TMP");
1125+
if (!result)
1126+
result = getenv("TEMP");
1127+
}
1128+
return result;
1129+
}
1130+
11311131
/*
11321132
* Note, this isn't a complete replacement for getaddrinfo. It assumes
11331133
* that service contains a numerical port, or that it is null. It

0 commit comments

Comments
 (0)