diff mbox series

[14/21] builtin/config: convert `do_not_match` to a local variable

Message ID 2b40b784fe146b4d17de9accd4afc53144c93812.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 `do_not_match` variable is used by the `format_config()` callback as
an indicator whteher or not the passed regular expression is negated. It
is only ever set up by its only caller, `collect_config()` and can thus
easily be moved into the `collect_config_data` structure.

Do so to remove our reliance on global state.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/config.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Eric Sunshine May 11, 2024, 4:42 p.m. UTC | #1
On Sat, May 11, 2024 at 5:25 AM Patrick Steinhardt <ps@pks.im> wrote:
> The `do_not_match` variable is used by the `format_config()` callback as
> an indicator whteher or not the passed regular expression is negated. It
> is only ever set up by its only caller, `collect_config()` and can thus
> easily be moved into the `collect_config_data` structure.

s/whteher/whether/

> Do so to remove our reliance on global state.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
diff mbox series

Patch

diff --git a/builtin/config.c b/builtin/config.c
index d11d0b4784..9d5d8c8df3 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -128,7 +128,6 @@  static const char *value_pattern;
 static regex_t *regexp;
 static int use_key_regexp;
 static int do_all;
-static int do_not_match;
 static int fixed_value;
 
 #define TYPE_BOOL		1
@@ -327,6 +326,7 @@  static int format_config(const struct config_display_options *opts,
 struct collect_config_data {
 	const struct config_display_options *display_opts;
 	struct strbuf_list *values;
+	int do_not_match;
 };
 
 static int collect_config(const char *key_, const char *value_,
@@ -343,7 +343,7 @@  static int collect_config(const char *key_, const char *value_,
 	if (fixed_value && strcmp(value_pattern, (value_?value_:"")))
 		return 0;
 	if (regexp != NULL &&
-	    (do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0)))
+	    (data->do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0)))
 		return 0;
 
 	ALLOC_GROW(values->items, values->nr + 1, values->alloc);
@@ -400,7 +400,7 @@  static int get_value(const struct config_location_options *opts,
 		value_pattern = regex_;
 	else if (regex_) {
 		if (regex_[0] == '!') {
-			do_not_match = 1;
+			data.do_not_match = 1;
 			regex_++;
 		}