Skip to content

Commit 6dc905d

Browse files
ROGERSM94gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a5cb420 commit 6dc905d

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

config.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,15 +1724,12 @@ static int do_git_config_sequence(const struct config_options *opts,
17241724
if (user_config && !access_or_die(user_config, R_OK, ACCESS_EACCES_OK))
17251725
ret += git_config_from_file(fn, user_config, data);
17261726

1727-
current_parsing_scope = CONFIG_SCOPE_REPO;
1727+
current_parsing_scope = CONFIG_SCOPE_LOCAL;
17281728
if (!opts->ignore_repo && repo_config &&
17291729
!access_or_die(repo_config, R_OK, 0))
17301730
ret += git_config_from_file(fn, repo_config, data);
17311731

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;
17361733
if (!opts->ignore_worktree && repository_format_worktree_config) {
17371734
char *path = git_pathdup("config.worktree");
17381735
if (!access_or_die(path, R_OK, 0))
@@ -3304,8 +3301,10 @@ const char *config_scope_name(enum config_scope scope)
33043301
return "system";
33053302
case CONFIG_SCOPE_GLOBAL:
33063303
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";
33093308
case CONFIG_SCOPE_CMDLINE:
33103309
return "cmdline";
33113310
default:

config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ enum config_scope {
298298
CONFIG_SCOPE_UNKNOWN = 0,
299299
CONFIG_SCOPE_SYSTEM,
300300
CONFIG_SCOPE_GLOBAL,
301-
CONFIG_SCOPE_REPO,
301+
CONFIG_SCOPE_LOCAL,
302+
CONFIG_SCOPE_WORKTREE,
302303
CONFIG_SCOPE_CMDLINE,
303304
};
304305
const char *config_scope_name(enum config_scope scope);

remote.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ static int handle_config(const char *key, const char *value, void *cb)
369369
}
370370
remote = make_remote(name, namelen);
371371
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)
373374
remote->configured_in_repo = 1;
374375
if (!strcmp(subkey, "mirror"))
375376
remote->mirror = git_config_bool(key, value);

t/t1308-config-set.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ test_expect_success 'iteration shows correct origins' '
259259
value=from-repo
260260
origin=file
261261
name=.git/config
262-
scope=repo
262+
scope=local
263263
264264
key=foo.bar
265265
value=from-cmdline

upload-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,8 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
10731073
precomposed_unicode = git_config_bool(var, value);
10741074
}
10751075

1076-
if (current_config_scope() != CONFIG_SCOPE_REPO) {
1076+
if (current_config_scope() != CONFIG_SCOPE_LOCAL &&
1077+
current_config_scope() != CONFIG_SCOPE_WORKTREE) {
10771078
if (!strcmp("uploadpack.packobjectshook", var))
10781079
return git_config_string(&pack_objects_hook, var, value);
10791080
}

0 commit comments

Comments
 (0)