Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 2e69421

Browse files
committed
Merge 'home' into HEAD
2 parents 9e8817c + 8dfd8dc commit 2e69421

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

compat/mingw.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,24 @@ int mingw_offset_1st_component(const char *path)
19931993
return offset + is_dir_sep(path[offset]);
19941994
}
19951995

1996+
const char *get_windows_home_directory(void)
1997+
{
1998+
static const char *home_directory = NULL;
1999+
struct strbuf buf = STRBUF_INIT;
2000+
2001+
if (home_directory)
2002+
return home_directory;
2003+
2004+
home_directory = getenv("HOME");
2005+
if (home_directory && *home_directory)
2006+
return home_directory;
2007+
2008+
strbuf_addf(&buf, "%s/%s", getenv("HOMEDRIVE"), getenv("HOMEPATH"));
2009+
home_directory = strbuf_detach(&buf, NULL);
2010+
2011+
return home_directory;
2012+
}
2013+
19962014
int xutftowcsn(wchar_t *wcs, const char *utfs, size_t wcslen, int utflen)
19972015
{
19982016
int upos = 0, wpos = 0;

compat/mingw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,6 @@ static int mingw_main(c,v)
489489
* Used by Pthread API implementation for Windows
490490
*/
491491
extern int err_win_to_posix(DWORD winerr);
492+
493+
extern const char *get_windows_home_directory();
494+
#define get_home_directory() get_windows_home_directory()

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,4 +731,8 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
731731
#define mark_as_git_dir(x) /* noop */
732732
#endif
733733

734+
#ifndef get_home_directory
735+
#define get_home_directory() getenv("HOME")
736+
#endif
737+
734738
#endif

path.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ char *git_path(const char *fmt, ...)
133133
void home_config_paths(char **global, char **xdg, char *file)
134134
{
135135
char *xdg_home = getenv("XDG_CONFIG_HOME");
136-
char *home = getenv("HOME");
136+
const char *home = get_home_directory();
137137
char *to_free = NULL;
138138

139139
if (!home) {
@@ -274,7 +274,7 @@ char *expand_user_path(const char *path)
274274
const char *username = path + 1;
275275
size_t username_len = first_slash - username;
276276
if (username_len == 0) {
277-
const char *home = getenv("HOME");
277+
const char *home = get_home_directory();
278278
if (!home)
279279
goto return_null;
280280
strbuf_add(&user_path, home, strlen(home));

shell.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static char *make_cmd(const char *prog)
5555

5656
static void cd_to_homedir(void)
5757
{
58-
const char *home = getenv("HOME");
58+
const char *home = get_home_directory();
5959
if (!home)
6060
die("could not determine user's home directory; HOME is unset");
6161
if (chdir(home) == -1)

0 commit comments

Comments
 (0)