From a5cb4204b63b57e99ae3a44f23a7945f146fe078 Mon Sep 17 00:00:00 2001 From: Matthew Rogers Date: Mon, 10 Feb 2020 00:30:53 +0000 Subject: config: make scope_name non-static and rename it To prepare for the upcoming --show-scope option, we require the ability to convert a config_scope enum to a string. As this was originally implemented as a static function 'scope_name()' in t/helper/test-config.c, we expose it via config.h and give it a less ambiguous name 'config_scope_name()' Signed-off-by: Matthew Rogers Signed-off-by: Junio C Hamano --- config.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'config.c') diff --git a/config.c b/config.c index d75f88ca0c..a922b136e5 100644 --- a/config.c +++ b/config.c @@ -3297,6 +3297,22 @@ const char *current_config_origin_type(void) } } +const char *config_scope_name(enum config_scope scope) +{ + switch (scope) { + case CONFIG_SCOPE_SYSTEM: + return "system"; + case CONFIG_SCOPE_GLOBAL: + return "global"; + case CONFIG_SCOPE_REPO: + return "repo"; + case CONFIG_SCOPE_CMDLINE: + return "cmdline"; + default: + return "unknown"; + } +} + const char *current_config_name(void) { const char *name; -- cgit v1.2.3 From 6dc905d97431d683b418978819629a2626555b2e Mon Sep 17 00:00:00 2001 From: Matthew Rogers Date: Mon, 10 Feb 2020 00:30:54 +0000 Subject: config: split repo scope to local and worktree Previously when iterating through git config variables, worktree config and local config were both considered "CONFIG_SCOPE_REPO". This was never a problem before as no one had needed to differentiate between the two cases, but future functionality may care whether or not the config options come from a worktree or from the repository's actual local config file. For example, the planned feature to add a '--show-scope' to config to allow a user to see which scope listed config options come from would confuse users if it just printed 'repo' rather than 'local' or 'worktree' as the documentation would lead them to expect. As well as the additional benefit of making the implementation look more like how the documentation describes the interface. To accomplish this we split out what was previously considered repo scope to be local and worktree. The clients of 'current_config_scope()' who cared about CONFIG_SCOPE_REPO are also modified to similarly care about CONFIG_SCOPE_WORKTREE and CONFIG_SCOPE_LOCAL to preserve previous behavior. Signed-off-by: Matthew Rogers Signed-off-by: Junio C Hamano --- config.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index a922b136e5..f68eec766f 100644 --- a/config.c +++ b/config.c @@ -1724,15 +1724,12 @@ static int do_git_config_sequence(const struct config_options *opts, if (user_config && !access_or_die(user_config, R_OK, ACCESS_EACCES_OK)) ret += git_config_from_file(fn, user_config, data); - current_parsing_scope = CONFIG_SCOPE_REPO; + current_parsing_scope = CONFIG_SCOPE_LOCAL; if (!opts->ignore_repo && repo_config && !access_or_die(repo_config, R_OK, 0)) ret += git_config_from_file(fn, repo_config, data); - /* - * Note: this should have a new scope, CONFIG_SCOPE_WORKTREE. - * But let's not complicate things before it's actually needed. - */ + current_parsing_scope = CONFIG_SCOPE_WORKTREE; if (!opts->ignore_worktree && repository_format_worktree_config) { char *path = git_pathdup("config.worktree"); if (!access_or_die(path, R_OK, 0)) @@ -3304,8 +3301,10 @@ const char *config_scope_name(enum config_scope scope) return "system"; case CONFIG_SCOPE_GLOBAL: return "global"; - case CONFIG_SCOPE_REPO: - return "repo"; + case CONFIG_SCOPE_LOCAL: + return "local"; + case CONFIG_SCOPE_WORKTREE: + return "worktree"; case CONFIG_SCOPE_CMDLINE: return "cmdline"; default: -- cgit v1.2.3 From 6766e41b8aae21927625adbb8cdc87804153639a Mon Sep 17 00:00:00 2001 From: Matthew Rogers Date: Mon, 10 Feb 2020 00:30:55 +0000 Subject: config: clarify meaning of command line scoping CONFIG_SCOPE_CMDLINE is generally used in the code to refer to config values passed in via the -c option. Options passed in using this mechanism share similar scoping characteristics with the --file and --blob options of the 'config' command, namely that they are only in use for that single invocation of git, and that they supersede the normal system/global/local hierarchy. This patch introduces CONFIG_SCOPE_COMMAND to reflect this new idea, which also makes CONFIG_SCOPE_CMDLINE redundant. Signed-off-by: Matthew Rogers Signed-off-by: Junio C Hamano --- config.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index f68eec766f..fe1e44a43a 100644 --- a/config.c +++ b/config.c @@ -1737,7 +1737,7 @@ static int do_git_config_sequence(const struct config_options *opts, free(path); } - current_parsing_scope = CONFIG_SCOPE_CMDLINE; + current_parsing_scope = CONFIG_SCOPE_COMMAND; if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0) die(_("unable to parse command-line config")); @@ -3305,8 +3305,8 @@ const char *config_scope_name(enum config_scope scope) return "local"; case CONFIG_SCOPE_WORKTREE: return "worktree"; - case CONFIG_SCOPE_CMDLINE: - return "cmdline"; + case CONFIG_SCOPE_COMMAND: + return "command"; default: return "unknown"; } -- cgit v1.2.3 From 5c105a842eae59a3271f5db861ef8d85de6bc2f8 Mon Sep 17 00:00:00 2001 From: Matthew Rogers Date: Mon, 10 Feb 2020 00:30:56 +0000 Subject: config: preserve scope in do_git_config_sequence do_git_config_sequence operated under the assumption that it was correct to set current_parsing_scope to CONFIG_SCOPE_UNKNOWN as part of the cleanup it does after it finishes execution. This is incorrect, as it blows away the current_parsing_scope if do_git_config_sequence is called recursively. As such situations are rare (git config running with the '--blob' option is one example) this has yet to cause a problem, but the upcoming '--show-scope' option will experience issues in that case, lets teach do_git_config_sequence to preserve the current_parsing_scope from before it started execution. Signed-off-by: Matthew Rogers Signed-off-by: Junio C Hamano --- config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index fe1e44a43a..0e2c693e78 100644 --- a/config.c +++ b/config.c @@ -1702,6 +1702,7 @@ static int do_git_config_sequence(const struct config_options *opts, char *xdg_config = xdg_config_home("config"); char *user_config = expand_user_path("~/.gitconfig", 0); char *repo_config; + enum config_scope prev_parsing_scope = current_parsing_scope; if (opts->commondir) repo_config = mkpathdup("%s/config", opts->commondir); @@ -1741,7 +1742,7 @@ static int do_git_config_sequence(const struct config_options *opts, if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0) die(_("unable to parse command-line config")); - current_parsing_scope = CONFIG_SCOPE_UNKNOWN; + current_parsing_scope = prev_parsing_scope; free(xdg_config); free(user_config); free(repo_config); -- cgit v1.2.3 From e37efa40e122c4408c89c437e8a375df2147feac Mon Sep 17 00:00:00 2001 From: Matthew Rogers Date: Mon, 10 Feb 2020 00:30:57 +0000 Subject: config: teach git_config_source to remember its scope There are many situations where the scope of a config command is known beforehand, such as passing of '--local', '--file', etc. to an invocation of git config. However, this information is lost when moving from builtin/config.c to /config.c. This historically hasn't been a big deal, but to prepare for the upcoming --show-scope option we teach git_config_source to keep track of the source and the config machinery to use that information to set current_parsing_scope appropriately. Signed-off-by: Matthew Rogers Signed-off-by: Junio C Hamano --- config.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'config.c') diff --git a/config.c b/config.c index 0e2c693e78..9b6afca210 100644 --- a/config.c +++ b/config.c @@ -1763,6 +1763,9 @@ int config_with_options(config_fn_t fn, void *data, data = &inc; } + if (config_source) + current_parsing_scope = config_source->scope; + /* * If we have a specific filename, use it. Otherwise, follow the * regular lookup sequence. -- cgit v1.2.3 From 9a83d088ee00dcdab171b2020ab334e369437a33 Mon Sep 17 00:00:00 2001 From: Matthew Rogers Date: Mon, 10 Feb 2020 00:30:58 +0000 Subject: submodule-config: add subomdule config scope Before the changes to teach git_config_source to remember scope information submodule-config.c never needed to consider the question of config scope. Even though zeroing out git_config_source is still correct and preserved the previous behavior of setting the scope to CONFIG_SCOPE_UNKNOWN, it's better to be explicit about such situations by explicitly setting the scope. As none of the current config_scope enumerations make sense we create CONFIG_SCOPE_SUBMODULE to describe the situation. Signed-off-by: Matthew Rogers Signed-off-by: Junio C Hamano --- config.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'config.c') diff --git a/config.c b/config.c index 9b6afca210..18a6bdd9ff 100644 --- a/config.c +++ b/config.c @@ -3311,6 +3311,8 @@ const char *config_scope_name(enum config_scope scope) return "worktree"; case CONFIG_SCOPE_COMMAND: return "command"; + case CONFIG_SCOPE_SUBMODULE: + return "submodule"; default: return "unknown"; } -- cgit v1.2.3