From patchwork Fri May 10 11:24:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13661367 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 BBCC3165FB6 for ; Fri, 10 May 2024 11:24:32 +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=1715340274; cv=none; b=Zsc6ZZsZfLRSYC3HT2d9jKrH//NiLfMCef40ylKiQrgqSUHjY9OT/qNgf0uihi3SwBSbrSIV1juQmefCVAXTzaBRqcpeCDdWZGqE8mOran0W3xzqKq944hcknFu7jegH2vzWtoi16Q/bkVsXFQFCfP/xjhcoxOA8QdjtDZBxjMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340274; c=relaxed/simple; bh=vr6LD2HPdPIk5d27M5j5UnBeBs3zwuc4q/0nbXfuaJw=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JupjW2I49noC8aC70FoTX+P6uGF39+REN055QNNeIQ0CkB6mXfFRuuIf/B7NZ6oNn3wYifrODIEDWEosf7qg0Pi7ybkIjYMCSviBcHBSyQWoIhtFcXw8gLWaxOzo3uIqlIJn7tKduqkvh8JAudJ61hHTDx+7w2vjah/73cZufFs= 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=gKcDsGdu; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=anuGZJBI; 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="gKcDsGdu"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="anuGZJBI" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.west.internal (Postfix) with ESMTP id EF71018000DC for ; Fri, 10 May 2024 07:24:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 10 May 2024 07:24:32 -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=1715340271; x=1715426671; bh=YBEvUeX/J8 c6jYqaBI85r5olmoK8m7JBuH3P7hWLWF0=; b=gKcDsGdu4cq7DydAqR6akGz2HP l6H8Qb2Hyotnv+Jz3GTCNr2jb5wSs6CEU5vVEciQlI9PdKe3/Qj1Nv4+5//myale K8IFj51kHHtt4nWgROXlD9vvKVEXXV9QsLK0pOzRSA21RCZrqceVxDwq9aP3mgWU eP5JIwBo6FPILFhZsmIw3pT0GjWDVjSpWxQImdPKlUp/gd6CbXGjYJUFFS8HKvEb ZHiGvhlMU/9R5S7+Yr+B6+FuQeUxqG7ZZ0KKMCJya3DbvesDsBWUf4Rq2IB2J72c ooGCsDBfbXnvqa05CywgPvamWNvb+aWn6nMrk4hisCTxFHbLfSk/HVQosjAA== 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=1715340271; x=1715426671; bh=YBEvUeX/J8c6jYqaBI85r5olmoK8 m7JBuH3P7hWLWF0=; b=anuGZJBIh3CW/jYyN7HWKqP30rACbpOFf5SW30mul1Y+ BjUSn+Td52xiJ9mXvHQkSdwag7taQWzQ623e+xL3vE2XpXeKTfLZ8kSqgsC/E3TI ngmrx03lLD1/+2izCGM86VItB+JzcSvU4ju/3MTszSEgzwqzyFMlD4H8fr6ZcewA PZ4rT9dynX2bU2sn9zA/yVW8SidMov3mj2oGTQ3EvYs+YZGfiHF7fOA8L8jXXnTL NRvplqaQYx8dUbulEoFCmwCvIY33lTCDnZRBNj/I5xgRd+bRk2Pg5RG7/JJqP9Na 8ZoujAWu9o5nZiyrAWUSXPOSq5TvI/mx6qS5TIphiw== 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:30 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 7c77fdee (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 10 May 2024 11:24:17 +0000 (UTC) Date: Fri, 10 May 2024 13:24:28 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 01/21] builtin/config: stop printing full usage on misuse Message-ID: <0ba76281267b324dd7fe8094132dbce11e9f2182.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: 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