Merge 'home' into HEAD

This commit is contained in:
Stepan Kasal
2014-05-29 11:08:05 +02:00
5 changed files with 28 additions and 3 deletions

View File

@@ -1993,6 +1993,24 @@ int mingw_offset_1st_component(const char *path)
return offset + is_dir_sep(path[offset]);
}
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;
}
int xutftowcsn(wchar_t *wcs, const char *utfs, size_t wcslen, int utflen)
{
int upos = 0, wpos = 0;

View File

@@ -489,3 +489,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()

View File

@@ -731,4 +731,8 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
#define mark_as_git_dir(x) /* noop */
#endif
#ifndef get_home_directory
#define get_home_directory() getenv("HOME")
#endif
#endif

4
path.c
View File

@@ -133,7 +133,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) {
@@ -274,7 +274,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));

View File

@@ -55,7 +55,7 @@ static char *make_cmd(const char *prog)
static void cd_to_homedir(void)
{
const char *home = getenv("HOME");
const char *home = get_home_directory();
if (!home)
die("could not determine user's home directory; HOME is unset");
if (chdir(home) == -1)