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 <mattr94@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthew Rogers committed
Feb 10, 2020 at 00:30 UTC
e37efa40e122c4408c89c437e8a375df2147feac
3 files changed
+27
-13
builtin/config.c
+13
-3
@@ -622,6 +622,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
622
!strcmp(given_config_source.file, "-")) {
623
given_config_source.file = NULL;
624
given_config_source.use_stdin = 1;
625
+ given_config_source.scope = CONFIG_SCOPE_COMMAND;
626
}
627
628
if (use_global_config) {
@@ -637,6 +638,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
638
*/
639
die(_("$HOME not set"));
640
641
+ given_config_source.scope = CONFIG_SCOPE_GLOBAL;
642
+
643
if (access_or_warn(user_config, R_OK, 0) &&
644
xdg_config && !access_or_warn(xdg_config, R_OK, 0)) {
645
given_config_source.file = xdg_config;
@@ -646,11 +649,13 @@ int cmd_config(int argc, const char **argv, const char *prefix)
649
free(xdg_config);
650
}
651
}
649
- else if (use_system_config)
652
+ else if (use_system_config) {
653
given_config_source.file = git_etc_gitconfig();
651
- else if (use_local_config)
654
+ given_config_source.scope = CONFIG_SCOPE_SYSTEM;
655
+ } else if (use_local_config) {
656
given_config_source.file = git_pathdup("config");
653
- else if (use_worktree_config) {
657
+ given_config_source.scope = CONFIG_SCOPE_LOCAL;
658
+ } else if (use_worktree_config) {
659
struct worktree **worktrees = get_worktrees(0);
660
if (repository_format_worktree_config)
661
given_config_source.file = git_pathdup("config.worktree");
@@ -662,13 +667,18 @@ int cmd_config(int argc, const char **argv, const char *prefix)
667
"section in \"git help worktree\" for details"));
668
else
669
given_config_source.file = git_pathdup("config");
670
+ given_config_source.scope = CONFIG_SCOPE_LOCAL;
671
free_worktrees(worktrees);
672
} else if (given_config_source.file) {
673
if (!is_absolute_path(given_config_source.file) && prefix)
674
given_config_source.file =
675
prefix_filename(prefix, given_config_source.file);
676
+ given_config_source.scope = CONFIG_SCOPE_COMMAND;
677
+ } else if (given_config_source.blob) {
678
+ given_config_source.scope = CONFIG_SCOPE_COMMAND;
679
}
680
681
+
682
if (respect_includes_opt == -1)
683
config_options.respect_includes = !given_config_source.file;
684
else
config.c
+3
@@ -1763,6 +1763,9 @@ int config_with_options(config_fn_t fn, void *data,
1763
data = &inc;
1764
}
1765
1766
+ if (config_source)
1767
+ current_parsing_scope = config_source->scope;
1768
+
1769
/*
1770
* If we have a specific filename, use it. Otherwise, follow the
1771
* regular lookup sequence.
config.h
+11
-10
@@ -35,10 +35,21 @@ struct object_id;
35
36
#define CONFIG_REGEX_NONE ((void *)1)
37
38
+enum config_scope {
39
+ CONFIG_SCOPE_UNKNOWN = 0,
40
+ CONFIG_SCOPE_SYSTEM,
41
+ CONFIG_SCOPE_GLOBAL,
42
+ CONFIG_SCOPE_LOCAL,
43
+ CONFIG_SCOPE_WORKTREE,
44
+ CONFIG_SCOPE_COMMAND,
45
+};
46
+const char *config_scope_name(enum config_scope scope);
47
+
48
struct git_config_source {
49
unsigned int use_stdin:1;
50
const char *file;
51
const char *blob;
52
+ enum config_scope scope;
53
};
54
55
enum config_origin_type {
@@ -294,16 +305,6 @@ int config_error_nonbool(const char *);
305
306
int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
307
297
-enum config_scope {
298
- CONFIG_SCOPE_UNKNOWN = 0,
299
- CONFIG_SCOPE_SYSTEM,
300
- CONFIG_SCOPE_GLOBAL,
301
- CONFIG_SCOPE_LOCAL,
302
- CONFIG_SCOPE_WORKTREE,
303
- CONFIG_SCOPE_COMMAND,
304
-};
305
-const char *config_scope_name(enum config_scope scope);
306
-
308
enum config_scope current_config_scope(void);
309
const char *current_config_origin_type(void);
310
const char *current_config_name(void);