summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a3ca9b0)
raw | patch | inline | side by side (parent: a3ca9b0)
author | Carlos Martín Nieto <cmn@elego.de> | |
Thu, 17 Mar 2011 11:26:46 +0000 (12:26 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 17 Mar 2011 23:08:30 +0000 (16:08 -0700) |
Rename the make_*_path functions so it's clearer what they do, in
particlar make clear what the differnce between make_absolute_path and
make_nonrelative_path is by renaming them real_path and absolute_path
respectively. make_relative_path has an understandable name and is
renamed to relative_path to maintain the name convention.
The function calls have been replaced 1-to-1 in their usage.
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
particlar make clear what the differnce between make_absolute_path and
make_nonrelative_path is by renaming them real_path and absolute_path
respectively. make_relative_path has an understandable name and is
renamed to relative_path to maintain the name convention.
The function calls have been replaced 1-to-1 in their usage.
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
14 files changed:
abspath.c | patch | blob | history | |
builtin/clone.c | patch | blob | history | |
builtin/init-db.c | patch | blob | history | |
builtin/receive-pack.c | patch | blob | history | |
cache.h | patch | blob | history | |
dir.c | patch | blob | history | |
environment.c | patch | blob | history | |
exec_cmd.c | patch | blob | history | |
lockfile.c | patch | blob | history | |
path.c | patch | blob | history | |
setup.c | patch | blob | history | |
t/t0000-basic.sh | patch | blob | history | |
test-path-utils.c | patch | blob | history | |
wrapper.c | patch | blob | history |
diff --git a/abspath.c b/abspath.c
index ff140689ed2453809e7c3794c9989918e90df392..3005aedde68b48297aacd2082797b2e2f249b094 100644 (file)
--- a/abspath.c
+++ b/abspath.c
/* We allow "recursive" symbolic links. Only within reason, though. */
#define MAXDEPTH 5
-const char *make_absolute_path(const char *path)
+/*
+ * Use this to get the real path, i.e. resolve links. If you want an
+ * absolute path but don't mind links, use absolute_path.
+ *
+ * If path is our buffer, then return path, as it's already what the
+ * user wants.
+ */
+const char *real_path(const char *path)
{
static char bufs[2][PATH_MAX + 1], *buf = bufs[0], *next_buf = bufs[1];
char cwd[1024] = "";
return cwd;
}
-const char *make_nonrelative_path(const char *path)
+/*
+ * Use this to get an absolute path from a relative one. If you want
+ * to resolve links, you should use real_path.
+ *
+ * If the path is already absolute, then return path. As the user is
+ * never meant to free the return value, we're safe.
+ */
+const char *absolute_path(const char *path)
{
static char buf[PATH_MAX + 1];
diff --git a/builtin/clone.c b/builtin/clone.c
index 2ee1fa984620de4fad79ce94d4f993f5e83a053d..404f589680151c69a57f746eb5b225e54aa8d8a0 100644 (file)
--- a/builtin/clone.c
+++ b/builtin/clone.c
path = mkpath("%s%s", repo, suffix[i]);
if (is_directory(path)) {
*is_bundle = 0;
- return xstrdup(make_nonrelative_path(path));
+ return xstrdup(absolute_path(path));
}
}
path = mkpath("%s%s", repo, bundle_suffix[i]);
if (!stat(path, &st) && S_ISREG(st.st_mode)) {
*is_bundle = 1;
- return xstrdup(make_nonrelative_path(path));
+ return xstrdup(absolute_path(path));
}
}
struct transport *transport;
const struct ref *extra;
- ref_git = make_absolute_path(option_reference);
+ ref_git = real_path(option_reference);
if (is_directory(mkpath("%s/.git/objects", ref_git)))
ref_git = mkpath("%s/.git", ref_git);
path = get_repo_path(repo_name, &is_bundle);
if (path)
- repo = xstrdup(make_nonrelative_path(repo_name));
+ repo = xstrdup(absolute_path(repo_name));
else if (!strchr(repo_name, ':'))
die("repository '%s' does not exist", repo_name);
else
if (safe_create_leading_directories_const(git_dir) < 0)
die("could not create leading directories of '%s'", git_dir);
- set_git_dir(make_absolute_path(git_dir));
+ set_git_dir(real_path(git_dir));
if (0 <= option_verbosity)
printf("Cloning into %s%s...\n",
diff --git a/builtin/init-db.c b/builtin/init-db.c
index fbeb380ee2af2b21478e5766a3dd956b8fe06104..8f5cfd712243975dacd08cb51c69c2e174e470b1 100644 (file)
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
const char *git_dir_parent = strrchr(git_dir, '/');
if (git_dir_parent) {
char *rel = xstrndup(git_dir, git_dir_parent - git_dir);
- git_work_tree_cfg = xstrdup(make_absolute_path(rel));
+ git_work_tree_cfg = xstrdup(real_path(rel));
free(rel);
}
if (!git_work_tree_cfg) {
die_errno ("Cannot access current working directory");
}
if (work_tree)
- set_git_work_tree(make_absolute_path(work_tree));
+ set_git_work_tree(real_path(work_tree));
else
set_git_work_tree(git_work_tree_cfg);
if (access(get_git_work_tree(), X_OK))
}
else {
if (work_tree)
- set_git_work_tree(make_absolute_path(work_tree));
+ set_git_work_tree(real_path(work_tree));
}
- set_git_dir(make_absolute_path(git_dir));
+ set_git_dir(real_path(git_dir));
return init_db(template_dir, flags);
}
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 760817dbd7fec0086a0a1b62e58ab4438f227b7b..d883585804224d3c1bbc2699da94b2632dcf8064 100644 (file)
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -740,7 +740,7 @@ static int add_refs_from_alternate(struct alternate_object_database *e, void *un
const struct ref *extra;
e->name[-1] = '\0';
- other = xstrdup(make_absolute_path(e->base));
+ other = xstrdup(real_path(e->base));
e->name[-1] = '/';
len = strlen(other);
index cbdeaa1d0d23c7e82dd7bd9ea8f97917285b62ff..a99fd560e97193a1750433be8c674cbc4eb73e19 100644 (file)
--- a/cache.h
+++ b/cache.h
return path[0] == '/' || has_dos_drive_prefix(path);
}
int is_directory(const char *);
-const char *make_absolute_path(const char *path);
-const char *make_nonrelative_path(const char *path);
-const char *make_relative_path(const char *abs, const char *base);
+const char *real_path(const char *path);
+const char *absolute_path(const char *path);
+const char *relative_path(const char *abs, const char *base);
int normalize_path_copy(char *dst, const char *src);
int longest_ancestor_length(const char *path, const char *prefix_list);
char *strip_path_suffix(const char *path, const char *suffix);
index 168dad615230d77d7719101b76b50b4f6fe02777..325fb56ad395c9b47dcbdea47b2833a4287198bc 100644 (file)
--- a/dir.c
+++ b/dir.c
die_errno("can't find the current directory");
if (!is_absolute_path(dir))
- dir = make_absolute_path(dir);
+ dir = real_path(dir);
while (*dir && *dir == *cwd) {
dir++;
diff --git a/environment.c b/environment.c
index c3efbb96084de04465f7eff45376cadc3ab2526b..cc670b1562504f9cfe79247d98e50c62c50eaea5 100644 (file)
--- a/environment.c
+++ b/environment.c
void set_git_work_tree(const char *new_work_tree)
{
if (git_work_tree_initialized) {
- new_work_tree = make_absolute_path(new_work_tree);
+ new_work_tree = real_path(new_work_tree);
if (strcmp(new_work_tree, work_tree))
die("internal error: work tree has already been set\n"
"Current worktree: %s\nNew worktree: %s",
return;
}
git_work_tree_initialized = 1;
- work_tree = xstrdup(make_absolute_path(new_work_tree));
+ work_tree = xstrdup(real_path(new_work_tree));
}
const char *get_git_work_tree(void)
diff --git a/exec_cmd.c b/exec_cmd.c
index 38545e8bfd72c8cd4f91e0d33257b143db86bac5..171e841531de7fd5b51aa26f639104382395b854 100644 (file)
--- a/exec_cmd.c
+++ b/exec_cmd.c
if (is_absolute_path(path))
strbuf_addstr(out, path);
else
- strbuf_addstr(out, make_nonrelative_path(path));
+ strbuf_addstr(out, absolute_path(path));
strbuf_addch(out, PATH_SEP);
}
diff --git a/lockfile.c b/lockfile.c
index b0d74cdddee2407de590cb9f725e8e24093d9d35..c6fb77b26fd88f4edf85a8920a6d72e49551deed 100644 (file)
--- a/lockfile.c
+++ b/lockfile.c
"If no other git process is currently running, this probably means a\n"
"git process crashed in this repository earlier. Make sure no other git\n"
"process is running and remove the file manually to continue.",
- make_nonrelative_path(path), strerror(err));
+ absolute_path(path), strerror(err));
} else
strbuf_addf(&buf, "Unable to create '%s.lock': %s",
- make_nonrelative_path(path), strerror(err));
+ absolute_path(path), strerror(err));
return strbuf_detach(&buf, NULL);
}
index 8951333cb88a6e28ef29538183ebf71e3b0913fa..4d73cc9cd26708b4cb41e86fb319b93f526cb2f2 100644 (file)
--- a/path.c
+++ b/path.c
return 0;
}
-const char *make_relative_path(const char *abs, const char *base)
+const char *relative_path(const char *abs, const char *base)
{
static char buf[PATH_MAX + 1];
int i = 0, j = 0;
index 021d0133ae1d6cf7f3a6a8284cb5b6e9a42dbe0d..03cd84f2fcbf9cdbc25116308a9c2c9407af8e71 100644 (file)
--- a/setup.c
+++ b/setup.c
const char *orig = path;
char *sanitized;
if (is_absolute_path(orig)) {
- const char *temp = make_absolute_path(path);
+ const char *temp = real_path(path);
sanitized = xmalloc(len + strlen(temp) + 1);
strcpy(sanitized, temp);
} else {
work_tree = get_git_work_tree();
git_dir = get_git_dir();
if (!is_absolute_path(git_dir))
- git_dir = make_absolute_path(git_dir);
+ git_dir = real_path(get_git_dir());
if (!work_tree || chdir(work_tree))
die("This operation must be run in a work tree");
if (getenv(GIT_WORK_TREE_ENVIRONMENT))
setenv(GIT_WORK_TREE_ENVIRONMENT, ".", 1);
- set_git_dir(make_relative_path(git_dir, work_tree));
+ set_git_dir(relative_path(git_dir, work_tree));
initialized = 1;
}
if (!is_git_directory(dir))
die("Not a git repository: %s", dir);
- path = make_absolute_path(dir);
+ path = real_path(dir);
free(buf);
return path;
if (!prefixcmp(cwd, worktree) &&
cwd[strlen(worktree)] == '/') { /* cwd inside worktree */
- set_git_dir(make_absolute_path(gitdirenv));
+ set_git_dir(real_path(gitdirenv));
if (chdir(worktree))
die_errno("Could not chdir to '%s'", worktree);
cwd[len++] = '/';
/* --work-tree is set without --git-dir; use discovered one */
if (getenv(GIT_WORK_TREE_ENVIRONMENT) || git_work_tree_cfg) {
if (offset != len && !is_absolute_path(gitdir))
- gitdir = xstrdup(make_absolute_path(gitdir));
+ gitdir = xstrdup(real_path(gitdir));
if (chdir(cwd))
die_errno("Could not come back to cwd");
return setup_explicit_git_dir(gitdir, cwd, len, nongit_ok);
/* #16.2, #17.2, #20.2, #21.2, #24, #25, #28, #29 (see t1510) */
if (is_bare_repository_cfg > 0) {
- set_git_dir(offset == len ? gitdir : make_absolute_path(gitdir));
+ set_git_dir(offset == len ? gitdir : real_path(gitdir));
if (chdir(cwd))
die_errno("Could not come back to cwd");
return NULL;
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 8deec75c3a0eef961986a0bb313a918ab532f58d..f4e8f43bae5d1929718578a2a589125beb5d30c8 100755 (executable)
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
test $numpath0 = 1
'
-test_expect_success SYMLINKS 'absolute path works as expected' '
+test_expect_success SYMLINKS 'real path works as expected' '
mkdir first &&
ln -s ../.git first/.git &&
mkdir second &&
mkdir third &&
dir="$(cd .git; pwd -P)" &&
dir2=third/../second/other/.git &&
- test "$dir" = "$(test-path-utils make_absolute_path $dir2)" &&
+ test "$dir" = "$(test-path-utils real_path $dir2)" &&
file="$dir"/index &&
- test "$file" = "$(test-path-utils make_absolute_path $dir2/index)" &&
+ test "$file" = "$(test-path-utils real_path $dir2/index)" &&
basename=blub &&
- test "$dir/$basename" = "$(cd .git && test-path-utils make_absolute_path "$basename")" &&
+ test "$dir/$basename" = "$(cd .git && test-path-utils real_path "$basename")" &&
ln -s ../first/file .git/syml &&
sym="$(cd first; pwd -P)"/file &&
- test "$sym" = "$(test-path-utils make_absolute_path "$dir2/syml")"
+ test "$sym" = "$(test-path-utils real_path "$dir2/syml")"
'
test_expect_success 'very long name in the index handled sanely' '
diff --git a/test-path-utils.c b/test-path-utils.c
index d261398d6c50aeefa7450b99caae23ee5cdff0d0..e7671593df6bf014f3a9d8bd5173d1edcfd6545b 100644 (file)
--- a/test-path-utils.c
+++ b/test-path-utils.c
return 0;
}
- if (argc >= 2 && !strcmp(argv[1], "make_absolute_path")) {
+ if (argc >= 2 && !strcmp(argv[1], "real_path")) {
while (argc > 2) {
- puts(make_absolute_path(argv[2]));
+ puts(real_path(argv[2]));
argc--;
argv++;
}
diff --git a/wrapper.c b/wrapper.c
index 4c147d6c48c000bab636fad3edc2fe7da6670948..28290002b9f6434d716a39612f3afc9958c292af 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
if (!template[0])
template = origtemplate;
- nonrelative_template = make_nonrelative_path(template);
+ nonrelative_template = absolute_path(template);
errno = saved_errno;
die_errno("Unable to create temporary file '%s'",
nonrelative_template);
if (!template[0])
template = origtemplate;
- nonrelative_template = make_nonrelative_path(template);
+ nonrelative_template = absolute_path(template);
errno = saved_errno;
die_errno("Unable to create temporary file '%s'",
nonrelative_template);