summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'config.c')
-rw-r--r--config.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/config.c b/config.c
index 6428393a41..f9c400ad30 100644
--- a/config.c
+++ b/config.c
@@ -1180,20 +1180,6 @@ static void die_bad_number(const char *name, const char *value)
}
}
-NORETURN
-static void die_bad_bool(const char *name, const char *value)
-{
- if (!strcmp(name, "GIT_TEST_GETTEXT_POISON"))
- /*
- * We explicitly *don't* use _() here since it would
- * cause an infinite loop with _() needing to call
- * use_gettext_poison().
- */
- die("bad boolean config value '%s' for '%s'", value, name);
- else
- die(_("bad boolean config value '%s' for '%s'"), value, name);
-}
-
int git_config_int(const char *name, const char *value)
{
int ret;
@@ -1268,7 +1254,7 @@ int git_config_bool(const char *name, const char *value)
{
int v = git_parse_maybe_bool(value);
if (v < 0)
- die_bad_bool(name, value);
+ die(_("bad boolean config value '%s' for '%s'"), value, name);
return v;
}
@@ -1844,12 +1830,26 @@ static int git_config_from_blob_ref(config_fn_t fn,
return git_config_from_blob_oid(fn, name, &oid, data);
}
-const char *git_etc_gitconfig(void)
+char *git_system_config(void)
+{
+ char *system_config = xstrdup_or_null(getenv("GIT_CONFIG_SYSTEM"));
+ if (system_config)
+ return system_config;
+ return system_path(ETC_GITCONFIG);
+}
+
+void git_global_config(char **user_out, char **xdg_out)
{
- static const char *system_wide;
- if (!system_wide)
- system_wide = system_path(ETC_GITCONFIG);
- return system_wide;
+ char *user_config = xstrdup_or_null(getenv("GIT_CONFIG_GLOBAL"));
+ char *xdg_config = NULL;
+
+ if (!user_config) {
+ user_config = expand_user_path("~/.gitconfig", 0);
+ xdg_config = xdg_config_home("config");
+ }
+
+ *user_out = user_config;
+ *xdg_out = xdg_config;
}
/*
@@ -1883,8 +1883,9 @@ 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", 0);
+ char *system_config = git_system_config();
+ char *xdg_config = NULL;
+ char *user_config = NULL;
char *repo_config;
enum config_scope prev_parsing_scope = current_parsing_scope;
@@ -1896,13 +1897,14 @@ static int do_git_config_sequence(const struct config_options *opts,
repo_config = NULL;
current_parsing_scope = CONFIG_SCOPE_SYSTEM;
- if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK,
- opts->system_gently ?
- ACCESS_EACCES_OK : 0))
- ret += git_config_from_file(fn, git_etc_gitconfig(),
- data);
+ if (git_config_system() && system_config &&
+ !access_or_die(system_config, R_OK,
+ opts->system_gently ? ACCESS_EACCES_OK : 0))
+ ret += git_config_from_file(fn, system_config, data);
current_parsing_scope = CONFIG_SCOPE_GLOBAL;
+ git_global_config(&user_config, &xdg_config);
+
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK))
ret += git_config_from_file(fn, xdg_config, data);
@@ -1927,6 +1929,7 @@ static int do_git_config_sequence(const struct config_options *opts,
die(_("unable to parse command-line config"));
current_parsing_scope = prev_parsing_scope;
+ free(system_config);
free(xdg_config);
free(user_config);
free(repo_config);