mirror of
https://github.com/git/git.git
synced 2026-02-12 02:38:53 +00:00
Merge pull request #73 from kblees/kb/environment-fixes
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
@@ -2218,6 +2218,62 @@ int handle_long_path(wchar_t *path, int len, int max_path, int expand)
|
||||
}
|
||||
}
|
||||
|
||||
static void setup_windows_environment()
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
/* on Windows it is TMP and TEMP */
|
||||
if (!getenv("TMPDIR")) {
|
||||
if (!(tmp = getenv("TMP")))
|
||||
tmp = getenv("TEMP");
|
||||
if (tmp)
|
||||
setenv("TMPDIR", tmp, 1);
|
||||
}
|
||||
|
||||
if ((tmp = getenv("TMPDIR"))) {
|
||||
/*
|
||||
* Convert all dir separators to forward slashes,
|
||||
* to help shell commands called from the Git
|
||||
* executable (by not mistaking the dir separators
|
||||
* for escape characters).
|
||||
*/
|
||||
for (; *tmp; tmp++)
|
||||
if (*tmp == '\\')
|
||||
*tmp = '/';
|
||||
}
|
||||
|
||||
if (!getenv("TZ") && (tmp = getenv("MSYS2_TZ")))
|
||||
setenv("TZ", tmp, 1);
|
||||
|
||||
/* simulate TERM to enable auto-color (see color.c) */
|
||||
if (!getenv("TERM"))
|
||||
setenv("TERM", "cygwin", 1);
|
||||
|
||||
/* calculate HOME if not set */
|
||||
if (!getenv("HOME")) {
|
||||
/*
|
||||
* try $HOMEDRIVE$HOMEPATH - the home share may be a network
|
||||
* location, thus also check if the path exists (i.e. is not
|
||||
* disconnected)
|
||||
*/
|
||||
if ((tmp = getenv("HOMEDRIVE"))) {
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
strbuf_addstr(&buf, tmp);
|
||||
if ((tmp = getenv("HOMEPATH"))) {
|
||||
strbuf_addstr(&buf, tmp);
|
||||
if (is_directory(buf.buf))
|
||||
setenv("HOME", buf.buf, 1);
|
||||
else
|
||||
tmp = NULL; /* use $USERPROFILE */
|
||||
}
|
||||
strbuf_release(&buf);
|
||||
}
|
||||
/* use $USERPROFILE if the home share is not available */
|
||||
if (!tmp && (tmp = getenv("USERPROFILE")))
|
||||
setenv("HOME", tmp, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Disable MSVCRT command line wildcard expansion (__getmainargs called from
|
||||
* mingw startup code, see init.c in mingw runtime).
|
||||
@@ -2287,26 +2343,8 @@ void mingw_startup()
|
||||
__argv[0] = wcstoutfdup_startup(buffer, _wpgmptr, maxlen);
|
||||
for (i = 1; i < argc; i++)
|
||||
__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
|
||||
for (i = 0; wenv[i]; i++) {
|
||||
for (i = 0; wenv[i]; i++)
|
||||
environ[i] = wcstoutfdup_startup(buffer, wenv[i], maxlen);
|
||||
if (!strncasecmp(environ[i], "MSYS2_TZ=", 9)) {
|
||||
char *to_free = environ[i];
|
||||
environ[i] = xstrdup(to_free + 6);
|
||||
free(to_free);
|
||||
}
|
||||
if (!strncasecmp(environ[i], "TMP=", 4)) {
|
||||
/*
|
||||
* Convert all dir separators to forward slashes,
|
||||
* to help shell commands called from the Git
|
||||
* executable (by not mistaking the dir separators
|
||||
* for escape characters).
|
||||
*/
|
||||
char *p;
|
||||
for (p = environ[i]; *p; p++)
|
||||
if (*p == '\\')
|
||||
*p = '/';
|
||||
}
|
||||
}
|
||||
environ[i] = NULL;
|
||||
free(buffer);
|
||||
|
||||
@@ -2314,19 +2352,7 @@ void mingw_startup()
|
||||
qsort(environ, i, sizeof(char*), compareenv);
|
||||
|
||||
/* fix Windows specific environment settings */
|
||||
|
||||
/* on Windows it is TMP and TEMP */
|
||||
if (!mingw_getenv("TMPDIR")) {
|
||||
const char *tmp = mingw_getenv("TMP");
|
||||
if (!tmp)
|
||||
tmp = mingw_getenv("TEMP");
|
||||
if (tmp)
|
||||
setenv("TMPDIR", tmp, 1);
|
||||
}
|
||||
|
||||
/* simulate TERM to enable auto-color (see color.c) */
|
||||
if (!getenv("TERM"))
|
||||
setenv("TERM", "cygwin", 1);
|
||||
setup_windows_environment();
|
||||
|
||||
/*
|
||||
* Avoid a segmentation fault when cURL tries to set the CHARSET
|
||||
|
||||
@@ -48,21 +48,33 @@ static void setup_environment(LPWSTR exepath, int full_path)
|
||||
L"MINGW%d", (int) sizeof(void *) * 8);
|
||||
SetEnvironmentVariable(L"MSYSTEM", msystem);
|
||||
|
||||
/* if not set, set TERM to cygwin */
|
||||
if (!GetEnvironmentVariable(L"TERM", NULL, 0))
|
||||
SetEnvironmentVariable(L"TERM", L"cygwin");
|
||||
|
||||
/* if not set, set PLINK_PROTOCOL to ssh */
|
||||
if (!GetEnvironmentVariable(L"PLINK_PROTOCOL", NULL, 0))
|
||||
SetEnvironmentVariable(L"PLINK_PROTOCOL", L"ssh");
|
||||
|
||||
/* set HOME to %HOMEDRIVE%%HOMEPATH% or %USERPROFILE%
|
||||
/*
|
||||
* set HOME to %HOMEDRIVE%%HOMEPATH% or %USERPROFILE%
|
||||
* With roaming profiles: HOMEPATH is the roaming location and
|
||||
* USERPROFILE is the local location
|
||||
*/
|
||||
if (!GetEnvironmentVariable(L"HOME", NULL, 0)) {
|
||||
LPWSTR e = NULL;
|
||||
len = GetEnvironmentVariable(L"HOMEPATH", NULL, 0);
|
||||
if (len) {
|
||||
DWORD attr, drvlen = GetEnvironmentVariable(L"HOMEDRIVE", NULL, 0);
|
||||
e = (LPWSTR)malloc(sizeof(WCHAR) * (drvlen + len));
|
||||
drvlen = GetEnvironmentVariable(L"HOMEDRIVE", e, drvlen);
|
||||
GetEnvironmentVariable(L"HOMEPATH", e + drvlen, len);
|
||||
/* check if the path exists */
|
||||
attr = GetFileAttributesW(e);
|
||||
if (attr != INVALID_FILE_ATTRIBUTES
|
||||
&& (attr & FILE_ATTRIBUTE_DIRECTORY))
|
||||
SetEnvironmentVariable(L"HOME", e);
|
||||
else
|
||||
len = 0; /* use USERPROFILE */
|
||||
free(e);
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
len = GetEnvironmentVariable(L"USERPROFILE", NULL, 0);
|
||||
if (len != 0) {
|
||||
@@ -72,15 +84,6 @@ static void setup_environment(LPWSTR exepath, int full_path)
|
||||
free(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int n;
|
||||
len += GetEnvironmentVariable(L"HOMEDRIVE", NULL, 0);
|
||||
e = (LPWSTR)malloc(sizeof(WCHAR) * (len + 2));
|
||||
n = GetEnvironmentVariable(L"HOMEDRIVE", e, len);
|
||||
GetEnvironmentVariable(L"HOMEPATH", &e[n], len-n);
|
||||
SetEnvironmentVariable(L"HOME", e);
|
||||
free(e);
|
||||
}
|
||||
}
|
||||
|
||||
/* extend the PATH */
|
||||
|
||||
Reference in New Issue
Block a user