real_path: have callers use real_pathdup and strbuf_realpath
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>
Brandon Williams committed
Dec 12, 2016 at 10:16 UTC
4ac9006f832d98ca1f25d956e12f3ff79e0d25bc
7 files changed
+16
-13
builtin/init-db.c
+3
-3
@@ -338,7 +338,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
338
{
339
int reinit;
340
int exist_ok = flags & INIT_DB_EXIST_OK;
341
- char *original_git_dir = xstrdup(real_path(git_dir));
341
+ char *original_git_dir = real_pathdup(git_dir);
342
343
if (real_git_dir) {
344
struct stat st;
@@ -489,7 +489,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
489
argc = parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);
490
491
if (real_git_dir && !is_absolute_path(real_git_dir))
492
- real_git_dir = xstrdup(real_path(real_git_dir));
492
+ real_git_dir = real_pathdup(real_git_dir);
493
494
if (argc == 1) {
495
int mkdir_tried = 0;
@@ -560,7 +560,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
560
const char *git_dir_parent = strrchr(git_dir, '/');
561
if (git_dir_parent) {
562
char *rel = xstrndup(git_dir, git_dir_parent - git_dir);
563
- git_work_tree_cfg = xstrdup(real_path(rel));
563
+ git_work_tree_cfg = real_pathdup(rel);
564
free(rel);
565
}
566
if (!git_work_tree_cfg)
environment.c
+1
-1
@@ -259,7 +259,7 @@ void set_git_work_tree(const char *new_work_tree)
259
return;
260
}
261
git_work_tree_initialized = 1;
262
- work_tree = xstrdup(real_path(new_work_tree));
262
+ work_tree = real_pathdup(new_work_tree);
263
}
264
265
const char *get_git_work_tree(void)
setup.c
+8
-5
@@ -256,8 +256,10 @@ int get_common_dir_noenv(struct strbuf *sb, const char *gitdir)
256
strbuf_addbuf(&path, &data);
257
strbuf_addstr(sb, real_path(path.buf));
258
ret = 1;
259
- } else
259
+ } else {
260
strbuf_addstr(sb, gitdir);
261
+ }
262
+
263
strbuf_release(&data);
264
strbuf_release(&path);
265
return ret;
@@ -692,7 +694,7 @@ static const char *setup_discovered_git_dir(const char *gitdir,
694
/* --work-tree is set without --git-dir; use discovered one */
695
if (getenv(GIT_WORK_TREE_ENVIRONMENT) || git_work_tree_cfg) {
696
if (offset != cwd->len && !is_absolute_path(gitdir))
695
- gitdir = xstrdup(real_path(gitdir));
697
+ gitdir = real_pathdup(gitdir);
698
if (chdir(cwd->buf))
699
die_errno("Could not come back to cwd");
700
return setup_explicit_git_dir(gitdir, cwd, nongit_ok);
@@ -800,11 +802,12 @@ static int canonicalize_ceiling_entry(struct string_list_item *item,
802
/* Keep entry but do not canonicalize it */
803
return 1;
804
} else {
803
- const char *real_path = real_path_if_valid(ceil);
804
- if (!real_path)
805
+ char *real_path = real_pathdup(ceil);
806
+ if (!real_path) {
807
return 0;
808
+ }
809
free(item->string);
807
- item->string = xstrdup(real_path);
810
+ item->string = real_path;
811
return 1;
812
}
813
}
sha1_file.c
+1
-1
@@ -291,7 +291,7 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base,
291
struct strbuf pathbuf = STRBUF_INIT;
292
293
if (!is_absolute_path(entry) && relative_base) {
294
- strbuf_addstr(&pathbuf, real_path(relative_base));
294
+ strbuf_realpath(&pathbuf, relative_base, 1);
295
strbuf_addch(&pathbuf, '/');
296
}
297
strbuf_addstr(&pathbuf, entry);
submodule.c
+1
-1
@@ -1227,7 +1227,7 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
1227
{
1228
struct strbuf file_name = STRBUF_INIT;
1229
struct strbuf rel_path = STRBUF_INIT;
1230
- const char *real_work_tree = xstrdup(real_path(work_tree));
1230
+ const char *real_work_tree = real_pathdup(work_tree);
1231
1232
/* Update gitfile */
1233
strbuf_addf(&file_name, "%s/.git", work_tree);
transport.c
+1
-1
@@ -1130,7 +1130,7 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
1130
const struct ref *extra;
1131
struct alternate_refs_data *cb = data;
1132
1133
- other = xstrdup(real_path(e->path));
1133
+ other = real_pathdup(e->path);
1134
len = strlen(other);
1135
1136
while (other[len-1] == '/')
worktree.c
+1
-1
@@ -255,7 +255,7 @@ struct worktree *find_worktree(struct worktree **list,
255
return wt;
256
257
arg = prefix_filename(prefix, strlen(prefix), arg);
258
- path = xstrdup(real_path(arg));
258
+ path = real_pathdup(arg);
259
for (; *list; list++)
260
if (!fspathcmp(path, real_path((*list)->path)))
261
break;