Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- abspath.c | 5 +++++ builtin/clone.c | 2 +- builtin/init-db.c | 6 +++--- cache.h | 1 + setup.c | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/abspath.c b/abspath.c index 5edb4e7..ca44eb9 100644 --- a/abspath.c +++ b/abspath.c @@ -135,6 +135,11 @@ const char *real_path(const char *path) return real_path_internal(path, 1); } +char *real_path_dup(const char *path) +{ + return xstrdup(real_path(path)); +} + const char *real_path_if_valid(const char *path) { return real_path_internal(path, 0); diff --git a/builtin/clone.c b/builtin/clone.c index a0b3cd9..7652e03 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -280,7 +280,7 @@ static int add_one_reference(struct string_list_item *item, void *cb_data) struct strbuf alternate = STRBUF_INIT; /* Beware: read_gitfile(), real_path() and mkpath() return static buffer */ - ref_git = xstrdup(real_path(item->string)); + ref_git = real_path_dup(item->string); repo = read_gitfile(ref_git); if (!repo) diff --git a/builtin/init-db.c b/builtin/init-db.c index 07229d6..65c95fd 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -315,7 +315,7 @@ int set_git_dir_init(const char *git_dir, const char *real_git_dir, * make sure symlinks are resolved because we'll be * moving the target repo later on in separate_git_dir() */ - git_link = xstrdup(real_path(git_dir)); + git_link = real_path_dup(git_dir); set_git_dir(real_path(real_git_dir)); } else { @@ -480,7 +480,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0); if (real_git_dir && !is_absolute_path(real_git_dir)) - real_git_dir = xstrdup(real_path(real_git_dir)); + real_git_dir = real_path_dup(real_git_dir); if (argc == 1) { int mkdir_tried = 0; @@ -551,7 +551,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) const char *git_dir_parent = strrchr(git_dir, '/'); if (git_dir_parent) { char *rel = xstrndup(git_dir, git_dir_parent - git_dir); - git_work_tree_cfg = xstrdup(real_path(rel)); + git_work_tree_cfg = real_path_dup(rel); free(rel); } if (!git_work_tree_cfg) diff --git a/cache.h b/cache.h index c63fcc1..fbe29ac 100644 --- a/cache.h +++ b/cache.h @@ -960,6 +960,7 @@ static inline int is_absolute_path(const char *path) int is_directory(const char *); const char *real_path(const char *path); const char *real_path_if_valid(const char *path); +char *real_path_dup(const char *path); const char *absolute_path(const char *path); const char *remove_leading_path(const char *in, const char *prefix); const char *relative_path(const char *in, const char *prefix, struct strbuf *sb); diff --git a/setup.c b/setup.c index 6ee2b23..8b02429 100644 --- a/setup.c +++ b/setup.c @@ -643,7 +643,7 @@ static const char *setup_discovered_git_dir(const char *gitdir, /* --work-tree is set without --git-dir; use discovered one */ if (getenv(GIT_WORK_TREE_ENVIRONMENT) || git_work_tree_cfg) { if (offset != cwd->len && !is_absolute_path(gitdir)) - gitdir = xstrdup(real_path(gitdir)); + gitdir = real_path_dup(gitdir); if (chdir(cwd->buf)) die_errno("Could not come back to cwd"); return setup_explicit_git_dir(gitdir, cwd, nongit_ok); -- 2.7.0.96.g5373197 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html