diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-05-15 08:42:53 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-05-15 16:17:55 +0200 |
commit | fdfaaa1b68f61eccd7423da558e9c69e3c7bb908 (patch) | |
tree | 599433fd97ddbcdc26a5398d4acaea1bfeb14184 /builtin/config.c | |
parent | builtin/config: convert `regexp` to a local variable (diff) | |
download | git-fdfaaa1b68f61eccd7423da558e9c69e3c7bb908.tar.xz git-fdfaaa1b68f61eccd7423da558e9c69e3c7bb908.zip |
builtin/config: convert `key_regexp` to a local variable
The `key_regexp` variable is used by the `format_config()` callback when
`use_key_regexp` is 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>
Diffstat (limited to '')
-rw-r--r-- | builtin/config.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/builtin/config.c b/builtin/config.c index ae609c9b97..08a11b7999 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -124,7 +124,6 @@ struct config_display_options { } static char *key; -static regex_t *key_regexp; static int use_key_regexp; static int do_all; static int fixed_value; @@ -327,6 +326,7 @@ struct collect_config_data { struct strbuf_list *values; const char *value_pattern; regex_t *regexp; + regex_t *key_regexp; int do_not_match; }; @@ -339,7 +339,7 @@ static int collect_config(const char *key_, const char *value_, if (!use_key_regexp && strcmp(key_, key)) return 0; - if (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0)) + if (use_key_regexp && regexec(data->key_regexp, key_, 0, NULL, 0)) return 0; if (fixed_value && strcmp(data->value_pattern, (value_?value_:""))) return 0; @@ -383,10 +383,10 @@ static int get_value(const struct config_location_options *opts, for (tl = key; *tl && *tl != '.'; tl++) *tl = tolower(*tl); - key_regexp = (regex_t*)xmalloc(sizeof(regex_t)); - if (regcomp(key_regexp, key, REG_EXTENDED)) { + data.key_regexp = (regex_t*)xmalloc(sizeof(regex_t)); + if (regcomp(data.key_regexp, key, REG_EXTENDED)) { error(_("invalid key pattern: %s"), key_); - FREE_AND_NULL(key_regexp); + FREE_AND_NULL(data.key_regexp); ret = CONFIG_INVALID_PATTERN; goto free_strings; } @@ -444,9 +444,9 @@ static int get_value(const struct config_location_options *opts, free_strings: free(key); - if (key_regexp) { - regfree(key_regexp); - free(key_regexp); + if (data.key_regexp) { + regfree(data.key_regexp); + free(data.key_regexp); } if (data.regexp) { regfree(data.regexp); |