From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 4/6] abspath.c: add and use real_path_dup()
Date: Mon, 18 Jan 2016 18:21:32 +0700 [thread overview]
Message-ID: <1453116094-4987-5-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1453116094-4987-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
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
next prev parent reply other threads:[~2016-01-18 11:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-18 11:21 [PATCH v2 0/6] Kill and replace update_linked_gitdir() Nguyễn Thái Ngọc Duy
2016-01-18 11:21 ` [PATCH v2 1/6] worktree.c: fix indentation Nguyễn Thái Ngọc Duy
2016-01-18 11:21 ` [PATCH v2 2/6] worktree: stop supporting moving worktrees manually Nguyễn Thái Ngọc Duy
2016-01-18 18:24 ` Eric Sunshine
2016-01-18 11:21 ` [PATCH v2 3/6] worktree.txt: how to fix up after moving a worktree Nguyễn Thái Ngọc Duy
2016-01-18 18:30 ` Eric Sunshine
2016-01-19 5:20 ` Duy Nguyen
2016-01-18 11:21 ` Nguyễn Thái Ngọc Duy [this message]
2016-01-18 11:21 ` [PATCH v2 5/6] setup.c: record the location of .git file Nguyễn Thái Ngọc Duy
2016-01-18 11:21 ` [PATCH v2 6/6] worktree: new command to fix up worktree's info after moving Nguyễn Thái Ngọc Duy
2016-01-18 13:07 ` Philip Oakley
2016-01-19 18:25 ` Junio C Hamano
2016-01-22 8:35 ` [PATCH v3 0/2] Kill and replace update_linked_gitdir() Nguyễn Thái Ngọc Duy
2016-01-22 8:35 ` [PATCH v3 1/2] worktree.c: fix indentation Nguyễn Thái Ngọc Duy
2016-01-22 8:35 ` [PATCH v3 2/2] worktree: stop supporting moving worktrees manually Nguyễn Thái Ngọc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1453116094-4987-5-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).