Skip to content

Commit 4090a9c

Browse files
pks-tgitster
authored andcommitted
builtin/config: move default value into display options
The default value is tracked via a global variable. Move it into the display options instead. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 94c4693 commit 4090a9c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

builtin/config.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct config_display_options {
108108
int show_scope;
109109
int show_keys;
110110
int type;
111+
char *default_value;
111112
/* Populated via `display_options_init()`. */
112113
int term;
113114
int delim;
@@ -126,7 +127,6 @@ static regex_t *regexp;
126127
static int use_key_regexp;
127128
static int do_all;
128129
static int do_not_match;
129-
static char *default_value;
130130
static int respect_includes_opt = -1;
131131
static int fixed_value;
132132

@@ -416,17 +416,18 @@ static int get_value(const struct config_location_options *opts,
416416
&opts->source, the_repository,
417417
&opts->options);
418418

419-
if (!values.nr && default_value) {
419+
if (!values.nr && display_opts->default_value) {
420420
struct key_value_info kvi = KVI_INIT;
421421
struct strbuf *item;
422422

423423
kvi_from_param(&kvi);
424424
ALLOC_GROW(values.items, values.nr + 1, values.alloc);
425425
item = &values.items[values.nr++];
426426
strbuf_init(item, 0);
427-
if (format_config(display_opts, item, key_, default_value, &kvi) < 0)
427+
if (format_config(display_opts, item, key_,
428+
display_opts->default_value, &kvi) < 0)
428429
die(_("failed to format default config value: %s"),
429-
default_value);
430+
display_opts->default_value);
430431
}
431432

432433
ret = !values.nr;
@@ -850,7 +851,8 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix)
850851
CONFIG_DISPLAY_OPTIONS(display_opts),
851852
OPT_GROUP(N_("Other")),
852853
OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")),
853-
OPT_STRING(0, "default", &default_value, N_("value"), N_("use default value when missing entry")),
854+
OPT_STRING(0, "default", &display_opts.default_value,
855+
N_("value"), N_("use default value when missing entry")),
854856
OPT_END(),
855857
};
856858
int ret;
@@ -861,7 +863,7 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix)
861863

862864
if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern)
863865
die(_("--fixed-value only applies with 'value-pattern'"));
864-
if (default_value && (do_all || url))
866+
if (display_opts.default_value && (do_all || url))
865867
die(_("--default= cannot be used with --all or --url="));
866868
if (url && (do_all || use_key_regexp || value_pattern))
867869
die(_("--url= cannot be used with --all, --regexp or --value"));
@@ -1127,7 +1129,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
11271129
OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot [<stdout-is-tty>]"), ACTION_GET_COLORBOOL),
11281130
CONFIG_DISPLAY_OPTIONS(display_opts),
11291131
OPT_GROUP(N_("Other")),
1130-
OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")),
1132+
OPT_STRING(0, "default", &display_opts.default_value,
1133+
N_("value"), N_("with --get, use default value when missing entry")),
11311134
OPT_STRING(0, "comment", &comment_arg, N_("value"), N_("human-readable comment string (# will be prepended as needed)")),
11321135
OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")),
11331136
OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")),
@@ -1172,7 +1175,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
11721175
exit(129);
11731176
}
11741177

1175-
if (default_value && !(actions & ACTION_GET)) {
1178+
if (display_opts.default_value && !(actions & ACTION_GET)) {
11761179
error(_("--default is only applicable to --get"));
11771180
exit(129);
11781181
}

0 commit comments

Comments
 (0)