Skip to content

Commit ab8bac8

Browse files
pks-tgitster
authored andcommitted
builtin/config: track "fixed value" option via flags only
We track the "fixed value" option via two separate bits: once via the global variable `fixed_value`, and once via the CONFIG_FLAGS_FIXED_VALUE bit in `flags`. This is confusing and may easily lead to issues when one is not aware that this is tracked via two separate mechanisms. Refactor the code to use the flag exclusively. We already pass it to all the required callsites anyway, except for `collect_config()`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 040b141 commit ab8bac8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

builtin/config.c

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

126126
static int use_key_regexp;
127127
static int do_all;
128-
static int fixed_value;
129128

130129
#define TYPE_BOOL 1
131130
#define TYPE_INT 2
@@ -328,6 +327,7 @@ struct collect_config_data {
328327
regex_t *regexp;
329328
regex_t *key_regexp;
330329
int do_not_match;
330+
unsigned flags;
331331
};
332332

333333
static int collect_config(const char *key_, const char *value_,
@@ -341,7 +341,8 @@ static int collect_config(const char *key_, const char *value_,
341341
return 0;
342342
if (use_key_regexp && regexec(data->key_regexp, key_, 0, NULL, 0))
343343
return 0;
344-
if (fixed_value && strcmp(data->value_pattern, (value_?value_:"")))
344+
if ((data->flags & CONFIG_FLAGS_FIXED_VALUE) &&
345+
strcmp(data->value_pattern, (value_?value_:"")))
345346
return 0;
346347
if (data->regexp &&
347348
(data->do_not_match ^ !!regexec(data->regexp, (value_?value_:""), 0, NULL, 0)))
@@ -363,6 +364,7 @@ static int get_value(const struct config_location_options *opts,
363364
struct collect_config_data data = {
364365
.display_opts = display_opts,
365366
.values = &values,
367+
.flags = flags,
366368
};
367369
char *key = NULL;
368370
int i;
@@ -1117,6 +1119,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
11171119
struct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT;
11181120
const char *comment_arg = NULL;
11191121
int actions = 0;
1122+
unsigned flags = 0;
11201123
struct option opts[] = {
11211124
CONFIG_LOCATION_OPTIONS(location_opts),
11221125
OPT_GROUP(N_("Action")),
@@ -1139,13 +1142,12 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
11391142
OPT_STRING(0, "default", &display_opts.default_value,
11401143
N_("value"), N_("with --get, use default value when missing entry")),
11411144
OPT_STRING(0, "comment", &comment_arg, N_("value"), N_("human-readable comment string (# will be prepended as needed)")),
1142-
OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")),
1145+
OPT_BIT(0, "fixed-value", &flags, N_("use string equality when comparing values to value pattern"), CONFIG_FLAGS_FIXED_VALUE),
11431146
OPT_BOOL(0, "includes", &location_opts.respect_includes_opt,
11441147
N_("respect include directives on lookup")),
11451148
OPT_END(),
11461149
};
11471150
char *value = NULL, *comment = NULL;
1148-
int flags = 0;
11491151
int ret = 0;
11501152
struct key_value_info default_kvi = KVI_INIT;
11511153

@@ -1195,7 +1197,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
11951197
}
11961198

11971199
/* check usage of --fixed-value */
1198-
if (fixed_value) {
1200+
if (flags & CONFIG_FLAGS_FIXED_VALUE) {
11991201
int allowed_usage = 0;
12001202

12011203
switch (actions) {
@@ -1226,8 +1228,6 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
12261228
error(_("--fixed-value only applies with 'value-pattern'"));
12271229
exit(129);
12281230
}
1229-
1230-
flags |= CONFIG_FLAGS_FIXED_VALUE;
12311231
}
12321232

12331233
comment = git_config_prepare_comment_string(comment_arg);

0 commit comments

Comments
 (0)