From patchwork Fri May 10 11:24:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13661369 Received: from wfhigh2-smtp.messagingengine.com (wfhigh2-smtp.messagingengine.com [64.147.123.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 C9E49170897 for ; Fri, 10 May 2024 11:24:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340283; cv=none; b=PIiFNzjFxL4DqLyyIMBm8plLf0qeLT1WA9xkfIA61kDLJ5EOC3tEscbL7bb93H+4qegCk19wi5ScJz3ZqpBHi2p+H+Y9Lg7v2GBPwI/eBuhtWIe1RDw8rNpriPi9YXVPfLVXG+lQ/qIRuDKe5BseSI3Na+g01sosKXeIfULhelc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340283; c=relaxed/simple; bh=34umLqZHvQA3rdsIHYdM/Ra1sku3O73VV/85C1NSKtI=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bF96v/mjDJCsLEjGbHgqOQDuS+zxXIfsxPsJkvOQmkcCvo12xvTr1vunyEgv0zi7/DkCqyNCBKvwG0LUeTvtCYv1zhBhzylK2R2vECS4rNvHrOgQ5KLYPTwX7kEZOucPYBD6CHHyzj1VGc49ZQbvPTX0oI9oJxmm/Nwa24T8++0= 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=NuRQdEXE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bSTCYDQT; arc=none smtp.client-ip=64.147.123.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="NuRQdEXE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bSTCYDQT" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id 01EEC180012E for ; Fri, 10 May 2024 07:24:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 10 May 2024 07:24:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715340280; x=1715426680; bh=jEeCMaeqQk jdJD1wuMS1u5hX3B5hi1xwp0M7j1qNc88=; b=NuRQdEXEX8igcAQwsi1ijJxW0q zg6/Xv5x17TQOAW9TalF7yhACpeMmCNOmGpNRbdgZsEDwOXmC3HeszP1vFDws3wh CWZezKfJY8g6+nGF7E6Fm2irLZplpGso33DI6ax7pRKj9Afr36LZPtJhYJev7Acg 0qC5oPqTBG9c5IMdOoywQ/Q2IWEoZamGoBo4UeaGQ4PRAf0vxOWl2cdrYwJztOF4 GQTK4SAJFeLOgmtgloAnJWeGgQYbf0HOWhf2ZYe2pJSplMFnwEPqp/yTvQmN2WV7 mAyqT/Qcz1HsQi3QODe4NpJLrXmEmPiEZtHK2J0Rai/woORuqG9eJ9jqhQow== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715340280; x=1715426680; bh=jEeCMaeqQkjdJD1wuMS1u5hX3B5h i1xwp0M7j1qNc88=; b=bSTCYDQT3nvRZIO+EMmMPrXRlco1QoENtVWD4c2ED1ec gnLWaGNY1aKMdDRuQRCLEH8ZOw5LtPRXKBVP9KG8RgGVBcKuGOthXG8dHl6qtVQM YmTd4p50OeRtGTNF0foEDdr5QnuFQ0T2egrBdTJ+BmjomA/hxUDtOEgUwEifpvWs YC3MBGoUM4WpTZKR29EpJ8K9OqYCIeSF7m2NJoDEOU6AutEhM77pBrlICBI9hk3/ Ngp/G0xOpue7z05ZLpIR6u4seiSdOjCUSwtPXIyydR4wgqhTJ9FzaqizYu064uhB WodaoNwQUNrotICarmRAdn96seUc0qOOsjTdGwTETw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgfeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 10 May 2024 07:24:39 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 4a7ba4e3 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 10 May 2024 11:24:27 +0000 (UTC) Date: Fri, 10 May 2024 13:24:37 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 03/21] builtin/config: move subcommand options into `cmd_config()` Message-ID: <1239c151d08448f5782cdd12c5cf10fd5d2719d4.1715339393.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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); }