From patchwork Fri May 10 11:25:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13661377 Received: from wfout8-smtp.messagingengine.com (wfout8-smtp.messagingengine.com [64.147.123.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D251117089C for ; Fri, 10 May 2024 11:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340323; cv=none; b=Qho8beNIEuAniZeN+XEEqFnKkB0pxKT+yOeYI/2Eh2sGudVclwlRrDaBC14Ujt+sl9a3hqOSmiCM5wu0kafDbVb4U0/hwrCdZMXMXsOjmG1yKRIxw8LpNflOG0jhDbW+YSJKP1+sTPUYUUneNjKyBtgjCrIGQjyPZcac9bgttjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340323; c=relaxed/simple; bh=POYZhvoPzpLJCRiyUBWN0srjVqTmgQ9G42W78xHT3f8=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=E5undl1MkZ02Wcr0IGW03WlOKW3sLAWBk6nHa3YYZmn4CfvuWMtHPzbzg0CB8jfsFB6uUww0GZ8TfdSB0oYot1FQ8GKmXvyEVrjDWyqkX75QJw2MaGPFkiXdliWwgZs6d2d/DbdIE1wm+7D3XQixyJ0DNqkPZrB+y2T+vZW+02A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=dZ2WO7RM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=j3Ca5mnZ; arc=none smtp.client-ip=64.147.123.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="dZ2WO7RM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="j3Ca5mnZ" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id 180421C00098 for ; Fri, 10 May 2024 07:25:21 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 10 May 2024 07:25:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715340320; x=1715426720; bh=YVb8TYgRuw HSnjN8vDiwIR1lMeaAFV+ygocaVFDh3C8=; b=dZ2WO7RMba066CRCN8hhgWCF60 +arlwPiegYPEaE4Au7RP1ydf8BAJnSXH43FW+15gkEnoaPoNcyXVGJjCkbYM6+hv pt6CqWwoBiQjeXS6pmJ67feCF1GEdnCtuDXlPGbDbI8GSUW3tW3Y9qGn29oc6As+ 93LJYI1hJLM5TYJG9KpdzaLNFBhi03J1JQ2pCAIJWdNXyCErHHywBXuLSzMlSbQc 3IqV1cFaHIPjWpPNCoi6SMThztn68zK3guzY/IKj0TDfc6E2veChvgOvAprHqPiN XbptEG1vM8rdhIdP6itvbnY0qEDCURRwP0CyDMhhteID6fHsBp0WHTD7qvDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715340320; x=1715426720; bh=YVb8TYgRuwHSnjN8vDiwIR1lMeaA FV+ygocaVFDh3C8=; b=j3Ca5mnZV8CjM9TRBwNDGX517r+YkJLX0wHXbmjk/fKd 7Hb2J1b0UC1/HS/HHvVE9rM+NOJAkNl3JnIxcAq+NhjFdCi4jwJgU8rEznxcbnu2 SIrbM18fpjOqGo3lTndISyDGVqjCkeZfQ9CJdMdMdm1kr0VOn3NZZiPoy+uo2jD9 nmbUy/NrL+SpTPBUNCcZ6VjBxRhG4SBdr0xhXcJaG0NUoaL22up22XT9KF3ENDTv jh7pIU+w06wbYsYOmTXSY6E04qEw678fCOZF5QliZTq0PsgZR0UFYde0X+gbVsx3 5Nn4pz13VyvnWJ7G9UijsNWcMKqLPr/M/JrVKBS7FQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedggedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 10 May 2024 07:25:19 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 888ecf8d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 10 May 2024 11:25:06 +0000 (UTC) Date: Fri, 10 May 2024 13:25:17 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 11/21] builtin/config: move type options into display options Message-ID: <96108976627fbb4b650156538441e2f3f5a8a490.1715339393.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The type options are tracked via a global variable. Move it into the display options instead. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 60 +++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 7089692c4b..1f864f71c4 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -81,13 +81,24 @@ struct config_location_options { }; #define CONFIG_LOCATION_OPTIONS_INIT {0} +#define CONFIG_TYPE_OPTIONS(type) \ + OPT_GROUP(N_("Type")), \ + OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), \ + OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), \ + OPT_CALLBACK_VALUE(0, "int", &type, N_("value is decimal number"), TYPE_INT), \ + OPT_CALLBACK_VALUE(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT), \ + OPT_CALLBACK_VALUE(0, "bool-or-str", &type, N_("value is --bool or string"), TYPE_BOOL_OR_STR), \ + OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), \ + OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE) + #define CONFIG_DISPLAY_OPTIONS(opts) \ OPT_GROUP(N_("Display options")), \ OPT_BOOL('z', "null", &opts.end_nul, N_("terminate values with NUL byte")), \ OPT_BOOL(0, "name-only", &opts.omit_values, N_("show variable names only")), \ OPT_BOOL(0, "show-origin", &opts.show_origin, N_("show origin of config (file, standard input, blob, command line)")), \ OPT_BOOL(0, "show-scope", &opts.show_scope, N_("show scope of config (worktree, local, global, system, command)")), \ - OPT_BOOL(0, "show-names", &opts.show_keys, N_("show config keys in addition to their values")) + OPT_BOOL(0, "show-names", &opts.show_keys, N_("show config keys in addition to their values")), \ + CONFIG_TYPE_OPTIONS(opts.type) struct config_display_options { int end_nul; @@ -95,6 +106,7 @@ struct config_display_options { int show_origin; int show_scope; int show_keys; + int type; /* Populated via `display_options_init()`. */ int term; int delim; @@ -113,8 +125,6 @@ static regex_t *regexp; static int use_key_regexp; static int do_all; static int do_not_match; - -static int type; static char *default_value; static int respect_includes_opt = -1; static int fixed_value; @@ -264,13 +274,13 @@ static int format_config(const struct config_display_options *opts, if (opts->show_keys) strbuf_addch(buf, opts->key_delim); - if (type == TYPE_INT) + if (opts->type == TYPE_INT) strbuf_addf(buf, "%"PRId64, git_config_int64(key_, value_ ? value_ : "", kvi)); - else if (type == TYPE_BOOL) + else if (opts->type == TYPE_BOOL) strbuf_addstr(buf, git_config_bool(key_, value_) ? "true" : "false"); - else if (type == TYPE_BOOL_OR_INT) { + else if (opts->type == TYPE_BOOL_OR_INT) { int is_bool, v; v = git_config_bool_or_int(key_, value_, kvi, &is_bool); @@ -278,24 +288,24 @@ static int format_config(const struct config_display_options *opts, strbuf_addstr(buf, v ? "true" : "false"); else strbuf_addf(buf, "%d", v); - } else if (type == TYPE_BOOL_OR_STR) { + } else if (opts->type == TYPE_BOOL_OR_STR) { int v = git_parse_maybe_bool(value_); if (v < 0) strbuf_addstr(buf, value_); else strbuf_addstr(buf, v ? "true" : "false"); - } else if (type == TYPE_PATH) { + } else if (opts->type == TYPE_PATH) { const char *v; if (git_config_pathname(&v, key_, value_) < 0) return -1; strbuf_addstr(buf, v); free((char *)v); - } else if (type == TYPE_EXPIRY_DATE) { + } else if (opts->type == TYPE_EXPIRY_DATE) { timestamp_t t; if (git_config_expiry_date(&t, key_, value_) < 0) return -1; strbuf_addf(buf, "%"PRItime, t); - } else if (type == TYPE_COLOR) { + } else if (opts->type == TYPE_COLOR) { char v[COLOR_MAXLEN]; if (git_config_color(v, key_, value_) < 0) return -1; @@ -443,7 +453,7 @@ static int get_value(const struct config_location_options *opts, } static char *normalize_value(const char *key, const char *value, - struct key_value_info *kvi) + int type, struct key_value_info *kvi) { if (!value) return NULL; @@ -787,16 +797,6 @@ static void display_options_init(struct config_display_options *opts) } } -#define CONFIG_TYPE_OPTIONS \ - OPT_GROUP(N_("Type")), \ - OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), \ - OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), \ - OPT_CALLBACK_VALUE(0, "int", &type, N_("value is decimal number"), TYPE_INT), \ - OPT_CALLBACK_VALUE(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT), \ - OPT_CALLBACK_VALUE(0, "bool-or-str", &type, N_("value is --bool or string"), TYPE_BOOL_OR_STR), \ - OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), \ - OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE) - static int cmd_config_list(int argc, const char **argv, const char *prefix) { struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; @@ -839,7 +839,6 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) int flags = 0; struct option opts[] = { CONFIG_LOCATION_OPTIONS(location_opts), - CONFIG_TYPE_OPTIONS, OPT_GROUP(N_("Filter options")), OPT_BOOL(0, "all", &do_all, N_("return all values for multi-valued config options")), OPT_BOOL(0, "regexp", &use_key_regexp, N_("interpret the name as a regular expression")), @@ -884,10 +883,10 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix) struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; const char *value_pattern = NULL, *comment_arg = NULL; char *comment = NULL; - int flags = 0, append = 0; + int flags = 0, append = 0, type = 0; struct option opts[] = { CONFIG_LOCATION_OPTIONS(location_opts), - CONFIG_TYPE_OPTIONS, + CONFIG_TYPE_OPTIONS(type), OPT_GROUP(N_("Filter")), OPT_BIT(0, "all", &flags, N_("replace multi-valued config option with new value"), CONFIG_FLAGS_MULTI_REPLACE), OPT_STRING(0, "value", &value_pattern, N_("pattern"), N_("show config with values matching the pattern")), @@ -917,7 +916,7 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix) location_options_init(&location_opts, prefix); check_write(&location_opts.source); - value = normalize_value(argv[0], argv[1], &default_kvi); + value = normalize_value(argv[0], argv[1], type, &default_kvi); if ((flags & CONFIG_FLAGS_MULTI_REPLACE) || value_pattern) { ret = git_config_set_multivar_in_file_gently(location_opts.source.file, @@ -1124,7 +1123,6 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) OPT_CMDMODE('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), OPT_CMDMODE(0, "get-color", &actions, N_("find the color configured: slot []"), ACTION_GET_COLOR), OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot []"), ACTION_GET_COLORBOOL), - CONFIG_TYPE_OPTIONS, CONFIG_DISPLAY_OPTIONS(display_opts), OPT_GROUP(N_("Other")), OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), @@ -1145,7 +1143,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) location_options_init(&location_opts, prefix); display_options_init(&display_opts); - if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && type) { + if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && display_opts.type) { error(_("--get-color and variable type are incoherent")); exit(129); } @@ -1242,7 +1240,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) else if (actions == ACTION_SET) { check_write(&location_opts.source); check_argc(argc, 2, 2); - value = normalize_value(argv[0], argv[1], &default_kvi); + value = normalize_value(argv[0], argv[1], display_opts.type, &default_kvi); ret = git_config_set_in_file_gently(location_opts.source.file, argv[0], comment, value); if (ret == CONFIG_NOTHING_SET) error(_("cannot overwrite multiple values with a single value\n" @@ -1251,7 +1249,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) else if (actions == ACTION_SET_ALL) { check_write(&location_opts.source); check_argc(argc, 2, 3); - value = normalize_value(argv[0], argv[1], &default_kvi); + value = normalize_value(argv[0], argv[1], display_opts.type, &default_kvi); ret = git_config_set_multivar_in_file_gently(location_opts.source.file, argv[0], value, argv[2], comment, flags); @@ -1259,7 +1257,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) else if (actions == ACTION_ADD) { check_write(&location_opts.source); check_argc(argc, 2, 2); - value = normalize_value(argv[0], argv[1], &default_kvi); + value = normalize_value(argv[0], argv[1], display_opts.type, &default_kvi); ret = git_config_set_multivar_in_file_gently(location_opts.source.file, argv[0], value, CONFIG_REGEX_NONE, @@ -1268,7 +1266,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) else if (actions == ACTION_REPLACE_ALL) { check_write(&location_opts.source); check_argc(argc, 2, 3); - value = normalize_value(argv[0], argv[1], &default_kvi); + value = normalize_value(argv[0], argv[1], display_opts.type, &default_kvi); ret = git_config_set_multivar_in_file_gently(location_opts.source.file, argv[0], value, argv[2], comment, flags | CONFIG_FLAGS_MULTI_REPLACE);