Merge branch 'rs/absolute-pathdup'
Code cleanup. * rs/absolute-pathdup: use absolute_pathdup() abspath: add absolute_pathdup()
This commit is contained in:
commit
6f1c08bdb7
@ -239,6 +239,13 @@ const char *absolute_path(const char *path)
|
|||||||
return sb.buf;
|
return sb.buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *absolute_pathdup(const char *path)
|
||||||
|
{
|
||||||
|
struct strbuf sb = STRBUF_INIT;
|
||||||
|
strbuf_add_absolute_path(&sb, path);
|
||||||
|
return strbuf_detach(&sb, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unlike prefix_path, this should be used if the named file does
|
* Unlike prefix_path, this should be used if the named file does
|
||||||
* not have to interact with index entry; i.e. name of a random file
|
* not have to interact with index entry; i.e. name of a random file
|
||||||
|
@ -170,7 +170,7 @@ static char *get_repo_path(const char *repo, int *is_bundle)
|
|||||||
|
|
||||||
strbuf_addstr(&path, repo);
|
strbuf_addstr(&path, repo);
|
||||||
raw = get_repo_path_1(&path, is_bundle);
|
raw = get_repo_path_1(&path, is_bundle);
|
||||||
canon = raw ? xstrdup(absolute_path(raw)) : NULL;
|
canon = raw ? absolute_pathdup(raw) : NULL;
|
||||||
strbuf_release(&path);
|
strbuf_release(&path);
|
||||||
return canon;
|
return canon;
|
||||||
}
|
}
|
||||||
@ -894,7 +894,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
path = get_repo_path(repo_name, &is_bundle);
|
path = get_repo_path(repo_name, &is_bundle);
|
||||||
if (path)
|
if (path)
|
||||||
repo = xstrdup(absolute_path(repo_name));
|
repo = absolute_pathdup(repo_name);
|
||||||
else if (!strchr(repo_name, ':'))
|
else if (!strchr(repo_name, ':'))
|
||||||
die(_("repository '%s' does not exist"), repo_name);
|
die(_("repository '%s' does not exist"), repo_name);
|
||||||
else
|
else
|
||||||
|
@ -626,7 +626,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
|
|||||||
module_clone_options);
|
module_clone_options);
|
||||||
|
|
||||||
strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
|
strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
|
||||||
sm_gitdir = xstrdup(absolute_path(sb.buf));
|
sm_gitdir = absolute_pathdup(sb.buf);
|
||||||
strbuf_reset(&sb);
|
strbuf_reset(&sb);
|
||||||
|
|
||||||
if (!is_absolute_path(path)) {
|
if (!is_absolute_path(path)) {
|
||||||
|
1
cache.h
1
cache.h
@ -1101,6 +1101,7 @@ const char *real_path(const char *path);
|
|||||||
const char *real_path_if_valid(const char *path);
|
const char *real_path_if_valid(const char *path);
|
||||||
char *real_pathdup(const char *path);
|
char *real_pathdup(const char *path);
|
||||||
const char *absolute_path(const char *path);
|
const char *absolute_path(const char *path);
|
||||||
|
char *absolute_pathdup(const char *path);
|
||||||
const char *remove_leading_path(const char *in, const char *prefix);
|
const char *remove_leading_path(const char *in, const char *prefix);
|
||||||
const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
|
const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
|
||||||
int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
|
int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
|
||||||
|
@ -5,3 +5,9 @@ expression V;
|
|||||||
- if (E)
|
- if (E)
|
||||||
- V = xstrdup(E);
|
- V = xstrdup(E);
|
||||||
+ V = xstrdup_or_null(E);
|
+ V = xstrdup_or_null(E);
|
||||||
|
|
||||||
|
@@
|
||||||
|
expression E;
|
||||||
|
@@
|
||||||
|
- xstrdup(absolute_path(E))
|
||||||
|
+ absolute_pathdup(E)
|
||||||
|
@ -145,7 +145,7 @@ done:
|
|||||||
|
|
||||||
static void mark_current_worktree(struct worktree **worktrees)
|
static void mark_current_worktree(struct worktree **worktrees)
|
||||||
{
|
{
|
||||||
char *git_dir = xstrdup(absolute_path(get_git_dir()));
|
char *git_dir = absolute_pathdup(get_git_dir());
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; worktrees[i]; i++) {
|
for (i = 0; worktrees[i]; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user