diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-02-02 13:36:55 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-02-02 13:36:55 -0800 |
commit | 6f1c08bdb75b37ad30103f0f12339780fdc004e2 (patch) | |
tree | 3a6909ffaaa512519c3f6f6e7a11f0956276bcd1 | |
parent | Merge branch 'js/unzip-in-usr-bin-workaround' (diff) | |
parent | use absolute_pathdup() (diff) | |
download | tgif-6f1c08bdb75b37ad30103f0f12339780fdc004e2.tar.xz |
Merge branch 'rs/absolute-pathdup'
Code cleanup.
* rs/absolute-pathdup:
use absolute_pathdup()
abspath: add absolute_pathdup()
-rw-r--r-- | abspath.c | 7 | ||||
-rw-r--r-- | builtin/clone.c | 4 | ||||
-rw-r--r-- | builtin/submodule--helper.c | 2 | ||||
-rw-r--r-- | cache.h | 1 | ||||
-rw-r--r-- | contrib/coccinelle/xstrdup_or_null.cocci | 6 | ||||
-rw-r--r-- | worktree.c | 2 |
6 files changed, 18 insertions, 4 deletions
@@ -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 diff --git a/builtin/clone.c b/builtin/clone.c index 5ef81927a6..3f63edbbf9 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -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 diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 74614a951e..899dc334e3 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -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)) { @@ -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); diff --git a/contrib/coccinelle/xstrdup_or_null.cocci b/contrib/coccinelle/xstrdup_or_null.cocci index 3fceef132b..8e05d1ca4b 100644 --- a/contrib/coccinelle/xstrdup_or_null.cocci +++ b/contrib/coccinelle/xstrdup_or_null.cocci @@ -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) diff --git a/worktree.c b/worktree.c index 53b4771c04..d633761575 100644 --- a/worktree.c +++ b/worktree.c @@ -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++) { |