Skip to content

Commit fdfaaa1

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4ff8feb commit fdfaaa1

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

builtin/config.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ struct config_display_options {
124124
}
125125

126126
static char *key;
127-
static regex_t *key_regexp;
128127
static int use_key_regexp;
129128
static int do_all;
130129
static int fixed_value;
@@ -327,6 +326,7 @@ struct collect_config_data {
327326
struct strbuf_list *values;
328327
const char *value_pattern;
329328
regex_t *regexp;
329+
regex_t *key_regexp;
330330
int do_not_match;
331331
};
332332

@@ -339,7 +339,7 @@ static int collect_config(const char *key_, const char *value_,
339339

340340
if (!use_key_regexp && strcmp(key_, key))
341341
return 0;
342-
if (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0))
342+
if (use_key_regexp && regexec(data->key_regexp, key_, 0, NULL, 0))
343343
return 0;
344344
if (fixed_value && strcmp(data->value_pattern, (value_?value_:"")))
345345
return 0;
@@ -383,10 +383,10 @@ static int get_value(const struct config_location_options *opts,
383383
for (tl = key; *tl && *tl != '.'; tl++)
384384
*tl = tolower(*tl);
385385

386-
key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
387-
if (regcomp(key_regexp, key, REG_EXTENDED)) {
386+
data.key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
387+
if (regcomp(data.key_regexp, key, REG_EXTENDED)) {
388388
error(_("invalid key pattern: %s"), key_);
389-
FREE_AND_NULL(key_regexp);
389+
FREE_AND_NULL(data.key_regexp);
390390
ret = CONFIG_INVALID_PATTERN;
391391
goto free_strings;
392392
}
@@ -444,9 +444,9 @@ static int get_value(const struct config_location_options *opts,
444444

445445
free_strings:
446446
free(key);
447-
if (key_regexp) {
448-
regfree(key_regexp);
449-
free(key_regexp);
447+
if (data.key_regexp) {
448+
regfree(data.key_regexp);
449+
free(data.key_regexp);
450450
}
451451
if (data.regexp) {
452452
regfree(data.regexp);

0 commit comments

Comments
 (0)