From patchwork Thu Jan 16 01:25:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13941123 Received: from fout-a4-smtp.messagingengine.com (fout-a4-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 99EFF282ED for ; Thu, 16 Jan 2025 01:25:28 +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=1736990730; cv=none; b=BlLwfR9VKf3LUk124zcJmt6MX8Xv5P8nT41Fj9EFUuUaEX96XKTIjOhlOuojyUEuBpCvNYUfpPd1he5FrfCu/QiC3qLek1ny1dBAHr6q1fAeOmMJMLW/ubfpP+jdGTroYpwmtxVR2eKZGDNA2z3kojRVfgYZIP8oZplktHLoBu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736990730; c=relaxed/simple; bh=UEn3GRybQ5utchFqJne+waThsBuw/MihnOIEbe2YH+A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TQkzIUrTxXdSKzPuR5HsSxwrcveSn7qz02SRqDyQEXj6vCbNGU2ut5D8GQJ8HVZNnv2dzIrDuQCImLKiInuxBzg/t5u7bRpl6zu5yu3l+ifAeLrYQI7ByjJcpOGCns9YZpGrSKFu6zuoufHa162Bl6Hgr1aqSu1N4W0e483ov/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=EOVlOKIf; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Bt76Eadx; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="EOVlOKIf"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Bt76Eadx" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id B3017138027A; Wed, 15 Jan 2025 20:25:27 -0500 (EST) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-11.internal (MEProxy); Wed, 15 Jan 2025 20:25:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1736990727; x= 1737077127; bh=s34lI+/Ty5hLkGPSj8mEBTUOI9QXGYy8naBuvnH7BWs=; b=E OVlOKIfCqaTcbftHaSJ36WVXxmLOWmNL/f9hdv6N/6DQLHK/bCgXfS1mUvAIoxK+ ZvoF67vOpFinlpmICh2+3aGeo1XP8hcPRqHu0YmiYKa1FY0IHZUGdCPwba6o/tk+ Ma3mnyHOTjdco+mfd5AGCZxxo66e7zaWumJBjlpULvSW1FgtWokjHStpjQ7jqeMa 0gHLqwg1Q1KjXWEgSY1iB3BvMbYPQiB3t2Fq8lbTxRKEuurctj6NjfZZOFdJ9yh5 ayVCy8hp2mJ5H4+Bp4NyHQgI5cP36UmJqqDfSvlvQmQ1/iFPgn5D/+trC9YWUxh7 IKKhokkQnHT5TK3cT/HfQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender :x-me-sender:x-sasl-enc; s=fm2; t=1736990727; x=1737077127; bh=s 34lI+/Ty5hLkGPSj8mEBTUOI9QXGYy8naBuvnH7BWs=; b=Bt76EadxqoIx3FGDK gDDj49pn37QEMzXTeD799vxrYmiB9wtvJNuu4hVPgZtWkscG0BxsYcLefye77l81 RYejhrK1KeER7PHbPtXjIa5Iuc+5BoYz+MG0Y6060clbnIS6r1jHXzaxhmCsxU6Q i2L3Kpds3g5YWXnYcAdSoB6LMGuWSCXM542XW+Z8VMCy2NQSqKvgSjYWvpGNXEAt rxiBpvcgdGFZRb89b5jtNkOlQvlP341l0eyHJlT1rdxKFTi0/WQpc3i5AxlKEi6W 6g7WDDtvLgFKomfJhkrGaVPIsPth82n9R02H8wopR2ja5ck4+3MmkuTUC34CbvE+ JZ50A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeitddgfeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefluhhnihhoucevucfjrghmrghn ohcuoehgihhtshhtvghrsehpohgsohigrdgtohhmqeenucggtffrrghtthgvrhhnpedvff elhfeutefgkeettdfhudelffduteelfeeiueelhfdvudeiueekhfdtvddukeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehgihhtshhtvghrse hpohgsohigrdgtohhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepph gvfhhfsehpvghffhdrnhgvthdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgt ohhm X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Jan 2025 20:25:27 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH v3 1/6] parse-options: add show_usage_help_and_exit_if_asked() Date: Wed, 15 Jan 2025 17:25:18 -0800 Message-ID: <20250116012524.1557441-2-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-191-gafe818080f In-Reply-To: <20250116012524.1557441-1-gitster@pobox.com> References: <20250116012524.1557441-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Many commands call usage_with_options() when they are asked to give the help message, but it incorrectly sends the help text to the standard error stream. When the user asked for it with "git cmd -h", the help message is the primary output from the command, hence we should send it to the standard output stream. Introduce a helper function that captures the common pattern if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(usage, options); and replaces it with show_usage_help_and_exit_if_asked(argc, argv, usage, options); to help correct code paths (there are 40 or so of them). Note that this helper function still exits with status 129, and t0012 insists on it. After converting all the mistaken callers of usage_with_options() to call this new helper, we may want to address it---the end user is asking us to give the help text, and we are doing exactly as asked, so there is no reason to exit with non-zero status. Suggested-by: Jeff King Signed-off-by: Junio C Hamano --- parse-options.c | 10 ++++++++++ parse-options.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/parse-options.c b/parse-options.c index 33bfba0ed4..8a8b934e67 100644 --- a/parse-options.c +++ b/parse-options.c @@ -1282,6 +1282,16 @@ void NORETURN usage_with_options(const char * const *usagestr, exit(129); } +void show_usage_help_and_exit_if_asked(int ac, const char **av, + const char * const *usagestr, + const struct option *opts) +{ + if (ac == 2 && !strcmp(av[1], "-h")) { + usage_with_options_internal(NULL, usagestr, opts, 0, 0); + exit(129); + } +} + void NORETURN usage_msg_opt(const char *msg, const char * const *usagestr, const struct option *options) diff --git a/parse-options.h b/parse-options.h index d01361ca97..6af4ee148a 100644 --- a/parse-options.h +++ b/parse-options.h @@ -402,6 +402,10 @@ int parse_options(int argc, const char **argv, const char *prefix, NORETURN void usage_with_options(const char * const *usagestr, const struct option *options); +void show_usage_help_and_exit_if_asked(int ac, const char **av, + const char * const *usage, + const struct option *options); + NORETURN void usage_msg_opt(const char *msg, const char * const *usagestr, const struct option *options); From patchwork Thu Jan 16 01:25:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13941124 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 306D23595F for ; Thu, 16 Jan 2025 01:25:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736990731; cv=none; b=XxQuDo9zsYoek57+Ej671llWIS0dQVsK0DiLLTvb3//FaVWQiqVT+BPNOk/pK1xSoOx8+1IQ3nyS/jajf6hmzge9hI6YkD7HdzHkwhv1Uh7YZSPkH7SaIz4sp/2buec8GtuMX3ZmxdyUVjoOo4ZSV/UjEo1gXfDNQgaM3fPV3wU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736990731; c=relaxed/simple; bh=L86UTu8HZyrq9X1pkKU4X7tx7u2818HWV1OJYnrsEL4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EwwnYZtR+Q8w5hE7FGN1X1ZPJQMFPEM7BF3Mf1wKRGfX4wsUCN0Uq+9iL3d0mLC7A6G6Rc4DJXSxXtakmJ+Wq+M4HAW+lAaQm0IbwIC45NNh4enMmJA4oxBpmlbqbWH72TYwkve/udplfn23/OAhe6N0BCEjfxBP81CyXUHZrPg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=EvBifBg0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Vor6WkHf; arc=none smtp.client-ip=103.168.172.159 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="EvBifBg0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Vor6WkHf" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 28DDB114010A; Wed, 15 Jan 2025 20:25:29 -0500 (EST) Received: from phl-frontend-01 ([10.202.2.160]) by phl-compute-05.internal (MEProxy); Wed, 15 Jan 2025 20:25:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1736990729; x= 1737077129; bh=5dN9r93SEL7Y5cYHWJA8XRvyi+eov6aLFS11jRLS4KQ=; b=E vBifBg0HWr2IJuxbTPMHPEv9O4rdXcPgjBTXvP9ElHFbM6nHRiKEd9c9ZLl8bKkl XKqB99LQrcF3TaMVB+U/2+FYJw/luMt9eg63GubO941D4Uh+KnlBHeMRumF1vAo4 ukaicpy5G7DU8jHxJDMMIEYfz0ywzWXyY38l2Ryh/ld0updnnO52VXqnqUjWlURP s1gRdNf1gHPfFLQQiAFDcDuSqk0PnaonlG9HwyDGVnp+Cd6722OY/n9CM8MwD9E2 8eWgwMACRF7rqRQT1P3FEszvkYH8jvhHxeKtr6zb03kg1a2jKQZpvhWrJCl1BYBe aRlV1thq5gEdL1RyTxvRA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender :x-me-sender:x-sasl-enc; s=fm2; t=1736990729; x=1737077129; bh=5 dN9r93SEL7Y5cYHWJA8XRvyi+eov6aLFS11jRLS4KQ=; b=Vor6WkHfAjpa/hyOC yUfxkNli7A06L49jx1QH5qlzkqGN6hFVfGhmdZIkHPnKF4IG9/zXaQ0JQNC4r2r5 w7lXu+bXO0slwg8Lt3JrAzFzmzwEDfsqkQ4CHIvOYyUgSQK3a9fF458wDqF95iYi KRMIA1Cwkpk8Y/KaHzAP4c8363X2Bia1rs9RQfqZSAE1e8eppuFa48qd7sZXz8+x xY1yIGDm+HEZFVxba6f56v2JdCx3sfJoKV32KjZZiCrojzI83EtPSADHsob0ENxb Dn0fzXfZM9m/xR7vYVk/IgvV10/tvG9pLlr6fE0I+tQC6sk3C1ZGpnIMh+L1SNcQ qGp/g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeitddgfeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefluhhnihhoucevucfjrghmrghn ohcuoehgihhtshhtvghrsehpohgsohigrdgtohhmqeenucggtffrrghtthgvrhhnpedvff elhfeutefgkeettdfhudelffduteelfeeiueelhfdvudeiueekhfdtvddukeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehgihhtshhtvghrse hpohgsohigrdgtohhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepph gvfhhfsehpvghffhdrnhgvthdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgt ohhm X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Jan 2025 20:25:28 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH v3 2/6] t0012: optionally check that "-h" output goes to stdout Date: Wed, 15 Jan 2025 17:25:19 -0800 Message-ID: <20250116012524.1557441-3-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-191-gafe818080f In-Reply-To: <20250116012524.1557441-1-gitster@pobox.com> References: <20250116012524.1557441-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jeff King For most commands, "git foo -h" will send the help output to stdout, as this is what parse-options.c does. But some commands send it to stderr instead. This is usually because they call usage_with_options(), and should be switched to show_usage_help_and_exit_if_asked(). Currently t0012 is permissive and allows either behavior. We'd like it to eventually enforce that help goes to stdout, and teaching it to do so identifies the commands that need to be changed. But during the transition period, we don't want to enforce that for most test runs. So let's introduce a flag that will let most test runs use the permissive behavior, and people interested in converting commands can run: GIT_TEST_HELP_MUST_BE_STDOUT=1 ./t0012-help.sh to see the failures. Eventually (when all builtins have been converted) we'll remove this flag entirely and always check the strict behavior. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0012-help.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/t/t0012-help.sh b/t/t0012-help.sh index 1d273d91c2..9c7ae9fd36 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -255,9 +255,16 @@ do ( GIT_CEILING_DIRECTORIES=$(pwd) && export GIT_CEILING_DIRECTORIES && - test_expect_code 129 git -C sub $builtin -h >output 2>&1 + test_expect_code 129 git -C sub $builtin -h >output 2>err ) && - test_grep usage output + if test -n "$GIT_TEST_HELP_MUST_BE_STDOUT" + then + test_must_be_empty err && + test_grep usage output + else + test_grep usage output || + test_grep usage err + fi ' done X-Patchwork-Id: 13941125 Received: from fout-a4-smtp.messagingengine.com (fout-a4-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 995CC4502B for ; Thu, 16 Jan 2025 01:25:31 +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=1736990733; cv=none; b=PBs4Pb0aTZi5AdQTgn+ZYnRjMtBmwCT3875Ndl0ywY17Omtoqg9olA8e1pL1FF/QH+Vq/sj7acsCXRPESNxaNYpKZi2JytR4wQjdwGzAniZz3opfRVLs7ys5+US6T77vnEK+RX/CjvxoCEsvwteD/hetuqnxiG52/O1IAM8WUXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736990733; c=relaxed/simple; bh=qgn+J1XRarmqJZ7c/2at5jH59NwXi6yaeJZchJNbVdg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d1W9KbuW/eTaQCt0/Pa2DrIoOkm8SyLB3t3rFAqt1VSDGKO/W8HyUY9EjQkVixpOcFrdTWziw5iueJOMntu2viHhHNOWhhmGip2DtTeLwR0C+NDXkMHn08hccttaTgY07qFM6QEoMghmxPRLtGs3A13KL+6clEqmCOyVuxV/vrM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=SMgrt4mL; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=GYqQSLUf; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="SMgrt4mL"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GYqQSLUf" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id 969E3138022C; Wed, 15 Jan 2025 20:25:30 -0500 (EST) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-11.internal (MEProxy); Wed, 15 Jan 2025 20:25:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1736990730; x= 1737077130; bh=6fcmytmPptUP93DPgRIh8SW6ky8F8bvGxFtOKvoCH2A=; b=S Mgrt4mLOwVl3ytegwcc/YVuHTHORb7ojVRpcMPeXkqyJRoqRaKW75KUXqWGgNN44 Kcsb/cr8gZz9fHAPb2sqgFO74zn8P3JX+2YoNR8uAS9RyY9kNNfB7SrBGbN9m35W Rhrl3gHHHsUxBW+FP0KG0WZRkx8AhB72/epoLN7PfbXaNKBaN8TIAubSiGrPNLHz Snc0MsaEGxwdaIyLaz9i/ipgaiB8oR36RmxGp/RqdP67S/wbcQRqzNISIlVTiERz u+CQa+BGARSj5de+g1opoyOBzwNihhn6YiEuQF22zzXeupZwfM6kha/QqbZZQKdo X6OAdCL/dlJp5USGqm3qg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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-sender:x-me-sender:x-sasl-enc; s= fm2; t=1736990730; x=1737077130; bh=6fcmytmPptUP93DPgRIh8SW6ky8F 8bvGxFtOKvoCH2A=; b=GYqQSLUfMeF5CMvJ6k321dwhA9XlgNWYSRtZlWsOVMo+ E7hRuKkYtTmFaQfc6MWdDDDjfZRXd59sNbOZhwmPtk+DL1oudg/m3M3peDCafYpK rg5D8ljD3RtCtddA9ClQP8BM05dY8iznA8d171S/9/Lr2RRWG601KINoI6aZOMci iIlHuJZLoyv7jKnDgXLb56lCUFeHm6wci0P/4I/ZrxSBAYXjt9BKdIYISIZlP7U9 jYyI7KB7nd77phBsVhfwrPuWFmaFW3sS7HWCEnT4RJplmnmTZAdxvfqsfN4zYFL3 ksSRlM6lyvgVdZX6MDYsKy/oqgze9aHLvD6c3fggyw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeitddgfeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvffuff fkofgjfhgggfestdekredtredttdenucfhrhhomheplfhunhhiohcuvecujfgrmhgrnhho uceoghhithhsthgvrhesphhosghogidrtghomheqnecuggftrfgrthhtvghrnhepleevie efieeuffeugefhveeugefgfeevvdefleevuedvfedvudefkeehtdeftdegnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhithhsthgvrhesph hosghogidrtghomhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhr tghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgih htshhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Jan 2025 20:25:30 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v3 3/6] builtins: send usage_with_options() help text to standard output Date: Wed, 15 Jan 2025 17:25:20 -0800 Message-ID: <20250116012524.1557441-4-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-191-gafe818080f In-Reply-To: <20250116012524.1557441-1-gitster@pobox.com> References: <20250116012524.1557441-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using the show_usage_help_and_exit_if_asked() helper we introduced earlier, fix callers of usage_with_options() that want to show the help text when explicitly asked by the end-user. The help text now goes to the standard output stream for them. The test in t7600 for "git merge -h" may want to be retired, as the same is covered by t0012 already. It would be even more true if we later consider changing the exit status from 129 to 0. Signed-off-by: Junio C Hamano --- builtin/am.c | 3 +-- builtin/branch.c | 4 ++-- builtin/checkout--worker.c | 6 +++--- builtin/checkout-index.c | 6 +++--- builtin/commit-tree.c | 4 ++-- builtin/commit.c | 8 ++++---- builtin/fsmonitor--daemon.c | 4 ++-- builtin/gc.c | 4 ++-- builtin/ls-files.c | 4 ++-- builtin/merge.c | 4 ++-- builtin/rebase.c | 6 +++--- builtin/update-index.c | 4 ++-- t/t7600-merge.sh | 2 +- 13 files changed, 29 insertions(+), 30 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 1338b606fe..0801b556c2 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -2427,8 +2427,7 @@ int cmd_am(int argc, OPT_END() }; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(usage, options); + show_usage_help_and_exit_if_asked(argc, argv, usage, options); git_config(git_default_config, NULL); diff --git a/builtin/branch.c b/builtin/branch.c index 6e7b0cfddb..366729a78b 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -784,8 +784,8 @@ int cmd_branch(int argc, filter.kind = FILTER_REFS_BRANCHES; filter.abbrev = -1; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(builtin_branch_usage, options); + show_usage_help_and_exit_if_asked(argc, argv, + builtin_branch_usage, options); /* * Try to set sort keys from config. If config does not set any, diff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c index b81002a1df..7093d1efd5 100644 --- a/builtin/checkout--worker.c +++ b/builtin/checkout--worker.c @@ -128,9 +128,9 @@ int cmd_checkout__worker(int argc, OPT_END() }; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(checkout_worker_usage, - checkout_worker_options); + show_usage_help_and_exit_if_asked(argc, argv, + checkout_worker_usage, + checkout_worker_options); git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, checkout_worker_options, diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index a81501098d..d928d6b5e3 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -250,9 +250,9 @@ int cmd_checkout_index(int argc, OPT_END() }; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(builtin_checkout_index_usage, - builtin_checkout_index_options); + show_usage_help_and_exit_if_asked(argc, argv, + builtin_checkout_index_usage, + builtin_checkout_index_options); git_config(git_default_config, NULL); prefix_length = prefix ? strlen(prefix) : 0; diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index 2ca1a57ebb..2efc224d32 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -119,8 +119,8 @@ int cmd_commit_tree(int argc, git_config(git_default_config, NULL); - if (argc < 2 || !strcmp(argv[1], "-h")) - usage_with_options(commit_tree_usage, options); + show_usage_help_and_exit_if_asked(argc, argv, + commit_tree_usage, options); argc = parse_options(argc, argv, prefix, options, commit_tree_usage, 0); diff --git a/builtin/commit.c b/builtin/commit.c index ef5e622c07..4268915120 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1559,8 +1559,8 @@ struct repository *repo UNUSED) OPT_END(), }; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(builtin_status_usage, builtin_status_options); + show_usage_help_and_exit_if_asked(argc, argv, + builtin_status_usage, builtin_status_options); prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; @@ -1736,8 +1736,8 @@ int cmd_commit(int argc, struct strbuf err = STRBUF_INIT; int ret = 0; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(builtin_commit_usage, builtin_commit_options); + show_usage_help_and_exit_if_asked(argc, argv, + builtin_commit_usage, builtin_commit_options); prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c index 029dc64d6c..dabf190bbe 100644 --- a/builtin/fsmonitor--daemon.c +++ b/builtin/fsmonitor--daemon.c @@ -1598,8 +1598,8 @@ int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix UNUSED OPT_END() }; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(builtin_fsmonitor__daemon_usage, options); + show_usage_help_and_exit_if_asked(argc, argv, + builtin_fsmonitor__daemon_usage, options); die(_("fsmonitor--daemon not supported on this platform")); } diff --git a/builtin/gc.c b/builtin/gc.c index a9b1c36de2..5f831e1f94 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -710,8 +710,8 @@ struct repository *repo UNUSED) OPT_END() }; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(builtin_gc_usage, builtin_gc_options); + show_usage_help_and_exit_if_asked(argc, argv, + builtin_gc_usage, builtin_gc_options); strvec_pushl(&reflog, "reflog", "expire", "--all", NULL); strvec_pushl(&repack, "repack", "-d", "-l", NULL); diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 15499cd12b..9efe92b7c0 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -644,8 +644,8 @@ int cmd_ls_files(int argc, }; int ret = 0; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(ls_files_usage, builtin_ls_files_options); + show_usage_help_and_exit_if_asked(argc, argv, + ls_files_usage, builtin_ls_files_options); prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; diff --git a/builtin/merge.c b/builtin/merge.c index 5f67007bba..95d798fc89 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1300,8 +1300,8 @@ int cmd_merge(int argc, void *branch_to_free; int orig_argc = argc; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(builtin_merge_usage, builtin_merge_options); + show_usage_help_and_exit_if_asked(argc, argv, + builtin_merge_usage, builtin_merge_options); prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; diff --git a/builtin/rebase.c b/builtin/rebase.c index 0498fff3c9..cb49323c44 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1223,9 +1223,9 @@ int cmd_rebase(int argc, }; int i; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(builtin_rebase_usage, - builtin_rebase_options); + show_usage_help_and_exit_if_asked(argc, argv, + builtin_rebase_usage, + builtin_rebase_options); prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; diff --git a/builtin/update-index.c b/builtin/update-index.c index 74bbad9f87..b0e2ad4970 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1045,8 +1045,8 @@ int cmd_update_index(int argc, OPT_END() }; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(update_index_usage, options); + show_usage_help_and_exit_if_asked(argc, argv, + update_index_usage, options); git_config(git_default_config, NULL); diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index ef54cff4fa..2a8df29219 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -173,7 +173,7 @@ test_expect_success 'merge -h with invalid index' ' cd broken && git init && >.git/index && - test_expect_code 129 git merge -h 2>usage + test_expect_code 129 git merge -h >usage ) && test_grep "[Uu]sage: git merge" broken/usage ' From patchwork Thu Jan 16 01:25:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13941126 Received: from fout-a4-smtp.messagingengine.com (fout-a4-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 D6E485674D for ; Thu, 16 Jan 2025 01:25:32 +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=1736990734; cv=none; b=Xx0USO3LBixchWYy/FHZDdmmgXAkqkp5jcgOxqJbbHQ6l/DPe9E2v/JYzwLKXdhVvx4xpr/bzxMyaJ12RdftDW9U8QpifBv5YLnmv6LbjFc4IaEr8/n+2b67c+aEiVS5hO/5QUp3nLnUYRp+rcaLIlYKWsbAAKozlMUFVfKjdpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736990734; c=relaxed/simple; bh=j6gWbIZNNEh6chUr5makqZtgofiUG8MRhH3YWkHuWMk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qbv42CxQPwDrnPzBR5liMj59bdOZQxHEEjVItu4nt3TyYg43ovtI4u3M52qoM070Sl5Y7PgpxIXoKDVRn6BcPoJUUlfOW5gXzjiJg34rs+Yl0Bm+JXotfDkcdycGznuT9hUdCFLvqRkVfzqRA129nI5ygsBdQubCX2uNM4VK5rk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=pUTwiQPf; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=hfSnHRE0; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="pUTwiQPf"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="hfSnHRE0" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id F1AE41380231; Wed, 15 Jan 2025 20:25:31 -0500 (EST) Received: from phl-frontend-01 ([10.202.2.160]) by phl-compute-02.internal (MEProxy); Wed, 15 Jan 2025 20:25:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1736990731; x= 1737077131; bh=jq76kOpYlSZD2g37Q75mprLnNU4RxLxhMWf/1vvAlRc=; b=p UTwiQPfZKircrsi3L3NlIm677GizVn2tIR6lvMHkTdf1oxT/iqs881cjJ6A0SBkv XP3s2ZQ6/nmOtVstXeBy+bW4SG8ARV/mNLGffXCJHNCkRfvBZjyqec+Zl6V5yajj O13haDL5NVIWyLehcg1jFgls9uzzSzMWFhwQRfIMOjsK6hBMSG2SnTRFKj2CIahD nYTQhb+soW7wHZgST3clPZWKMmG/ROIvS8402syEHqRmkiHY856zQiaAVPS/DWK5 Zvuazn66WyQYS3TAQOSYaLxVlOOvv9dt++PNLCMVGoaj8alyQk+TsTXcaknI0aMQ jyeirAXILv26qKIGDFHqw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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-sender:x-me-sender:x-sasl-enc; s= fm2; t=1736990731; x=1737077131; bh=jq76kOpYlSZD2g37Q75mprLnNU4R xLxhMWf/1vvAlRc=; b=hfSnHRE0ce/eVCkl6PIvAnetsQb7SP7IoUZRYxFX8WJe ZwvZf8YltkM85dDHmUzZPJNRVUmDotYCIoNl2wfMpUDVz6KNCv/STconE6AEqrbb JfaybzPpnGFFUBwU9dfTH3keP6Zdf6FTKx+sULBZQx5xc12A9pDZ/NR7KvlmvJjt kITkprOXKFoqdtk7Ey3/olDSlESQR27EoZn5Sd8TaFF1pVuaQsM5GYYTyS/YDvbK vyHCEKAGcACcZSE5wnBpzwlU9J41zKHoSK0ubg8cPsPDSoQ/TCYSV7Qh8NPQY4HZ OIsSUfyFkaQFghTMPqxp7oR5dCQ6pR3RiQb6NqJQzA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeitddgfeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvffuff fkofgjfhgggfestdekredtredttdenucfhrhhomheplfhunhhiohcuvecujfgrmhgrnhho uceoghhithhsthgvrhesphhosghogidrtghomheqnecuggftrfgrthhtvghrnhepleevie efieeuffeugefhveeugefgfeevvdefleevuedvfedvudefkeehtdeftdegnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhithhsthgvrhesph hosghogidrtghomhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhr tghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgih htshhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Jan 2025 20:25:31 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v3 4/6] usage: add show_usage_and_exit_if_asked() Date: Wed, 15 Jan 2025 17:25:21 -0800 Message-ID: <20250116012524.1557441-5-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-191-gafe818080f In-Reply-To: <20250116012524.1557441-1-gitster@pobox.com> References: <20250116012524.1557441-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some commands call usage() when they are asked to give the help message with "git cmd -h", but this has the same problem as we fixed with callers of usage_with_options() for the same purpose. Introduce a helper function that captures the common pattern if (argc == 2 && !strcmp(argv[1], "-h")) usage(usage); and replaces it with show_usage_and_exit_if_asked(argc, argv, usage); to help correct these code paths. Note that this helper function still exits with status 129, and t0012 insists on it. After converting all the mistaken callers of usage_with_options() to call this new helper, we may want to address it---the end user is asking us to give the help text, and we are doing exactly as asked, so there is no reason to exit with non-zero status. Signed-off-by: Junio C Hamano --- git-compat-util.h | 2 ++ usage.c | 28 +++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/git-compat-util.h b/git-compat-util.h index e283c46c6f..6edf50bc95 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -701,6 +701,8 @@ int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2))); void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2))); +void show_usage_and_exit_if_asked(int ac, const char **av, const char *err); + #ifndef NO_OPENSSL #ifdef APPLE_COMMON_CRYPTO #include "compat/apple-common-crypto.h" diff --git a/usage.c b/usage.c index 47709006c1..26cd54a511 100644 --- a/usage.c +++ b/usage.c @@ -8,7 +8,7 @@ #include "gettext.h" #include "trace2.h" -static void vreportf(const char *prefix, const char *err, va_list params) +static void vfdreportf(int fd, const char *prefix, const char *err, va_list params) { char msg[4096]; char *p, *pend = msg + sizeof(msg); @@ -32,8 +32,14 @@ static void vreportf(const char *prefix, const char *err, va_list params) } *(p++) = '\n'; /* we no longer need a NUL */ - fflush(stderr); - write_in_full(2, msg, p - msg); + if (fd == 2) + fflush(stderr); + write_in_full(fd, msg, p - msg); +} + +static void vreportf(const char *prefix, const char *err, va_list params) +{ + vfdreportf(2, prefix, err, params); } static NORETURN void usage_builtin(const char *err, va_list params) @@ -173,6 +179,22 @@ void NORETURN usage(const char *err) usagef("%s", err); } +static void show_usage_and_exit_if_asked_helper(const char *err, ...) +{ + va_list params; + + va_start(params, err); + vfdreportf(1, _("usage: "), err, params); + va_end(params); + exit(129); +} + +void show_usage_and_exit_if_asked(int ac, const char **av, const char *err) +{ + if (ac == 2 && !strcmp(av[1], "-h")) + show_usage_and_exit_if_asked_helper(err); +} + void NORETURN die(const char *err, ...) { va_list params; From patchwork Thu Jan 16 01:25:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13941127 Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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 6A1217081B for ; Thu, 16 Jan 2025 01:25:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736990736; cv=none; b=UkmsyKq2pFmKiQi2N1Jz0c2ZrG5z83pc5XcQKePheAcAxXuQNNtsXsvqGziT9zRGd/3gy8HKJkzCa1bTHcVpMOCDeMIQo+1IAFe6H7HC2T8mNDG/i9LpEwZJh+WyxorCS39BzvLJOZN4ZCyqhMeoZ9GdZBLfJeMquml/kT/uxYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736990736; c=relaxed/simple; bh=019usVTayZ8lqBWWQi44x9IxpqT3MkJIqemZOqXxtmM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JJxO6i3ERxdtAK54oUN/ukjFKg0YmofOVc7So+TydMaU1v5RuHTgzlAnbYA646551JlyyKzXsZ+xy40fDsJWb1ucs2XFwAV6lA4ioFYRokbI0/aMyIzCgJ1D8+GB2b6S60f6hC75KeJdox65idUyKg0sFlyEDRDASBD9QONRxg0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=LuOhI1A7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Z6wENsLY; arc=none smtp.client-ip=103.168.172.159 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="LuOhI1A7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Z6wENsLY" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 62C8C1140190; Wed, 15 Jan 2025 20:25:33 -0500 (EST) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-05.internal (MEProxy); Wed, 15 Jan 2025 20:25:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1736990733; x= 1737077133; bh=UktsyEHPiLei5xnLVXGpFIw42qAhxzrafqObFfiKBqk=; b=L uOhI1A7lepoOPJluo3IQuqCLz/clmgnqzWbe2diSSNUYytVIbUm+2TWRHRcV1Gx/ QqQOLUawVKEfLQMxz8rrT/fiU5a38HCHlzNnE4tQ1Oit66N06Z5P7a3+AtffjZk1 7zvAFUiUKQhStE2Nc3/r9MHVcW3HGmVRwJ+HbvfocRxrseFvQnJcdBUa3UoXNhIE KZ4hFyJvJma8bVzmuPykEQmYOA8+hr+nuSN+3sutBhPWi4RgFxf6Iks+Uqq5QKqk b3yKSUgjEX09pQk6mmok/vGXWDnn3vNxB7HFqIbOIRkqxSuQ3n3wYSLDrA+elyaX rYsgRmCFhk/Iuv1VezuwA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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-sender:x-me-sender:x-sasl-enc; s= fm2; t=1736990733; x=1737077133; bh=UktsyEHPiLei5xnLVXGpFIw42qAh xzrafqObFfiKBqk=; b=Z6wENsLY9ofyqomakMA3CbAcVhgKGPA/hvphQV9JYk8+ QGkX93pR8qgHA+9X5JzWGesQDXXgHQW/ut0+9aTgxVlFpstnEPbGoVwBImXynw3s ng0/l9d84s0LRZT7a4rTp8KUgiULgsojYPJaDxU7pLFr0wQ8BzdP2B+RfZc6w67o +XlnWdbDDM/nUUqgVCl4Rsqwl2to/Yl/m0WbM0Ubc5/fwIAktfwSEjBcO5ZqKbhr gytnX1ATxLG98QNSJtuBF5ljaQ2C//x7JIYIoL9rbf+tw+VRP8gBBHNwMkdIgOGN 4ac2r9+oCIxJf4pbqsZvgnLtJdj9XuCZBFpd+wJLLg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeitddgfeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvffuff fkofgjfhgggfestdekredtredttdenucfhrhhomheplfhunhhiohcuvecujfgrmhgrnhho uceoghhithhsthgvrhesphhosghogidrtghomheqnecuggftrfgrthhtvghrnhepleevie efieeuffeugefhveeugefgfeevvdefleevuedvfedvudefkeehtdeftdegnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhithhsthgvrhesph hosghogidrtghomhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhr tghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgih htshhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Jan 2025 20:25:32 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v3 5/6] oddballs: send usage() help text to standard output Date: Wed, 15 Jan 2025 17:25:22 -0800 Message-ID: <20250116012524.1557441-6-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-191-gafe818080f In-Reply-To: <20250116012524.1557441-1-gitster@pobox.com> References: <20250116012524.1557441-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using the show_usage_and_exit_if_asked() helper we introduced earlier, fix callers of usage() that want to show the help text when explicitly asked by the end-user. The help text now goes to the standard output stream for them. The callers in this step are oddballs in that their invocations of usage() are *not* guarded by if (argc == 2 && !strcmp(argv[1], "-h") usage(...); They are (unnecessarily) being clever and do things like if (argc != 2 || !strcmp(argv[1], "-h") usage(...); to say "I know I take only one argument, so argc != 2 is always an error regardless of what is in argv[]. Ah, by the way, even if argc is 2, "-h" is a request for usage text, so we do the same". Some just do not treat "-h" any specially, and let it take the same error code paths as a parameter error. Now we cannot do the same, so these callers are rewrittin to do the show_usage_and_exit_if_asked() first and then handle the usage error the way they used to. Signed-off-by: Junio C Hamano --- builtin/credential.c | 3 ++- builtin/unpack-file.c | 8 ++++++-- builtin/upload-archive.c | 3 ++- builtin/var.c | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/builtin/credential.c b/builtin/credential.c index 14c8c6608b..8a8cffecc8 100644 --- a/builtin/credential.c +++ b/builtin/credential.c @@ -18,7 +18,8 @@ int cmd_credential(int argc, git_config(git_default_config, NULL); - if (argc != 2 || !strcmp(argv[1], "-h")) + show_usage_and_exit_if_asked(argc, argv, usage_msg); + if (argc != 2) usage(usage_msg); op = argv[1]; diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c index 6da2825753..307351af55 100644 --- a/builtin/unpack-file.c +++ b/builtin/unpack-file.c @@ -26,6 +26,9 @@ static char *create_temp_file(struct object_id *oid) return path; } +static const char usage_msg[] = +"git unpack-file "; + int cmd_unpack_file(int argc, const char **argv, const char *prefix UNUSED, @@ -33,8 +36,9 @@ int cmd_unpack_file(int argc, { struct object_id oid; - if (argc != 2 || !strcmp(argv[1], "-h")) - usage("git unpack-file "); + show_usage_and_exit_if_asked(argc, argv, usage_msg); + if (argc != 2) + usage(usage_msg); if (repo_get_oid(the_repository, argv[1], &oid)) die("Not a valid object name %s", argv[1]); diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index 9e9343f121..3b282d41e6 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -27,7 +27,8 @@ int cmd_upload_archive_writer(int argc, const char *arg_cmd = "argument "; int ret; - if (argc != 2 || !strcmp(argv[1], "-h")) + show_usage_and_exit_if_asked(argc, argv, upload_archive_usage); + if (argc != 2) usage(upload_archive_usage); if (!enter_repo(argv[1], 0)) diff --git a/builtin/var.c b/builtin/var.c index 1449656cc9..6a09c1c39a 100644 --- a/builtin/var.c +++ b/builtin/var.c @@ -221,6 +221,7 @@ int cmd_var(int argc, const struct git_var *git_var; char *val; + show_usage_and_exit_if_asked(argc, argv, var_usage); if (argc != 2) usage(var_usage); From patchwork Thu Jan 16 01:25:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13941128 Received: from fout-a4-smtp.messagingengine.com (fout-a4-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 ADDDF7083C for ; Thu, 16 Jan 2025 01:25:35 +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=1736990737; cv=none; b=kuMuHvXH6C0KMPCYvycIenJonC8G6iZx13zEWra3ILmp0bLzuJQyutUtKaIRrF6bxgfjiym+BQejPT9RUSnuChXTdPQIzsNBFMvy/jDgQv6dKJhOcICqLGtZ1z3myfphgwtHNTrUHR6hfl3G3NvpHSgF51AamD4JILsa14b2WuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736990737; c=relaxed/simple; bh=Tw17AmR3GvW1X2dVO6hB82i1ebZOI03vo99LJ3cTi2A=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lKGCv16V3cLy3WEQnFpCPlbWUqJ15NHej8001mxwTbkg21dFtVXgk2jk3KZU5kC2k62pNoZ5nuDJTn5lwG0goNqSVGe0mCBYPgA0JiJmDr7DnMlipIfWOO++YJRjbHmm+mXlJfTC7oLKHmr86bnwKspr7UejcJ9dLubH8KNGtCE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=RI0I6IFD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Vc6a4DfM; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="RI0I6IFD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Vc6a4DfM" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id CA8871380281; Wed, 15 Jan 2025 20:25:34 -0500 (EST) Received: from phl-frontend-01 ([10.202.2.160]) by phl-compute-03.internal (MEProxy); Wed, 15 Jan 2025 20:25:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1736990734; x= 1737077134; bh=fZAfMo+XaoMZxh88ZKe/QxA8R7bCuZbMT3j/MMWXDu0=; b=R I0I6IFDay5mKvBvv+SO3rWk9kRNu9/0ys8h5o/F6TARmujG/qCU72ng4ltQyIojE ngajHMGE7vlvKTcatloFjL6CY/dlxTcPUJs2NCQXYoijHFQ5AMTIoObZmEAR9I2n CqWRwrBmslgV6AF4uTuiG48Ta3p4K2t59R4hT4mC6TuNVBev65ZbO1EOPImZIkAw jSD3Hgqqm0yurDw050ev6IRb+E0CX4v+ddsV4GydgiCnPuLE1z4ylexH1aoz7WTZ 8etnYW+a8BJ7t1g9E3tVSAfY4/qK0Og6OqrpxZdcB+HXQQmacBPhUcgTayujibDO CM6/gW9f+TJryLDDNciKw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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-sender:x-me-sender:x-sasl-enc; s= fm2; t=1736990734; x=1737077134; bh=fZAfMo+XaoMZxh88ZKe/QxA8R7bC uZbMT3j/MMWXDu0=; b=Vc6a4DfMeeXRBRe/Hn1tbYKARiqj8d6TJcbj071HRHLi bIFWGLD/JJ7ScvDOcsNXMjB5MmIfsR3kUjIAKGpwR8mrj3iJbkNOSjL+mZN4APNG QvOjrdeROULtof6TG8zV/4rXZkmQ8OBCzItPUcBA/2h7m2O21PVImXR/1KoAKRnf hEBUXGWMUXj1aDC7a66tBz1Ywci0acbRnicXF0pyNt8TsAzZ0GBA8MMKSHCQiWwY 5vo3dJml3RGlr+65MB7Rtt2syXd8lR5TZUzW4t9fM5rlpNB9K4pZK9toKAPXJcBm 9GFYoMzFjOBCNVZZXnH3CiLa0hrFFugV5UuU/Yhnwg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeitddgfeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvffuff fkofgjfhgggfestdekredtredttdenucfhrhhomheplfhunhhiohcuvecujfgrmhgrnhho uceoghhithhsthgvrhesphhosghogidrtghomheqnecuggftrfgrthhtvghrnhepleevie efieeuffeugefhveeugefgfeevvdefleevuedvfedvudefkeehtdeftdegnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhithhsthgvrhesph hosghogidrtghomhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhr tghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgih htshhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Jan 2025 20:25:34 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v3 6/6] builtin: send usage() help text to standard output Date: Wed, 15 Jan 2025 17:25:23 -0800 Message-ID: <20250116012524.1557441-7-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-191-gafe818080f In-Reply-To: <20250116012524.1557441-1-gitster@pobox.com> References: <20250116012524.1557441-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using the show_usage_and_exit_if_asked() helper we introduced earlier, fix callers of usage() that want to show the help text when explicitly asked by the end-user. The help text now goes to the standard output stream for them. These are the bog standard "if we got only '-h', then that is a request for help" callers. Their if (argc == 2 && !strcmp(argv[1], "-h")) usage(message); are simply replaced with show_usage_and_exit_if_asked(argc, argv, message); With this, the built-ins tested by t0012 all send their help text to their standard output stream, so the check in t0012 that was half tightened earlier is now fully tightened to insist on standard error stream being empty. Signed-off-by: Junio C Hamano --- builtin/check-ref-format.c | 4 ++-- builtin/diff-files.c | 3 +-- builtin/diff-index.c | 3 +-- builtin/diff-tree.c | 3 +-- builtin/fast-import.c | 3 +-- builtin/fetch-pack.c | 3 +++ builtin/get-tar-commit-id.c | 4 +++- builtin/index-pack.c | 3 +-- builtin/mailsplit.c | 4 ++-- builtin/merge-index.c | 7 ++++++- builtin/merge-ours.c | 3 +-- builtin/merge-recursive.c | 6 ++++++ builtin/pack-redundant.c | 3 +-- builtin/remote-ext.c | 2 ++ builtin/remote-fd.c | 1 + builtin/rev-list.c | 3 +-- builtin/rev-parse.c | 2 ++ builtin/unpack-objects.c | 2 ++ builtin/upload-archive.c | 3 +-- t/helper/test-simple-ipc.c | 4 ++-- t/t0012-help.sh | 10 ++-------- 21 files changed, 42 insertions(+), 34 deletions(-) diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c index cef1ffe3ce..acc4366d85 100644 --- a/builtin/check-ref-format.c +++ b/builtin/check-ref-format.c @@ -64,8 +64,8 @@ int cmd_check_ref_format(int argc, BUG_ON_NON_EMPTY_PREFIX(prefix); - if (argc == 2 && !strcmp(argv[1], "-h")) - usage(builtin_check_ref_format_usage); + show_usage_and_exit_if_asked(argc, argv, + builtin_check_ref_format_usage); if (argc == 3 && !strcmp(argv[1], "--branch")) return check_ref_format_branch(argv[2]); diff --git a/builtin/diff-files.c b/builtin/diff-files.c index 604b04bb2c..f8816e0d9e 100644 --- a/builtin/diff-files.c +++ b/builtin/diff-files.c @@ -29,8 +29,7 @@ int cmd_diff_files(int argc, int result; unsigned options = 0; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage(diff_files_usage); + show_usage_and_exit_if_asked(argc, argv, diff_files_usage); git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ diff --git a/builtin/diff-index.c b/builtin/diff-index.c index ebc824602e..a1759b8291 100644 --- a/builtin/diff-index.c +++ b/builtin/diff-index.c @@ -26,8 +26,7 @@ int cmd_diff_index(int argc, int i; int result; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage(diff_cache_usage); + show_usage_and_exit_if_asked(argc, argv, diff_cache_usage); git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 40804e7b48..fc7c026555 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -122,8 +122,7 @@ int cmd_diff_tree(int argc, int read_stdin = 0; int merge_base = 0; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage(diff_tree_usage); + show_usage_and_exit_if_asked(argc, argv, diff_tree_usage); git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 0f86392761..e1f6bfdc73 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -3565,8 +3565,7 @@ int cmd_fast_import(int argc, { unsigned int i; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage(fast_import_usage); + show_usage_and_exit_if_asked(argc, argv, fast_import_usage); reset_pack_idx_option(&pack_idx_opts); git_pack_config(); diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index bed2816c2d..9bd4b29c5b 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -176,6 +176,9 @@ int cmd_fetch_pack(int argc, list_objects_filter_set_no_filter(&args.filter_options); continue; } + + if (!strcmp(arg, "-h")) + show_usage_and_exit_if_asked(2, &arg - 1, fetch_pack_usage); usage(fetch_pack_usage); } if (deepen_not.nr) diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c index 6bec0d1854..033a205ba4 100644 --- a/builtin/get-tar-commit-id.c +++ b/builtin/get-tar-commit-id.c @@ -13,7 +13,7 @@ static const char builtin_get_tar_commit_id_usage[] = #define HEADERSIZE (2 * RECORDSIZE) int cmd_get_tar_commit_id(int argc, - const char **argv UNUSED, + const char **argv, const char *prefix, struct repository *repo UNUSED) { @@ -27,6 +27,8 @@ int cmd_get_tar_commit_id(int argc, BUG_ON_NON_EMPTY_PREFIX(prefix); + show_usage_and_exit_if_asked(argc, argv, builtin_get_tar_commit_id_usage); + if (argc != 1) usage(builtin_get_tar_commit_id_usage); diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 0b62b2589f..92ef59fad5 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1897,8 +1897,7 @@ int cmd_index_pack(int argc, */ fetch_if_missing = 0; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage(index_pack_usage); + show_usage_and_exit_if_asked(argc, argv, index_pack_usage); disable_replace_refs(); fsck_options.walk = mark_link; diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c index 41dd304731..9e11bffdfb 100644 --- a/builtin/mailsplit.c +++ b/builtin/mailsplit.c @@ -284,6 +284,8 @@ int cmd_mailsplit(int argc, BUG_ON_NON_EMPTY_PREFIX(prefix); + show_usage_and_exit_if_asked(argc, argv, git_mailsplit_usage); + for (argp = argv+1; *argp; argp++) { const char *arg = *argp; @@ -297,8 +299,6 @@ int cmd_mailsplit(int argc, continue; } else if ( arg[1] == 'f' ) { nr = strtol(arg+2, NULL, 10); - } else if ( arg[1] == 'h' ) { - usage(git_mailsplit_usage); } else if ( arg[1] == 'b' && !arg[2] ) { allow_bare = 1; } else if (!strcmp(arg, "--keep-cr")) { diff --git a/builtin/merge-index.c b/builtin/merge-index.c index 342699edb7..f243a55d32 100644 --- a/builtin/merge-index.c +++ b/builtin/merge-index.c @@ -75,6 +75,9 @@ static void merge_all(void) } } +static const char usage_string[] = +"git merge-index [-o] [-q] (-a | [--] [...])"; + int cmd_merge_index(int argc, const char **argv, const char *prefix UNUSED, @@ -87,8 +90,10 @@ int cmd_merge_index(int argc, */ signal(SIGCHLD, SIG_DFL); + show_usage_and_exit_if_asked(argc, argv, usage_string); + if (argc < 3) - usage("git merge-index [-o] [-q] (-a | [--] [...])"); + usage(usage_string); repo_read_index(the_repository); diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c index 3ecd9172f1..ab78fffb52 100644 --- a/builtin/merge-ours.c +++ b/builtin/merge-ours.c @@ -23,8 +23,7 @@ int cmd_merge_ours(int argc, const char *prefix UNUSED, struct repository *repo UNUSED) { - if (argc == 2 && !strcmp(argv[1], "-h")) - usage(builtin_merge_ours_usage); + show_usage_and_exit_if_asked(argc, argv, builtin_merge_ours_usage); /* * The contents of the current index becomes the tree we diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c index 1dd295558b..b71c7e1c2f 100644 --- a/builtin/merge-recursive.c +++ b/builtin/merge-recursive.c @@ -38,6 +38,12 @@ int cmd_merge_recursive(int argc, if (argv[0] && ends_with(argv[0], "-subtree")) o.subtree_shift = ""; + if (argc == 2 && !strcmp(argv[1], "-h")) { + struct strbuf msg = STRBUF_INIT; + strbuf_addf(&msg, builtin_merge_recursive_usage, argv[0]); + show_usage_and_exit_if_asked(argc, argv, msg.buf); + } + if (argc < 4) usagef(builtin_merge_recursive_usage, argv[0]); diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index e046575871..ce2e1fde8d 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -595,8 +595,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s struct strbuf idx_name = STRBUF_INIT; char buf[GIT_MAX_HEXSZ + 2]; /* hex hash + \n + \0 */ - if (argc == 2 && !strcmp(argv[1], "-h")) - usage(pack_redundant_usage); + show_usage_and_exit_if_asked(argc, argv, pack_redundant_usage); for (i = 1; i < argc; i++) { const char *arg = argv[i]; diff --git a/builtin/remote-ext.c b/builtin/remote-ext.c index 33c8ae0fc7..f7591e7701 100644 --- a/builtin/remote-ext.c +++ b/builtin/remote-ext.c @@ -202,6 +202,8 @@ int cmd_remote_ext(int argc, { BUG_ON_NON_EMPTY_PREFIX(prefix); + show_usage_and_exit_if_asked(argc, argv, usage_msg); + if (argc != 3) usage(usage_msg); diff --git a/builtin/remote-fd.c b/builtin/remote-fd.c index ae896eda57..1a1aa65273 100644 --- a/builtin/remote-fd.c +++ b/builtin/remote-fd.c @@ -64,6 +64,7 @@ int cmd_remote_fd(int argc, BUG_ON_NON_EMPTY_PREFIX(prefix); + show_usage_and_exit_if_asked(argc, argv, usage_msg); if (argc != 3) usage(usage_msg); diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 3196da7b2d..5a21d57c43 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -542,8 +542,7 @@ int cmd_rev_list(int argc, const char *show_progress = NULL; int ret = 0; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage(rev_list_usage); + show_usage_and_exit_if_asked(argc, argv, rev_list_usage); git_config(git_default_config, NULL); repo_init_revisions(the_repository, &revs, prefix); diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 949747a6b6..f4c2b1b000 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -713,6 +713,8 @@ int cmd_rev_parse(int argc, int seen_end_of_options = 0; enum format_type format = FORMAT_DEFAULT; + show_usage_and_exit_if_asked(argc, argv, builtin_rev_parse_usage); + if (argc > 1 && !strcmp("--parseopt", argv[1])) return cmd_parseopt(argc - 1, argv + 1, prefix); diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 2197d6d933..1f1fb8e682 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -619,6 +619,8 @@ int cmd_unpack_objects(int argc, quiet = !isatty(2); + show_usage_and_exit_if_asked(argc, argv, unpack_usage); + for (i = 1 ; i < argc; i++) { const char *arg = argv[i]; diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index 3b282d41e6..42d8f67174 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -93,8 +93,7 @@ struct repository *repo UNUSED) BUG_ON_NON_EMPTY_PREFIX(prefix); - if (argc == 2 && !strcmp(argv[1], "-h")) - usage(upload_archive_usage); + show_usage_and_exit_if_asked(argc, argv, upload_archive_usage); /* * Set up sideband subprocess. diff --git a/t/helper/test-simple-ipc.c b/t/helper/test-simple-ipc.c index fb5927775d..d7a41cd053 100644 --- a/t/helper/test-simple-ipc.c +++ b/t/helper/test-simple-ipc.c @@ -612,8 +612,8 @@ int cmd__simple_ipc(int argc, const char **argv) if (argc < 2) usage_with_options(simple_ipc_usage, options); - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(simple_ipc_usage, options); + show_usage_help_and_exit_if_asked(argc, argv, + simple_ipc_usage, options); if (argc == 2 && !strcmp(argv[1], "SUPPORTS_SIMPLE_IPC")) return 0; diff --git a/t/t0012-help.sh b/t/t0012-help.sh index 9c7ae9fd36..d3a0967e9d 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -257,14 +257,8 @@ do export GIT_CEILING_DIRECTORIES && test_expect_code 129 git -C sub $builtin -h >output 2>err ) && - if test -n "$GIT_TEST_HELP_MUST_BE_STDOUT" - then - test_must_be_empty err && - test_grep usage output - else - test_grep usage output || - test_grep usage err - fi + test_must_be_empty err && + test_grep usage output ' done