]> git.ipfire.org Git - thirdparty/git.git/commitdiff
config: split repo scope to local and worktree
authorMatthew Rogers <mattr94@gmail.com>
Mon, 10 Feb 2020 00:30:54 +0000 (00:30 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Feb 2020 18:32:20 +0000 (10:32 -0800)
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 <mattr94@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c
config.h
remote.c
t/t1308-config-set.sh
upload-pack.c

index a922b136e5514f07fccf42be95d8cd9db4bc7dfe..f68eec766f544e719d5babf38418e58e35a42a05 100644 (file)
--- 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:
index c063f33ff6539c3bbddd6f692a8a4cbb20a5e640..49297b507788008a9a03009d8085b336ff5df9e0 100644 (file)
--- a/config.h
+++ b/config.h
@@ -298,7 +298,8 @@ enum config_scope {
        CONFIG_SCOPE_UNKNOWN = 0,
        CONFIG_SCOPE_SYSTEM,
        CONFIG_SCOPE_GLOBAL,
-       CONFIG_SCOPE_REPO,
+       CONFIG_SCOPE_LOCAL,
+       CONFIG_SCOPE_WORKTREE,
        CONFIG_SCOPE_CMDLINE,
 };
 const char *config_scope_name(enum config_scope scope);
index 5c4666b53abc0c84fa863c172387fa6c2cc159d5..593ce297ed2ad41e150a077b67623e12ceaa3d25 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -369,7 +369,8 @@ static int handle_config(const char *key, const char *value, void *cb)
        }
        remote = make_remote(name, namelen);
        remote->origin = REMOTE_CONFIG;
-       if (current_config_scope() == CONFIG_SCOPE_REPO)
+       if (current_config_scope() == CONFIG_SCOPE_LOCAL ||
+       current_config_scope() == CONFIG_SCOPE_WORKTREE)
                remote->configured_in_repo = 1;
        if (!strcmp(subkey, "mirror"))
                remote->mirror = git_config_bool(key, value);
index 7b4e1a63eba2ffc2083061285b1a6cbbcb9c253d..90196e286222e20346351b1a0a0adb77ec9e673f 100755 (executable)
@@ -259,7 +259,7 @@ test_expect_success 'iteration shows correct origins' '
        value=from-repo
        origin=file
        name=.git/config
-       scope=repo
+       scope=local
 
        key=foo.bar
        value=from-cmdline
index a00d7ece6b9c9af0534a5458d1991bdf8646765a..c53249cac19a33351f4f747782b71f877fc0692f 100644 (file)
@@ -1073,7 +1073,8 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
                precomposed_unicode = git_config_bool(var, value);
        }
 
-       if (current_config_scope() != CONFIG_SCOPE_REPO) {
+       if (current_config_scope() != CONFIG_SCOPE_LOCAL &&
+       current_config_scope() != CONFIG_SCOPE_WORKTREE) {
                if (!strcmp("uploadpack.packobjectshook", var))
                        return git_config_string(&pack_objects_hook, var, value);
        }