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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed May 15, 2024 at 08:42 UTC 4090a9c948eaf755be203d313dd78b1189828f8b
1 file changed +11 -8
builtin/config.c
+11 -8
@@ -108,6 +108,7 @@ struct config_display_options {
108 int show_scope;
109 int show_keys;
110 int type;
111 + char *default_value;
112 /* Populated via `display_options_init()`. */
113 int term;
114 int delim;
@@ -126,7 +127,6 @@ static regex_t *regexp;
127 static int use_key_regexp;
128 static int do_all;
129 static int do_not_match;
129 -static char *default_value;
130 static int respect_includes_opt = -1;
131 static int fixed_value;
132
@@ -416,7 +416,7 @@ static int get_value(const struct config_location_options *opts,
416 &opts->source, the_repository,
417 &opts->options);
418
419 - if (!values.nr && default_value) {
419 + if (!values.nr && display_opts->default_value) {
420 struct key_value_info kvi = KVI_INIT;
421 struct strbuf *item;
422
@@ -424,9 +424,10 @@ static int get_value(const struct config_location_options *opts,
424 ALLOC_GROW(values.items, values.nr + 1, values.alloc);
425 item = &values.items[values.nr++];
426 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)
429 die(_("failed to format default config value: %s"),
429 - default_value);
430 + display_opts->default_value);
431 }
432
433 ret = !values.nr;
@@ -850,7 +851,8 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix)
851 CONFIG_DISPLAY_OPTIONS(display_opts),
852 OPT_GROUP(N_("Other")),
853 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")),
856 OPT_END(),
857 };
858 int ret;
@@ -861,7 +863,7 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix)
863
864 if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern)
865 die(_("--fixed-value only applies with 'value-pattern'"));
864 - if (default_value && (do_all || url))
866 + if (display_opts.default_value && (do_all || url))
867 die(_("--default= cannot be used with --all or --url="));
868 if (url && (do_all || use_key_regexp || value_pattern))
869 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)
1129 OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot [<stdout-is-tty>]"), ACTION_GET_COLORBOOL),
1130 CONFIG_DISPLAY_OPTIONS(display_opts),
1131 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")),
1134 OPT_STRING(0, "comment", &comment_arg, N_("value"), N_("human-readable comment string (# will be prepended as needed)")),
1135 OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")),
1136 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)
1175 exit(129);
1176 }
1177
1175 - if (default_value && !(actions & ACTION_GET)) {
1178 + if (display_opts.default_value && !(actions & ACTION_GET)) {
1179 error(_("--default is only applicable to --get"));
1180 exit(129);
1181 }