int check_filename(const char *prefix, const char *arg)
{
const char *name;
+ char *to_free = NULL;
struct stat st;
if (starts_with(arg, ":/")) {
return 1;
name = arg + 2;
} else if (prefix)
- name = prefix_filename(prefix, strlen(prefix), arg);
+ name = to_free = prefix_filename(prefix, arg);
else
name = arg;
- if (!lstat(name, &st))
+ if (!lstat(name, &st)) {
+ free(to_free);
return 1; /* file exists */
- if (errno == ENOENT || errno == ENOTDIR)
+ }
+ if (errno == ENOENT || errno == ENOTDIR) {
+ free(to_free);
return 0; /* file does not exist */
+ }
die_errno("failed to stat '%s'", arg);
}
if (!is_absolute_path(data.buf))
strbuf_addf(&path, "%s/", gitdir);
strbuf_addbuf(&path, &data);
- strbuf_addstr(sb, real_path(path.buf));
+ strbuf_add_real_path(sb, path.buf);
ret = 1;
} else {
strbuf_addstr(sb, gitdir);
/* --work-tree is set without --git-dir; use discovered one */
if (getenv(GIT_WORK_TREE_ENVIRONMENT) || git_work_tree_cfg) {
if (offset != cwd->len && !is_absolute_path(gitdir))
- gitdir = real_pathdup(gitdir);
+ gitdir = real_pathdup(gitdir, 1);
if (chdir(cwd->buf))
die_errno("Could not come back to cwd");
return setup_explicit_git_dir(gitdir, cwd, nongit_ok);
/* Keep entry but do not canonicalize it */
return 1;
} else {
- char *real_path = real_pathdup(ceil);
+ char *real_path = real_pathdup(ceil, 0);
if (!real_path) {
return 0;
}
{
static struct strbuf cwd = STRBUF_INIT;
struct strbuf dir = STRBUF_INIT, gitdir = STRBUF_INIT;
- const char *prefix;
+ const char *prefix, *env_prefix;
/*
* We may have read an incomplete configuration before
die("BUG: unhandled setup_git_directory_1() result");
}
+ env_prefix = getenv(GIT_TOPLEVEL_PREFIX_ENVIRONMENT);
+ if (env_prefix)
+ prefix = env_prefix;
+
if (prefix)
setenv(GIT_PREFIX_ENVIRONMENT, prefix, 1);
else