git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 4/6] abspath.c: add and use real_path_dup()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 18, 2016, 11:21 UTC
Message-ID
<1453116094-4987-5-git-send-email-pclouds@gmail.com>
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
Previous: Duy NguyenNext: Nguyễn Thái Ngọc Duy
Message 8 of 15 in “Kill and replace update_linked_gitdir()”
  1. 0/6 Kill and replace update_linked_gitdir()Nguyễn Thái Ngọc Duy, Jan 18, 2016
  2. 1/6 worktree.c: fix indentationNguyễn Thái Ngọc Duy, Jan 18, 2016
  3. 2/6 worktree: stop supporting moving worktrees manuallyNguyễn Thái Ngọc Duy, Jan 18, 2016
  4. Eric SunshineJan 18, 2016
  5. 3/6 worktree.txt: how to fix up after moving a worktreeNguyễn Thái Ngọc Duy, Jan 18, 2016
  6. Eric SunshineJan 18, 2016
  7. Duy NguyenJan 19, 2016
  8. 4/6 abspath.c: add and use real_path_dup()Nguyễn Thái Ngọc Duy, Jan 18, 2016
  9. 5/6 setup.c: record the location of .git fileNguyễn Thái Ngọc Duy, Jan 18, 2016
  10. 6/6 worktree: new command to fix up worktree's info after movingNguyễn Thái Ngọc Duy, Jan 18, 2016
  11. Philip OakleyJan 18, 2016
  12. Junio C HamanoJan 19, 2016
  13. 0/2 Kill and replace update_linked_gitdir()Nguyễn Thái Ngọc Duy, Jan 22, 2016
  14. 1/2 worktree.c: fix indentationNguyễn Thái Ngọc Duy, Jan 22, 2016
  15. 2/2 worktree: stop supporting moving worktrees manuallyNguyễn Thái Ngọc Duy, Jan 22, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.