mirror of
https://github.com/git/git.git
synced 2026-02-12 02:38:53 +00:00
Add a Windows-specific fallback to getenv("HOME");
This fixes msysGit issue 482 properly. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
committed by
Pat Thoyts
parent
85fdf1d0f6
commit
1bf1431c67
@@ -1899,3 +1899,21 @@ pid_t waitpid(pid_t pid, int *status, int options)
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *get_windows_home_directory(void)
|
||||
{
|
||||
static const char *home_directory = NULL;
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
|
||||
if (home_directory)
|
||||
return home_directory;
|
||||
|
||||
home_directory = getenv("HOME");
|
||||
if (home_directory && *home_directory)
|
||||
return home_directory;
|
||||
|
||||
strbuf_addf(&buf, "%s/%s", getenv("HOMEDRIVE"), getenv("HOMEPATH"));
|
||||
home_directory = strbuf_detach(&buf, NULL);
|
||||
|
||||
return home_directory;
|
||||
}
|
||||
|
||||
@@ -357,3 +357,6 @@ static int mingw_main(c,v)
|
||||
* Used by Pthread API implementation for Windows
|
||||
*/
|
||||
extern int err_win_to_posix(DWORD winerr);
|
||||
|
||||
extern const char *get_windows_home_directory();
|
||||
#define get_home_directory() get_windows_home_directory()
|
||||
|
||||
@@ -654,4 +654,8 @@ struct passwd *xgetpwuid_self(void);
|
||||
#define mark_as_git_dir(x) /* noop */
|
||||
#endif
|
||||
|
||||
#ifndef get_home_directory
|
||||
#define get_home_directory() getenv("HOME")
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
4
path.c
4
path.c
@@ -132,7 +132,7 @@ char *git_path(const char *fmt, ...)
|
||||
void home_config_paths(char **global, char **xdg, char *file)
|
||||
{
|
||||
char *xdg_home = getenv("XDG_CONFIG_HOME");
|
||||
char *home = getenv("HOME");
|
||||
const char *home = get_home_directory();
|
||||
char *to_free = NULL;
|
||||
|
||||
if (!home) {
|
||||
@@ -273,7 +273,7 @@ char *expand_user_path(const char *path)
|
||||
const char *username = path + 1;
|
||||
size_t username_len = first_slash - username;
|
||||
if (username_len == 0) {
|
||||
const char *home = getenv("HOME");
|
||||
const char *home = get_home_directory();
|
||||
if (!home)
|
||||
goto return_null;
|
||||
strbuf_add(&user_path, home, strlen(home));
|
||||
|
||||
Reference in New Issue
Block a user