]> git.ipfire.org Git - thirdparty/git.git/commitdiff
real_path: have callers use real_pathdup and strbuf_realpath
authorBrandon Williams <bmwill@google.com>
Mon, 12 Dec 2016 18:16:55 +0000 (10:16 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Dec 2016 23:22:32 +0000 (15:22 -0800)
Migrate callers of real_path() who duplicate the retern value to use
real_pathdup or strbuf_realpath.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/init-db.c
environment.c
setup.c
sha1_file.c
submodule.c
transport.c
worktree.c

index 2399b97d902668a08c3c881d544f4d6a88f4e263..76d68fad001083d85800b937798529a1682959c9 100644 (file)
@@ -338,7 +338,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
 {
        int reinit;
        int exist_ok = flags & INIT_DB_EXIST_OK;
-       char *original_git_dir = xstrdup(real_path(git_dir));
+       char *original_git_dir = real_pathdup(git_dir);
 
        if (real_git_dir) {
                struct stat st;
@@ -489,7 +489,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_pathdup(real_git_dir);
 
        if (argc == 1) {
                int mkdir_tried = 0;
@@ -560,7 +560,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_pathdup(rel);
                        free(rel);
                }
                if (!git_work_tree_cfg)
index 0935ec696e530e1b610c71eda0a0a7072d1d656f..9b943d2d5bbc109cabd24f0f2efea7a5e79875a5 100644 (file)
@@ -259,7 +259,7 @@ void set_git_work_tree(const char *new_work_tree)
                return;
        }
        git_work_tree_initialized = 1;
-       work_tree = xstrdup(real_path(new_work_tree));
+       work_tree = real_pathdup(new_work_tree);
 }
 
 const char *get_git_work_tree(void)
diff --git a/setup.c b/setup.c
index fe572b82c355390e6101aea15d2d53ec5b3b1e15..1b534a750810f3773ba9c21a5ec221f54857349b 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -256,8 +256,10 @@ int get_common_dir_noenv(struct strbuf *sb, const char *gitdir)
                strbuf_addbuf(&path, &data);
                strbuf_addstr(sb, real_path(path.buf));
                ret = 1;
-       } else
+       } else {
                strbuf_addstr(sb, gitdir);
+       }
+
        strbuf_release(&data);
        strbuf_release(&path);
        return ret;
@@ -692,7 +694,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_pathdup(gitdir);
                if (chdir(cwd->buf))
                        die_errno("Could not come back to cwd");
                return setup_explicit_git_dir(gitdir, cwd, nongit_ok);
@@ -800,11 +802,12 @@ static int canonicalize_ceiling_entry(struct string_list_item *item,
                /* Keep entry but do not canonicalize it */
                return 1;
        } else {
-               const char *real_path = real_path_if_valid(ceil);
-               if (!real_path)
+               char *real_path = real_pathdup(ceil);
+               if (!real_path) {
                        return 0;
+               }
                free(item->string);
-               item->string = xstrdup(real_path);
+               item->string = real_path;
                return 1;
        }
 }
index 9c86d1924a23e4c81369f34ec8e1058c2dd15c1f..6a03cc39342cde47adee9664786fcf3af93c7f0d 100644 (file)
@@ -291,7 +291,7 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base,
        struct strbuf pathbuf = STRBUF_INIT;
 
        if (!is_absolute_path(entry) && relative_base) {
-               strbuf_addstr(&pathbuf, real_path(relative_base));
+               strbuf_realpath(&pathbuf, relative_base, 1);
                strbuf_addch(&pathbuf, '/');
        }
        strbuf_addstr(&pathbuf, entry);
index 6f7d883de950af8ba6427537d09e021a4bed36bd..c85ba50110606a72776fc7a95a2c6be3875b1751 100644 (file)
@@ -1227,7 +1227,7 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 {
        struct strbuf file_name = STRBUF_INIT;
        struct strbuf rel_path = STRBUF_INIT;
-       const char *real_work_tree = xstrdup(real_path(work_tree));
+       const char *real_work_tree = real_pathdup(work_tree);
 
        /* Update gitfile */
        strbuf_addf(&file_name, "%s/.git", work_tree);
index d57e8dec28d6890ce981a8422e9b8b60b697ecd6..236c6f6b095ad508c57e6ff1048d3b7ca623ca2e 100644 (file)
@@ -1130,7 +1130,7 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
        const struct ref *extra;
        struct alternate_refs_data *cb = data;
 
-       other = xstrdup(real_path(e->path));
+       other = real_pathdup(e->path);
        len = strlen(other);
 
        while (other[len-1] == '/')
index f7869f8d6072c98c3e9be3387a9a3c19508e13ea..c90e0139855bd39343f262c557fd57daaa14650b 100644 (file)
@@ -255,7 +255,7 @@ struct worktree *find_worktree(struct worktree **list,
                return wt;
 
        arg = prefix_filename(prefix, strlen(prefix), arg);
-       path = xstrdup(real_path(arg));
+       path = real_pathdup(arg);
        for (; *list; list++)
                if (!fspathcmp(path, real_path((*list)->path)))
                        break;