@matheusbsbs / matheus-bagliano / commits / 6dc905d974
Fork 0

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 <mattr94@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matthew Rogers committed Feb 10, 2020 at 00:30 UTC 6dc905d97431d683b418978819629a2626555b2e
5 files changed +13 -11
config.c
+6 -7
@@ -1724,15 +1724,12 @@ static int do_git_config_sequence(const struct config_options *opts,
1724 if (user_config && !access_or_die(user_config, R_OK, ACCESS_EACCES_OK))
1725 ret += git_config_from_file(fn, user_config, data);
1726
1727 - current_parsing_scope = CONFIG_SCOPE_REPO;
1727 + current_parsing_scope = CONFIG_SCOPE_LOCAL;
1728 if (!opts->ignore_repo && repo_config &&
1729 !access_or_die(repo_config, R_OK, 0))
1730 ret += git_config_from_file(fn, repo_config, data);
1731
1732 - /*
1733 - * Note: this should have a new scope, CONFIG_SCOPE_WORKTREE.
1734 - * But let's not complicate things before it's actually needed.
1735 - */
1732 + current_parsing_scope = CONFIG_SCOPE_WORKTREE;
1733 if (!opts->ignore_worktree && repository_format_worktree_config) {
1734 char *path = git_pathdup("config.worktree");
1735 if (!access_or_die(path, R_OK, 0))
@@ -3304,8 +3301,10 @@ const char *config_scope_name(enum config_scope scope)
3301 return "system";
3302 case CONFIG_SCOPE_GLOBAL:
3303 return "global";
3307 - case CONFIG_SCOPE_REPO:
3308 - return "repo";
3304 + case CONFIG_SCOPE_LOCAL:
3305 + return "local";
3306 + case CONFIG_SCOPE_WORKTREE:
3307 + return "worktree";
3308 case CONFIG_SCOPE_CMDLINE:
3309 return "cmdline";
3310 default:
config.h
+2 -1
@@ -298,7 +298,8 @@ enum config_scope {
298 CONFIG_SCOPE_UNKNOWN = 0,
299 CONFIG_SCOPE_SYSTEM,
300 CONFIG_SCOPE_GLOBAL,
301 - CONFIG_SCOPE_REPO,
301 + CONFIG_SCOPE_LOCAL,
302 + CONFIG_SCOPE_WORKTREE,
303 CONFIG_SCOPE_CMDLINE,
304 };
305 const char *config_scope_name(enum config_scope scope);
remote.c
+2 -1
@@ -369,7 +369,8 @@ static int handle_config(const char *key, const char *value, void *cb)
369 }
370 remote = make_remote(name, namelen);
371 remote->origin = REMOTE_CONFIG;
372 - if (current_config_scope() == CONFIG_SCOPE_REPO)
372 + if (current_config_scope() == CONFIG_SCOPE_LOCAL ||
373 + current_config_scope() == CONFIG_SCOPE_WORKTREE)
374 remote->configured_in_repo = 1;
375 if (!strcmp(subkey, "mirror"))
376 remote->mirror = git_config_bool(key, value);
t/t1308-config-set.sh
+1 -1
@@ -259,7 +259,7 @@ test_expect_success 'iteration shows correct origins' '
259 value=from-repo
260 origin=file
261 name=.git/config
262 - scope=repo
262 + scope=local
263
264 key=foo.bar
265 value=from-cmdline
upload-pack.c
+2 -1
@@ -1073,7 +1073,8 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
1073 precomposed_unicode = git_config_bool(var, value);
1074 }
1075
1076 - if (current_config_scope() != CONFIG_SCOPE_REPO) {
1076 + if (current_config_scope() != CONFIG_SCOPE_LOCAL &&
1077 + current_config_scope() != CONFIG_SCOPE_WORKTREE) {
1078 if (!strcmp("uploadpack.packobjectshook", var))
1079 return git_config_string(&pack_objects_hook, var, value);
1080 }