config: rename `git_etc_config()`
The `git_etc_gitconfig()` function retrieves the system-level path of the configuration file. We're about to introduce a way to override it via an environment variable, at which point the name of this function would start to become misleading. Rename the function to `git_system_config()` as a preparatory step. While at it, the function is also refactored to pass memory ownership to the caller. This is done to better match semantics of `git_global_config()`, which is going to be introduced in the next commit. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Apr 19, 2021 at 14:31 UTC
c62a999c6e595692ee3bd8ff1e9435491872a79c
3 files changed
+11
-12
builtin/config.c
+1
-1
@@ -695,7 +695,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
695
}
696
}
697
else if (use_system_config) {
698
- given_config_source.file = git_etc_gitconfig();
698
+ given_config_source.file = git_system_config();
699
given_config_source.scope = CONFIG_SCOPE_SYSTEM;
700
} else if (use_local_config) {
701
given_config_source.file = git_pathdup("config");
config.c
+8
-10
@@ -1844,12 +1844,9 @@ static int git_config_from_blob_ref(config_fn_t fn,
1844
return git_config_from_blob_oid(fn, name, &oid, data);
1845
}
1846
1847
-const char *git_etc_gitconfig(void)
1847
+char *git_system_config(void)
1848
{
1849
- static const char *system_wide;
1850
- if (!system_wide)
1851
- system_wide = system_path(ETC_GITCONFIG);
1852
- return system_wide;
1849
+ return system_path(ETC_GITCONFIG);
1850
}
1851
1852
/*
@@ -1883,6 +1880,7 @@ static int do_git_config_sequence(const struct config_options *opts,
1880
config_fn_t fn, void *data)
1881
{
1882
int ret = 0;
1883
+ char *system_config = git_system_config();
1884
char *xdg_config = xdg_config_home("config");
1885
char *user_config = expand_user_path("~/.gitconfig", 0);
1886
char *repo_config;
@@ -1896,11 +1894,10 @@ static int do_git_config_sequence(const struct config_options *opts,
1894
repo_config = NULL;
1895
1896
current_parsing_scope = CONFIG_SCOPE_SYSTEM;
1899
- if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK,
1900
- opts->system_gently ?
1901
- ACCESS_EACCES_OK : 0))
1902
- ret += git_config_from_file(fn, git_etc_gitconfig(),
1903
- data);
1897
+ if (git_config_system() && system_config &&
1898
+ !access_or_die(system_config, R_OK,
1899
+ opts->system_gently ? ACCESS_EACCES_OK : 0))
1900
+ ret += git_config_from_file(fn, system_config, data);
1901
1902
current_parsing_scope = CONFIG_SCOPE_GLOBAL;
1903
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK))
@@ -1927,6 +1924,7 @@ static int do_git_config_sequence(const struct config_options *opts,
1924
die(_("unable to parse command-line config"));
1925
1926
current_parsing_scope = prev_parsing_scope;
1927
+ free(system_config);
1928
free(xdg_config);
1929
free(user_config);
1930
free(repo_config);
config.h
+2
-1
@@ -318,7 +318,6 @@ int git_config_rename_section(const char *, const char *);
318
int git_config_rename_section_in_file(const char *, const char *, const char *);
319
int git_config_copy_section(const char *, const char *);
320
int git_config_copy_section_in_file(const char *, const char *, const char *);
321
-const char *git_etc_gitconfig(void);
321
int git_env_bool(const char *, int);
322
unsigned long git_env_ulong(const char *, unsigned long);
323
int git_config_system(void);
@@ -327,6 +326,8 @@ int config_error_nonbool(const char *);
326
#define config_error_nonbool(s) (config_error_nonbool(s), const_error())
327
#endif
328
329
+char *git_system_config(void);
330
+
331
int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
332
333
enum config_scope current_config_scope(void);