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);
}
{
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