char *prefix_path(const char *prefix, int len, const char *path)
{
const char *orig = path;
- char *sanitized = xmalloc(len + strlen(path) + 1);
- if (is_absolute_path(orig))
- strcpy(sanitized, path);
- else {
+ char *sanitized;
+ if (is_absolute_path(orig)) {
+ const char *temp = real_path(path);
+ sanitized = xmalloc(len + strlen(temp) + 1);
+ strcpy(sanitized, temp);
+ } else {
+ sanitized = xmalloc(len + strlen(path) + 1);
if (len)
memcpy(sanitized, prefix, len);
strcpy(sanitized + len, path);
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;
}
const char *slash;
struct stat st;
int fd;
- size_t len;
+ ssize_t len;
if (stat(path, &st))
return NULL;
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;