Skip to content

Commit 4ff8feb

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

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

builtin/config.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ struct config_display_options {
125125

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

@@ -343,8 +343,8 @@ static int collect_config(const char *key_, const char *value_,
343343
return 0;
344344
if (fixed_value && strcmp(data->value_pattern, (value_?value_:"")))
345345
return 0;
346-
if (regexp != NULL &&
347-
(data->do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0)))
346+
if (data->regexp &&
347+
(data->do_not_match ^ !!regexec(data->regexp, (value_?value_:""), 0, NULL, 0)))
348348
return 0;
349349

350350
ALLOC_GROW(values->items, values->nr + 1, values->alloc);
@@ -405,10 +405,10 @@ static int get_value(const struct config_location_options *opts,
405405
regex_++;
406406
}
407407

408-
regexp = (regex_t*)xmalloc(sizeof(regex_t));
409-
if (regcomp(regexp, regex_, REG_EXTENDED)) {
408+
data.regexp = (regex_t*)xmalloc(sizeof(regex_t));
409+
if (regcomp(data.regexp, regex_, REG_EXTENDED)) {
410410
error(_("invalid pattern: %s"), regex_);
411-
FREE_AND_NULL(regexp);
411+
FREE_AND_NULL(data.regexp);
412412
ret = CONFIG_INVALID_PATTERN;
413413
goto free_strings;
414414
}
@@ -448,9 +448,9 @@ static int get_value(const struct config_location_options *opts,
448448
regfree(key_regexp);
449449
free(key_regexp);
450450
}
451-
if (regexp) {
452-
regfree(regexp);
453-
free(regexp);
451+
if (data.regexp) {
452+
regfree(data.regexp);
453+
free(data.regexp);
454454
}
455455

456456
return ret;

0 commit comments

Comments
 (0)