diff mbox series

[13/21] builtin/config: move `respect_includes_opt` into location options

Message ID b9ebfbd667d0ff0d500dc1088a4352d666fc8570.1715339393.git.ps@pks.im (mailing list archive)
State Superseded
Headers show
Series builtin/config: remove global state | expand

Commit Message

Patrick Steinhardt May 10, 2024, 11:25 a.m. UTC
The variable tracking whether or not we want to honor includes is
tracked via a global variable. Move it into the location options
instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/config.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/builtin/config.c b/builtin/config.c
index eca5179f5f..d11d0b4784 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -78,8 +78,11 @@  struct config_location_options {
 	int use_system_config;
 	int use_local_config;
 	int use_worktree_config;
+	int respect_includes_opt;
 };
-#define CONFIG_LOCATION_OPTIONS_INIT {0}
+#define CONFIG_LOCATION_OPTIONS_INIT { \
+	.respect_includes_opt = -1, \
+}
 
 #define CONFIG_TYPE_OPTIONS(type) \
 	OPT_GROUP(N_("Type")), \
@@ -126,7 +129,6 @@  static regex_t *regexp;
 static int use_key_regexp;
 static int do_all;
 static int do_not_match;
-static int respect_includes_opt = -1;
 static int fixed_value;
 
 #define TYPE_BOOL		1
@@ -774,10 +776,10 @@  static void location_options_init(struct config_location_options *opts,
 		opts->source.scope = CONFIG_SCOPE_COMMAND;
 	}
 
-	if (respect_includes_opt == -1)
+	if (opts->respect_includes_opt == -1)
 		opts->options.respect_includes = !opts->source.file;
 	else
-		opts->options.respect_includes = respect_includes_opt;
+		opts->options.respect_includes = opts->respect_includes_opt;
 	if (startup_info->have_repository) {
 		opts->options.commondir = get_git_common_dir();
 		opts->options.git_dir = get_git_dir();
@@ -806,7 +808,8 @@  static int cmd_config_list(int argc, const char **argv, const char *prefix)
 		CONFIG_LOCATION_OPTIONS(location_opts),
 		CONFIG_DISPLAY_OPTIONS(display_opts),
 		OPT_GROUP(N_("Other")),
-		OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")),
+		OPT_BOOL(0, "includes", &location_opts.respect_includes_opt,
+			 N_("respect include directives on lookup")),
 		OPT_END(),
 	};
 
@@ -848,7 +851,8 @@  static int cmd_config_get(int argc, const char **argv, const char *prefix)
 		OPT_STRING(0, "url", &url, N_("URL"), N_("show config matching the given URL")),
 		CONFIG_DISPLAY_OPTIONS(display_opts),
 		OPT_GROUP(N_("Other")),
-		OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")),
+		OPT_BOOL(0, "includes", &location_opts.respect_includes_opt,
+			 N_("respect include directives on lookup")),
 		OPT_STRING(0, "default", &display_opts.default_value,
 			   N_("value"), N_("use default value when missing entry")),
 		OPT_END(),
@@ -1131,7 +1135,8 @@  static int cmd_config_actions(int argc, const char **argv, const char *prefix)
 			   N_("value"), N_("with --get, use default value when missing entry")),
 		OPT_STRING(0, "comment", &comment_arg, N_("value"), N_("human-readable comment string (# will be prepended as needed)")),
 		OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")),
-		OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")),
+		OPT_BOOL(0, "includes", &location_opts.respect_includes_opt,
+			 N_("respect include directives on lookup")),
 		OPT_END(),
 	};
 	char *value = NULL, *comment = NULL;