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); }