summaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2017-04-05 17:24:38 +0700
committerJunio C Hamano <gitster@pobox.com>2017-04-14 23:51:38 -0700
commit4aad2f1627bb74948874c0f31e8ce256bf236aa6 (patch)
treede6b04a3b94f2d709971e878375168120e4fa359 /path.c
parent3efd0bedc6625a6b194c1f6e5f1b7aa7d8b7e6bb (diff)
downloadgit-4aad2f1627bb74948874c0f31e8ce256bf236aa6.tar.gz
path.c: and an option to call real_path() in expand_user_path()
In the next patch we need the ability to expand '~' to real_path($HOME). But we can't do that from outside because '~' is part of a pattern, not a true path. Add an option to expand_user_path() to do so. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r--path.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/path.c b/path.c
index efcedafba6..8b7687d53a 100644
--- a/path.c
+++ b/path.c
@@ -638,8 +638,10 @@ static struct passwd *getpw_str(const char *username, size_t len)
* Return a string with ~ and ~user expanded via getpw*. If buf != NULL,
* then it is a newly allocated string. Returns NULL on getpw failure or
* if path is NULL.
+ *
+ * If real_home is true, real_path($HOME) is used in the expansion.
*/
-char *expand_user_path(const char *path)
+char *expand_user_path(const char *path, int real_home)
{
struct strbuf user_path = STRBUF_INIT;
const char *to_copy = path;
@@ -654,7 +656,10 @@ char *expand_user_path(const char *path)
const char *home = getenv("HOME");
if (!home)
goto return_null;
- strbuf_addstr(&user_path, home);
+ if (real_home)
+ strbuf_addstr(&user_path, real_path(home));
+ else
+ strbuf_addstr(&user_path, home);
#ifdef GIT_WINDOWS_NATIVE
convert_slashes(user_path.buf);
#endif
@@ -723,7 +728,7 @@ const char *enter_repo(const char *path, int strict)
strbuf_add(&validated_path, path, len);
if (used_path.buf[0] == '~') {
- char *newpath = expand_user_path(used_path.buf);
+ char *newpath = expand_user_path(used_path.buf, 0);
if (!newpath)
return NULL;
strbuf_attach(&used_path, newpath, strlen(newpath),