mingw: prepare the TMPDIR environment variable for shell scripts

When shell scripts access a $TMPDIR variable containing backslashes, they will be mistaken for escape characters. Let's not let that happen by converting them to forward slashes. This partially fixes t7800 with MSYS2. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jan 26, 2016 at 15:34 UTC 1fc7bf79e5f907b85aa0213c0ad4969506cf8f2b
1 file changed +19 -4
compat/mingw.c
+19 -4
@@ -2046,13 +2046,28 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen)
2046
2047 static void setup_windows_environment()
2048 {
2049 + char *tmp = getenv("TMPDIR");
2050 +
2051 /* on Windows it is TMP and TEMP */
2050 - if (!getenv("TMPDIR")) {
2051 - const char *tmp = getenv("TMP");
2052 - if (!tmp)
2052 + if (!tmp) {
2053 + if (!(tmp = getenv("TMP")))
2054 tmp = getenv("TEMP");
2054 - if (tmp)
2055 + if (tmp) {
2056 setenv("TMPDIR", tmp, 1);
2057 + tmp = getenv("TMPDIR");
2058 + }
2059 + }
2060 +
2061 + if (tmp) {
2062 + /*
2063 + * Convert all dir separators to forward slashes,
2064 + * to help shell commands called from the Git
2065 + * executable (by not mistaking the dir separators
2066 + * for escape characters).
2067 + */
2068 + for (; *tmp; tmp++)
2069 + if (*tmp == '\\')
2070 + *tmp = '/';
2071 }
2072
2073 /* simulate TERM to enable auto-color (see color.c) */