All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add a Windows-specific fallback to getenv("HOME");
@ 2014-06-04 11:47 Stepan Kasal
  2014-06-04 13:47 ` Duy Nguyen
  0 siblings, 1 reply; 31+ messages in thread
From: Stepan Kasal @ 2014-06-04 11:47 UTC (permalink / raw)
  To: GIT Mailing-list; +Cc: Thomas Braun, msysgit

From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Wed, 2 Jun 2010 00:41:33 +0200

If HOME is not set, use $HOMEDRIVE/$HOMEPATH

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
Hi,
   this patch is present in msysGit for 4 years.
Stepan

 compat/mingw.c    | 18 ++++++++++++++++++
 compat/mingw.h    |  3 +++
 git-compat-util.h |  4 ++++
 path.c            |  4 ++--
 shell.c           |  2 +-
 5 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index a0e13bc..8eb21dc 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1847,3 +1847,21 @@ 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;
+}
diff --git a/compat/mingw.h b/compat/mingw.h
index 3eaf822..a88a7ab 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -386,3 +386,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()
diff --git a/git-compat-util.h b/git-compat-util.h
index b6f03b3..409e644 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -740,4 +740,8 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
 #define gmtime_r git_gmtime_r
 #endif
 
+#ifndef get_home_directory
+#define get_home_directory() getenv("HOME")
+#endif
+
 #endif
diff --git a/path.c b/path.c
index bc804a3..09b362c 100644
--- a/path.c
+++ b/path.c
@@ -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));
diff --git a/shell.c b/shell.c
index 5c0d47a..edd8c3a 100644
--- a/shell.c
+++ b/shell.c
@@ -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)
-- 
1.9.2.msysgit.0.655.g1a42564

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2014-06-06 19:26 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-04 11:47 [PATCH] Add a Windows-specific fallback to getenv("HOME"); Stepan Kasal
2014-06-04 13:47 ` Duy Nguyen
2014-06-04 14:05   ` Erik Faye-Lund
2014-06-04 14:55     ` Karsten Blees
2014-06-04 15:14     ` Johannes Schindelin
2014-06-04 15:18       ` Erik Faye-Lund
2014-06-04 15:27         ` Johannes Schindelin
2014-06-04 15:45           ` Stepan Kasal
2014-06-04 15:56             ` [msysGit] " Johannes Schindelin
2014-06-04 16:16               ` Stepan Kasal
2014-06-04 17:49                 ` [msysGit] " Johannes Schindelin
2014-06-06  9:12                   ` Git for Windows SDK Philip Oakley
2014-06-04 23:10                 ` Re: [PATCH] Add a Windows-specific fallback to getenv("HOME"); Duy Nguyen
2014-06-06 19:26                 ` Sebastian Schuberth
2014-06-04 15:46           ` Johannes Schindelin
2014-06-05  1:42             ` Karsten Blees
2014-06-05  8:03               ` [PATCH v2] " Stepan Kasal
2014-06-05  8:32                 ` [msysGit] " Torsten Bögershausen
2014-06-05 10:23                   ` [PATCH v3] " Stepan Kasal
2014-06-05  9:40                 ` [PATCH v2] " Karsten Blees
2014-06-05  9:58                   ` Erik Faye-Lund
2014-06-05 21:44                     ` Karsten Blees
2014-06-06  8:03                       ` Stepan Kasal
2014-06-05 11:23                   ` Stepan Kasal
2014-06-05 13:39                   ` Johannes Schindelin
2014-06-05 20:03                     ` Karsten Blees
2014-06-05 12:03               ` Re: [PATCH] " Johannes Schindelin
2014-06-05 12:15                 ` [msysGit] " Stepan Kasal
2014-06-05 14:33                 ` Karsten Blees
2014-06-04 14:53   ` Stepan Kasal
2014-06-04 15:13   ` Johannes Schindelin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.