aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-05-15 08:42:49 +0200
committerJunio C Hamano <gitster@pobox.com>2024-05-15 07:17:55 -0700
commit4ff8feb307432e20b2b79e7fc0fde3f2e282b5a6 (patch)
tree6e46aa0599206929f46c7133e6f0d6ba2f7d3375
parentbfe45f83e7a7815cbaea04f380cd807c18c088ea (diff)
downloadgit-4ff8feb307432e20b2b79e7fc0fde3f2e282b5a6.tar.gz
builtin/config: convert `regexp` to a local variable
The `regexp` variable is used by the `format_config()` callback when `CONFIG_FLAGS_FIXED_VALUE` is not set. 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/config.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/builtin/config.c b/builtin/config.c
index aac5f7b976..ae609c9b97 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -125,7 +125,6 @@ struct config_display_options {
static char *key;
static regex_t *key_regexp;
-static regex_t *regexp;
static int use_key_regexp;
static int do_all;
static int fixed_value;
@@ -327,6 +326,7 @@ struct collect_config_data {
const struct config_display_options *display_opts;
struct strbuf_list *values;
const char *value_pattern;
+ regex_t *regexp;
int do_not_match;
};
@@ -343,8 +343,8 @@ static int collect_config(const char *key_, const char *value_,
return 0;
if (fixed_value && strcmp(data->value_pattern, (value_?value_:"")))
return 0;
- if (regexp != NULL &&
- (data->do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0)))
+ if (data->regexp &&
+ (data->do_not_match ^ !!regexec(data->regexp, (value_?value_:""), 0, NULL, 0)))
return 0;
ALLOC_GROW(values->items, values->nr + 1, values->alloc);
@@ -405,10 +405,10 @@ static int get_value(const struct config_location_options *opts,
regex_++;
}
- regexp = (regex_t*)xmalloc(sizeof(regex_t));
- if (regcomp(regexp, regex_, REG_EXTENDED)) {
+ data.regexp = (regex_t*)xmalloc(sizeof(regex_t));
+ if (regcomp(data.regexp, regex_, REG_EXTENDED)) {
error(_("invalid pattern: %s"), regex_);
- FREE_AND_NULL(regexp);
+ FREE_AND_NULL(data.regexp);
ret = CONFIG_INVALID_PATTERN;
goto free_strings;
}
@@ -448,9 +448,9 @@ free_strings:
regfree(key_regexp);
free(key_regexp);
}
- if (regexp) {
- regfree(regexp);
- free(regexp);
+ if (data.regexp) {
+ regfree(data.regexp);
+ free(data.regexp);
}
return ret;