Merge branch 'rs/absolute-pathdup'

Code cleanup.

* rs/absolute-pathdup:
  use absolute_pathdup()
  abspath: add absolute_pathdup()
This commit is contained in:
Junio C Hamano 2017-02-02 13:36:55 -08:00
commit 6f1c08bdb7
6 changed files with 18 additions and 4 deletions

View File

@ -239,6 +239,13 @@ const char *absolute_path(const char *path)
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
* not have to interact with index entry; i.e. name of a random file

View File

@ -170,7 +170,7 @@ static char *get_repo_path(const char *repo, int *is_bundle)
strbuf_addstr(&path, repo);
raw = get_repo_path_1(&path, is_bundle);
canon = raw ? xstrdup(absolute_path(raw)) : NULL;
canon = raw ? absolute_pathdup(raw) : NULL;
strbuf_release(&path);
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);
if (path)
repo = xstrdup(absolute_path(repo_name));
repo = absolute_pathdup(repo_name);
else if (!strchr(repo_name, ':'))
die(_("repository '%s' does not exist"), repo_name);
else

View File

@ -626,7 +626,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
module_clone_options);
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);
if (!is_absolute_path(path)) {

View File

@ -1101,6 +1101,7 @@ const char *real_path(const char *path);
const char *real_path_if_valid(const char *path);
char *real_pathdup(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 *relative_path(const char *in, const char *prefix, struct strbuf *sb);
int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);

View File

@ -5,3 +5,9 @@ expression V;
- if (E)
- V = xstrdup(E);
+ V = xstrdup_or_null(E);
@@
expression E;
@@
- xstrdup(absolute_path(E))
+ absolute_pathdup(E)

View File

@ -145,7 +145,7 @@ done:
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;
for (i = 0; worktrees[i]; i++) {