From patchwork Wed May 15 06:41:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664668 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 2F2F53D984 for ; Wed, 15 May 2024 06:41:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755305; cv=none; b=VdJmbOxbjK4CjhAE7lTF0lEn01d6ITq0BqfGz2o++o+mBdXcPJuhhI7JcfLz+YdKiYLHr1hxTK0MDEunV8gGJNMikMj1Nl8Gf+qflHLse7vxN5cYqLSH08OdbTJhPiqeABei0TB/QtvvzJB1H6aWPpz38rQ85FSax4u+pEGrkS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755305; c=relaxed/simple; bh=ms/S5F1877L3tjjlCdcIPBncgqsl6Wdzm5/5ZnHGcRk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XKleyYzxEdqgFlHN0/4ZKmuu/3l6pISbncNKuJFrjm5kw4zjEfdk4oxf3NxSmB6JPe7bKWq+KSWKf4Yvyrasn/qWlNJUQMtMfmTgUonbTW5Ro55wporFs9quOfsiFyjeQ7sw8+IjLKFxVl4VeS9H6W2MLCMev1VhGJbGGkFxPA4= 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=O3x+Qt7T; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KyLvV8Lc; arc=none smtp.client-ip=103.168.172.153 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="O3x+Qt7T"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KyLvV8Lc" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 30EC611400F9; Wed, 15 May 2024 02:41:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 15 May 2024 02:41:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755302; x=1715841702; bh=CQMH3+Gi8c DLedxydyECVd9qgxgP35vlAJ9Si3KeZJY=; b=O3x+Qt7T8c6dH3A3LNGQ1rw1D5 0R2gdfEAFVJBUlKbSTwsOHbR+H8bzd2yVcZBRfnhAGrHjnjUZgOQ83jz8eKGn/Jx XX+Y96Cj8tMpogSU04QRuK5YiTGsWwJphl+rFfuqiW+Shcu3kGVjLrx0VPjWim8y hQ10iMdN3jRiVgMic0KcHyxzd7rxwmRCpHXoxYhVNBeXcxX3Rz/g5bEcqblO3tjO tBbmCih8ZrkoDZPPrgDIyk5wxlkL0wQ/9Wqv/REg1yOTV6wj45Y+U6flJzQgvbjw ZYDlcqqozOQVlhg1blZ0mIG4ukL4z1wMqoYIoaHExQ05DVL2ErpqR+Vjx0iQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755302; x=1715841702; bh=CQMH3+Gi8cDLedxydyECVd9qgxgP 35vlAJ9Si3KeZJY=; b=KyLvV8Lc1n97ctXyewZM3hAjNg1aXJvgvgM1yt6Ae9yV 8hNVl6g8sSnic6Bv2RZe5+eq3HgRZllfuTqjRQlfM77L3Gks56ucjfrCs20snA21 P/dqVeI0zrf4lGXeeEx+TtGCSaj2YAv7fQfBC1ZVgbSAHGsNIeoiJsFtL/7N44sw yn8zEK1eTnP7c9CDum6IKQTq7TB7BG3hfDS5TDVt9TyCBiBmu7hQ+GNVAA6gJELh j2wVPlDd4Xl/9LgooR6lVnWTye0BO8sjLjX8CehWxPuolKxxY+v6SQ2VwE8oDX6w GtS2MVC2VlY4YE1TkcPpLddcBHIFJIT1MSHM6XYW7A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddthecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:41:40 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id e6ae0b37 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:41:18 +0000 (UTC) Date: Wed, 15 May 2024 08:41:38 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 01/21] builtin/config: stop printing full usage on misuse Message-ID: <32380a12fd8dff2b700d3076e5f5a5441d573405.1715755055.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: When invoking git-config(1) with a wrong set of arguments we end up calling `usage_builtin_config()` after printing an error message that says what was wrong. As that function ends up printing the full list of options, which is quite long, the actual error message will be buried by a wall of text. This makes it really hard to figure out what exactly caused the error. Furthermore, now that we have recently introduced subcommands, the usage information may actually be misleading as we unconditionally print options of the subcommand-less mode. Fix both of these issues by just not printing the options at all anymore. Instead, we call `usage()` that makes us report in a single line what has gone wrong. This should be way more discoverable for our users and addresses the inconsistency. Furthermore, this change allow us to inline the options into the respective functions that use them to parse the command line. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 28 +++++++++++----------------- t/t1300-config.sh | 3 ++- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 80aa9d8a66..3a71d3253f 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -125,8 +125,6 @@ static const char *comment_arg; { OPTION_CALLBACK, (s), (l), (v), NULL, (h), PARSE_OPT_NOARG | \ PARSE_OPT_NONEG, option_parse_type, (i) } -static NORETURN void usage_builtin_config(void); - static int option_parse_type(const struct option *opt, const char *arg, int unset) { @@ -171,7 +169,7 @@ static int option_parse_type(const struct option *opt, const char *arg, * --type=int'. */ error(_("only one type at a time")); - usage_builtin_config(); + exit(129); } *to_type = new_type; @@ -187,7 +185,7 @@ static void check_argc(int argc, int min, int max) else error(_("wrong number of arguments, should be from %d to %d"), min, max); - usage_builtin_config(); + exit(129); } static void show_config_origin(const struct key_value_info *kvi, @@ -672,7 +670,7 @@ static void handle_config_location(const char *prefix) use_worktree_config + !!given_config_source.file + !!given_config_source.blob > 1) { error(_("only one config file at a time")); - usage_builtin_config(); + exit(129); } if (!startup_info->have_repository) { @@ -802,11 +800,6 @@ static struct option builtin_config_options[] = { OPT_END(), }; -static NORETURN void usage_builtin_config(void) -{ - usage_with_options(builtin_config_usage, builtin_config_options); -} - static int cmd_config_list(int argc, const char **argv, const char *prefix) { struct option opts[] = { @@ -1110,7 +1103,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && type) { error(_("--get-color and variable type are incoherent")); - usage_builtin_config(); + exit(129); } if (actions == 0) @@ -1119,30 +1112,31 @@ int cmd_config(int argc, const char **argv, const char *prefix) case 2: actions = ACTION_SET; break; case 3: actions = ACTION_SET_ALL; break; default: - usage_builtin_config(); + error(_("no action specified")); + exit(129); } if (omit_values && !(actions == ACTION_LIST || actions == ACTION_GET_REGEXP)) { error(_("--name-only is only applicable to --list or --get-regexp")); - usage_builtin_config(); + exit(129); } if (show_origin && !(actions & (ACTION_GET|ACTION_GET_ALL|ACTION_GET_REGEXP|ACTION_LIST))) { error(_("--show-origin is only applicable to --get, --get-all, " "--get-regexp, and --list")); - usage_builtin_config(); + exit(129); } if (default_value && !(actions & ACTION_GET)) { error(_("--default is only applicable to --get")); - usage_builtin_config(); + exit(129); } if (comment_arg && !(actions & (ACTION_ADD|ACTION_SET|ACTION_SET_ALL|ACTION_REPLACE_ALL))) { error(_("--comment is only applicable to add/set/replace operations")); - usage_builtin_config(); + exit(129); } /* check usage of --fixed-value */ @@ -1175,7 +1169,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) if (!allowed_usage) { error(_("--fixed-value only applies with 'value-pattern'")); - usage_builtin_config(); + exit(129); } flags |= CONFIG_FLAGS_FIXED_VALUE; diff --git a/t/t1300-config.sh b/t/t1300-config.sh index f3c4d28e06..d90a69b29f 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -596,7 +596,8 @@ test_expect_success 'get bool variable with empty value' ' test_expect_success 'no arguments, but no crash' ' test_must_fail git config >output 2>&1 && - test_grep usage output + echo "error: no action specified" >expect && + test_cmp expect output ' cat > .git/config << EOF From patchwork Wed May 15 06:41:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664669 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 50D9E45944 for ; Wed, 15 May 2024 06:41:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755309; cv=none; b=NpPpRIqIkUmcEfheqMuK+TjA+bbCrLuv78P8mc3zwQykl1C3jiDnMKslneJzlVIckjSAb2TqKQ+nB/14a025sj500PWswYNVT1TJ4/qJi3YzXtDoTUD3+817vgfLuMhGFJwxTxceSRew7eY2XJcEmjxZzsZKCSjxxFWqIONdsQ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755309; c=relaxed/simple; bh=2Mj6+IGUpdoEpDnIWEcZKlHSzWEr3xVg9nuBLn5NdSw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HvJioRcX/HuqAdcGvmUeCwnvUMpFh6zEDNc6RQepp7F07mgibKHd3wtdKEZynWumYa1oMFpBt+ZKkBhP2+Yy4cTMqVKMAIM75/TqMCCv0IAuOrjwuwqbm0M1N0kK6MUvlf7RRdopyXgpgUNi6lEQkblhY4TQy+eJe9E8Ui0eoxU= 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=EJ7KwLXv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=S6E1PIsM; arc=none smtp.client-ip=103.168.172.153 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="EJ7KwLXv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="S6E1PIsM" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 815BF11400F9; Wed, 15 May 2024 02:41:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 15 May 2024 02:41:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755306; x=1715841706; bh=ojazCZhhmX wEUbSdyk+zK69H6RZAOlE0MPq6n6p9Cnk=; b=EJ7KwLXvvbECXt6Has28AlQCZ1 3l31COSIm+xl9NejKKePzuPh8ctX3hMlZwFTRMonkcriofncJLPDJ+7MCVrR1vy4 48PTYXWIlVGJP8rQrw1UWT0Myq8mT8FbQQXW2nt0bc45SSbZI064+OMvXQYA6E7n bLi/HCDQgBjKxfAO+1uGzZhRWA8pIOX7Z2XUrV8c5MCVRlNiViBqeeZNgN02hln8 q4/fwDd27LD8HBIchV5lyeROCgw/dBvWRmALiersUCwcWqfY6yNVbR2o1QiJ9L60 mt6QQckqmGnnlt8sBUfZXF6Wa8fRYdMAxnX8K54jOZg0Pgt04hNxgcS+fK3Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755306; x=1715841706; bh=ojazCZhhmXwEUbSdyk+zK69H6RZA OlE0MPq6n6p9Cnk=; b=S6E1PIsM+FTd8k1I+6NliLdhNs32Nu4XYELNce8oy7Ne J4q9eVeOZTSvgjGLYho4SBAIO3M0Hg/mwsVZWZyYtjPlNoR8s9t4rtIQX8Y4W7nE 53DV4Fs2ee9AzjZPS5cjsjG5cCTTOXgJV+cFbMWgbA0YqD0ZXQvkBlwylMHLVXVK t31TGAtjoLv4qbN+Ru1CMwkZNSCu5PFRJ2OFNOT7IBb+551G92617gpDLEn/KuSF +4nTSTYtBZpdGGQjmG54yl2GsJlpxveh3a6upTpDayju5G90bxqgYg2KNiZ6rVC0 8RX/eDofTIeFa4c34OwifMwPg/X+Zii6tF/H+y5d8g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddthecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:41:45 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id a6c814a9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:41:23 +0000 (UTC) Date: Wed, 15 May 2024 08:41:43 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 02/21] builtin/config: move legacy mode into its own function Message-ID: <8b07b280a9a8cdadbffb649d4cadc8750ed797ba.1715755055.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: In `cmd_config()` we first try to parse the provided arguments as subcommands and, if this is successful, call the respective functions of that subcommand. Otherwise we continue with the "legacy" mode that uses implicit actions and/or flags. Disentangle this by moving the legacy mode into its own function. This allows us to move the options into the respective functions and clearly separates concerns. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 3a71d3253f..f6c7e7a082 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -1069,31 +1069,13 @@ static struct option builtin_subcommand_options[] = { OPT_END(), }; -int cmd_config(int argc, const char **argv, const char *prefix) +static int cmd_config_actions(int argc, const char **argv, const char *prefix) { char *value = NULL, *comment = NULL; int flags = 0; int ret = 0; struct key_value_info default_kvi = KVI_INIT; - given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); - - /* - * This is somewhat hacky: we first parse the command line while - * keeping all args intact in order to determine whether a subcommand - * has been specified. If so, we re-parse it a second time, but this - * time we drop KEEP_ARGV0. This is so that we don't munge the command - * line in case no subcommand was given, which would otherwise confuse - * us when parsing the legacy-style modes that don't use subcommands. - */ - argc = parse_options(argc, argv, prefix, builtin_subcommand_options, builtin_config_usage, - PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_ARGV0|PARSE_OPT_KEEP_UNKNOWN_OPT); - if (subcommand) { - argc = parse_options(argc, argv, prefix, builtin_subcommand_options, builtin_config_usage, - PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_UNKNOWN_OPT); - return subcommand(argc, argv, prefix); - } - argc = parse_options(argc, argv, prefix, builtin_config_options, builtin_config_usage, PARSE_OPT_STOP_AT_NON_OPTION); @@ -1306,3 +1288,26 @@ int cmd_config(int argc, const char **argv, const char *prefix) free(value); return ret; } + +int cmd_config(int argc, const char **argv, const char *prefix) +{ + given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); + + /* + * This is somewhat hacky: we first parse the command line while + * keeping all args intact in order to determine whether a subcommand + * has been specified. If so, we re-parse it a second time, but this + * time we drop KEEP_ARGV0. This is so that we don't munge the command + * line in case no subcommand was given, which would otherwise confuse + * us when parsing the legacy-style modes that don't use subcommands. + */ + argc = parse_options(argc, argv, prefix, builtin_subcommand_options, builtin_config_usage, + PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_ARGV0|PARSE_OPT_KEEP_UNKNOWN_OPT); + if (subcommand) { + argc = parse_options(argc, argv, prefix, builtin_subcommand_options, builtin_config_usage, + PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_UNKNOWN_OPT); + return subcommand(argc, argv, prefix); + } + + return cmd_config_actions(argc, argv, prefix); +} From patchwork Wed May 15 06:41:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664670 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 E1B0F47F7E for ; Wed, 15 May 2024 06:41:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755314; cv=none; b=QzlDVQ2z6cquGgn851oIhTLM68R1KJ2fa1jiZwqCx37hDs2IS/fzzA/Cidb/yN2jcAiSRN6fe6XBi5jjvzDpYjxGqa5ntxm0QrQDFIoVMeWsWR4uv0Gz9ut91cSTuJc8jVXSBzIY6h28l3LEw/kmYjyVycMiOfaDB/6TMNEkm3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755314; c=relaxed/simple; bh=f7rCj2t19WxBdKNMwIhCalGlsYY6H5K3jpkbsViagjw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jh8jMkWww3D7A9mREbb5Cv3A10fgHqJuHYXMTzJsCNhBlfBg/GThsTOz5qq2XJ96nM9LjmyeWopvWwQfs0oD2Z0QDahsn6xAq6dJcEkQ4DyMdpjoSRCJV9hTEl/BVP4CUja0hRWVaA/NY7p/wb/jEfbKqcvh9lhz9qpDufswZq8= 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=A0kbECu+; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PgVYLi8S; arc=none smtp.client-ip=103.168.172.153 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="A0kbECu+"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PgVYLi8S" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E565F11400FA; Wed, 15 May 2024 02:41:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 15 May 2024 02:41:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755311; x=1715841711; bh=EM7SACTZAq bmfIQZG1DH95ZawkaVqX5XFksjOD2yaNc=; b=A0kbECu+tLqPjv9ivu0Z4I07MH 2wlbkj3nDI/PIDs0PE5gyPG65zmBp9PTi0aDgjKN0fSTag5cORLXRPXFKMh+ShUx 2ZNG9upuKDWErz3b/WkxwNtSU9VbTVQJVTm+sKKZPYU2nvGNB3+WC9aWcyKYirwf 8Kkz2gFa6FYIYCuyqJsMXHP/nnHsSlX6U7q/X5CCt2gv9SZ2LyqD219vm/+/zGux CxhxiBqo4PcnqiQAI+KW6MXE5g034mrDR/3uY3yaPg9KLRfXIdiGFBLkw1RntS/z 3E5pB40N+1/iC9xBXrKFZm+3WrObomuQ0tiFqsmVrZGWTzOyUocvstmsXfUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755311; x=1715841711; bh=EM7SACTZAqbmfIQZG1DH95ZawkaV qX5XFksjOD2yaNc=; b=PgVYLi8S/iEaxLVK4RMjPNpSzPRzmXlqB88lcQrts11X uEB/idqLRUc5qJBum0iMfd9Txm17PZh/4G2Z8zCIa8PCUedGT/qe1/peFa2A/5je puKSkN4nwKkKc9hNTuUk57fz59J+4IesKQ+cVQYvQQPzNbLhT4wKTlrXSP7iYPd3 YJ1faYU8Veyft3spETrcnUqyCS9QwuiG3Xa4DoL13LqjtomHxCiWQIuE1JtebdcT AYpWr22BWXklQe/sU7Q8mgekxvhtL9H53xNNrW6xGgRgQq7PPiBTXD6PZwIubyR2 /wWQZj3Intyvd0ZrfmP9CgFNgilUG1JzHFRqcg8B/w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddthecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:41:50 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id e95f6e7a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:41:27 +0000 (UTC) Date: Wed, 15 May 2024 08:41:47 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 03/21] builtin/config: move subcommand options into `cmd_config()` Message-ID: 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: Move the subcommand options as well as the `subcommand` variable into `cmd_config()`. This reduces our reliance on global state. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index f6c7e7a082..58c8b0abda 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -75,7 +75,6 @@ static char delim = '='; static char key_delim = ' '; static char term = '\n'; -static parse_opt_subcommand_fn *subcommand; static int use_global_config, use_system_config, use_local_config; static int use_worktree_config; static struct git_config_source given_config_source; @@ -1058,17 +1057,6 @@ static int cmd_config_edit(int argc, const char **argv, const char *prefix) return show_editor(); } -static struct option builtin_subcommand_options[] = { - OPT_SUBCOMMAND("list", &subcommand, cmd_config_list), - OPT_SUBCOMMAND("get", &subcommand, cmd_config_get), - OPT_SUBCOMMAND("set", &subcommand, cmd_config_set), - OPT_SUBCOMMAND("unset", &subcommand, cmd_config_unset), - OPT_SUBCOMMAND("rename-section", &subcommand, cmd_config_rename_section), - OPT_SUBCOMMAND("remove-section", &subcommand, cmd_config_remove_section), - OPT_SUBCOMMAND("edit", &subcommand, cmd_config_edit), - OPT_END(), -}; - static int cmd_config_actions(int argc, const char **argv, const char *prefix) { char *value = NULL, *comment = NULL; @@ -1291,6 +1279,18 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) int cmd_config(int argc, const char **argv, const char *prefix) { + parse_opt_subcommand_fn *subcommand = NULL; + struct option subcommand_opts[] = { + OPT_SUBCOMMAND("list", &subcommand, cmd_config_list), + OPT_SUBCOMMAND("get", &subcommand, cmd_config_get), + OPT_SUBCOMMAND("set", &subcommand, cmd_config_set), + OPT_SUBCOMMAND("unset", &subcommand, cmd_config_unset), + OPT_SUBCOMMAND("rename-section", &subcommand, cmd_config_rename_section), + OPT_SUBCOMMAND("remove-section", &subcommand, cmd_config_remove_section), + OPT_SUBCOMMAND("edit", &subcommand, cmd_config_edit), + OPT_END(), + }; + given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); /* @@ -1301,10 +1301,10 @@ int cmd_config(int argc, const char **argv, const char *prefix) * line in case no subcommand was given, which would otherwise confuse * us when parsing the legacy-style modes that don't use subcommands. */ - argc = parse_options(argc, argv, prefix, builtin_subcommand_options, builtin_config_usage, + argc = parse_options(argc, argv, prefix, subcommand_opts, builtin_config_usage, PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_ARGV0|PARSE_OPT_KEEP_UNKNOWN_OPT); if (subcommand) { - argc = parse_options(argc, argv, prefix, builtin_subcommand_options, builtin_config_usage, + argc = parse_options(argc, argv, prefix, subcommand_opts, builtin_config_usage, PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_UNKNOWN_OPT); return subcommand(argc, argv, prefix); } From patchwork Wed May 15 06:41:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664671 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 2453C3FB1B for ; Wed, 15 May 2024 06:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755321; cv=none; b=fURu6rQ0QdKNZ+210I+B6Qle/cjMSG1WsdnFH83kTvF9tczXVfaL4Sg9eTdoloE1ZR2vboh3KazuAlxUg4ZNmOyutr9ZlKzwjeGwfV6QUdCjoenrtJARGS4HmTl9jA0VdwjoDRt/wUCV/hc6qhCT2+Ic7eVJyK1mZgBcbSymOZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755321; c=relaxed/simple; bh=jZww6FId8GQ465XEtTU+7VsAquOCDjfv63exdB5Kzm0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bVqsgg7+37cxR+tC/hy7yEODCIThJjAeV0BGIqGpH14O93cNszw0bbXDwVmMQpGQc/h8hC/pAiaDkMC1WN6gLMsoCASDUYiK89I66hDT/MZfj6SV9/nVuuAgVtvMJ+w6JDC3ohMnMGjRFqshj8kd3bBBPFlEKZ+R+y1S+JtYIIc= 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=klevbPJ0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SxoAXMeB; arc=none smtp.client-ip=103.168.172.153 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="klevbPJ0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SxoAXMeB" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3A33911400AC; Wed, 15 May 2024 02:41:56 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 15 May 2024 02:41:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755316; x=1715841716; bh=mXMhkp7/cW CX+Uty4nYse7Aha7E68Sy9RYPAAAnwBIE=; b=klevbPJ0ZxUPavKyeq421AHUyp u0LymzeqOwwRAAKOrjhfSCOEukJRdWGJvgD0SKMkGkU6e9XD64cv+1jOVZUJyZL9 ELbreC6godA0GNk+n1eVX3kWkrHWIwYz9lz/+H7Gml8AmUjiFedamqfR8Z1E8izU 4JYFEy+niI7r3HJsKqTlV/vTcRlsuIXQmcBp5xDrhcATjOedACQzTocotEG8vH4D B7EEYXxQsz3JL9/Zm+bYJ7JxPSec5XqfgL/JpU663K+HwEYWa342rjz3XP3bS8SG luVrJDY4CJ5nyUYXCFO4lp8M2UzATG7C80iTvr3sewuUi7QfC3HBg+J1s6Ug== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755316; x=1715841716; bh=mXMhkp7/cWCX+Uty4nYse7Aha7E6 8Sy9RYPAAAnwBIE=; b=SxoAXMeB44rYv/Rs0npIdFTRWkUECNQYNmCJRllhVFER FmMmP80wEVI/HysjUX3vnlw+KEX3exlCe5uJDTIgNL+NSoVpfmq+0PsNR0Xe1t+7 SOMJb7antHnY6Yi7T6U1hNMwYh3a4GmeKkXak61XNo9QtyINKlRFcYmGuJs1sYcK 6edigL7KVyZUNUfeBfSMTpc3VipaJ7Yo2oasxR7AUw+zEzSQAn5luelSNyQKSG3U GnI+OVL5ZqIxnJHebdA9vKw0Lfp1+M7Aust3IZVN3nh9kdBkhdgVvQwb+CHgklKb otl9F179cuM5tkLw90IVCepu/fQ6y4uyy7tGu0IQQw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddthecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:41:55 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 7fcb97fe (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:41:32 +0000 (UTC) Date: Wed, 15 May 2024 08:41:52 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 04/21] builtin/config: move legacy options into `cmd_config()` Message-ID: <1a0c6a83844bf455e57db3435793ef6ccbe6a7b0.1715755055.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: Move the legacy options as well some of the variables it references into `cmd_config_action()`. This reduces our reliance on global state. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 60 ++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 58c8b0abda..e9956574fe 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -78,7 +78,7 @@ static char term = '\n'; static int use_global_config, use_system_config, use_local_config; static int use_worktree_config; static struct git_config_source given_config_source; -static int actions, type; +static int type; static char *default_value; static int end_nul; static int respect_includes_opt = -1; @@ -86,7 +86,6 @@ static struct config_options config_options; static int show_origin; static int show_scope; static int fixed_value; -static const char *comment_arg; #define ACTION_GET (1<<0) #define ACTION_GET_ALL (1<<1) @@ -772,33 +771,6 @@ static void handle_nul(void) { OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), \ OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")) -static struct option builtin_config_options[] = { - CONFIG_LOCATION_OPTIONS, - OPT_GROUP(N_("Action")), - OPT_CMDMODE(0, "get", &actions, N_("get value: name []"), ACTION_GET), - OPT_CMDMODE(0, "get-all", &actions, N_("get all values: key []"), ACTION_GET_ALL), - OPT_CMDMODE(0, "get-regexp", &actions, N_("get values for regexp: name-regex []"), ACTION_GET_REGEXP), - OPT_CMDMODE(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), - OPT_CMDMODE(0, "replace-all", &actions, N_("replace all matching variables: name value []"), ACTION_REPLACE_ALL), - OPT_CMDMODE(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), - OPT_CMDMODE(0, "unset", &actions, N_("remove a variable: name []"), ACTION_UNSET), - OPT_CMDMODE(0, "unset-all", &actions, N_("remove all matches: name []"), ACTION_UNSET_ALL), - OPT_CMDMODE(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), - OPT_CMDMODE(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), - OPT_CMDMODE('l', "list", &actions, N_("list all"), ACTION_LIST), - 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, - OPT_GROUP(N_("Other")), - OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), - OPT_STRING(0, "comment", &comment_arg, N_("value"), N_("human-readable comment string (# will be prepended as needed)")), - OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), - OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), - OPT_END(), -}; - static int cmd_config_list(int argc, const char **argv, const char *prefix) { struct option opts[] = { @@ -1059,12 +1031,40 @@ static int cmd_config_edit(int argc, const char **argv, const char *prefix) static int cmd_config_actions(int argc, const char **argv, const char *prefix) { + const char *comment_arg = NULL; + int actions = 0; + struct option opts[] = { + CONFIG_LOCATION_OPTIONS, + OPT_GROUP(N_("Action")), + OPT_CMDMODE(0, "get", &actions, N_("get value: name []"), ACTION_GET), + OPT_CMDMODE(0, "get-all", &actions, N_("get all values: key []"), ACTION_GET_ALL), + OPT_CMDMODE(0, "get-regexp", &actions, N_("get values for regexp: name-regex []"), ACTION_GET_REGEXP), + OPT_CMDMODE(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), + OPT_CMDMODE(0, "replace-all", &actions, N_("replace all matching variables: name value []"), ACTION_REPLACE_ALL), + OPT_CMDMODE(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), + OPT_CMDMODE(0, "unset", &actions, N_("remove a variable: name []"), ACTION_UNSET), + OPT_CMDMODE(0, "unset-all", &actions, N_("remove all matches: name []"), ACTION_UNSET_ALL), + OPT_CMDMODE(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), + OPT_CMDMODE(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), + OPT_CMDMODE('l', "list", &actions, N_("list all"), ACTION_LIST), + 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, + OPT_GROUP(N_("Other")), + OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), + OPT_STRING(0, "comment", &comment_arg, N_("value"), N_("human-readable comment string (# will be prepended as needed)")), + OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), + OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), + OPT_END(), + }; char *value = NULL, *comment = NULL; int flags = 0; int ret = 0; struct key_value_info default_kvi = KVI_INIT; - argc = parse_options(argc, argv, prefix, builtin_config_options, + argc = parse_options(argc, argv, prefix, opts, builtin_config_usage, PARSE_OPT_STOP_AT_NON_OPTION); From patchwork Wed May 15 06:41:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664672 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 61D5B4594C for ; Wed, 15 May 2024 06:42:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755322; cv=none; b=taReVsy2IwZONFpC9hvWT2KTLho8JqwCvzjXLSTs53m1zIb2A+9Vv3DMaaU0Hysqnuu5+xzf4LjfdUqPPK7v2aBYKs4TJaao/WQyTwJzgzGQyT0N/I6XpeHbfB+QNM/FPGUCY0f6cTa5/AxaBdVBJQBRXArb+P74Q0Y6ZeXsi9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755322; c=relaxed/simple; bh=AwBQFwTze18dMZf3Bb23nJ67cWsfdyS7RyQ/vSt6pvQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ByQhRa8RCj3NJrU0Dqa4E/9EdBzCuM0A0lUPEUCdQWNPNE12t4OBz8cseNpUDcLXQg2/3qkJH9rioRojK3iDpXz73MEmv9NM+EtB/WChTj7Cn/yKTDp0Mjchn9yS1yn2ckOfwfLgZS3htSITSPmSzqRDdENvz2v2ikU0eiIoTag= 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=V+f0MdS9; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=IR7p8fTs; arc=none smtp.client-ip=103.168.172.153 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="V+f0MdS9"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="IR7p8fTs" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 9590F11400C7; Wed, 15 May 2024 02:42:00 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 15 May 2024 02:42:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755320; x=1715841720; bh=4xvDSRvaJh POcz+fFTPEbmjluNnhey3h8a3fyH4gGcI=; b=V+f0MdS9tW7GX9ypmoRjY+DGfg Y9nbGmrBvCUVt0C2+RmlJ8hJFX4C8LHaAMiqq0YhaxORyVAI6n3D6pQ0Efx9a/Mu 87hZLcTco60BKJCr+lqgZchX+zB6y8idNRY/edUCQhZaA9pFB1ToF5Vot9TmFHMh sH17k4SOd9BlJdnatLuU3fa5vvM1UAYLQcUtlEzcO1qSqZxgD3oKfO+A97rEO+xM oEEcneiXM9RpBPz4NCw+oh0qTOYmUTUFMHs5Dt7Lk1dnDA9doZ6ZC/VFbaL4CAYM EkVAFnfAMipl4xb+UN4E5Q3GWR2DLdjeI1Y7xxk4SEmQ+F4v05syKYhQeGKw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755320; x=1715841720; bh=4xvDSRvaJhPOcz+fFTPEbmjluNnh ey3h8a3fyH4gGcI=; b=IR7p8fTsRC3VGaLjbRW7QOI/jbPG+WzYxNmIaEWP5IBF 2Pnao2sGtog2+RmsetZVqmRBq9lFV5cG+QCRMaByLQH1Bk1CT6RFdyz/goFM+GMo MTc1CgHp/QZFM7bsYHkUnOoaenVSLfx360f6Joy4UqDtn8khrWLjttaEWzNzQRht +vEeUXhVfxjZ7fLy4153M3pSjFsT6r8xD4e+XOacg5myrzZYoCJBzH4yO/e8Kd5p 4AJJ5B4sazeFrhCOUMGrikk9nGwRoDtJ3EKPvkz5WDfKRbnV30+RK7Hgw5CXiGUJ 0T+ENh9MATkOyQ3XCPO1RkceVVW6GN5t4CIn3ZqG1g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:41:59 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id aa5de69f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:41:37 +0000 (UTC) Date: Wed, 15 May 2024 08:41:57 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 05/21] builtin/config: move actions into `cmd_config_actions()` Message-ID: <4950ddcecd30257469acc27dd6f5fb4ea7b3a050.1715755055.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: We only use actions in the legacy mode. Convert them to an enum and move them into `cmd_config_actions()` to clearly demonstrate that they are not used anywhere else. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index e9956574fe..0842e4f198 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -87,30 +87,6 @@ static int show_origin; static int show_scope; static int fixed_value; -#define ACTION_GET (1<<0) -#define ACTION_GET_ALL (1<<1) -#define ACTION_GET_REGEXP (1<<2) -#define ACTION_REPLACE_ALL (1<<3) -#define ACTION_ADD (1<<4) -#define ACTION_UNSET (1<<5) -#define ACTION_UNSET_ALL (1<<6) -#define ACTION_RENAME_SECTION (1<<7) -#define ACTION_REMOVE_SECTION (1<<8) -#define ACTION_LIST (1<<9) -#define ACTION_EDIT (1<<10) -#define ACTION_SET (1<<11) -#define ACTION_SET_ALL (1<<12) -#define ACTION_GET_COLOR (1<<13) -#define ACTION_GET_COLORBOOL (1<<14) -#define ACTION_GET_URLMATCH (1<<15) - -/* - * The actions "ACTION_LIST | ACTION_GET_*" which may produce more than - * one line of output and which should therefore be paged. - */ -#define PAGING_ACTIONS (ACTION_LIST | ACTION_GET_ALL | \ - ACTION_GET_REGEXP | ACTION_GET_URLMATCH) - #define TYPE_BOOL 1 #define TYPE_INT 2 #define TYPE_BOOL_OR_INT 3 @@ -1031,6 +1007,24 @@ static int cmd_config_edit(int argc, const char **argv, const char *prefix) static int cmd_config_actions(int argc, const char **argv, const char *prefix) { + enum { + ACTION_GET = (1<<0), + ACTION_GET_ALL = (1<<1), + ACTION_GET_REGEXP = (1<<2), + ACTION_REPLACE_ALL = (1<<3), + ACTION_ADD = (1<<4), + ACTION_UNSET = (1<<5), + ACTION_UNSET_ALL = (1<<6), + ACTION_RENAME_SECTION = (1<<7), + ACTION_REMOVE_SECTION = (1<<8), + ACTION_LIST = (1<<9), + ACTION_EDIT = (1<<10), + ACTION_SET = (1<<11), + ACTION_SET_ALL = (1<<12), + ACTION_GET_COLOR = (1<<13), + ACTION_GET_COLORBOOL = (1<<14), + ACTION_GET_URLMATCH = (1<<15), + }; const char *comment_arg = NULL; int actions = 0; struct option opts[] = { @@ -1147,7 +1141,11 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) comment = git_config_prepare_comment_string(comment_arg); - if (actions & PAGING_ACTIONS) + /* + * The following actions may produce more than one line of output and + * should therefore be paged. + */ + if (actions & (ACTION_LIST | ACTION_GET_ALL | ACTION_GET_REGEXP | ACTION_GET_URLMATCH)) setup_auto_pager("config", 1); if (actions == ACTION_LIST) { From patchwork Wed May 15 06:42:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664673 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 B382F4EB3D for ; Wed, 15 May 2024 06:42:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755328; cv=none; b=UMf2RSyrOIhl1cJVsFRe+AuPoOURpVrh7H5enOaJ5UBT34tsnFz6qFpQ/0fy6KsFUBBq184W6txbyUtkWX2LrJ5UKkvKWEWjXBBjlFA6F9zqJFdszeiml9pb7bbZpZXwgOMmdfHS/koJTPJZCIeSjovPFqdb1v2Jujjx4RvEMLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755328; c=relaxed/simple; bh=2Bb7TeC+CyOYgZtWaTAzAPKd+J/5nvxW/dDaMVfynBk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QEf5lHaiTnIYWZdgJvWxMWu58yXMlgalPUViStR8fj8vx7M3XZllUJte9Q7t1hNI/pFSIxxRU7V9f3EnEjksPIw7Ki3jm3+LimDDWuJCPAJWDOAtx1Mu3C5LOxG9eT9QcQupwkyFm5703k7RcRTE/3C9+Hhh3NvUcxFSgZWeKwo= 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=ZtUAnOEP; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Cl3RV9u4; arc=none smtp.client-ip=103.168.172.147 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="ZtUAnOEP"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Cl3RV9u4" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id EA5381380234; Wed, 15 May 2024 02:42:05 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 15 May 2024 02:42:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755325; x=1715841725; bh=IsPuoGndHK yCnyq6Ct9ljc5nih4W5SjF6+PDt6awMSE=; b=ZtUAnOEPb83YLwo80vp8z8KLJG Jh6ukVpv7APTntGHqnwNAc1kAgcXvlrB0P4sW7G0qJipxvaiV1NpUY8x51M8y8Ad kw0YkVIWz8J+WTtlFP7AZy37V91Uxam+itFtVOmYG6p+Wd9mpC7PcKIURDXzL3qc z6dnjyfPJ9lKR6Du61HQaSIPywAr1WThOchg5PZV4Jp3r9V5OvEm08jvVJ9W4CDZ ev1A7ODoADbA/opbwaR38Yb990HAAscaB5D5HzJBznQ8FblcygeFk9pzdGQwm9UB ru/Dh5Zxvudvl9hIYBHcq5JcEQ3uGZICobxzGcO7KPj2PVGfOvKYEMmi0yjA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755325; x=1715841725; bh=IsPuoGndHKyCnyq6Ct9ljc5nih4W 5SjF6+PDt6awMSE=; b=Cl3RV9u47328jc/Q7P0Jzj2x36pgTNQs/ti22zhVT7cX AjsoLoTMbTKkDFO5erPHMIzc797Gj8ZcJrIvrtSAcgSFQnelFeyxrWbfEqBmlhhH KFSUtEd8KC/3pLOvUKRCaKCdXqTA8jdzeBU3lpO5s/tZTgjz+Ky2EO7zXHdp8q05 l9F8vb1+vpukQPHYsluvLqm6hLxzIadAmcTqrOXHIVbkAeYo2MOZfs1YXHvk3RXY CYd0f1pLsVpc6lRuyHIf2G6rFG2FxPq0VxYqeKx5D4EfKTslDRfoKk8PxKv4kjsL 54pcQUrIPCFu79qxnqYUD3W1qestEkTM02/dwlVCpw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddthecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:42:04 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 7830cecd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:41:42 +0000 (UTC) Date: Wed, 15 May 2024 08:42:02 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 06/21] builtin/config: check for writeability after source is set up Message-ID: <6de9097fb2c339be72aab3810abbccbfc39bd480.1715755055.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 `check_write()` function verifies that we do not try to write to a config source that cannot be written to, like for example stdin. But while the new subcommands do call this function, they do so before calling `handle_config_location()`. Consequently, we only end up checking the default config location for writeability, not the location that was actually specified by the caller of git-config(1). Fix this by calling `check_write()` after `handle_config_location()`. We will further clarify the relationship between those two functions in a subsequent commit where we remove the global state that both implicitly rely on. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 10 +++++----- t/t1300-config.sh | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 0842e4f198..9866d1a055 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -843,7 +843,6 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, opts, builtin_config_set_usage, PARSE_OPT_STOP_AT_NON_OPTION); - check_write(); check_argc(argc, 2, 2); if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern) @@ -856,6 +855,7 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix) comment = git_config_prepare_comment_string(comment_arg); handle_config_location(prefix); + check_write(); value = normalize_value(argv[0], argv[1], &default_kvi); @@ -891,13 +891,13 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, opts, builtin_config_unset_usage, PARSE_OPT_STOP_AT_NON_OPTION); - check_write(); check_argc(argc, 1, 1); if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern) die(_("--fixed-value only applies with 'value-pattern'")); handle_config_location(prefix); + check_write(); if ((flags & CONFIG_FLAGS_MULTI_REPLACE) || value_pattern) return git_config_set_multivar_in_file_gently(given_config_source.file, @@ -918,10 +918,10 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr argc = parse_options(argc, argv, prefix, opts, builtin_config_rename_section_usage, PARSE_OPT_STOP_AT_NON_OPTION); - check_write(); check_argc(argc, 2, 2); handle_config_location(prefix); + check_write(); ret = git_config_rename_section_in_file(given_config_source.file, argv[0], argv[1]); @@ -943,10 +943,10 @@ static int cmd_config_remove_section(int argc, const char **argv, const char *pr argc = parse_options(argc, argv, prefix, opts, builtin_config_remove_section_usage, PARSE_OPT_STOP_AT_NON_OPTION); - check_write(); check_argc(argc, 1, 1); handle_config_location(prefix); + check_write(); ret = git_config_rename_section_in_file(given_config_source.file, argv[0], NULL); @@ -997,10 +997,10 @@ static int cmd_config_edit(int argc, const char **argv, const char *prefix) }; argc = parse_options(argc, argv, prefix, opts, builtin_config_edit_usage, 0); - check_write(); check_argc(argc, 0, 0); handle_config_location(prefix); + check_write(); return show_editor(); } diff --git a/t/t1300-config.sh b/t/t1300-config.sh index d90a69b29f..9de2d95f06 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -2835,6 +2835,12 @@ test_expect_success 'specifying multiple modes causes failure' ' test_cmp expect err ' +test_expect_success 'writing to stdin is rejected' ' + echo "fatal: writing to stdin is not supported" >expect && + test_must_fail git config ${mode_set} --file - foo.bar baz 2>err && + test_cmp expect err +' + done test_done From patchwork Wed May 15 06:42:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664674 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 5A79B4F1EE for ; Wed, 15 May 2024 06:42:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755332; cv=none; b=VAdK9rggKw0wyRAswaH3CXsVpLEGcWmVs6xB+4J877wFu6eE+PpxfRAAw2oZFF8CcLu6rUJnxJDube+NB/ElNI+BmOMKZZ0wL4ZcHbnCpsO7bsm3jc8ldmYmuPilU31vK3UbcfrTyNtTvzDycewka1IiTBOgyoiiJYIZ7idvDGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755332; c=relaxed/simple; bh=aLFVda5epiDPugnLxRhwOLAMrKY3C3ofWWcdnCZiPHM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Hvlgvq903l+MqIT7tK87/DhEz4wnE0mLZ+u0KBlVUgpCR664W5+aFZZyLAlbvYxsKieJmQzoimCKpSQnkpKykmxU+W5pq6iwkTN22Cx9DVm45EqVRtYXdrjqeMiJKqwFY+dVaYjCci3IYzAulkZlL3VWNTUY9P5YH6xQScR/GuA= 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=WYmdK8+8; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kLok6yKq; arc=none smtp.client-ip=103.168.172.147 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="WYmdK8+8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kLok6yKq" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 5EE4A1380251; Wed, 15 May 2024 02:42:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Wed, 15 May 2024 02:42:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755330; x=1715841730; bh=sprCNmcXek 5scsGPEJcEbQwV9k8FEO9WpLAKn2OM4MM=; b=WYmdK8+8/Gq00YndCFN/7785KL 73RlIMbKN5tf9hdq+a4D/WLqxzqYC8+MoHjHmQt769WsdwwZ+9DBh9oqQZEjuApk yziMJEtSeNQI1lsRJ2qQRq4wpRWHsgKJTi9omf3aHVF0hvCODGMjpWZ8iKoqm4m9 8gfHNExrVSWR/+fAQ08P9drbrorLtmmqOIGCKZzwgdtKDy973EpnObSBfzQATY2W pf8rVeVy90u7R1kOTfZXtAzo4CszIlqTdmzxt2Kj/EHPbodCtgKuoW1RRvAPwKrG Alqj5r0/HYqeJNAMReLvT9O7fWKYOmV8DUG+ZqWK5dloQoHn6cyt/HIlTlUQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755330; x=1715841730; bh=sprCNmcXek5scsGPEJcEbQwV9k8F EO9WpLAKn2OM4MM=; b=kLok6yKqN6cFV89WilYYZhXHs3SoYSwsoOs91NvPSIIG NhmTV29UG1jUfXMoFFPVDJFDagln9nQy+vA+nwekS5fr3wCbSX/yAnFSSTCWJubQ VW7YD0T6Fdnili0UYW1E/UxAMmVlpSBonKql5oleWiTIbDtG03gncJ26avEOLO8j DRsgOjN/nivFFby91vRCfinGaAJmms5N1V1eBJPp04mONzgirK8dWnj3piyMNZP5 d74jutMh++EYOJIrOr/rbRhmdXhDDf2G1VZD9twhCYIUFmpRd16rwEWjuPtcvNKL RA2JHoBHah0RwzA7kfnko7HE/k8u4KYfgwep05iGUA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:42:09 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 2fc334a7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:41:46 +0000 (UTC) Date: Wed, 15 May 2024 08:42:06 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 07/21] config: make the config source const Message-ID: <24053f8f4fcd89406cefa5fd289097b9cea29405.1715755055.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 `struct git_config_source` passed to `config_with_options()` is never modified. Let's mark it as `const` to clarify. Signed-off-by: Patrick Steinhardt --- config.c | 4 ++-- config.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config.c b/config.c index a871c7729e..ca6dac6e23 100644 --- a/config.c +++ b/config.c @@ -125,7 +125,7 @@ struct config_include_data { config_fn_t fn; void *data; const struct config_options *opts; - struct git_config_source *config_source; + const struct git_config_source *config_source; struct repository *repo; /* @@ -2116,7 +2116,7 @@ static int do_git_config_sequence(const struct config_options *opts, } int config_with_options(config_fn_t fn, void *data, - struct git_config_source *config_source, + const struct git_config_source *config_source, struct repository *repo, const struct config_options *opts) { diff --git a/config.h b/config.h index db8b608064..e66c84520b 100644 --- a/config.h +++ b/config.h @@ -232,7 +232,7 @@ void git_config(config_fn_t fn, void *); * sets `opts.respect_includes` to `1` by default. */ int config_with_options(config_fn_t fn, void *, - struct git_config_source *config_source, + const struct git_config_source *config_source, struct repository *repo, const struct config_options *opts); From patchwork Wed May 15 06:42:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664675 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 8F88550283 for ; Wed, 15 May 2024 06:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755338; cv=none; b=JxIVFi4wHFu2acAWhElbuZVx2S9UCGnLqXR+I9IsN05lKoGprHXimGnxblD/R9yQqAQy0CPf1Sr7Q8tOMAryboMee1kSg32RCR5v2VnErHV9nkZaYyZVxxraXZCecCkoxmKVm35sI9cMHBHvcUoCY9sBpHqKwnMbzSWRgQ8OD3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755338; c=relaxed/simple; bh=+isIhaK1+bwKBmO+0QMz0zHOwfnUaX4B534J5d1V8bM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=V8eZrxkakyhDGN65AZWO778a6vcZBrOuzMqmBPi2nCWg1WJpaFzhB4VyTYZZlc4bErJbXmU0KsdbfzxEpBfrexLgQFdgokg45HHG8cl92mO8J7pId0u2WDsYQzRfpiGuYYk7wQ3tAg3sB2I2FpSm6Lrg594BSc+u3aSUh13mlpA= 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=AYb8hK8u; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=JRA17mIl; arc=none smtp.client-ip=103.168.172.147 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="AYb8hK8u"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JRA17mIl" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id AFBA51380222; Wed, 15 May 2024 02:42:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 15 May 2024 02:42:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755335; x=1715841735; bh=mKRjbtgyhN xLkxWyQ6BSMq36p5F1wZlKh8HuFDXaOlU=; b=AYb8hK8u1C7h+lbGbqjbLM5utB 20YPNj2H1ONDZoaQNxWIImXNjWG53S9BNBlMH5Uu0WvDD4jivVFT5M5rKAsyvQao dGZ1H0BSMqLOSKmg3oVW4gCR4XB/WDkeCoFMGmMcd1xz6RMiOZzRFIrTNclIOJ4S yHSDHYRBbQWypUZtRU+mJmpkznwiGnzb2rV7kMqIcdXqbYSuhjy4naKR426RN5t/ mbek1K+m5i2evULgHdyA2xZrkxiS/BdpNajDtrqBZZA2PfazUufka3s/NUXAio3p yuEsHF5eutY8agy4/4hwp8utn5KMT7k00uZoRfE37GaLwjt95CbrkDGXJ3kg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755335; x=1715841735; bh=mKRjbtgyhNxLkxWyQ6BSMq36p5F1 wZlKh8HuFDXaOlU=; b=JRA17mIlabxebZQWo2E0t7SHcr7mefC2nXr572CRbhj9 0B9LBIW/6HNtuIUiLdEQWcNdW9atI/zmob5WLOS0hJe1OTPbTCADVs/beyOzYcri wBRJSmCdtXY02TgRRVB1uSmn7FFdj83ajzI/01pyJ1XzcNclzhGhle+xafVk8Syi G28Tv9EUc2ghfn9Qj8sZtUswKclXT7S9HivrgHmCXJ33mHmDF+/JOaXDr3Ea6MD0 oWUskFdBEUWpqTcEGDg34i/dH+Y/BRDyxqtzhVtfPVuOqNtvOwY0ymItFumKdGup sfMHKemkbqJBArH+vk8Tk5/cEa+zvrvkgNUuCjHaQA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:42:14 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id e963f88e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:41:51 +0000 (UTC) Date: Wed, 15 May 2024 08:42:11 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 08/21] builtin/config: refactor functions to have common exit paths Message-ID: <9dc1d00f715a6ded4d87ec3ffbd2a4546d6a59ac.1715755055.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: Refactor functions to have a single exit path. This will make it easier in subsequent commits to add common cleanup code. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 64 ++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 9866d1a055..155564b832 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -798,6 +798,7 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) OPT_STRING(0, "default", &default_value, N_("value"), N_("use default value when missing entry")), OPT_END(), }; + int ret; argc = parse_options(argc, argv, prefix, opts, builtin_config_get_usage, PARSE_OPT_STOP_AT_NON_OPTION); @@ -816,8 +817,11 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) setup_auto_pager("config", 1); if (url) - return get_urlmatch(argv[0], url); - return get_value(argv[0], value_pattern, flags); + ret = get_urlmatch(argv[0], url); + else + ret = get_value(argv[0], value_pattern, flags); + + return ret; } static int cmd_config_set(int argc, const char **argv, const char *prefix) @@ -888,6 +892,7 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix) OPT_BIT(0, "fixed-value", &flags, N_("use string equality when comparing values to value pattern"), CONFIG_FLAGS_FIXED_VALUE), OPT_END(), }; + int ret; argc = parse_options(argc, argv, prefix, opts, builtin_config_unset_usage, PARSE_OPT_STOP_AT_NON_OPTION); @@ -900,12 +905,14 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix) check_write(); if ((flags & CONFIG_FLAGS_MULTI_REPLACE) || value_pattern) - return git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], NULL, value_pattern, - NULL, flags); + ret = git_config_set_multivar_in_file_gently(given_config_source.file, + argv[0], NULL, value_pattern, + NULL, flags); else - return git_config_set_in_file_gently(given_config_source.file, argv[0], - NULL, NULL); + ret = git_config_set_in_file_gently(given_config_source.file, argv[0], + NULL, NULL); + + return ret; } static int cmd_config_rename_section(int argc, const char **argv, const char *prefix) @@ -926,11 +933,13 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr ret = git_config_rename_section_in_file(given_config_source.file, argv[0], argv[1]); if (ret < 0) - return ret; + goto out; else if (!ret) die(_("no such section: %s"), argv[0]); + ret = 0; - return 0; +out: + return ret; } static int cmd_config_remove_section(int argc, const char **argv, const char *prefix) @@ -951,11 +960,13 @@ static int cmd_config_remove_section(int argc, const char **argv, const char *pr ret = git_config_rename_section_in_file(given_config_source.file, argv[0], NULL); if (ret < 0) - return ret; + goto out; else if (!ret) die(_("no such section: %s"), argv[0]); + ret = 0; - return 0; +out: + return ret; } static int show_editor(void) @@ -1199,41 +1210,41 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) } else if (actions == ACTION_GET) { check_argc(argc, 1, 2); - return get_value(argv[0], argv[1], flags); + ret = get_value(argv[0], argv[1], flags); } else if (actions == ACTION_GET_ALL) { do_all = 1; check_argc(argc, 1, 2); - return get_value(argv[0], argv[1], flags); + ret = get_value(argv[0], argv[1], flags); } else if (actions == ACTION_GET_REGEXP) { show_keys = 1; use_key_regexp = 1; do_all = 1; check_argc(argc, 1, 2); - return get_value(argv[0], argv[1], flags); + ret = get_value(argv[0], argv[1], flags); } else if (actions == ACTION_GET_URLMATCH) { check_argc(argc, 2, 2); - return get_urlmatch(argv[0], argv[1]); + ret = get_urlmatch(argv[0], argv[1]); } else if (actions == ACTION_UNSET) { check_write(); check_argc(argc, 1, 2); if (argc == 2) - return git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], NULL, argv[1], - NULL, flags); + ret = git_config_set_multivar_in_file_gently(given_config_source.file, + argv[0], NULL, argv[1], + NULL, flags); else - return git_config_set_in_file_gently(given_config_source.file, - argv[0], NULL, NULL); + ret = git_config_set_in_file_gently(given_config_source.file, + argv[0], NULL, NULL); } else if (actions == ACTION_UNSET_ALL) { check_write(); check_argc(argc, 1, 2); - return git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], NULL, argv[1], - NULL, flags | CONFIG_FLAGS_MULTI_REPLACE); + ret = git_config_set_multivar_in_file_gently(given_config_source.file, + argv[0], NULL, argv[1], + NULL, flags | CONFIG_FLAGS_MULTI_REPLACE); } else if (actions == ACTION_RENAME_SECTION) { check_write(); @@ -1241,7 +1252,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) ret = git_config_rename_section_in_file(given_config_source.file, argv[0], argv[1]); if (ret < 0) - return ret; + goto out; else if (!ret) die(_("no such section: %s"), argv[0]); else @@ -1253,7 +1264,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) ret = git_config_rename_section_in_file(given_config_source.file, argv[0], NULL); if (ret < 0) - return ret; + goto out; else if (!ret) die(_("no such section: %s"), argv[0]); else @@ -1267,9 +1278,10 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) check_argc(argc, 1, 2); if (argc == 2) color_stdout_is_tty = git_config_bool("command line", argv[1]); - return get_colorbool(argv[0], argc == 2); + ret = get_colorbool(argv[0], argc == 2); } +out: free(comment); free(value); return ret; From patchwork Wed May 15 06:42:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664676 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 0A2BE53392 for ; Wed, 15 May 2024 06:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755343; cv=none; b=J8J5cGwMQR78mQnA4xmkyTDRSS8pt6aK5pR+C5l47aN4hkP/k4flJV1phfQgMkS0en433QTr367uihnFgUUe0av4CJX5bBzBro0W/uFdEBDe29oNNb6ovVnMo8iz6IsgaG5CG64w5CDn/RnquSVgcTh3EV0qmyyzmcUO1SXKc/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755343; c=relaxed/simple; bh=wwNrouROww+Iz/ymevMZw+48zWrwQEJZwVtb4ytizik=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AS+Yl04ET+PApwRAVUYZ/1PQA0TPrJwrvalMX2zLCb7SjMvD2u9Tq/567zxKoCwkFdynVxbMR0EQRhICPFJlO22eJnhNnImNYWMRNl1dzjq9e2FDgOHh3f1HwOGmO7wNMG2Jais6a4jgViiuIsB5SvhCZz/zbgnEXcg5ZvSNY8M= 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=FC1O5egU; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZBpqKp24; arc=none smtp.client-ip=103.168.172.147 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="FC1O5egU"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZBpqKp24" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 485121380222; Wed, 15 May 2024 02:42:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 15 May 2024 02:42:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755340; x=1715841740; bh=iLGxJ4pOaV kyGZlYzELByw9fCZMVt41NKaIsMBsvFMU=; b=FC1O5egUclJF8lKh5sc0EXN6l5 NLZoc1w5tk9rEKm5WOa1bk1ofUNqiMgwJGmDy6kQ8wLt3lbdYCZf++Ae4lO+6EkH TzovGtQJSabnERziC8E/KWdlEhz6aHjYyC9r1Y9Dk0lYa7H5SB7HSFmqMjlSSgyc xQ3iXnh3l5STAKLvkk3pj+fCBP0un2NYq+kGAxfP9jCum+ZuJKbhkNgn+uUio07l zdXA0XPP2U4XLrZS7P+vhQ7YkFhz+YTALh3g//J5U9sB2iOLEDfnWqejIPadO+s0 d+4nb8i5cAmtAFMSkN2kCGzuBnLQHPifSg7xMC86CTOKm4AdgUOnKQj+cyZQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755340; x=1715841740; bh=iLGxJ4pOaVkyGZlYzELByw9fCZMV t41NKaIsMBsvFMU=; b=ZBpqKp24dLRXmRIPTMpfaEqNH3btA+hOpOrhOOvWhdY0 h0wV/511onF1N8qmpUpjdoCMIaXM97wNaPZK5qcbpH5QC5NlexdUbopXI8UnFPk+ YZUnymFBQbsstHVjguPUu5MWt5ZQm3np232Avd7jcoOHb2aPa2gpxlCS0rPvX2o+ HLp+tBGwXo42UPOx65pcUudDAxZYXm9d07phuTr183lcUMKB//x3rkIQiOYKY8mU yrtqCSZWLJVsjTq+cTvXmpCQY+h/gD7HW7g2qBVLS+rQ6OiYprDnZ1KD+enJEMFO EaKrTDCwBeQQ3X9M80/DeAqoNvFTd2nXDMMS9ysSTQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:42:18 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 763c9b36 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:41:56 +0000 (UTC) Date: Wed, 15 May 2024 08:42:16 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 09/21] builtin/config: move location options into local variables Message-ID: <2ede4a204b3715b77b0dcb7d310b9e94fad60ec7.1715755055.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 location options are tracked via a set of global variables. Move them into a self-contained structure so that we can easily parse all relevant options and hand them over to the various functions that require them. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 313 ++++++++++++++++++++++++++--------------------- 1 file changed, 176 insertions(+), 137 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 155564b832..ec36d7289a 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -62,6 +62,26 @@ static const char *const builtin_config_edit_usage[] = { NULL }; +#define CONFIG_LOCATION_OPTIONS(opts) \ + OPT_GROUP(N_("Config file location")), \ + OPT_BOOL(0, "global", &opts.use_global_config, N_("use global config file")), \ + OPT_BOOL(0, "system", &opts.use_system_config, N_("use system config file")), \ + OPT_BOOL(0, "local", &opts.use_local_config, N_("use repository config file")), \ + OPT_BOOL(0, "worktree", &opts.use_worktree_config, N_("use per-worktree config file")), \ + OPT_STRING('f', "file", &opts.source.file, N_("file"), N_("use given config file")), \ + OPT_STRING(0, "blob", &opts.source.blob, N_("blob-id"), N_("read config from given blob object")) + +struct config_location_options { + struct git_config_source source; + struct config_options options; + char *file_to_free; + int use_global_config; + int use_system_config; + int use_local_config; + int use_worktree_config; +}; +#define CONFIG_LOCATION_OPTIONS_INIT {0} + static char *key; static regex_t *key_regexp; static const char *value_pattern; @@ -75,14 +95,10 @@ static char delim = '='; static char key_delim = ' '; static char term = '\n'; -static int use_global_config, use_system_config, use_local_config; -static int use_worktree_config; -static struct git_config_source given_config_source; static int type; static char *default_value; static int end_nul; static int respect_includes_opt = -1; -static struct config_options config_options; static int show_origin; static int show_scope; static int fixed_value; @@ -298,7 +314,8 @@ static int collect_config(const char *key_, const char *value_, return format_config(&values->items[values->nr++], key_, value_, kvi); } -static int get_value(const char *key_, const char *regex_, unsigned flags) +static int get_value(const struct config_location_options *opts, + const char *key_, const char *regex_, unsigned flags) { int ret = CONFIG_GENERIC_ERROR; struct strbuf_list values = {NULL}; @@ -353,8 +370,8 @@ static int get_value(const char *key_, const char *regex_, unsigned flags) } config_with_options(collect_config, &values, - &given_config_source, the_repository, - &config_options); + &opts->source, the_repository, + &opts->options); if (!values.nr && default_value) { struct key_value_info kvi = KVI_INIT; @@ -464,14 +481,15 @@ static int git_get_color_config(const char *var, const char *value, return 0; } -static void get_color(const char *var, const char *def_color) +static void get_color(const struct config_location_options *opts, + const char *var, const char *def_color) { get_color_slot = var; get_color_found = 0; parsed_color[0] = '\0'; config_with_options(git_get_color_config, NULL, - &given_config_source, the_repository, - &config_options); + &opts->source, the_repository, + &opts->options); if (!get_color_found && def_color) { if (color_parse(def_color, parsed_color) < 0) @@ -497,15 +515,16 @@ static int git_get_colorbool_config(const char *var, const char *value, return 0; } -static int get_colorbool(const char *var, int print) +static int get_colorbool(const struct config_location_options *opts, + const char *var, int print) { get_colorbool_slot = var; get_colorbool_found = -1; get_diff_color_found = -1; get_color_ui_found = -1; config_with_options(git_get_colorbool_config, NULL, - &given_config_source, the_repository, - &config_options); + &opts->source, the_repository, + &opts->options); if (get_colorbool_found < 0) { if (!strcmp(get_colorbool_slot, "color.diff")) @@ -527,15 +546,15 @@ static int get_colorbool(const char *var, int print) return get_colorbool_found ? 0 : 1; } -static void check_write(void) +static void check_write(const struct git_config_source *source) { - if (!given_config_source.file && !startup_info->have_repository) + if (!source->file && !startup_info->have_repository) die(_("not in a git directory")); - if (given_config_source.use_stdin) + if (source->use_stdin) die(_("writing to stdin is not supported")); - if (given_config_source.blob) + if (source->blob) die(_("writing config blobs is not supported")); } @@ -572,7 +591,8 @@ static int urlmatch_collect_fn(const char *var, const char *value, return 0; } -static int get_urlmatch(const char *var, const char *url) +static int get_urlmatch(const struct config_location_options *opts, + const char *var, const char *url) { int ret; char *section_tail; @@ -599,8 +619,8 @@ static int get_urlmatch(const char *var, const char *url) } config_with_options(urlmatch_config_entry, &config, - &given_config_source, the_repository, - &config_options); + &opts->source, the_repository, + &opts->options); ret = !values.nr; @@ -638,34 +658,39 @@ static char *default_user_config(void) return strbuf_detach(&buf, NULL); } -static void handle_config_location(const char *prefix) +static void location_options_init(struct config_location_options *opts, + const char *prefix) { - if (use_global_config + use_system_config + use_local_config + - use_worktree_config + - !!given_config_source.file + !!given_config_source.blob > 1) { + if (!opts->source.file) + opts->source.file = opts->file_to_free = + xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); + + if (opts->use_global_config + opts->use_system_config + + opts->use_local_config + opts->use_worktree_config + + !!opts->source.file + !!opts->source.blob > 1) { error(_("only one config file at a time")); exit(129); } if (!startup_info->have_repository) { - if (use_local_config) + if (opts->use_local_config) die(_("--local can only be used inside a git repository")); - if (given_config_source.blob) + if (opts->source.blob) die(_("--blob can only be used inside a git repository")); - if (use_worktree_config) + if (opts->use_worktree_config) die(_("--worktree can only be used inside a git repository")); } - if (given_config_source.file && - !strcmp(given_config_source.file, "-")) { - given_config_source.file = NULL; - given_config_source.use_stdin = 1; - given_config_source.scope = CONFIG_SCOPE_COMMAND; + if (opts->source.file && + !strcmp(opts->source.file, "-")) { + opts->source.file = NULL; + opts->source.use_stdin = 1; + opts->source.scope = CONFIG_SCOPE_COMMAND; } - if (use_global_config) { - given_config_source.file = git_global_config(); - if (!given_config_source.file) + if (opts->use_global_config) { + opts->source.file = opts->file_to_free = git_global_config(); + if (!opts->source.file) /* * It is unknown if HOME/.gitconfig exists, so * we do not know if we should write to XDG @@ -673,17 +698,18 @@ static void handle_config_location(const char *prefix) * is set and points at a sane location. */ die(_("$HOME not set")); - given_config_source.scope = CONFIG_SCOPE_GLOBAL; - } else if (use_system_config) { - given_config_source.file = git_system_config(); - given_config_source.scope = CONFIG_SCOPE_SYSTEM; - } else if (use_local_config) { - given_config_source.file = git_pathdup("config"); - given_config_source.scope = CONFIG_SCOPE_LOCAL; - } else if (use_worktree_config) { + opts->source.scope = CONFIG_SCOPE_GLOBAL; + } else if (opts->use_system_config) { + opts->source.file = opts->file_to_free = git_system_config(); + opts->source.scope = CONFIG_SCOPE_SYSTEM; + } else if (opts->use_local_config) { + opts->source.file = opts->file_to_free = git_pathdup("config"); + opts->source.scope = CONFIG_SCOPE_LOCAL; + } else if (opts->use_worktree_config) { struct worktree **worktrees = get_worktrees(); if (the_repository->repository_format_worktree_config) - given_config_source.file = git_pathdup("config.worktree"); + opts->source.file = opts->file_to_free = + git_pathdup("config.worktree"); else if (worktrees[0] && worktrees[1]) die(_("--worktree cannot be used with multiple " "working trees unless the config\n" @@ -691,28 +717,34 @@ static void handle_config_location(const char *prefix) "Please read \"CONFIGURATION FILE\"\n" "section in \"git help worktree\" for details")); else - given_config_source.file = git_pathdup("config"); - given_config_source.scope = CONFIG_SCOPE_LOCAL; + opts->source.file = opts->file_to_free = + git_pathdup("config"); + opts->source.scope = CONFIG_SCOPE_LOCAL; free_worktrees(worktrees); - } else if (given_config_source.file) { - if (!is_absolute_path(given_config_source.file) && prefix) - given_config_source.file = - prefix_filename(prefix, given_config_source.file); - given_config_source.scope = CONFIG_SCOPE_COMMAND; - } else if (given_config_source.blob) { - given_config_source.scope = CONFIG_SCOPE_COMMAND; + } else if (opts->source.file) { + if (!is_absolute_path(opts->source.file) && prefix) + opts->source.file = opts->file_to_free = + prefix_filename(prefix, opts->source.file); + opts->source.scope = CONFIG_SCOPE_COMMAND; + } else if (opts->source.blob) { + opts->source.scope = CONFIG_SCOPE_COMMAND; } if (respect_includes_opt == -1) - config_options.respect_includes = !given_config_source.file; + opts->options.respect_includes = !opts->source.file; else - config_options.respect_includes = respect_includes_opt; + opts->options.respect_includes = respect_includes_opt; if (startup_info->have_repository) { - config_options.commondir = get_git_common_dir(); - config_options.git_dir = get_git_dir(); + opts->options.commondir = get_git_common_dir(); + opts->options.git_dir = get_git_dir(); } } +static void location_options_release(struct config_location_options *opts) +{ + free(opts->file_to_free); +} + static void handle_nul(void) { if (end_nul) { term = '\0'; @@ -721,15 +753,6 @@ static void handle_nul(void) { } } -#define CONFIG_LOCATION_OPTIONS \ - OPT_GROUP(N_("Config file location")), \ - OPT_BOOL(0, "global", &use_global_config, N_("use global config file")), \ - OPT_BOOL(0, "system", &use_system_config, N_("use system config file")), \ - OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")), \ - OPT_BOOL(0, "worktree", &use_worktree_config, N_("use per-worktree config file")), \ - OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), \ - OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")) - #define CONFIG_TYPE_OPTIONS \ OPT_GROUP(N_("Type")), \ OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), \ @@ -749,8 +772,9 @@ static void handle_nul(void) { static int cmd_config_list(int argc, const char **argv, const char *prefix) { + struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; struct option opts[] = { - CONFIG_LOCATION_OPTIONS, + CONFIG_LOCATION_OPTIONS(location_opts), CONFIG_DISPLAY_OPTIONS, OPT_GROUP(N_("Other")), OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), @@ -760,30 +784,32 @@ static int cmd_config_list(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, opts, builtin_config_list_usage, 0); check_argc(argc, 0, 0); - handle_config_location(prefix); + location_options_init(&location_opts, prefix); handle_nul(); setup_auto_pager("config", 1); if (config_with_options(show_all_config, NULL, - &given_config_source, the_repository, - &config_options) < 0) { - if (given_config_source.file) + &location_opts.source, the_repository, + &location_opts.options) < 0) { + if (location_opts.source.file) die_errno(_("unable to read config file '%s'"), - given_config_source.file); + location_opts.source.file); else die(_("error processing config file(s)")); } + location_options_release(&location_opts); return 0; } static int cmd_config_get(int argc, const char **argv, const char *prefix) { + struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; const char *value_pattern = NULL, *url = NULL; int flags = 0; struct option opts[] = { - CONFIG_LOCATION_OPTIONS, + 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")), @@ -811,26 +837,28 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) if (url && (do_all || use_key_regexp || value_pattern)) die(_("--url= cannot be used with --all, --regexp or --value")); - handle_config_location(prefix); + location_options_init(&location_opts, prefix); handle_nul(); setup_auto_pager("config", 1); if (url) - ret = get_urlmatch(argv[0], url); + ret = get_urlmatch(&location_opts, argv[0], url); else - ret = get_value(argv[0], value_pattern, flags); + ret = get_value(&location_opts, argv[0], value_pattern, flags); + location_options_release(&location_opts); return ret; } 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; struct option opts[] = { - CONFIG_LOCATION_OPTIONS, + CONFIG_LOCATION_OPTIONS(location_opts), CONFIG_TYPE_OPTIONS, OPT_GROUP(N_("Filter")), OPT_BIT(0, "all", &flags, N_("replace multi-valued config option with new value"), CONFIG_FLAGS_MULTI_REPLACE), @@ -858,23 +886,24 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix) comment = git_config_prepare_comment_string(comment_arg); - handle_config_location(prefix); - check_write(); + location_options_init(&location_opts, prefix); + check_write(&location_opts.source); value = normalize_value(argv[0], argv[1], &default_kvi); if ((flags & CONFIG_FLAGS_MULTI_REPLACE) || value_pattern) { - ret = git_config_set_multivar_in_file_gently(given_config_source.file, + ret = git_config_set_multivar_in_file_gently(location_opts.source.file, argv[0], value, value_pattern, comment, flags); } else { - ret = git_config_set_in_file_gently(given_config_source.file, + 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" " Use a regexp, --add or --replace-all to change %s."), argv[0]); } + location_options_release(&location_opts); free(comment); free(value); return ret; @@ -882,10 +911,11 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix) static int cmd_config_unset(int argc, const char **argv, const char *prefix) { + struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; const char *value_pattern = NULL; int flags = 0; struct option opts[] = { - CONFIG_LOCATION_OPTIONS, + CONFIG_LOCATION_OPTIONS(location_opts), 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")), @@ -901,24 +931,26 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix) if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern) die(_("--fixed-value only applies with 'value-pattern'")); - handle_config_location(prefix); - check_write(); + location_options_init(&location_opts, prefix); + check_write(&location_opts.source); if ((flags & CONFIG_FLAGS_MULTI_REPLACE) || value_pattern) - ret = git_config_set_multivar_in_file_gently(given_config_source.file, + ret = git_config_set_multivar_in_file_gently(location_opts.source.file, argv[0], NULL, value_pattern, NULL, flags); else - ret = git_config_set_in_file_gently(given_config_source.file, argv[0], + ret = git_config_set_in_file_gently(location_opts.source.file, argv[0], NULL, NULL); + location_options_release(&location_opts); return ret; } static int cmd_config_rename_section(int argc, const char **argv, const char *prefix) { + struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; struct option opts[] = { - CONFIG_LOCATION_OPTIONS, + CONFIG_LOCATION_OPTIONS(location_opts), OPT_END(), }; int ret; @@ -927,10 +959,10 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr PARSE_OPT_STOP_AT_NON_OPTION); check_argc(argc, 2, 2); - handle_config_location(prefix); - check_write(); + location_options_init(&location_opts, prefix); + check_write(&location_opts.source); - ret = git_config_rename_section_in_file(given_config_source.file, + ret = git_config_rename_section_in_file(location_opts.source.file, argv[0], argv[1]); if (ret < 0) goto out; @@ -939,13 +971,15 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr ret = 0; out: + location_options_release(&location_opts); return ret; } static int cmd_config_remove_section(int argc, const char **argv, const char *prefix) { + struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; struct option opts[] = { - CONFIG_LOCATION_OPTIONS, + CONFIG_LOCATION_OPTIONS(location_opts), OPT_END(), }; int ret; @@ -954,10 +988,10 @@ static int cmd_config_remove_section(int argc, const char **argv, const char *pr PARSE_OPT_STOP_AT_NON_OPTION); check_argc(argc, 1, 1); - handle_config_location(prefix); - check_write(); + location_options_init(&location_opts, prefix); + check_write(&location_opts.source); - ret = git_config_rename_section_in_file(given_config_source.file, + ret = git_config_rename_section_in_file(location_opts.source.file, argv[0], NULL); if (ret < 0) goto out; @@ -966,24 +1000,25 @@ static int cmd_config_remove_section(int argc, const char **argv, const char *pr ret = 0; out: + location_options_release(&location_opts); return ret; } -static int show_editor(void) +static int show_editor(struct config_location_options *opts) { char *config_file; - if (!given_config_source.file && !startup_info->have_repository) + if (!opts->source.file && !startup_info->have_repository) die(_("not in a git directory")); - if (given_config_source.use_stdin) + if (opts->source.use_stdin) die(_("editing stdin is not supported")); - if (given_config_source.blob) + if (opts->source.blob) die(_("editing blobs is not supported")); git_config(git_default_config, NULL); - config_file = given_config_source.file ? - xstrdup(given_config_source.file) : + config_file = opts->source.file ? + xstrdup(opts->source.file) : git_pathdup("config"); - if (use_global_config) { + if (opts->use_global_config) { int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666); if (fd >= 0) { char *content = default_user_config(); @@ -1002,18 +1037,22 @@ static int show_editor(void) static int cmd_config_edit(int argc, const char **argv, const char *prefix) { + struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; struct option opts[] = { - CONFIG_LOCATION_OPTIONS, + CONFIG_LOCATION_OPTIONS(location_opts), OPT_END(), }; + int ret; argc = parse_options(argc, argv, prefix, opts, builtin_config_edit_usage, 0); check_argc(argc, 0, 0); - handle_config_location(prefix); - check_write(); + location_options_init(&location_opts, prefix); + check_write(&location_opts.source); - return show_editor(); + ret = show_editor(&location_opts); + location_options_release(&location_opts); + return ret; } static int cmd_config_actions(int argc, const char **argv, const char *prefix) @@ -1036,10 +1075,11 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) ACTION_GET_COLORBOOL = (1<<14), ACTION_GET_URLMATCH = (1<<15), }; + struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; const char *comment_arg = NULL; int actions = 0; struct option opts[] = { - CONFIG_LOCATION_OPTIONS, + CONFIG_LOCATION_OPTIONS(location_opts), OPT_GROUP(N_("Action")), OPT_CMDMODE(0, "get", &actions, N_("get value: name []"), ACTION_GET), OPT_CMDMODE(0, "get-all", &actions, N_("get all values: key []"), ACTION_GET_ALL), @@ -1073,7 +1113,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) builtin_config_usage, PARSE_OPT_STOP_AT_NON_OPTION); - handle_config_location(prefix); + location_options_init(&location_opts, prefix); handle_nul(); if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && type) { @@ -1162,94 +1202,94 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) if (actions == ACTION_LIST) { check_argc(argc, 0, 0); if (config_with_options(show_all_config, NULL, - &given_config_source, the_repository, - &config_options) < 0) { - if (given_config_source.file) + &location_opts.source, the_repository, + &location_opts.options) < 0) { + if (location_opts.source.file) die_errno(_("unable to read config file '%s'"), - given_config_source.file); + location_opts.source.file); else die(_("error processing config file(s)")); } } else if (actions == ACTION_EDIT) { - ret = show_editor(); + ret = show_editor(&location_opts); } else if (actions == ACTION_SET) { - check_write(); + check_write(&location_opts.source); check_argc(argc, 2, 2); value = normalize_value(argv[0], argv[1], &default_kvi); - ret = git_config_set_in_file_gently(given_config_source.file, argv[0], comment, value); + 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" " Use a regexp, --add or --replace-all to change %s."), argv[0]); } else if (actions == ACTION_SET_ALL) { - check_write(); + check_write(&location_opts.source); check_argc(argc, 2, 3); value = normalize_value(argv[0], argv[1], &default_kvi); - ret = git_config_set_multivar_in_file_gently(given_config_source.file, + ret = git_config_set_multivar_in_file_gently(location_opts.source.file, argv[0], value, argv[2], comment, flags); } else if (actions == ACTION_ADD) { - check_write(); + check_write(&location_opts.source); check_argc(argc, 2, 2); value = normalize_value(argv[0], argv[1], &default_kvi); - ret = git_config_set_multivar_in_file_gently(given_config_source.file, + ret = git_config_set_multivar_in_file_gently(location_opts.source.file, argv[0], value, CONFIG_REGEX_NONE, comment, flags); } else if (actions == ACTION_REPLACE_ALL) { - check_write(); + check_write(&location_opts.source); check_argc(argc, 2, 3); value = normalize_value(argv[0], argv[1], &default_kvi); - ret = git_config_set_multivar_in_file_gently(given_config_source.file, + ret = git_config_set_multivar_in_file_gently(location_opts.source.file, argv[0], value, argv[2], comment, flags | CONFIG_FLAGS_MULTI_REPLACE); } else if (actions == ACTION_GET) { check_argc(argc, 1, 2); - ret = get_value(argv[0], argv[1], flags); + ret = get_value(&location_opts, argv[0], argv[1], flags); } else if (actions == ACTION_GET_ALL) { do_all = 1; check_argc(argc, 1, 2); - ret = get_value(argv[0], argv[1], flags); + ret = get_value(&location_opts, argv[0], argv[1], flags); } else if (actions == ACTION_GET_REGEXP) { show_keys = 1; use_key_regexp = 1; do_all = 1; check_argc(argc, 1, 2); - ret = get_value(argv[0], argv[1], flags); + ret = get_value(&location_opts, argv[0], argv[1], flags); } else if (actions == ACTION_GET_URLMATCH) { check_argc(argc, 2, 2); - ret = get_urlmatch(argv[0], argv[1]); + ret = get_urlmatch(&location_opts, argv[0], argv[1]); } else if (actions == ACTION_UNSET) { - check_write(); + check_write(&location_opts.source); check_argc(argc, 1, 2); if (argc == 2) - ret = git_config_set_multivar_in_file_gently(given_config_source.file, + ret = git_config_set_multivar_in_file_gently(location_opts.source.file, argv[0], NULL, argv[1], NULL, flags); else - ret = git_config_set_in_file_gently(given_config_source.file, + ret = git_config_set_in_file_gently(location_opts.source.file, argv[0], NULL, NULL); } else if (actions == ACTION_UNSET_ALL) { - check_write(); + check_write(&location_opts.source); check_argc(argc, 1, 2); - ret = git_config_set_multivar_in_file_gently(given_config_source.file, + ret = git_config_set_multivar_in_file_gently(location_opts.source.file, argv[0], NULL, argv[1], NULL, flags | CONFIG_FLAGS_MULTI_REPLACE); } else if (actions == ACTION_RENAME_SECTION) { - check_write(); + check_write(&location_opts.source); check_argc(argc, 2, 2); - ret = git_config_rename_section_in_file(given_config_source.file, + ret = git_config_rename_section_in_file(location_opts.source.file, argv[0], argv[1]); if (ret < 0) goto out; @@ -1259,9 +1299,9 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) ret = 0; } else if (actions == ACTION_REMOVE_SECTION) { - check_write(); + check_write(&location_opts.source); check_argc(argc, 1, 1); - ret = git_config_rename_section_in_file(given_config_source.file, + ret = git_config_rename_section_in_file(location_opts.source.file, argv[0], NULL); if (ret < 0) goto out; @@ -1272,16 +1312,17 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) } else if (actions == ACTION_GET_COLOR) { check_argc(argc, 1, 2); - get_color(argv[0], argv[1]); + get_color(&location_opts, argv[0], argv[1]); } else if (actions == ACTION_GET_COLORBOOL) { check_argc(argc, 1, 2); if (argc == 2) color_stdout_is_tty = git_config_bool("command line", argv[1]); - ret = get_colorbool(argv[0], argc == 2); + ret = get_colorbool(&location_opts, argv[0], argc == 2); } out: + location_options_release(&location_opts); free(comment); free(value); return ret; @@ -1301,8 +1342,6 @@ int cmd_config(int argc, const char **argv, const char *prefix) OPT_END(), }; - given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); - /* * This is somewhat hacky: we first parse the command line while * keeping all args intact in order to determine whether a subcommand From patchwork Wed May 15 06:42:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664677 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 869D443ADC for ; Wed, 15 May 2024 06:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755347; cv=none; b=fxqbSSzw5LF7Xint33Uh8vSKKNKE1oGqn5uHkNy5VY2W45YSXNVuPwdihXKPvlXuE+Zv3C9DpT2OlLjBAHou7ES133shpnGZu1Db8N65pn08GZwzUVpIq676mlW0pKVAti6dmgh5WC7jy+6xzzwqeJ8tjUi9yw0CBkED4Q0GJUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755347; c=relaxed/simple; bh=j1Fvs2ru4Z7dIimRxvns7UhNhRXi/93J6aKyotMftJI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JHkIYZSgiFNPVpoJkHxo1NlQu7hcLO2ow09vVL9d+3Vum6HahNQkWPMZLTtUxMUx94vjAj90Op6+x1aRO3ddOdN8Zwb7jiy3f5GgpDgpKqsV0WZFlDvk+sHaZedHAOJoNJWvqAhgWmgi97sVV8UmvF/Ei00q4ps5HHlkMNB7yas= 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=dyKau5Is; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=biqNu6sg; arc=none smtp.client-ip=103.168.172.153 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="dyKau5Is"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="biqNu6sg" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A4135114011D; Wed, 15 May 2024 02:42:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 15 May 2024 02:42:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755344; x=1715841744; bh=Ow82PO+Oa5 moXdMESaOFOxHqnn98S6Ieo19cEqS9BBA=; b=dyKau5IszNRcemAV1UNpMGUUJR vKlHIb1ubvYh87Eu9HGJgtnzsUs20N/nYM6dMVGKCIALmNyrg8tMERo967rYqatG 5jieY+DcY9G8rWKWUmsrcNvnFDTiTfNIeap8ZiUlcWyG/Zp8Nx43ckRUPKXren7X ILUbqiyvEH5xZnwtBzMXgmLo8f/6RZT3lKWIkLokr3n7jtq1ldE/o3dtQdkPNVFP WxzdvRqEwrgFVmTNSi2QMmBzuuZ0vJ5nUdl40TkohZfi52WMlW1y+mo46lSVvFWE VLDIwiMIMLjickrD/FAnF/XJGJy7bQximojXYr8eCqLP45yjNcexa2kugaIA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755344; x=1715841744; bh=Ow82PO+Oa5moXdMESaOFOxHqnn98 S6Ieo19cEqS9BBA=; b=biqNu6sg+Vdeed5i0asr9conNdlbaFeQabIeLCziRm1A VQc0yykttdyRDqphz/EHrvKlRuLWtU8PyKq96ohf7aKo0YQSProIKjQvDMx+ngkA pJAHMBZMMJGCS2tHjzqlR9me3G8sFSF1B7V5nqgaEVtd9pxwy3IRa76LVWS//I1O 8QxZkaFtom4tuk7+gjQLL7CqGw+uniKZyAHtu+p+A41MuQ44GvokITj3yc9Gd1i6 smi1p2eOkv1WM35tO6Y3TeWesCleqpGGeeOe3q6hy0dG6c0suPwzcmTpo3o9+OPR Zmpu63yQnfOCgU3kKlOMvDbGnTFnH/vvk3gBehgcxg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:42:23 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ee2e9f25 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:42:00 +0000 (UTC) Date: Wed, 15 May 2024 08:42:21 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 10/21] builtin/config: move display options into local variables Message-ID: <4d157942e66f9b864e8f3cfe58c945269877f43b.1715755055.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 display options are tracked via a set of global variables. Move them into a self-contained structure so that we can easily parse all relevant options and hand them over to the various functions that require them. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 171 ++++++++++++++++++++++++++++------------------- 1 file changed, 101 insertions(+), 70 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index ec36d7289a..1a67a6caef 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -82,25 +82,42 @@ struct config_location_options { }; #define CONFIG_LOCATION_OPTIONS_INIT {0} +#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")) + +struct config_display_options { + int end_nul; + int omit_values; + int show_origin; + int show_scope; + int show_keys; + /* Populated via `display_options_init()`. */ + int term; + int delim; + int key_delim; +}; +#define CONFIG_DISPLAY_OPTIONS_INIT { \ + .term = '\n', \ + .delim = '=', \ + .key_delim = ' ', \ +} + static char *key; static regex_t *key_regexp; static const char *value_pattern; static regex_t *regexp; -static int show_keys; -static int omit_values; static int use_key_regexp; static int do_all; static int do_not_match; -static char delim = '='; -static char key_delim = ' '; -static char term = '\n'; static int type; static char *default_value; -static int end_nul; static int respect_includes_opt = -1; -static int show_origin; -static int show_scope; static int fixed_value; #define TYPE_BOOL 1 @@ -178,24 +195,26 @@ static void check_argc(int argc, int min, int max) exit(129); } -static void show_config_origin(const struct key_value_info *kvi, +static void show_config_origin(const struct config_display_options *opts, + const struct key_value_info *kvi, struct strbuf *buf) { - const char term = end_nul ? '\0' : '\t'; + const char term = opts->end_nul ? '\0' : '\t'; strbuf_addstr(buf, config_origin_type_name(kvi->origin_type)); strbuf_addch(buf, ':'); - if (end_nul) + if (opts->end_nul) strbuf_addstr(buf, kvi->filename ? kvi->filename : ""); else quote_c_style(kvi->filename ? kvi->filename : "", buf, NULL, 0); strbuf_addch(buf, term); } -static void show_config_scope(const struct key_value_info *kvi, +static void show_config_scope(const struct config_display_options *opts, + const struct key_value_info *kvi, struct strbuf *buf) { - const char term = end_nul ? '\0' : '\t'; + const char term = opts->end_nul ? '\0' : '\t'; const char *scope = config_scope_name(kvi->scope); strbuf_addstr(buf, N_(scope)); @@ -204,24 +223,25 @@ static void show_config_scope(const struct key_value_info *kvi, static int show_all_config(const char *key_, const char *value_, const struct config_context *ctx, - void *cb UNUSED) + void *cb) { + const struct config_display_options *opts = cb; const struct key_value_info *kvi = ctx->kvi; - if (show_origin || show_scope) { + if (opts->show_origin || opts->show_scope) { struct strbuf buf = STRBUF_INIT; - if (show_scope) - show_config_scope(kvi, &buf); - if (show_origin) - show_config_origin(kvi, &buf); + if (opts->show_scope) + show_config_scope(opts, kvi, &buf); + if (opts->show_origin) + show_config_origin(opts, kvi, &buf); /* Use fwrite as "buf" can contain \0's if "end_null" is set. */ fwrite(buf.buf, 1, buf.len, stdout); strbuf_release(&buf); } - if (!omit_values && value_) - printf("%s%c%s%c", key_, delim, value_, term); + if (!opts->omit_values && value_) + printf("%s%c%s%c", key_, opts->delim, value_, opts->term); else - printf("%s%c", key_, term); + printf("%s%c", key_, opts->term); return 0; } @@ -231,18 +251,19 @@ struct strbuf_list { int alloc; }; -static int format_config(struct strbuf *buf, const char *key_, +static int format_config(const struct config_display_options *opts, + struct strbuf *buf, const char *key_, const char *value_, const struct key_value_info *kvi) { - if (show_scope) - show_config_scope(kvi, buf); - if (show_origin) - show_config_origin(kvi, buf); - if (show_keys) + if (opts->show_scope) + show_config_scope(opts, kvi, buf); + if (opts->show_origin) + show_config_origin(opts, kvi, buf); + if (opts->show_keys) strbuf_addstr(buf, key_); - if (!omit_values) { - if (show_keys) - strbuf_addch(buf, key_delim); + if (!opts->omit_values) { + if (opts->show_keys) + strbuf_addch(buf, opts->key_delim); if (type == TYPE_INT) strbuf_addf(buf, "%"PRId64, @@ -284,18 +305,24 @@ static int format_config(struct strbuf *buf, const char *key_, strbuf_addstr(buf, value_); } else { /* Just show the key name; back out delimiter */ - if (show_keys) + if (opts->show_keys) strbuf_setlen(buf, buf->len - 1); } } - strbuf_addch(buf, term); + strbuf_addch(buf, opts->term); return 0; } +struct collect_config_data { + const struct config_display_options *display_opts; + struct strbuf_list *values; +}; + static int collect_config(const char *key_, const char *value_, const struct config_context *ctx, void *cb) { - struct strbuf_list *values = cb; + struct collect_config_data *data = cb; + struct strbuf_list *values = data->values; const struct key_value_info *kvi = ctx->kvi; if (!use_key_regexp && strcmp(key_, key)) @@ -311,14 +338,20 @@ static int collect_config(const char *key_, const char *value_, ALLOC_GROW(values->items, values->nr + 1, values->alloc); strbuf_init(&values->items[values->nr], 0); - return format_config(&values->items[values->nr++], key_, value_, kvi); + return format_config(data->display_opts, &values->items[values->nr++], + key_, value_, kvi); } static int get_value(const struct config_location_options *opts, + const struct config_display_options *display_opts, const char *key_, const char *regex_, unsigned flags) { int ret = CONFIG_GENERIC_ERROR; struct strbuf_list values = {NULL}; + struct collect_config_data data = { + .display_opts = display_opts, + .values = &values, + }; int i; if (use_key_regexp) { @@ -369,7 +402,7 @@ static int get_value(const struct config_location_options *opts, } } - config_with_options(collect_config, &values, + config_with_options(collect_config, &data, &opts->source, the_repository, &opts->options); @@ -381,7 +414,7 @@ static int get_value(const struct config_location_options *opts, ALLOC_GROW(values.items, values.nr + 1, values.alloc); item = &values.items[values.nr++]; strbuf_init(item, 0); - if (format_config(item, key_, default_value, &kvi) < 0) + if (format_config(display_opts, item, key_, default_value, &kvi) < 0) die(_("failed to format default config value: %s"), default_value); } @@ -592,10 +625,12 @@ static int urlmatch_collect_fn(const char *var, const char *value, } static int get_urlmatch(const struct config_location_options *opts, + const struct config_display_options *_display_opts, const char *var, const char *url) { int ret; char *section_tail; + struct config_display_options display_opts = *_display_opts; struct string_list_item *item; struct urlmatch_config config = URLMATCH_CONFIG_INIT; struct string_list values = STRING_LIST_INIT_DUP; @@ -612,10 +647,10 @@ static int get_urlmatch(const struct config_location_options *opts, if (section_tail) { *section_tail = '\0'; config.key = section_tail + 1; - show_keys = 0; + display_opts.show_keys = 0; } else { config.key = NULL; - show_keys = 1; + display_opts.show_keys = 1; } config_with_options(urlmatch_config_entry, &config, @@ -628,7 +663,7 @@ static int get_urlmatch(const struct config_location_options *opts, struct urlmatch_current_candidate_value *matched = item->util; struct strbuf buf = STRBUF_INIT; - format_config(&buf, item->string, + format_config(&display_opts, &buf, item->string, matched->value_is_null ? NULL : matched->value.buf, &matched->kvi); fwrite(buf.buf, 1, buf.len, stdout); @@ -745,11 +780,12 @@ static void location_options_release(struct config_location_options *opts) free(opts->file_to_free); } -static void handle_nul(void) { - if (end_nul) { - term = '\0'; - delim = '\n'; - key_delim = '\n'; +static void display_options_init(struct config_display_options *opts) +{ + if (opts->end_nul) { + opts->term = '\0'; + opts->delim = '\n'; + opts->key_delim = '\n'; } } @@ -763,19 +799,13 @@ static void handle_nul(void) { 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 \ - OPT_GROUP(N_("Display options")), \ - OPT_BOOL('z', "null", &end_nul, N_("terminate values with NUL byte")), \ - OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")), \ - OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), \ - OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")) - static int cmd_config_list(int argc, const char **argv, const char *prefix) { struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; + struct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT; struct option opts[] = { CONFIG_LOCATION_OPTIONS(location_opts), - CONFIG_DISPLAY_OPTIONS, + CONFIG_DISPLAY_OPTIONS(display_opts), OPT_GROUP(N_("Other")), OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), OPT_END(), @@ -785,11 +815,11 @@ static int cmd_config_list(int argc, const char **argv, const char *prefix) check_argc(argc, 0, 0); location_options_init(&location_opts, prefix); - handle_nul(); + display_options_init(&display_opts); setup_auto_pager("config", 1); - if (config_with_options(show_all_config, NULL, + if (config_with_options(show_all_config, &display_opts, &location_opts.source, the_repository, &location_opts.options) < 0) { if (location_opts.source.file) @@ -806,6 +836,7 @@ static int cmd_config_list(int argc, const char **argv, const char *prefix) static int cmd_config_get(int argc, const char **argv, const char *prefix) { struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; + struct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT; const char *value_pattern = NULL, *url = NULL; int flags = 0; struct option opts[] = { @@ -817,8 +848,7 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) OPT_STRING(0, "value", &value_pattern, N_("pattern"), N_("show config with values matching the pattern")), OPT_BIT(0, "fixed-value", &flags, N_("use string equality when comparing values to value pattern"), CONFIG_FLAGS_FIXED_VALUE), OPT_STRING(0, "url", &url, N_("URL"), N_("show config matching the given URL")), - CONFIG_DISPLAY_OPTIONS, - OPT_BOOL(0, "show-names", &show_keys, N_("show config keys in addition to their values")), + CONFIG_DISPLAY_OPTIONS(display_opts), OPT_GROUP(N_("Other")), OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), OPT_STRING(0, "default", &default_value, N_("value"), N_("use default value when missing entry")), @@ -838,14 +868,14 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) die(_("--url= cannot be used with --all, --regexp or --value")); location_options_init(&location_opts, prefix); - handle_nul(); + display_options_init(&display_opts); setup_auto_pager("config", 1); if (url) - ret = get_urlmatch(&location_opts, argv[0], url); + ret = get_urlmatch(&location_opts, &display_opts, argv[0], url); else - ret = get_value(&location_opts, argv[0], value_pattern, flags); + ret = get_value(&location_opts, &display_opts, argv[0], value_pattern, flags); location_options_release(&location_opts); return ret; @@ -1076,6 +1106,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) ACTION_GET_URLMATCH = (1<<15), }; struct config_location_options location_opts = CONFIG_LOCATION_OPTIONS_INIT; + struct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT; const char *comment_arg = NULL; int actions = 0; struct option opts[] = { @@ -1096,7 +1127,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) 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, + 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")), OPT_STRING(0, "comment", &comment_arg, N_("value"), N_("human-readable comment string (# will be prepended as needed)")), @@ -1114,7 +1145,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) PARSE_OPT_STOP_AT_NON_OPTION); location_options_init(&location_opts, prefix); - handle_nul(); + display_options_init(&display_opts); if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && type) { error(_("--get-color and variable type are incoherent")); @@ -1130,13 +1161,13 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) error(_("no action specified")); exit(129); } - if (omit_values && + if (display_opts.omit_values && !(actions == ACTION_LIST || actions == ACTION_GET_REGEXP)) { error(_("--name-only is only applicable to --list or --get-regexp")); exit(129); } - if (show_origin && !(actions & + if (display_opts.show_origin && !(actions & (ACTION_GET|ACTION_GET_ALL|ACTION_GET_REGEXP|ACTION_LIST))) { error(_("--show-origin is only applicable to --get, --get-all, " "--get-regexp, and --list")); @@ -1201,7 +1232,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) if (actions == ACTION_LIST) { check_argc(argc, 0, 0); - if (config_with_options(show_all_config, NULL, + if (config_with_options(show_all_config, &display_opts, &location_opts.source, the_repository, &location_opts.options) < 0) { if (location_opts.source.file) @@ -1250,23 +1281,23 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) } else if (actions == ACTION_GET) { check_argc(argc, 1, 2); - ret = get_value(&location_opts, argv[0], argv[1], flags); + ret = get_value(&location_opts, &display_opts, argv[0], argv[1], flags); } else if (actions == ACTION_GET_ALL) { do_all = 1; check_argc(argc, 1, 2); - ret = get_value(&location_opts, argv[0], argv[1], flags); + ret = get_value(&location_opts, &display_opts, argv[0], argv[1], flags); } else if (actions == ACTION_GET_REGEXP) { - show_keys = 1; + display_opts.show_keys = 1; use_key_regexp = 1; do_all = 1; check_argc(argc, 1, 2); - ret = get_value(&location_opts, argv[0], argv[1], flags); + ret = get_value(&location_opts, &display_opts, argv[0], argv[1], flags); } else if (actions == ACTION_GET_URLMATCH) { check_argc(argc, 2, 2); - ret = get_urlmatch(&location_opts, argv[0], argv[1]); + ret = get_urlmatch(&location_opts, &display_opts, argv[0], argv[1]); } else if (actions == ACTION_UNSET) { check_write(&location_opts.source); From patchwork Wed May 15 06:42:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664678 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 AA28445948 for ; Wed, 15 May 2024 06:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755351; cv=none; b=D4d2tH2zoMyASnJZGF7hj+VwCgI1uTowhSYSara1PHCuGh5qu9+Bpst1N96WGz5Ha8arNjT9ShkStd3tLrrruH+He+ghxVSSkQ80L1DWY9J7gSOpNFS1cBKFJbHN6GewQoPicZrN2qe/NN7Rb1e3apj29IattsI8wdw3GNXmSpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755351; c=relaxed/simple; bh=FUM7vffGEVbiD1yOzczlw2VZEdIDSJ/1UlOVBYSz+TI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hjFab6YfD9SmpjsxUtAI4C34gmB4rbBXl89FS1xU2f+80QculPnNUMa/bxccjJ48sXXXRdlNTYadQqOGIJrQMxo89HMykozld+6s1xmzNm26IQ70sP84g8r1ePvCCgqHPSllskDwoSKe2VogqdDr28/n+LWDYCmIteQjmv+gWZQ= 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=csF4SezW; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZSyJiY5S; arc=none smtp.client-ip=103.168.172.153 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="csF4SezW"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZSyJiY5S" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id F243311400AB; Wed, 15 May 2024 02:42:28 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 15 May 2024 02:42:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755348; x=1715841748; bh=UWwG16VCC3 PCZ1LBfhuNdGcDADG0aVkhl8jD+naDAAY=; b=csF4SezWaoy8EM0aHz6uKAe1dS kf/nS9WxEml5+GeSh/W/2H0EZYEFuGylxDqc0G+DXt8BsoIbqLf6LS79HByxKuY/ nPT0BLkuPcG4ThhHgHz/w7fHCxAjYng5VvS6UKv9yQ6D3cn1zz0ITEo1i5Ylslo+ UV8PiW/Prz3fcFFHy25Dtx0V3ncDMBPd5JQ/XyuuSAw5YGvFgV5smv7clrrHC8XX 17COvipFXZqTAKsEumbHkioSVsspfzGv59kfw3lW9DIffq1t6sBQTXT3kPxbI1JG h4CaT4S1ozcwbl9cOoLXFkola1l/YwR0AVyoFF4O55Svod5a8Hdqmco3rryw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755348; x=1715841748; bh=UWwG16VCC3PCZ1LBfhuNdGcDADG0 aVkhl8jD+naDAAY=; b=ZSyJiY5Sa4E6DkyNgw/zLlYbjNGraMQcfBUeEZdjFdHG NYsy2QC2R1uugOAZQnTC9BDLoCjYbBHruqaqezDxYFb8xfIn4sfZP57qxu4tsqZ1 V80OggNdO/dXNfi15kZpU2llH7eD+7CL1nQWvyq11vxscOcMrHzOQyJzYIPcE8OG g3g8ZAF0D+vdnzkqoazK7Mnv2M4TF6JZKmhdz6zjsu8dVGHEASSV9QQAoxsERadd r/qfrGn0qUmi8E/n/9mmDbOkOPvgqGsoQfAmtXjPMgiLHzR1iTYgIBxhXm07Qb7Q 23BRuWUyNI7b5xmg9gqMjcY6gXHGUD7ptHZxQVZjsw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddthecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:42:27 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id d5487d5c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:42:05 +0000 (UTC) Date: Wed, 15 May 2024 08:42:25 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 11/21] builtin/config: move type options into display options Message-ID: <5579371ad192ae4650e9598760df3350dca3b9c9.1715755055.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 1a67a6caef..ff111d83a9 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -82,13 +82,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; @@ -96,6 +107,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; @@ -114,8 +126,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; @@ -265,13 +275,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); @@ -279,24 +289,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; @@ -444,7 +454,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; @@ -789,16 +799,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; @@ -841,7 +841,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")), @@ -886,10 +885,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")), @@ -919,7 +918,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, @@ -1126,7 +1125,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")), @@ -1147,7 +1145,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); } @@ -1248,7 +1246,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" @@ -1257,7 +1255,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); @@ -1265,7 +1263,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, @@ -1274,7 +1272,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); From patchwork Wed May 15 06:42:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664679 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 3D2BC50A73 for ; Wed, 15 May 2024 06:42:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755356; cv=none; b=jHSTidWUyqF0Z/ydKcD2xfPSH90gcQsSCHDAtJqmRvHyTw6BBTWX+WTsPqs3j9GES2hfiNZYe6EjaOrpnsqqyBOvvM7x7GOVVH4pA4PhKnoKyosM0x7lWIKrCvFhzdEmbIzm6G8vnfxoW5Xjxp7Wu585II1PpBiTka4bbOq/cv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755356; c=relaxed/simple; bh=b3595SbwADJ9IkOeE4hWmm0DnUAmsevNdV7G7s8bcqw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=V2aY+8YzDUhXMz4WPlYqFlPqg+YusN4/hHow+zLvw29ofMgXbVqGRcyA3T73C5xUfZ+QObc+d27UPHWq++47BCsmtwse3g04Lonv27LpbP4g6aMbACTQsmTDRW90iWzxsbQNNji6MAQdcUt8mpCNt8QJYBBqpe584dfzvrcVMEI= 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=AGih56r6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gcy50OqC; arc=none smtp.client-ip=103.168.172.147 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="AGih56r6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gcy50OqC" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 476A51380222; Wed, 15 May 2024 02:42:34 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 15 May 2024 02:42:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755354; x=1715841754; bh=zefy4FTFRy nr1dyP2vvQzvFaOl1M0bcXawLuEEqm6O0=; b=AGih56r636yPeu8W8ttiBXZolk 051mWTvHbl9nugTqPZycFeTDVrft69jnXAG+SHkbz8W2PuQV1QPzbuHOiqm5Jhi9 UPU9+GmAOSKUqwe0u04Q3dZ5tg8aSiu/VtrqwEqfRy2erEiR5xSMSxwoUEyIBHM+ OFGzV+FvtZA7uKnKlMh/7tMBhOm7LGvhjvMqhsBCK8jqEfp1j4erTsJIlg11oFTr nM2tDFXd5LyL+bAe1Jdt/lUylmEvtyq8kbcp0j5/ZEvlPVkL9H6d3+zTR2qTLLjC Iv0nCUU+v9hE+PNlCTZ873ZQQnPTfSzSWbARtEsCAaSsmXgaykA8K2kugZHA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755354; x=1715841754; bh=zefy4FTFRynr1dyP2vvQzvFaOl1M 0bcXawLuEEqm6O0=; b=gcy50OqC6pqKog/XKw29WLqx8T67RiVPrrq3Q80g+IMe B9fRDb0VwQELIrKdbX3X/CHl3xHutF2qOg+bxLRw/a4R9khPajymFJ1sp9GpdYXR n+CFLCNca9EepP8a3mcyFHrHQhTBDpJgyKPkwwd2ZUErrkoiGBzsZOYD8Q78eutz euhGtjhxd8Jw91vpnSE/q2YPYiiTc2ASFB1yh6FyjcbBUOmvkzB5//Lol7+2Zuvx iLM3tUNq+kbXDisXqxCAd+NLm8ILQtFAm0410mkZIYjwYnHhlM1KoNJNwoO2cKtd 9+kWMAvto/VjxO+RfIye5qiu2GM3XsqAIVnMm2GiHA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddthecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:42:33 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 1f70ae88 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:42:10 +0000 (UTC) Date: Wed, 15 May 2024 08:42:30 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 12/21] builtin/config: move default value into display options Message-ID: <05a072d5d1b26c660f2467478fa75ba5373ac928.1715755055.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 default value is tracked via a global variable. Move it into the display options instead. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index ff111d83a9..8a327e770d 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -108,6 +108,7 @@ struct config_display_options { int show_scope; int show_keys; int type; + char *default_value; /* Populated via `display_options_init()`. */ int term; int delim; @@ -126,7 +127,6 @@ static regex_t *regexp; static int use_key_regexp; static int do_all; static int do_not_match; -static char *default_value; static int respect_includes_opt = -1; static int fixed_value; @@ -416,7 +416,7 @@ static int get_value(const struct config_location_options *opts, &opts->source, the_repository, &opts->options); - if (!values.nr && default_value) { + if (!values.nr && display_opts->default_value) { struct key_value_info kvi = KVI_INIT; struct strbuf *item; @@ -424,9 +424,10 @@ static int get_value(const struct config_location_options *opts, ALLOC_GROW(values.items, values.nr + 1, values.alloc); item = &values.items[values.nr++]; strbuf_init(item, 0); - if (format_config(display_opts, item, key_, default_value, &kvi) < 0) + if (format_config(display_opts, item, key_, + display_opts->default_value, &kvi) < 0) die(_("failed to format default config value: %s"), - default_value); + display_opts->default_value); } ret = !values.nr; @@ -850,7 +851,8 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) CONFIG_DISPLAY_OPTIONS(display_opts), OPT_GROUP(N_("Other")), OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), - OPT_STRING(0, "default", &default_value, N_("value"), N_("use default value when missing entry")), + OPT_STRING(0, "default", &display_opts.default_value, + N_("value"), N_("use default value when missing entry")), OPT_END(), }; int ret; @@ -861,7 +863,7 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern) die(_("--fixed-value only applies with 'value-pattern'")); - if (default_value && (do_all || url)) + if (display_opts.default_value && (do_all || url)) die(_("--default= cannot be used with --all or --url=")); if (url && (do_all || use_key_regexp || value_pattern)) 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) OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot []"), ACTION_GET_COLORBOOL), 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")), + OPT_STRING(0, "default", &display_opts.default_value, + N_("value"), N_("with --get, use default value when missing entry")), OPT_STRING(0, "comment", &comment_arg, N_("value"), N_("human-readable comment string (# will be prepended as needed)")), OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), 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) exit(129); } - if (default_value && !(actions & ACTION_GET)) { + if (display_opts.default_value && !(actions & ACTION_GET)) { error(_("--default is only applicable to --get")); exit(129); } From patchwork Wed May 15 06:42:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664680 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 5B6E13EA95 for ; Wed, 15 May 2024 06:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755360; cv=none; b=J9X8EXIaakn/bOHNbQ2UZDRyN/pOqjc1s5s0ow89014yRQ6+kpQMctPBNeL3td0uYD3BBPGzkIYaQkVhsjTrSvAq1Q1qUbE+JTd0RjtJKiJLzpstw+d0p0a0W5myVdAP/ZRgAdjCzMkzo3J6dsB6wrv3RDQqpulKglPfOZuzXNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755360; c=relaxed/simple; bh=Fef3VV9Xl6ZgF0Aj/2ts5PacsjR2n+9nLxKmawVd5Do=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FDQNL5n1b3j0yvz+o0JgT/+jNqi/Tg+lLSpE2dFTalRwVOhH+a8QvLA9TbGVwXF3QTsdR0z5BjLY/hgreiTy6U8B/PSG/3MoyME6R/qUgOWe9aunyZSiFzmAac5D596Rp/NtY1p04N6tXKHqs2tTjLo7Eth7DNmvN6U7gCL17Hg= 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=rfAdCwwB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=P2HgvY5p; arc=none smtp.client-ip=103.168.172.153 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="rfAdCwwB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="P2HgvY5p" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 9D3F611400AB; Wed, 15 May 2024 02:42:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 15 May 2024 02:42:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755358; x=1715841758; bh=tjf0GGkobq slKo9f90P1O9wJtLv2o7WYdiGgAOSPR2o=; b=rfAdCwwBJUBZ+G7mSR10VYLiDm 6RxSp54TWDq3gvKhLL5O1i10HTVfjvieNPSpWEfUVYosAuIqfuj5r/oNStyoQbu6 9iOjz6NsKg6Y68JpnXoNHfMzvoB0jqRoZK9fv6C9f/vqfCgUs7vs3JgAQlydMmKw N4ZXMDo+NQFUNqZoJ+Sn0stTfk88vFIZ2HOquJ5E1MLD/9fQ1ezWlq0H8ga80TlO I8I6/lm5U77UfxBHX0Mo0AW+IdXcPqFdeeFzijXoc5/sS0ddrm+aeKzqSJGsukj+ 2QVbHZm2bg+FqKTwwzVPuYBFrG3m/EHfg2HEgPPtP82L+okvHX3AhqXa7EhA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755358; x=1715841758; bh=tjf0GGkobqslKo9f90P1O9wJtLv2 o7WYdiGgAOSPR2o=; b=P2HgvY5pK9Bxw2Dj/PBnVhIzEHUDb+A9frRWphkVEjhH /9+7Q1UWDD/zyg+mVCF/pXBfTfy5zrl5xU034tHGinWCklvvuMkj/fgyBNPfMTwP i5kFU9wsv36SypKZ7ugI2lRtRUI7Knee6M/Qro2KMAWv5EWPlNt+vXiKwXQrQLEt JTeEnCgIBOFu+Cch6kIOcFimMGkhyktadbAFz2eE83xywL3Io/Ix6ptuptgTrtBj ALqzTtHe42A2GBpkuqvzZT7LCfqp7PPweZTZ/Behz3fP+G9ZwrIirkT0Ms1eHNt4 REsHHWglAy0kKgBwGwlv9UlmRaaf2FHtLk0SvcNHXQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:42:37 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 1be3ff23 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:42:14 +0000 (UTC) Date: Wed, 15 May 2024 08:42:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 13/21] builtin/config: move `respect_includes_opt` into location options Message-ID: <15d45ef7d42d49623577f9b856e3f791c9a65948.1715755055.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 variable tracking whether or not we want to honor includes is tracked via a global variable. Move it into the location options instead. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 8a327e770d..c54bdcbcdb 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -79,8 +79,11 @@ struct config_location_options { int use_system_config; int use_local_config; int use_worktree_config; + int respect_includes_opt; }; -#define CONFIG_LOCATION_OPTIONS_INIT {0} +#define CONFIG_LOCATION_OPTIONS_INIT { \ + .respect_includes_opt = -1, \ +} #define CONFIG_TYPE_OPTIONS(type) \ OPT_GROUP(N_("Type")), \ @@ -127,7 +130,6 @@ static regex_t *regexp; static int use_key_regexp; static int do_all; static int do_not_match; -static int respect_includes_opt = -1; static int fixed_value; #define TYPE_BOOL 1 @@ -776,10 +778,10 @@ static void location_options_init(struct config_location_options *opts, opts->source.scope = CONFIG_SCOPE_COMMAND; } - if (respect_includes_opt == -1) + if (opts->respect_includes_opt == -1) opts->options.respect_includes = !opts->source.file; else - opts->options.respect_includes = respect_includes_opt; + opts->options.respect_includes = opts->respect_includes_opt; if (startup_info->have_repository) { opts->options.commondir = get_git_common_dir(); opts->options.git_dir = get_git_dir(); @@ -808,7 +810,8 @@ static int cmd_config_list(int argc, const char **argv, const char *prefix) CONFIG_LOCATION_OPTIONS(location_opts), CONFIG_DISPLAY_OPTIONS(display_opts), OPT_GROUP(N_("Other")), - OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), + OPT_BOOL(0, "includes", &location_opts.respect_includes_opt, + N_("respect include directives on lookup")), OPT_END(), }; @@ -850,7 +853,8 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) OPT_STRING(0, "url", &url, N_("URL"), N_("show config matching the given URL")), CONFIG_DISPLAY_OPTIONS(display_opts), OPT_GROUP(N_("Other")), - OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), + OPT_BOOL(0, "includes", &location_opts.respect_includes_opt, + N_("respect include directives on lookup")), OPT_STRING(0, "default", &display_opts.default_value, N_("value"), N_("use default value when missing entry")), OPT_END(), @@ -1133,7 +1137,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) N_("value"), N_("with --get, use default value when missing entry")), OPT_STRING(0, "comment", &comment_arg, N_("value"), N_("human-readable comment string (# will be prepended as needed)")), OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), - OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), + OPT_BOOL(0, "includes", &location_opts.respect_includes_opt, + N_("respect include directives on lookup")), OPT_END(), }; char *value = NULL, *comment = NULL; From patchwork Wed May 15 06:42:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664681 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 D95DC3EA95 for ; Wed, 15 May 2024 06:42:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755365; cv=none; b=dbmte0Mc63GBOyYDfpr4ieEhQe23GLDQmlXAW1moMJRPlAGXOgD/N3k/rLiDHR1Yo9mkWTXIgCe7Ahct8G4ZSTTVCixS1eMmO1DejUHdwy97mSzrweLTkIgipoqWNjxAwBEPNGZDBRBG0utgtbHfgAwfq/06RTquvG6vB0tdtSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755365; c=relaxed/simple; bh=icuWIoML+DF1I7XwNnS+xm1k5XZYTtJYeAmTeOADAgU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JbwwkwOq1+3y/A3LrsaOqrEHzLiyWFBLuX63/egPqLlun5Nf86TH6rBqK2XtzWvo18gJ5hJSuAyImBHdEhi1ockH57dWlYpdf1WV8rtHPEKt+vHzd0IESlEH6ZGamH/IMNsfJ+A0SJbBICN1wY5pN2HPn4gTAQN9CrjX2Dd6b5c= 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=hs5JTgZQ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UsnU4m+T; arc=none smtp.client-ip=103.168.172.153 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="hs5JTgZQ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UsnU4m+T" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id F141211400AB; Wed, 15 May 2024 02:42:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 15 May 2024 02:42:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755362; x=1715841762; bh=3HeMrH7pxa 7qQSZmqYvSuKtTodIQjOsFgMpz7lWpOxg=; b=hs5JTgZQY/QA94KOtXWL6oCvhl aeQpFLNHsnRySHQ+ZgeJ0eHTYDiqqXWkUe9q4gJF675eUxX76sFivbgZyBmg6j8p +FfX2S9DEMNVWiy9zu9JJmsTFfi3N0DTSz69wwZRfFIKSwtuKwHK7pF3P1syqsLp XvXs4sduX9IK7YwP0g/H6hrlJIYHYgpP00UJdG5QZuciAe50NvBZKAPCE8hSR+4p zEbfvanx3U5grtNhP1yEyoI8lqMoPsWFXTFZ+WAjlx+Rn5naULYz4wkkJChpaxtU JVFrZ4iqAOcTk9ROEH2V/aqXPM/VglqRnAAbq12pAuweukoK9vXO7MNVtDZw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755362; x=1715841762; bh=3HeMrH7pxa7qQSZmqYvSuKtTodIQ jOsFgMpz7lWpOxg=; b=UsnU4m+TLKxhKZk3sBfg/U+d7sQlZUv8WLecZ24O7W9k EKQ6PThDMSnCfUxidT0YVFI6zGHcPVqNeoBqD8C3ixaGX/tAVsG6O7ZjOdxmUqUm dX9rOAOO/6MkLPtqAMgCabUvXsEjw17OZLpnHt+0IVZf1Kmy0u/94cVL3MWX7jJm FdA+6feN08iENtSpPLjR3TEqB31G28e6AE7TcBCYjwbyxf05/SocP05+dK/Q6vpg n2n6RwAzqbGgi/zKQlxcS3aWamx7kRVzSiUg2uidC2T92YxkZvx/hwiqXVHGTvXt 0gW1315VDKHb/GEMYNh84hYqN+PKm+o8I9mHJ2jpTw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:42:41 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c9248efa (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:42:19 +0000 (UTC) Date: Wed, 15 May 2024 08:42:39 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 14/21] builtin/config: convert `do_not_match` to a local variable Message-ID: 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 `do_not_match` variable is used by the `format_config()` callback as an indicator whether or not the passed regular expression is negated. 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 --- builtin/config.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index c54bdcbcdb..bc80fd293a 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -129,7 +129,6 @@ static const char *value_pattern; static regex_t *regexp; static int use_key_regexp; static int do_all; -static int do_not_match; static int fixed_value; #define TYPE_BOOL 1 @@ -328,6 +327,7 @@ static int format_config(const struct config_display_options *opts, struct collect_config_data { const struct config_display_options *display_opts; struct strbuf_list *values; + int do_not_match; }; static int collect_config(const char *key_, const char *value_, @@ -344,7 +344,7 @@ static int collect_config(const char *key_, const char *value_, if (fixed_value && strcmp(value_pattern, (value_?value_:""))) return 0; if (regexp != NULL && - (do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0))) + (data->do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0))) return 0; ALLOC_GROW(values->items, values->nr + 1, values->alloc); @@ -401,7 +401,7 @@ static int get_value(const struct config_location_options *opts, value_pattern = regex_; else if (regex_) { if (regex_[0] == '!') { - do_not_match = 1; + data.do_not_match = 1; regex_++; } From patchwork Wed May 15 06:42:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664682 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 36EEE55C3B for ; Wed, 15 May 2024 06:42:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755370; cv=none; b=DsYC7o/S5CcjALfTxNEYCp591LWu9EE0+9HohgPqFBqyifi/ScmhR98j+hQxft9NTPC3wIFotyBwfzwOwmpbm/sNQcvoTxQVw75Ud+MH/e85flw1yOsM0pIKLbZbQRqlPzaifpaSYm3+ICyL03/qsKyEc8LF7uX2rp96eWHRBB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755370; c=relaxed/simple; bh=zv0FlD7oM1OCX7SfQuqI4X4f1ZcodI9uxoJHsGdYV2E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nppcpAG1cGm3OvDym6dgaagAeT53yVag8ve6bT/Ol7wlF1DUjYqk0djCW4jtFHvjlZFsWO4dmWPoGB2Jhhq9NbcE0D5BUM44GiBjA+g2vtUR1WaABadcw39NJTlMjN4eLm0KJilNdptVOulGQpjeF5SxeWNRwYNYz5PmUDjyYQs= 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=TSypiw2G; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Fd0LxPjE; arc=none smtp.client-ip=103.168.172.147 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="TSypiw2G"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Fd0LxPjE" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 4E6711380259; Wed, 15 May 2024 02:42:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 15 May 2024 02:42:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755368; x=1715841768; bh=6VW1c3Hmwh 2zYDlJs7SCC7hvamWHieIHho9H1vAYVtM=; b=TSypiw2GzXCxxrZfXjWJCyzC3m EfajrM92JV1j/vflfEh3jS9cq8RVrfk3wXeh7eIf8D/1Z10cY1T2Xk8vlN3nipH/ 6DzIERGMdnBvWlaigTbjpsFg7IFH9HRHtyxyNSbwMhhscFp0WW7jDX6bm/OD2a6O u8ALfasZvyLhvAeFS82HGepu7toQWHu49xqcb5ZBn3vdbgoiO2PrrWKWJ9HnAmBF kFR1VTVXJuCsirYInzBGkpa2UrIjIwEdPBU73uTLoK4R0djH8AMAGF0v52yaLrEb JAkOU750/z/QP3rstwTresfiu7BXdAZRc7n9z5S0RVpaKgxoSw+csdQNUn7w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755368; x=1715841768; bh=6VW1c3Hmwh2zYDlJs7SCC7hvamWH ieIHho9H1vAYVtM=; b=Fd0LxPjEMqGuZc7OwW6N2cRzoa4rv95KIWuB9Bbj6k5A X/1D5mdLz6BISI/Q3zTnfrTotmm6I0QQ9aXMQtAjw+PuK/A0VBnU0u6bvGJB+W0F /EOJR5vPSK7B9fVbjE9OB3VwjH1TAeTQoeRhKWDVvtndiVOXo9JlLNTuqYENIkdJ Asq5OOK1x6CLadhd6JtVn+kr8k6Z4tcvwFSNt7Xsxv88FhlCWm+apdhb7HL39Wxn Zbx7rpZBH8vYcPGWIqzettCr7U4THrEmfraldkSP+K74BZ4TpeO9O94PsAe7TG2H 1PoLnaOA86MUhMiREMHwWaPmXugumK46E2EouwCivA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:42:47 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id af947207 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:42:24 +0000 (UTC) Date: Wed, 15 May 2024 08:42:44 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 15/21] builtin/config: convert `value_pattern` to a local variable Message-ID: <821bc68212a8c2a1dea4c72b2d1df5de63471177.1715755055.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 `value_pattern` variable is used by the `format_config()` callback when `CONFIG_FLAGS_FIXED_VALUE` is used. 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 --- builtin/config.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index bc80fd293a..aac5f7b976 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -125,7 +125,6 @@ struct config_display_options { static char *key; static regex_t *key_regexp; -static const char *value_pattern; static regex_t *regexp; static int use_key_regexp; static int do_all; @@ -327,6 +326,7 @@ static int format_config(const struct config_display_options *opts, struct collect_config_data { const struct config_display_options *display_opts; struct strbuf_list *values; + const char *value_pattern; int do_not_match; }; @@ -341,7 +341,7 @@ static int collect_config(const char *key_, const char *value_, return 0; if (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0)) return 0; - if (fixed_value && strcmp(value_pattern, (value_?value_:""))) + if (fixed_value && strcmp(data->value_pattern, (value_?value_:""))) return 0; if (regexp != NULL && (data->do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0))) @@ -398,7 +398,7 @@ static int get_value(const struct config_location_options *opts, } if (regex_ && (flags & CONFIG_FLAGS_FIXED_VALUE)) - value_pattern = regex_; + data.value_pattern = regex_; else if (regex_) { if (regex_[0] == '!') { data.do_not_match = 1; From patchwork Wed May 15 06:42:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664683 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 751C157C8A for ; Wed, 15 May 2024 06:42:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755374; cv=none; b=cS3YFxUb30BkonEnU0PM57kMSTF1MHUeH9kbQG98LLO3+GECN8K1h4HWHZvnEBm9coGuMlFhKsj8WGeCdhMbj2qOVGAftT7jXDK0h4D4AvTemgbQM0VoavaQ8oqWQPHbXlcMa+OiLIH5NWRCg8WQpSz2849uIonAGlA8l2sESg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755374; c=relaxed/simple; bh=Y+lF4DcQ6dYUz8LTRDQ+fWHuIoxRVUQNbz6c0qiXzzY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IbQsCw2iIxiDZCJoL8+KbznmAx4gARtyw4qOhlbiLqb89Tw/6WT+gtWpsiyaGfa4bgKDD9FBeGleIcT3omxdTAEJeOtTPuv1qAcA7ovc0KJ97BN19NZGkUzmy8OvUqphsJSfv9lCUHYBS9tbw9ubFvyYvpIAAUS9gbl9gGDvns0= 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=i49Kktl+; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fzRYp7rD; arc=none smtp.client-ip=103.168.172.147 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="i49Kktl+"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fzRYp7rD" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 9903E1380222; Wed, 15 May 2024 02:42:52 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 15 May 2024 02:42:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755372; x=1715841772; bh=LqrlEZvLZx dSKXRtElyRAzFnqaczGPdUJlfRy9qW1fg=; b=i49Kktl+8FPUjKMzOz1NKuqKsA g3IxodMsuHzpvSLGtHI0Nbi9tN2AUXpLetb6QlPrjclKw7lJRdTBNrCGRZO9onV0 pscEKTwH1OnXZj4LSK5K94rsH7SxntwlU8fqlzBTRCeK83S70AaPUXbZIPFtKYc6 kf3DgWUoO0ivZA8EQm7c71itoFWvXduA+sw1755L2FA2uPEz5tT1QHcDWOpQB8hf ASPHiB2p0+76j+iYSen4XShBVw8gvMyHlReqFwoGs3A0AS73/7uoE5uIb+0CnQfi BJGHRr/a//X9dYrzPgEN4RBOLbAHnlUyaVfuR9iX431OD/fJOOnydRgw738Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755372; x=1715841772; bh=LqrlEZvLZxdSKXRtElyRAzFnqacz GPdUJlfRy9qW1fg=; b=fzRYp7rD1K4XqpscjjWlp1OYtxK2vR2RDrANGw59FOHk nAJgNBj04VNbEkUiG3+h58R3JuXBMWAPJCsjnfnfaNWUBB4sVLCxQER5vJIkeGY9 4ODxY8XpP3OlOmb1AnptUYldStYNFfEIAt+I697OtvM7kw28SsRmgl1IPdxKjwfh ENLHvk9GIyCRsgrKf33RI20y++2MGse5FWEBBMRxHQxMwWMunDjp2O+oWGm1dufD H2kBTel5i0guj+YrCAGZjir1w2+6CCbNcUh6gR3w8auCRSmkNBRKsfv41xnCvvwh QubrWBqO+sBYPNCe3YPiEkth+b2S0Cgl/1aMqAXm7Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:42:51 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 1c82ca6f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:42:28 +0000 (UTC) Date: Wed, 15 May 2024 08:42:49 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 16/21] builtin/config: convert `regexp` to a local variable Message-ID: 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 `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 --- builtin/config.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index aac5f7b976..ae609c9b97 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -125,7 +125,6 @@ struct config_display_options { static char *key; static regex_t *key_regexp; -static regex_t *regexp; static int use_key_regexp; static int do_all; static int fixed_value; @@ -327,6 +326,7 @@ struct collect_config_data { const struct config_display_options *display_opts; struct strbuf_list *values; const char *value_pattern; + regex_t *regexp; int do_not_match; }; @@ -343,8 +343,8 @@ static int collect_config(const char *key_, const char *value_, return 0; if (fixed_value && strcmp(data->value_pattern, (value_?value_:""))) return 0; - if (regexp != NULL && - (data->do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0))) + if (data->regexp && + (data->do_not_match ^ !!regexec(data->regexp, (value_?value_:""), 0, NULL, 0))) return 0; ALLOC_GROW(values->items, values->nr + 1, values->alloc); @@ -405,10 +405,10 @@ static int get_value(const struct config_location_options *opts, regex_++; } - regexp = (regex_t*)xmalloc(sizeof(regex_t)); - if (regcomp(regexp, regex_, REG_EXTENDED)) { + data.regexp = (regex_t*)xmalloc(sizeof(regex_t)); + if (regcomp(data.regexp, regex_, REG_EXTENDED)) { error(_("invalid pattern: %s"), regex_); - FREE_AND_NULL(regexp); + FREE_AND_NULL(data.regexp); ret = CONFIG_INVALID_PATTERN; goto free_strings; } @@ -448,9 +448,9 @@ static int get_value(const struct config_location_options *opts, regfree(key_regexp); free(key_regexp); } - if (regexp) { - regfree(regexp); - free(regexp); + if (data.regexp) { + regfree(data.regexp); + free(data.regexp); } return ret; From patchwork Wed May 15 06:42:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664684 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 56C8D5914C for ; Wed, 15 May 2024 06:42:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755379; cv=none; b=bCyYObsiwvzYYLbWDdyhX3hyHc/RmaoPhsItw9kPF5QsCPaQxDrN+LHIH/ONc5R8JFJkKj+oHv9ZIuSfPpRSuKUiBPhwya63xr66QrNe1n9TES+FwAVyrRd6YS4h/Y4LMctX1DB6DCOWn3ERjvm4ZIwCnufgfn791+KsfZXUNVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755379; c=relaxed/simple; bh=levvc7MbXQTWxQE4h0zrAaE4RpymFNHvONCJ0MwLh/c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=M9bRKar82Zckzlzo6CPBOTmRTIyX4v7cfgLNgzDLMZNqYGOTrYryqQ9h/WC87EciluF7ou/ATxzYvslS+vbq5KM+qxC9UJKwmRBWaZxgaipVn4gC1g10R36iabn4OJWsd3xCKb7k7Z2/Y7Gxbb2CS8nWwOk2/jSwMUlKvYQmbTA= 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=ozjrn2BT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XeKIxdLz; arc=none smtp.client-ip=103.168.172.147 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="ozjrn2BT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XeKIxdLz" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 050321380222; Wed, 15 May 2024 02:42:56 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 15 May 2024 02:42:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755376; x=1715841776; bh=Paeo5Qwk14 ngxQ4fLXDBN+7fugWVbGJWD2oa+g6aLho=; b=ozjrn2BTNoomfqT8eG1MVHD5nF UsAoNVFase6x7r2UsurZe8R/LlxI5198OfVB8vg88H54iVDztRiKyvdFBq3dG8PH MwvqHOrg6mLzE5H3OOYanFn5YWgOgwXZr+L8Lm4wG1f/sSLDP4QCbar4YHpWyxcm y3NZJjjkydQT51Ql+9sn5Z2/3EdfrhfBS+HjYePZ78vl9anDy/4xUF31n1tD+PL7 5YN5G7crVXIVLlK05+1fQT1RcE486YPj+XIWsxrpKs/9MEJr0lNmKQmhXs/T0av5 sc8Vr/TX2r7RoJsnWPv/tWCOCMIwWdDXWkTRNygcIBoYPm68EjvauOB+jCjw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755376; x=1715841776; bh=Paeo5Qwk14ngxQ4fLXDBN+7fugWV bGJWD2oa+g6aLho=; b=XeKIxdLzACo4mlAesmiAAi/I+7R3ujZ25MFT6VrcmC9X PbJiXxcxrENQG1TpJ66ZcACMAGMB6VZ+f/egq8vf1imyVpdgNT5sc28DPPyaj7ZT IY4T3H92INDWSzW9S5b73tRjds16u/e73j9p58uZaANqgusEWd7dI3bRrzy31x8V 2FAK1MJbFxaziJTyLyxhmJgUAbKwuqM/rOOeRZvJezAhxAThF3C/jDqd/sGRZI/M 7m85NoNP8T8KRNZTiuE4bXnjumhTSGCFNJwtK/op2S5enN4mIHJOPGRqM41bRsqf iM1lnxUH2YiRpSPHYhPIJjedgjU8B13nzLiSY+Gmlw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:42:55 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id b6c608fc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:42:33 +0000 (UTC) Date: Wed, 15 May 2024 08:42:53 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 17/21] builtin/config: convert `key_regexp` to a local variable Message-ID: <746bdf873387090c80451cfc5e1950f737aea4f9.1715755055.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 `key_regexp` variable is used by the `format_config()` callback when `use_key_regexp` is 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 --- builtin/config.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index ae609c9b97..08a11b7999 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -124,7 +124,6 @@ struct config_display_options { } static char *key; -static regex_t *key_regexp; static int use_key_regexp; static int do_all; static int fixed_value; @@ -327,6 +326,7 @@ struct collect_config_data { struct strbuf_list *values; const char *value_pattern; regex_t *regexp; + regex_t *key_regexp; int do_not_match; }; @@ -339,7 +339,7 @@ static int collect_config(const char *key_, const char *value_, if (!use_key_regexp && strcmp(key_, key)) return 0; - if (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0)) + if (use_key_regexp && regexec(data->key_regexp, key_, 0, NULL, 0)) return 0; if (fixed_value && strcmp(data->value_pattern, (value_?value_:""))) return 0; @@ -383,10 +383,10 @@ static int get_value(const struct config_location_options *opts, for (tl = key; *tl && *tl != '.'; tl++) *tl = tolower(*tl); - key_regexp = (regex_t*)xmalloc(sizeof(regex_t)); - if (regcomp(key_regexp, key, REG_EXTENDED)) { + data.key_regexp = (regex_t*)xmalloc(sizeof(regex_t)); + if (regcomp(data.key_regexp, key, REG_EXTENDED)) { error(_("invalid key pattern: %s"), key_); - FREE_AND_NULL(key_regexp); + FREE_AND_NULL(data.key_regexp); ret = CONFIG_INVALID_PATTERN; goto free_strings; } @@ -444,9 +444,9 @@ static int get_value(const struct config_location_options *opts, free_strings: free(key); - if (key_regexp) { - regfree(key_regexp); - free(key_regexp); + if (data.key_regexp) { + regfree(data.key_regexp); + free(data.key_regexp); } if (data.regexp) { regfree(data.regexp); From patchwork Wed May 15 06:42:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664685 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 711D959173 for ; Wed, 15 May 2024 06:43:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755383; cv=none; b=Wd4EU/KRHj2ScZR5yKnMlfqNeYdFmYu/vmpPM/ioW6Z54VahNPgLSGEyU0vurdHYDiBzKrQWYBLNZ8Pz+/gU5y/vzaqD7BYhxuo7R3DA5IrxSJ2yRCX850z6xEwckFvan6kpUmSBAVTF6pPi/UhPdNP/+59RHgxi7zRb2HQAo80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755383; c=relaxed/simple; bh=GNZCMWsHEXP5R7EWjmiTLCPnJCH8lcO9H9Ii+Ofyq7M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IOwdftSO6oPQ+0HgcqJ1SfP3si5nMqJxEzZZ23cbMDXlzkG8PdLVvcZeg+oUBLDRfbsyoGK9LzyJExwFbZ/NWMv4e5ikhvb+79WeE/IvPIQBY/3pvjNw7/2pCXGJHWrbDC4b2y2TrZKtz2icLtSEYDiJVuVpGw2BoTjJL5xfeH0= 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=WLqQugv1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WIqqgZ4f; arc=none smtp.client-ip=103.168.172.153 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="WLqQugv1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WIqqgZ4f" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 9C23111400FB; Wed, 15 May 2024 02:43:01 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 15 May 2024 02:43:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755381; x=1715841781; bh=ZFTSiVVeAd UV6uzXIYHatnLJDfJpKYQqB/UJjSja5fs=; b=WLqQugv19ku9o6LUEWUHmrovyL jOTslSaSFIO+pepHojw2ff09a+7e+ezlORpBCwbk9RMZ7xa24YJBaledPDxcHZVG jYQPP95P+PDW/Z3foyfVQyb8ZJ53Q//zs5Orh9SksIxPvWQbLNNeMDyAzCtI4yXJ h/MDbUr9Px0aEgMOKuAdUhRqgukKba6UT6nGGcqiyzOgcE9yjIjaSHa/UTt42W2d qPqBK9wM8eluJqbKB8NsaqwtOjxHst9o9C5FrNEn5ZwpF6qzMQ9tlekPhNg40WgB ZUvimvI6DalbS1MvugJDWssdaEwpFbTibJZFkXI2Y4BYpLdR9iWoK18LhQUQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755381; x=1715841781; bh=ZFTSiVVeAdUV6uzXIYHatnLJDfJp KYQqB/UJjSja5fs=; b=WIqqgZ4fcfLoJmwrsTIH+rDC/+9TeqEkbGQr3WJA2m0J QXmR9Y0le8LNcE7KLo37M/of8CpZRNInzIHtCIn2iYNvOqjK2Y/qsOhZ/epp6YU8 FM6z1zQKWKRzgDfERYuDrpfAfmdZFUahsT9spYH25w6Ng2ACDSe7x9C6ax6DeawZ v/R3cJdr73xxcUTRDWyob32rX9b6ZZVgflmgsqeEeu+qwZ6fXJGQJJCb0jXuwnLA ktoWnVh2V3MzFBGKKbWkW1ywplCQ8wuZlcCLaAlYaeS2tIC4PRv9COWlfd6vmz35 Wyq8exaGjSp8Ydn+xBkxHLPgk3uA7Sy04Q0yHrIEhQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:43:00 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ebf90b73 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:42:38 +0000 (UTC) Date: Wed, 15 May 2024 08:42:58 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 18/21] builtin/config: convert `key` to a local variable Message-ID: 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 `key` variable is used by the `get_value()` function for two purposes: - It is used to store the result of `git_config_parse_key()`, which is then passed on to `collect_config()`. - It is used as a store to convert the provided key to an all-lowercase key when `use_key_regexp` is set. Neither of these cases warrant a global variable at all. In the former case we can pass the key via `struct collect_config_data`. And in the latter case we really only want to have it as a temporary local variable such that we can free associated memory. Refactor the code accordingly to reduce our reliance on global state. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 08a11b7999..5a03dbb452 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -123,7 +123,6 @@ struct config_display_options { .key_delim = ' ', \ } -static char *key; static int use_key_regexp; static int do_all; static int fixed_value; @@ -325,6 +324,7 @@ struct collect_config_data { const struct config_display_options *display_opts; struct strbuf_list *values; const char *value_pattern; + const char *key; regex_t *regexp; regex_t *key_regexp; int do_not_match; @@ -337,7 +337,7 @@ static int collect_config(const char *key_, const char *value_, struct strbuf_list *values = data->values; const struct key_value_info *kvi = ctx->kvi; - if (!use_key_regexp && strcmp(key_, key)) + if (!use_key_regexp && strcmp(key_, data->key)) return 0; if (use_key_regexp && regexec(data->key_regexp, key_, 0, NULL, 0)) return 0; @@ -364,6 +364,7 @@ static int get_value(const struct config_location_options *opts, .display_opts = display_opts, .values = &values, }; + char *key = NULL; int i; if (use_key_regexp) { @@ -395,6 +396,8 @@ static int get_value(const struct config_location_options *opts, ret = CONFIG_INVALID_KEY; goto free_strings; } + + data.key = key; } if (regex_ && (flags & CONFIG_FLAGS_FIXED_VALUE)) From patchwork Wed May 15 06:43:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664686 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 C52E73EA95 for ; Wed, 15 May 2024 06:43:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755389; cv=none; b=tbI0k8+DUPM/rCKQqxQ5USbO6Rx7r2dwl8dA0heuhwFhIST/tOoOcWf8ttsvFDZ1HGSf2SKNmdxfQ225B7xLGD2Z5QtDOk4E4qsClIQvGseUeYlC5h29HZPdje5QBbSFvOUXutkGpvG2wvHPGHbb9TzXjoRGPfFycqdKgy9FSAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755389; c=relaxed/simple; bh=ewZi5KBZTD8S4VAHr9PxeM9soG2cyNCqjJ59rJ8RvcQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=laB074RbAAer38RhIA7CSqbPh4TxbO2rcjNwPi+efFyVZnSlw0WNEncvNtUrqutiLIuAbDznqdKFDfO2q3d6cSd7R7NOO+nolkVYpOertCSMPGQRjx8i8/bKQOCzDykl1edU/3yNg6LQCsgTHz7fpU9ndhW0fhQW/eVuXddU6LE= 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=oa7AaZJe; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Vrsl13R4; arc=none smtp.client-ip=103.168.172.153 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="oa7AaZJe"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Vrsl13R4" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E8DE511400AB; Wed, 15 May 2024 02:43:06 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 15 May 2024 02:43:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755386; x=1715841786; bh=qr9yLRRohJ Z+o4hKxoFTNIqvGUizuD4zV7LinwpCOVU=; b=oa7AaZJecj89Fnm3cZUtdWI0de zhjqibmmph0aBM43Wh/E0lJDSIkWpo93hMTNOTeoG4Bifyg5ToBp4gGRPH20vD8u RzHaUQLHANuw49JXYvaba1pWd/Wk8/0XPkwePAQkSmL4cfTcitvQ+k12ubHL/QQ1 fblJhD1MPGN7MGo2t6BSMvdkCQLVZ8lZd0zcEAXGO2DxuDSET1G7V0I5rLXHb6W0 j6zXCTeyyRfQqxYEaAatY7s+kDg520OOHxqqIi+nAveT8bPGzbuSDpqBBSLNgpgQ ihzdWHoDfNELLqHXrLcb0Wn5pvfayO/nHUXzKMiV2QAGIMkjWN1UwkMoqb3Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755386; x=1715841786; bh=qr9yLRRohJZ+o4hKxoFTNIqvGUiz uD4zV7LinwpCOVU=; b=Vrsl13R4I1324+iIJpuIlqewfy/PKZ2B3LEEvQqySX7Z ihLaxxj1Risclildg7JZliP5QfaQM0pajpIaeJkosi/PTFHaXwCkS0rdBnVvT4cd dJulJBVfJLqsDNcMN96ObTodUfil7z6p8lPY8dzVhFQ47yS1sulLUgjVlqP42x9S Er/jp/l/c1vCHoTnfPVKfYLAcIyQHV1LyG+YoTpLF3fLeRouA+bEssyuU5nIUnzr iqE5p4oyCINCVarOYXrK3OLphyPtPHxey7IqeXsOSCk58S7w2DGwc1nMLEOCezVD +Ml9z77gdAvkMOo4hpMJEOfwES08JD825nimLzvrqg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddthecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:43:05 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 741fb314 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:42:42 +0000 (UTC) Date: Wed, 15 May 2024 08:43:02 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 19/21] builtin/config: track "fixed value" option via flags only Message-ID: 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: 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 --- builtin/config.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 5a03dbb452..1f673ebee7 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -125,7 +125,6 @@ struct config_display_options { static int use_key_regexp; static int do_all; -static int fixed_value; #define TYPE_BOOL 1 #define TYPE_INT 2 @@ -328,6 +327,7 @@ struct collect_config_data { regex_t *regexp; regex_t *key_regexp; int do_not_match; + unsigned flags; }; static int collect_config(const char *key_, const char *value_, @@ -341,7 +341,8 @@ static int collect_config(const char *key_, const char *value_, return 0; if (use_key_regexp && regexec(data->key_regexp, key_, 0, NULL, 0)) return 0; - if (fixed_value && strcmp(data->value_pattern, (value_?value_:""))) + if ((data->flags & CONFIG_FLAGS_FIXED_VALUE) && + strcmp(data->value_pattern, (value_?value_:""))) return 0; if (data->regexp && (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, struct collect_config_data data = { .display_opts = display_opts, .values = &values, + .flags = flags, }; char *key = NULL; int i; @@ -1117,6 +1119,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) struct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT; const char *comment_arg = NULL; int actions = 0; + unsigned flags = 0; struct option opts[] = { CONFIG_LOCATION_OPTIONS(location_opts), OPT_GROUP(N_("Action")), @@ -1139,13 +1142,12 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) OPT_STRING(0, "default", &display_opts.default_value, N_("value"), N_("with --get, use default value when missing entry")), OPT_STRING(0, "comment", &comment_arg, N_("value"), N_("human-readable comment string (# will be prepended as needed)")), - OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), + OPT_BIT(0, "fixed-value", &flags, N_("use string equality when comparing values to value pattern"), CONFIG_FLAGS_FIXED_VALUE), OPT_BOOL(0, "includes", &location_opts.respect_includes_opt, N_("respect include directives on lookup")), OPT_END(), }; char *value = NULL, *comment = NULL; - int flags = 0; int ret = 0; struct key_value_info default_kvi = KVI_INIT; @@ -1195,7 +1197,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) } /* check usage of --fixed-value */ - if (fixed_value) { + if (flags & CONFIG_FLAGS_FIXED_VALUE) { int allowed_usage = 0; switch (actions) { @@ -1226,8 +1228,6 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) error(_("--fixed-value only applies with 'value-pattern'")); exit(129); } - - flags |= CONFIG_FLAGS_FIXED_VALUE; } comment = git_config_prepare_comment_string(comment_arg); From patchwork Wed May 15 06:43:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664687 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 3FA0E3EA95 for ; Wed, 15 May 2024 06:43:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755393; cv=none; b=LCicTcWTGbm4HUwxYTETxMXMIotOBBKBS+dpdWdyMfWPQegmNyCS8AOokYm4V3cTHyUpJvS8Rk1J2/k5Et6XzOsHBlcPe52ZeDBYBbJ80WhJBNsYKEVXfdOKg105VDPVZLEXU9bl5jejCEXrGga3Oo7cwLw/XQpNb5/mWwB2nBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755393; c=relaxed/simple; bh=emfVNH2tKq/io4fmDeGffolV6SWlFqrnkOh6sM4i4ic=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z03iF2uQvx4XudB/X4tBPoszHq0ku4kL2oHEj+EilBrBokuRAK2fCTuPjDmdVLkKGEdIwKKCXQHfhpfuKtineFr0oZBf/plLRMAGMJg0HNbUJE7WW6Zfbwavpa241IGOedB0mW+vMRFNznzgu3UFyp0Fx9Mo8l5zJxmYgD3JgqI= 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=YddoOhpP; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gAyb338Y; arc=none smtp.client-ip=103.168.172.147 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="YddoOhpP"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gAyb338Y" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 630221380222; Wed, 15 May 2024 02:43:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 15 May 2024 02:43:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755391; x=1715841791; bh=epVOIppQiI ZrvimJ6QRFmeZ0bCLfBkE3ym5VA+NGWsw=; b=YddoOhpPp7P4zH7bOWCGUPPV+K O448YueO05ZrzTpqtpekr7739TpRXlVG8suYS5yKDpbjewCTp50dzwYb/Z+xNSwL YMon3M1yy1narKv9jmshIDSeS3MdndCn/p0qZ+rVP/8g9gb24bgdYBBaUPqUOXMz BaP1vzB1/uaH6WnB178aamTNCrUWvn2Nq2tjiq0P4MRtcRW/fIm8NrsK6gEd/K5R uXKnBqn0Uu3eZxjhYfwdaaOFdxuCia1mg6hlX4fM9NqgIYxwQq8kJscEL5zVt9+8 YnIX8frGmuF5OjNlJzkZ4Nc41ooOz1tOd+BCSK8m6XIDiH4hAz1+IAzIuAdQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755391; x=1715841791; bh=epVOIppQiIZrvimJ6QRFmeZ0bCLf BkE3ym5VA+NGWsw=; b=gAyb338YQ1osLJfuUjZIDoRrPFRLMpQhX14Q/LZnyIWn A+AcoEwExEtyM2rOC6cvZFi6hNQizxPfH76B6ixul8jpN8RtD/Wx4F08whns5MpX 3omTkJDZf9jh2VBYSPXh0i47k2ZMT9BIEyzpsgV2NOKpRY1Bpkd+nwWmQk3u1voy /N994HXcdYk2834E/S/rjMcXJ1O3HyAtG7mXT0svGtqSsfIFOdlWCh2rtV5WuPzo 08dCMjTGSOhPRjuyC0PNXl8JDWF7rUTUnY6kIyLnOzyB2lBxYgzCm/Jxpgd11i09 m4shOa/uWdKdHP4kxJ1BWG6zmNv0ZudTeELZ1SsO0A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpeehnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:43:10 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 783bd70d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:42:47 +0000 (UTC) Date: Wed, 15 May 2024 08:43:07 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 20/21] builtin/config: convert flags to a local variable Message-ID: 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: Both the `do_all` and `use_key_regexp` bits essentially act like flags to `get_value()`. Let's convert them to actual flags so that we can get rid of the last two remaining global variables that track options. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 1f673ebee7..3b588df8cf 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -123,9 +123,6 @@ struct config_display_options { .key_delim = ' ', \ } -static int use_key_regexp; -static int do_all; - #define TYPE_BOOL 1 #define TYPE_INT 2 #define TYPE_BOOL_OR_INT 3 @@ -319,6 +316,9 @@ static int format_config(const struct config_display_options *opts, return 0; } +#define GET_VALUE_ALL (1 << 0) +#define GET_VALUE_KEY_REGEXP (1 << 1) + struct collect_config_data { const struct config_display_options *display_opts; struct strbuf_list *values; @@ -327,6 +327,7 @@ struct collect_config_data { regex_t *regexp; regex_t *key_regexp; int do_not_match; + unsigned get_value_flags; unsigned flags; }; @@ -337,9 +338,11 @@ static int collect_config(const char *key_, const char *value_, struct strbuf_list *values = data->values; const struct key_value_info *kvi = ctx->kvi; - if (!use_key_regexp && strcmp(key_, data->key)) + if (!(data->get_value_flags & GET_VALUE_KEY_REGEXP) && + strcmp(key_, data->key)) return 0; - if (use_key_regexp && regexec(data->key_regexp, key_, 0, NULL, 0)) + if ((data->get_value_flags & GET_VALUE_KEY_REGEXP) && + regexec(data->key_regexp, key_, 0, NULL, 0)) return 0; if ((data->flags & CONFIG_FLAGS_FIXED_VALUE) && strcmp(data->value_pattern, (value_?value_:""))) @@ -357,19 +360,21 @@ static int collect_config(const char *key_, const char *value_, static int get_value(const struct config_location_options *opts, const struct config_display_options *display_opts, - const char *key_, const char *regex_, unsigned flags) + const char *key_, const char *regex_, + unsigned get_value_flags, unsigned flags) { int ret = CONFIG_GENERIC_ERROR; struct strbuf_list values = {NULL}; struct collect_config_data data = { .display_opts = display_opts, .values = &values, + .get_value_flags = get_value_flags, .flags = flags, }; char *key = NULL; int i; - if (use_key_regexp) { + if (get_value_flags & GET_VALUE_KEY_REGEXP) { char *tl; /* @@ -441,7 +446,7 @@ static int get_value(const struct config_location_options *opts, for (i = 0; i < values.nr; i++) { struct strbuf *buf = values.items + i; - if (do_all || i == values.nr - 1) + if ((get_value_flags & GET_VALUE_ALL) || i == values.nr - 1) fwrite(buf->buf, 1, buf->len, stdout); strbuf_release(buf); } @@ -848,11 +853,12 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) struct config_display_options display_opts = CONFIG_DISPLAY_OPTIONS_INIT; const char *value_pattern = NULL, *url = NULL; int flags = 0; + unsigned get_value_flags = 0; struct option opts[] = { CONFIG_LOCATION_OPTIONS(location_opts), 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")), + OPT_BIT(0, "all", &get_value_flags, N_("return all values for multi-valued config options"), GET_VALUE_ALL), + OPT_BIT(0, "regexp", &get_value_flags, N_("interpret the name as a regular expression"), GET_VALUE_KEY_REGEXP), OPT_STRING(0, "value", &value_pattern, N_("pattern"), N_("show config with values matching the pattern")), OPT_BIT(0, "fixed-value", &flags, N_("use string equality when comparing values to value pattern"), CONFIG_FLAGS_FIXED_VALUE), OPT_STRING(0, "url", &url, N_("URL"), N_("show config matching the given URL")), @@ -872,9 +878,12 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern) die(_("--fixed-value only applies with 'value-pattern'")); - if (display_opts.default_value && (do_all || url)) + if (display_opts.default_value && + ((get_value_flags & GET_VALUE_ALL) || url)) die(_("--default= cannot be used with --all or --url=")); - if (url && (do_all || use_key_regexp || value_pattern)) + if (url && ((get_value_flags & GET_VALUE_ALL) || + (get_value_flags & GET_VALUE_KEY_REGEXP) || + value_pattern)) die(_("--url= cannot be used with --all, --regexp or --value")); location_options_init(&location_opts, prefix); @@ -885,7 +894,8 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix) if (url) ret = get_urlmatch(&location_opts, &display_opts, argv[0], url); else - ret = get_value(&location_opts, &display_opts, argv[0], value_pattern, flags); + ret = get_value(&location_opts, &display_opts, argv[0], value_pattern, + get_value_flags, flags); location_options_release(&location_opts); return ret; @@ -1290,19 +1300,19 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) } else if (actions == ACTION_GET) { check_argc(argc, 1, 2); - ret = get_value(&location_opts, &display_opts, argv[0], argv[1], flags); + ret = get_value(&location_opts, &display_opts, argv[0], argv[1], + 0, flags); } else if (actions == ACTION_GET_ALL) { - do_all = 1; check_argc(argc, 1, 2); - ret = get_value(&location_opts, &display_opts, argv[0], argv[1], flags); + ret = get_value(&location_opts, &display_opts, argv[0], argv[1], + GET_VALUE_ALL, flags); } else if (actions == ACTION_GET_REGEXP) { display_opts.show_keys = 1; - use_key_regexp = 1; - do_all = 1; check_argc(argc, 1, 2); - ret = get_value(&location_opts, &display_opts, argv[0], argv[1], flags); + ret = get_value(&location_opts, &display_opts, argv[0], argv[1], + GET_VALUE_ALL|GET_VALUE_KEY_REGEXP, flags); } else if (actions == ACTION_GET_URLMATCH) { check_argc(argc, 2, 2); From patchwork Wed May 15 06:43:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664688 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 7308D4879B for ; Wed, 15 May 2024 06:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755397; cv=none; b=aiV/lkTj1KvJOVIEl2ZJ4sVHkkMBPdNH+YYiZZM6BfQRz+7ZNBTbNxpH8k+WuPymDBsggX2LTwmT6HDaY3Lf9yvOZTXYcqwi35Kck0xq06cfkchrc202Up1xELnSa6DF10205M1fpgmCU0Rpp0FU71QM035CQ2QvBXxwFX1uTys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755397; c=relaxed/simple; bh=YLCGG69oNerK5GkXKbJZfxJSRZzjHz3wXtJJdJKieAY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GGtc9KXDbD2n/rGtxRljMNLXQtMj55u1DY5mNq2JlCuR6x2uH3lt9STyv9Wqo6be7T8yKck52SVM1GO6ZNK2P7RmbRXuzpqcjcQwlyDXgrwi5j3X78zVu82zO/alWgnn8y+0O0vd/8CCa7ELgeQCy3mh5ilRKYR6ePyh0nql9Hk= 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=M/TIi2I9; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Vfv4cNp6; arc=none smtp.client-ip=103.168.172.147 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="M/TIi2I9"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Vfv4cNp6" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id B8FD01380278; Wed, 15 May 2024 02:43:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Wed, 15 May 2024 02:43:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1715755395; x=1715841795; bh=zXlaXT/CdV jpQpkSPamKGNLknER9KmW1aAHklEknXSs=; b=M/TIi2I9LFpzIy8XRKOsBu5SiP qUWNqUhNwsqw80cOvylOGtwIbTiOmy+/Z0HrG6izXQPqEglKJREtaDwnFp+mZ2qT 5xMJ9bxx9FsnJchqd0VeYCo57t/FqQI1EnwGzdPos3OJBKbJ7TFTgSkTZRgYPr93 By8F9jwuypGcE85FZUmblgKUazY64hsTbf4kvFnXE9sY9CF0/cSc3xOSEfBFt1Qj /b1Ek1tGkZFBmnETqN5YJTLtMVAuse/Xsfm1EnSHfZvdjBAQk1mSX55mLDz8iIYl OBvN1/nKkCJIlZW0ljSM7a/1du1qHTN+SHp+koZFIpMyIDEqhH0/kH45UxNw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1715755395; x=1715841795; bh=zXlaXT/CdVjpQpkSPamKGNLknER9 KmW1aAHklEknXSs=; b=Vfv4cNp68r/UhJ7CRoifMu4wk71jYiGOTYnklG5ujrxP ac4p2ryj8x/92Tl9HpUgCiV4L4iKEJaKgDfJveICERe3uJjYqH3cmO8LvBfMZrf2 yMkCOqPBZmFzH3lhc5+4AyGGZR8wpb0CgQfb6/BZsT34r5qgTR9vOqPaxtG+NLmr ciTgSDm8BKqMDGtQp5Id/oR2yX+CNDXNqssheLYCBoRa1VMukvsTMLvoNoEu2LIx /9i1atZgC807qVjR/jGq3EWhtj8Jalp5FiorZVF3w2dCdvmbyvPrVNu3JTvxbbUQ eDj3rznOSPDE6sIS9lG2NdLW2gUgGVMcOJicettIwA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:43:14 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 8c1f9035 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:42:51 +0000 (UTC) Date: Wed, 15 May 2024 08:43:12 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Kyle Lippincott , Eric Sunshine Subject: [PATCH v3 21/21] builtin/config: pass data between callbacks via local variables Message-ID: 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: We use several global variables to pass data between callers and callbacks in `get_color()` and `get_colorbool()`. Convert those to use callback data structures instead. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 90 ++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 38 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 3b588df8cf..c38264c999 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -518,21 +518,24 @@ static char *normalize_value(const char *key, const char *value, BUG("cannot normalize type %d", type); } -static int get_color_found; -static const char *get_color_slot; -static const char *get_colorbool_slot; -static char parsed_color[COLOR_MAXLEN]; +struct get_color_config_data { + int get_color_found; + const char *get_color_slot; + char parsed_color[COLOR_MAXLEN]; +}; static int git_get_color_config(const char *var, const char *value, const struct config_context *ctx UNUSED, - void *cb UNUSED) + void *cb) { - if (!strcmp(var, get_color_slot)) { + struct get_color_config_data *data = cb; + + if (!strcmp(var, data->get_color_slot)) { if (!value) config_error_nonbool(var); - if (color_parse(value, parsed_color) < 0) + if (color_parse(value, data->parsed_color) < 0) return -1; - get_color_found = 1; + data->get_color_found = 1; } return 0; } @@ -540,66 +543,77 @@ static int git_get_color_config(const char *var, const char *value, static void get_color(const struct config_location_options *opts, const char *var, const char *def_color) { - get_color_slot = var; - get_color_found = 0; - parsed_color[0] = '\0'; - config_with_options(git_get_color_config, NULL, + struct get_color_config_data data = { + .get_color_slot = var, + .parsed_color[0] = '\0', + }; + + config_with_options(git_get_color_config, &data, &opts->source, the_repository, &opts->options); - if (!get_color_found && def_color) { - if (color_parse(def_color, parsed_color) < 0) + if (!data.get_color_found && def_color) { + if (color_parse(def_color, data.parsed_color) < 0) die(_("unable to parse default color value")); } - fputs(parsed_color, stdout); + fputs(data.parsed_color, stdout); } -static int get_colorbool_found; -static int get_diff_color_found; -static int get_color_ui_found; +struct get_colorbool_config_data { + int get_colorbool_found; + int get_diff_color_found; + int get_color_ui_found; + const char *get_colorbool_slot; +}; + static int git_get_colorbool_config(const char *var, const char *value, const struct config_context *ctx UNUSED, - void *data UNUSED) + void *cb) { - if (!strcmp(var, get_colorbool_slot)) - get_colorbool_found = git_config_colorbool(var, value); + struct get_colorbool_config_data *data = cb; + + if (!strcmp(var, data->get_colorbool_slot)) + data->get_colorbool_found = git_config_colorbool(var, value); else if (!strcmp(var, "diff.color")) - get_diff_color_found = git_config_colorbool(var, value); + data->get_diff_color_found = git_config_colorbool(var, value); else if (!strcmp(var, "color.ui")) - get_color_ui_found = git_config_colorbool(var, value); + data->get_color_ui_found = git_config_colorbool(var, value); return 0; } static int get_colorbool(const struct config_location_options *opts, const char *var, int print) { - get_colorbool_slot = var; - get_colorbool_found = -1; - get_diff_color_found = -1; - get_color_ui_found = -1; - config_with_options(git_get_colorbool_config, NULL, + struct get_colorbool_config_data data = { + .get_colorbool_slot = var, + .get_colorbool_found = -1, + .get_diff_color_found = -1, + .get_color_ui_found = -1, + }; + + config_with_options(git_get_colorbool_config, &data, &opts->source, the_repository, &opts->options); - if (get_colorbool_found < 0) { - if (!strcmp(get_colorbool_slot, "color.diff")) - get_colorbool_found = get_diff_color_found; - if (get_colorbool_found < 0) - get_colorbool_found = get_color_ui_found; + if (data.get_colorbool_found < 0) { + if (!strcmp(data.get_colorbool_slot, "color.diff")) + data.get_colorbool_found = data.get_diff_color_found; + if (data.get_colorbool_found < 0) + data.get_colorbool_found = data.get_color_ui_found; } - if (get_colorbool_found < 0) + if (data.get_colorbool_found < 0) /* default value if none found in config */ - get_colorbool_found = GIT_COLOR_AUTO; + data.get_colorbool_found = GIT_COLOR_AUTO; - get_colorbool_found = want_color(get_colorbool_found); + data.get_colorbool_found = want_color(data.get_colorbool_found); if (print) { - printf("%s\n", get_colorbool_found ? "true" : "false"); + printf("%s\n", data.get_colorbool_found ? "true" : "false"); return 0; } else - return get_colorbool_found ? 0 : 1; + return data.get_colorbool_found ? 0 : 1; } static void check_write(const struct git_config_source *source)