Skip to content

Commit 4ac9006

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7241764 commit 4ac9006

File tree

7 files changed

+16
-13
lines changed

7 files changed

+16
-13
lines changed

builtin/init-db.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ int init_db(const char *git_dir, const char *real_git_dir,
338338
{
339339
int reinit;
340340
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);
342342

343343
if (real_git_dir) {
344344
struct stat st;
@@ -489,7 +489,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
489489
argc = parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);
490490

491491
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);
493493

494494
if (argc == 1) {
495495
int mkdir_tried = 0;
@@ -560,7 +560,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
560560
const char *git_dir_parent = strrchr(git_dir, '/');
561561
if (git_dir_parent) {
562562
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);
564564
free(rel);
565565
}
566566
if (!git_work_tree_cfg)

environment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ void set_git_work_tree(const char *new_work_tree)
259259
return;
260260
}
261261
git_work_tree_initialized = 1;
262-
work_tree = xstrdup(real_path(new_work_tree));
262+
work_tree = real_pathdup(new_work_tree);
263263
}
264264

265265
const char *get_git_work_tree(void)

setup.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,10 @@ int get_common_dir_noenv(struct strbuf *sb, const char *gitdir)
256256
strbuf_addbuf(&path, &data);
257257
strbuf_addstr(sb, real_path(path.buf));
258258
ret = 1;
259-
} else
259+
} else {
260260
strbuf_addstr(sb, gitdir);
261+
}
262+
261263
strbuf_release(&data);
262264
strbuf_release(&path);
263265
return ret;
@@ -692,7 +694,7 @@ static const char *setup_discovered_git_dir(const char *gitdir,
692694
/* --work-tree is set without --git-dir; use discovered one */
693695
if (getenv(GIT_WORK_TREE_ENVIRONMENT) || git_work_tree_cfg) {
694696
if (offset != cwd->len && !is_absolute_path(gitdir))
695-
gitdir = xstrdup(real_path(gitdir));
697+
gitdir = real_pathdup(gitdir);
696698
if (chdir(cwd->buf))
697699
die_errno("Could not come back to cwd");
698700
return setup_explicit_git_dir(gitdir, cwd, nongit_ok);
@@ -800,11 +802,12 @@ static int canonicalize_ceiling_entry(struct string_list_item *item,
800802
/* Keep entry but do not canonicalize it */
801803
return 1;
802804
} 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) {
805807
return 0;
808+
}
806809
free(item->string);
807-
item->string = xstrdup(real_path);
810+
item->string = real_path;
808811
return 1;
809812
}
810813
}

sha1_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base,
291291
struct strbuf pathbuf = STRBUF_INIT;
292292

293293
if (!is_absolute_path(entry) && relative_base) {
294-
strbuf_addstr(&pathbuf, real_path(relative_base));
294+
strbuf_realpath(&pathbuf, relative_base, 1);
295295
strbuf_addch(&pathbuf, '/');
296296
}
297297
strbuf_addstr(&pathbuf, entry);

submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
12271227
{
12281228
struct strbuf file_name = STRBUF_INIT;
12291229
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);
12311231

12321232
/* Update gitfile */
12331233
strbuf_addf(&file_name, "%s/.git", work_tree);

transport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
11301130
const struct ref *extra;
11311131
struct alternate_refs_data *cb = data;
11321132

1133-
other = xstrdup(real_path(e->path));
1133+
other = real_pathdup(e->path);
11341134
len = strlen(other);
11351135

11361136
while (other[len-1] == '/')

worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ struct worktree *find_worktree(struct worktree **list,
255255
return wt;
256256

257257
arg = prefix_filename(prefix, strlen(prefix), arg);
258-
path = xstrdup(real_path(arg));
258+
path = real_pathdup(arg);
259259
for (; *list; list++)
260260
if (!fspathcmp(path, real_path((*list)->path)))
261261
break;

0 commit comments

Comments
 (0)