if (!path)
return config_error_nonbool("include.path");
- expanded = expand_user_path(path);
+ expanded = expand_user_path(path, 0);
if (!expanded)
return error("could not expand include path '%s'", path);
path = expanded;
char *expanded;
int prefix = 0;
- expanded = expand_user_path(pat->buf);
+ expanded = expand_user_path(pat->buf, 1);
if (expanded) {
strbuf_reset(pat);
strbuf_addstr(pat, expanded);
return error(_("relative config include "
"conditionals must come from files"));
- strbuf_add_absolute_path(&path, cf->path);
+ strbuf_realpath(&path, cf->path, 1);
slash = find_last_dir_sep(path.buf);
if (!slash)
die("BUG: how is this possible?");
else
goto done;
- strbuf_add_absolute_path(&text, git_dir);
+ strbuf_realpath(&text, git_dir, 1);
strbuf_add(&pattern, cond, cond_len);
prefix = prepare_include_condition_pattern(&pattern);
return 1;
}
+static int git_parse_ssize_t(const char *value, ssize_t *ret)
+{
+ intmax_t tmp;
+ if (!git_parse_signed(value, &tmp, maximum_signed_value_of_type(ssize_t)))
+ return 0;
+ *ret = tmp;
+ return 1;
+}
+
NORETURN
static void die_bad_number(const char *name, const char *value)
{
return ret;
}
+ssize_t git_config_ssize_t(const char *name, const char *value)
+{
+ ssize_t ret;
+ if (!git_parse_ssize_t(value, &ret))
+ die_bad_number(name, value);
+ return ret;
+}
+
int git_parse_maybe_bool(const char *value)
{
if (!value)
{
if (!value)
return config_error_nonbool(var);
- *dest = expand_user_path(value);
+ *dest = expand_user_path(value, 0);
if (!*dest)
die(_("failed to expand user dir in: '%s'"), value);
return 0;
return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0);
}
-static int do_git_config_sequence(config_fn_t fn, void *data)
+static int do_git_config_sequence(const struct config_options *opts,
+ config_fn_t fn, void *data)
{
int ret = 0;
char *xdg_config = xdg_config_home("config");
- char *user_config = expand_user_path("~/.gitconfig");
- char *repo_config = have_git_dir() ? git_pathdup("config") : NULL;
+ char *user_config = expand_user_path("~/.gitconfig", 0);
+ char *repo_config;
+
+ if (opts->git_dir)
+ repo_config = mkpathdup("%s/config", opts->git_dir);
+ else if (have_git_dir())
+ repo_config = git_pathdup("config");
+ else
+ repo_config = NULL;
current_parsing_scope = CONFIG_SCOPE_SYSTEM;
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0))
else if (config_source && config_source->blob)
return git_config_from_blob_ref(fn, config_source->blob, data);
- return do_git_config_sequence(fn, data);
+ return do_git_config_sequence(opts, fn, data);
}
static void git_config_raw(config_fn_t fn, void *data)
{
struct config_options opts = {0};
struct strbuf buf = STRBUF_INIT;
- char *to_free = NULL;
opts.respect_includes = 1;
* call).
*/
else if (discover_git_directory(&buf))
- opts.git_dir = to_free = xstrdup(buf.buf);
+ opts.git_dir = buf.buf;
git_config_with_options(cb, data, NULL, &opts);
- if (!have_git_dir() && opts.git_dir) {
- struct git_config_source repo_config;
-
- memset(&repo_config, 0, sizeof(repo_config));
- strbuf_addstr(&buf, "/config");
- repo_config.file = buf.buf;
- git_config_with_options(cb, data, &repo_config, &opts);
- }
strbuf_release(&buf);
- free(to_free);
}
static void git_config_check_init(void);