From patchwork Thu Jan 16 21:35:48 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: 13942328 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 0B8728821 for ; Thu, 16 Jan 2025 21:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063360; cv=none; b=ejKOWejhKN/PwGvRYwfErBFyfKaLrbaePf7Ikl4qG9Lbjy1kFm1vfb7Hr2tvt0X9BOHsdVrPhWCABxAvE1wugrbh4hkzdaJXBv1gGVhTHZEzHGP6WGV8S/rYENDE9uPlhqTCc1UQUabdDDiS9f7duZVIHintd4SymX6jnXXsGCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063360; c=relaxed/simple; bh=XXrPZtgJcebV6H7r0OlPU2NyY+Eal4C9wj06G1XRUOI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q1EZzoGiqYgV5iL0uGC4dA4a3JTBFLEwn7o+0crOzGXS1HeTgqHD0ld9MeqkvpSHhYDaBAXXDVG6ZelD/aqcLXKlorcHnkxNYvY/bzPbWC1flBYOWpPlOBPAVfCsCis0K7oPywL7BBFKnVcZYulGlvXH7jgbbjofkXQSbj+gPRs= 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=oAmYyQcD; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=u7TrAgS+; arc=none smtp.client-ip=103.168.172.151 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="oAmYyQcD"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="u7TrAgS+" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id 1B08C138028F; Thu, 16 Jan 2025 16:35:57 -0500 (EST) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-11.internal (MEProxy); Thu, 16 Jan 2025 16:35:57 -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=1737063357; x= 1737149757; bh=eGgvm+BQvA0rTn8FNhysSVahGgHij9K+9UXkk0tGzq4=; b=o AmYyQcDtX93c2SJhXc6v1Dvsm4qQtVNIUSs8qzf066An/DttKC8mmxtBrsEMLneT KTwGIn+NXmYROCC9DbZ8N8U28RJvTxOJ+HE0yxkr8hVozuo9ZaZDUSf0lzKO0YVr xu3GAdLMcJn7Y6/rlsi0Skk9kk1trmV+Sk30mIARbexbhJlNCAe9Rsg4Kwqz2YKs BnKycY649qv0TWzQ21fiozh3vWZGne8j/KnQqw97PbWzJevTfKAp1GBXLJn25CQe hWIPL9zjC8eSFUf442JEuWjEE9xxDCIHEQJ460kkNvYpSVUy4QgSZ4UtjsnQhSl5 zXKUOJajyEVj+9EEb+hFA== 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=1737063357; x=1737149757; bh=e Ggvm+BQvA0rTn8FNhysSVahGgHij9K+9UXkk0tGzq4=; b=u7TrAgS+miuskZ7MU Lt5o/iEHERT9ixQlEnO2Hv4+9QG+iMhU4okK3Zg7/TSIqHQI5uKybxlQ5N7VqjOy Y8CZfKWRdXegcTzIYdgweJZepTA9TcH51qNyOyNA9EBQS1iwSCsLkyqUBDPy1hOt yd8fzbF0sYg1FMpv58tjyErf2FBeiHZu4KXJQ6ByNFJJMeU4Fh9Zh/0RKJSIOxsG mXVqomkpS+GL+QdQtt5wTB7y0iB8lwJEXX4mtFMYS61wVPtaDAnVG9+Ld2UuKC/7 e45Vp63EBvpZeYwnBSooAIe40LeqWlSsMQeFe7Z6jols/aBL/Mwfij83O7xJBNKs jlJUA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeiuddgudegjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomheplfhunhhiohcuvecujfgrmhgr nhhouceoghhithhsthgvrhesphhosghogidrtghomheqnecuggftrfgrthhtvghrnhepvd fflefhueetgfektedthfduleffudetleefieeulefhvdduieeukefhtddvudeknecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhithhsthgvrh esphhosghogidrtghomhdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhht pdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhope hpvghffhesphgvfhhfrdhnvghtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidr tghomh X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 16 Jan 2025 16:35:56 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH v4 1/6] t0012: optionally check that "-h" output goes to stdout Date: Thu, 16 Jan 2025 13:35:48 -0800 Message-ID: <20250116213553.2563751-2-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-210-gaa1682cadd In-Reply-To: <20250116213553.2563751-1-gitster@pobox.com> References: <20250116012524.1557441-1-gitster@pobox.com> <20250116213553.2563751-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 --- * Same as before. 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: 13942329 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 CAE201D63EB for ; Thu, 16 Jan 2025 21:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063361; cv=none; b=SRpjenoa7aFa9Oo/nQ2tVvqc0hcikdUZB9X8lLpcfwrZql0G9tlIweOa0YP4uFZrAmxGcCFVO55STJ/Sw/k0SBDE0wVL5zORpgceoKYPnz5Zku7p1a/zs3M+a+O2Y1pwAas22+jrTnl2sGJmt3a748QDw7v1FDnTF0Spa2RyL6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063361; c=relaxed/simple; bh=dbqv6ZMYuvkfkhhcSNsmdaBhPZ7d2ZbHtGkUpDj4l0A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y4760hNVjZcvWKa87MI1JHY4Cte/iVdSZ0Do3d0iz28/dQECs39HOshuTUVnoZQtPYyisiVGS6srXvfQJmwi7U+XlLyaVhoo6ZRg+f+njkDl4pDU8S6YGjNcw2UX95D9nGRUbhl0XJc+OBKERAE5c+D7OXoR4tfEb96Ecen28WQ= 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=fxOywGaC; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=pv5Yglal; arc=none smtp.client-ip=103.168.172.151 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="fxOywGaC"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="pv5Yglal" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id C76AE138021E; Thu, 16 Jan 2025 16:35:58 -0500 (EST) Received: from phl-frontend-01 ([10.202.2.160]) by phl-compute-02.internal (MEProxy); Thu, 16 Jan 2025 16:35:58 -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=1737063358; x= 1737149758; bh=3wjjqTWtcOm6RjDt7g0gCOrIY+yTm/8v2c46Yw+T+vU=; b=f xOywGaCquWILI593tTejrbrcdgJ76HB+av75ryXiZEgFa+Zg0qiQfEepD8ZTzjZ6 b/VdkycEgLcAXRzWNa8a1d4GN8FG8ZELfgkMdfHBZr/7g8bcS0P474B9Iy6F0NxU 3usBpbRiFvDFS6ZuKyU6uIjv9J0mwkWZN+c3p70sOyzSFNC2pBYgemMssOAkAzRz xaGw2sVPigJOpxJYd/3iwGTXKq05qGOBPTkW2FgNAk8x15vKnlO23BY5OWqrGo9a jKjUTsB9XHyjHuN4osb/0HScG9FKmbYyvWmJPcYk4L2o+PfRH6WwJ8zjfY9QHsL7 pmxVS3Eh33i55zdFbWypQ== 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=1737063358; x=1737149758; bh=3 wjjqTWtcOm6RjDt7g0gCOrIY+yTm/8v2c46Yw+T+vU=; b=pv5Yglal9kCydfoNa Rm1DTQXeM1LG9baf+HrfZbvqXI90uM4evonyWnc+MsyijsxMq8GZ6DrfdW0i0qe9 KCzTm9186Rant4Zc4HHvfNl+h0nm/0orrJcgI9y8hiwMmEZj0CQGwGq28uPFqXcd x98Ix9KgGxUneEa5bdBGJwGrSbPkwQtSB3fV65IEAtZcefdP/onFIlvEULNOXeqO 4vXdzBQKvFOxuaMbWWzAM/eeGAb89jqyNyIsxsEJV6TEiDidwvgybsd5tW5wZyz4 7gsnMEsmgquE5sl8m2rUz1XPoopmOVvzG/7Mo08szWv+7LVPxZPUW0NM9KsU3UyD cxgXg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeiuddgudegjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomheplfhunhhiohcuvecujfgrmhgr nhhouceoghhithhsthgvrhesphhosghogidrtghomheqnecuggftrfgrthhtvghrnhepvd fflefhueetgfektedthfduleffudetleefieeulefhvdduieeukefhtddvudeknecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhithhsthgvrh esphhosghogidrtghomhdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhht pdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhope hpvghffhesphgvfhhfrdhnvghtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidr tghomh X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 16 Jan 2025 16:35:58 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH v4 2/6] parse-options: add show_usage_with_options_if_asked() Date: Thu, 16 Jan 2025 13:35:49 -0800 Message-ID: <20250116213553.2563751-3-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-210-gaa1682cadd In-Reply-To: <20250116213553.2563751-1-gitster@pobox.com> References: <20250116012524.1557441-1-gitster@pobox.com> <20250116213553.2563751-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 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, instead. 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_with_options_if_asked(argc, argv, usage, options); to help correct 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. Suggested-by: Jeff King Signed-off-by: Junio C Hamano --- * Helper function renamed. 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..4051a8e1d1 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_with_options_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..39f0886254 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_with_options_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 21:35:50 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: 13942330 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 4AD8A1862 for ; Thu, 16 Jan 2025 21:36:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063363; cv=none; b=hksDc22SdqjRsexvsiXCMberuVmzOY9S5uSKL6JhaQECwCUskxzWqLn7M3g0eyGkhogZRA9jjdsQ4gwCQWCL+4+9/FziOUX/5nacZ0X4sJuOHbmRDn94tvIlAKBNcLacGH6MTaxttOvk7A0IwqiL1rE+KoC5Hc84caSGJgWnoMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063363; c=relaxed/simple; bh=riA/mmEX2eRmX8sEDFVDgPdnkMrWf3LCA/Fy30olJ70=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DWOKTPicxCidQC1MDyZm0rVSvW4Ida0Qz4aq5hI/TSgh7wCX2xTgFn3xON7VNXM23an7p2R2Nbag4EMhFtj2yZc3k1uwqGyMBCboSpUtKUMExKUVwhPXKcwVRnxQ08BWCpPF966gwlITI2q3VAAe+DxZWPNueXOjTlQHSkxt35Y= 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=dohDFD/d; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KkSSCtll; arc=none smtp.client-ip=103.168.172.155 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="dohDFD/d"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KkSSCtll" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id 44876114015B; Thu, 16 Jan 2025 16:36:00 -0500 (EST) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-03.internal (MEProxy); Thu, 16 Jan 2025 16:36:00 -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=1737063360; x= 1737149760; bh=CDBNdiJ2azPePsVjLKi5aVBT0zEDrKIUhJnqCZqNZPE=; b=d ohDFD/d5KBJPV0kg8Yg3b1BKiQvr2TtjK1L+xFeTuxvxL2CkNsMCPQhaI+SHneLn qYh4gbR2tUZDvI24DHzGRzPW61rRGc2p9Ety93XEiACgeEgOi236ZkkKUv5r99jH oFtIT85owzfYJz+/s7qf5Irg3wQ5BYGvNJzwKU9EEhQspeZ491WIuG0NI/evJFl0 ThmXlfZfspm6aZibXYzpgokDq05d+/XlML1AL1U/tdjeKCLydfp0AJUL0uhpl7w3 hOUdhTmNcPEGhHyVBnxL9crR/gv7FxKuq8083Cn7lH/cvwIRf38hQ/LX3Dc14Qhd 2iFGDfqtn4UPs90Le7Aeg== 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=1737063360; x=1737149760; bh=CDBNdiJ2azPePsVjLKi5aVBT0zED rKIUhJnqCZqNZPE=; b=KkSSCtllGEWMrcEE+f1ecgAyo92XaGWeOr27oACA7aeQ tqbSXlflozWpyd8wgiKSmCfBxbkmVp69WinNCvJvbo/7W0eRctYjPV0R4FYCAthc xVygh51//3decs0L44Szs3Kp6F+FyjPVyeoNDTYmYXlIeU2yEGnpM0XiNxR/MysB IEahhfoen3t4PQ+Akg1KmivLbgpLn+D/Zz4zIRGCglUQ0tnVaeyOEbzWSOxhGa7E LcWn+h7R1C/4DYC3BH9UBd0qzUMFQGcXEPqeOmLUbklAf3YSjukBJ0+/KSLQHFb4 snMTdULCnMTPGwYMaWVxuKVh7K+ZZ3hyTAlyIeDobQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeiuddgudegjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefluhhnihhoucevucfjrghmrghn ohcuoehgihhtshhtvghrsehpohgsohigrdgtohhmqeenucggtffrrghtthgvrhhnpeelve eifeeiueffueeghfevueeggfefvedvfeelveeuvdefvddufeekhedtfedtgeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehgihhtshhtvghrse hpohgsohigrdgtohhmpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepgh hithhsthgvrhesphhosghogidrtghomh X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 16 Jan 2025 16:35:59 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v4 3/6] usage: add show_usage_if_asked() Date: Thu, 16 Jan 2025 13:35:50 -0800 Message-ID: <20250116213553.2563751-4-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-210-gaa1682cadd In-Reply-To: <20250116213553.2563751-1-gitster@pobox.com> References: <20250116012524.1557441-1-gitster@pobox.com> <20250116213553.2563751-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_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 Signed-off-by: Junio C Hamano --- * Helper function renamed. 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..d43dd248c4 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_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..d9f323a0bd 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_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_if_asked(int ac, const char **av, const char *err) +{ + if (ac == 2 && !strcmp(av[1], "-h")) + show_usage_if_asked_helper(err); +} + void NORETURN die(const char *err, ...) { va_list params; From patchwork Thu Jan 16 21:35:51 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: 13942331 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 A671523F293 for ; Thu, 16 Jan 2025 21:36:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063364; cv=none; b=W3w8jFKoRdq/O3IKB+G48X41ZMm1/H493WwIDQ3HX/UaDocJLxNw3hN2RsQ7fkUl26d6VUzgBTYgR7xdSuD0gqYYZZm8wQypvDjqfzL+LPSTJV8d2IEJ9KOksCNgnfdEuG8+soVvyRpUMoSWun9eQfCNKI3hw01EswWeu9v35c4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063364; c=relaxed/simple; bh=3466YrW6VxD6+qpJn+bq9cTxNqYo87fidDJmvAHvpEw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C9TQogDkkxFWNodPxvdZ/WDehM/m+rwmlRSArlIyU0S3ZItjGiESpXos02KrRuinLUIfY14r6QqkGycjLfUxZWkgosqieTks3MjGkaHGT/lzEJQU0+CSLqaMYbZo4dqUDeu2z6pUg7dkqLsIzpMH09E/FXIYZLCUDnVr5/tgcWA= 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=1BXprMwa; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PNEdsDC6; arc=none smtp.client-ip=103.168.172.151 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="1BXprMwa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PNEdsDC6" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id A2FA1138021E; Thu, 16 Jan 2025 16:36:01 -0500 (EST) Received: from phl-frontend-01 ([10.202.2.160]) by phl-compute-03.internal (MEProxy); Thu, 16 Jan 2025 16:36:01 -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=1737063361; x= 1737149761; bh=lc2f+DSz3JTSwNZDWv3nu29brbO90bOCyYy5ZJYe5n8=; b=1 BXprMwarYZLTVoSgo5O4KZgpQ8NIyKTUbqR5BNFxdkEW0y0N7kaF70AKIfLle204 Da3JXS5dEbHUqMt6GRhYP2uPzNRMox7hiiLbcw/JdKdrEtfznbjFDP3O6ba/kp5Q onKmDaYWf3+2PCNdVofKixM15PjpAzDWOyMj7HgCDn1SYKBKDxw6cxQpNEDlbRRy 9oq0UTjaI4LAUpiIKFji2wNwihOgUDmFXGdioF9pi+P81nnDC+/Li6jg2cFqlg+1 MyBnIT1g/qCeDa9DViIoACn9SwRPd3y+lMJRlK6O0EvNYy1oNghTsGZD6qHxvIlz K7oZqR8fRo6BLP2fDH+LA== 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=1737063361; x=1737149761; bh=lc2f+DSz3JTSwNZDWv3nu29brbO9 0bOCyYy5ZJYe5n8=; b=PNEdsDC6QOqSSuRMGs8pTG2AwG27Im24ZV6b+8KyYJ0F Ai8RIObVMqCgO5I/pEoy+ufz9H2fycu9o0CAjxegnzQwLVegGF3O8wAoJKmPtGFr MSQ6YpcKagS0NgDwQpLX6Gkw/jMuwMeL+zQzcGKb75tfPlzYh7R13FESQL6u/xFL 9av3BDctE02ZarWv1uE/B+R1hOZPBbMHXiG4+nnVryxafgNcP9Th9Bc8wJHXbLhl Rz3e3EuaWm29se6DkU6Vv+0vyPH3JWSnvw/7xlhHMx1qUab77e0JvuJctIrynS+n VdwVdtwk42MYxP9zFgjqT8iw+ocucZoFgtgyopQLbQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeiuddgudegjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefluhhnihhoucevucfjrghmrghn ohcuoehgihhtshhtvghrsehpohgsohigrdgtohhmqeenucggtffrrghtthgvrhhnpeelve eifeeiueffueeghfevueeggfefvedvfeelveeuvdefvddufeekhedtfedtgeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehgihhtshhtvghrse hpohgsohigrdgtohhmpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepgh hithhsthgvrhesphhosghogidrtghomh X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 16 Jan 2025 16:36:01 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v4 4/6] builtins: send usage_with_options() help text to standard output Date: Thu, 16 Jan 2025 13:35:51 -0800 Message-ID: <20250116213553.2563751-5-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-210-gaa1682cadd In-Reply-To: <20250116213553.2563751-1-gitster@pobox.com> References: <20250116012524.1557441-1-gitster@pobox.com> <20250116213553.2563751-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_with_options_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, but it is specifically testing that the "-h" option gets a response even with a corrupt index file, so for now let's leave it there. Signed-off-by: Junio C Hamano --- * Helper function renamed. 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/helper/test-simple-ipc.c | 4 ++-- t/t7600-merge.sh | 2 +- 14 files changed, 31 insertions(+), 32 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 1338b606fe..8d8f38fa1d 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_with_options_if_asked(argc, argv, usage, options); git_config(git_default_config, NULL); diff --git a/builtin/branch.c b/builtin/branch.c index 6e7b0cfddb..7c8b4b65b6 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_with_options_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..da9345a44b 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_with_options_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..e30086c7d4 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_with_options_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..38457600a4 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_with_options_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..c84062bfc1 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_with_options_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_with_options_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..0820e524f1 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_with_options_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..ea007c8e7e 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_with_options_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..a4431429b7 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_with_options_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..ba9faf126a 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_with_options_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..6c9eaf3788 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_with_options_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..b2f6b1a3fb 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_with_options_if_asked(argc, argv, + update_index_usage, options); git_config(git_default_config, NULL); diff --git a/t/helper/test-simple-ipc.c b/t/helper/test-simple-ipc.c index fb5927775d..03cc5eea2c 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_with_options_if_asked(argc, argv, + simple_ipc_usage, options); if (argc == 2 && !strcmp(argv[1], "SUPPORTS_SIMPLE_IPC")) return 0; 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 21:35:52 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: 13942332 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 2AC6F2416A1 for ; Thu, 16 Jan 2025 21:36:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063365; cv=none; b=tjwl6yXUOoO0eqHQJI83PBOZb9MKAHHNMYxJExjgkOvNZ/FLkwNZ5mbtJVxm4n0KDwv6lNDPMW5oMNsFYIB8H68ZUvIo7b9iEvoe9gEXTF7u/62ZLP/NLG8/j6W15RrmWA8KqgyJiF5ZIKMqlQAHtlNrLYhkxqUtF13ypfyxBzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063365; c=relaxed/simple; bh=Ar8gfXflg7vNQvnCp61WgdbP9ZdzovxdJg4I7Yv4AjQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XexlTSQZGniXqzMIxDXuuMupFj0e5q6r+yl6YkX5Mk7rYoLTy70AR7gMjuIgTVl7xWm7DA3VJtdSZZuTZRVCPTZXJQRzA2YE1kD5ptjkDDs2fJIdntX/VKbAStQt7KoglqrwdLEqRCORX67Ls/ylAX9iqCoVGPFFjJteo7uiT+Y= 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=Px7O7poH; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=m3Rls0vU; arc=none smtp.client-ip=103.168.172.155 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="Px7O7poH"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="m3Rls0vU" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id 4AE9A114015B; Thu, 16 Jan 2025 16:36:03 -0500 (EST) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-10.internal (MEProxy); Thu, 16 Jan 2025 16:36:03 -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=1737063363; x= 1737149763; bh=XDn6qOep1UlzEMcRC82d65BjAMYW6QKZJmxhggIwrSo=; b=P x7O7poHWwx1g4GwAUilsBM8a0EYQxh4gL3ztB/3t9XoHeFfjYDO44Ir9XG6oIsjq 4/k8TW5CYL0d6GwmbH+W3r1Sxj3IWxwtdOjZs1IvTkiWeM6RrAqhxSupmg4Rv6r4 z0PQfswL6M5TiC7/ivQp8agtL5rVfAzeJh+WOvvS3bgU6+C0GTK7NIbrvKO0dcNb i0R7z+saN9edhmbIyz30jOISUvHK6wuwy+09owVkr7Lbhv/RMtnxwiqVPUSBCDXu bAbPHPQudtfS34EAGIXdctVh2NtIaEc/gKGlVPj3whYOCdGyMeBkPPFJ6ByYfqXZ 2tJkDJvcO7KityfNv4cfg== 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=1737063363; x=1737149763; bh=XDn6qOep1UlzEMcRC82d65BjAMYW 6QKZJmxhggIwrSo=; b=m3Rls0vUcmMaeQY2odcgwc+WsTZyu0CLv8/p5wQt8P1s p6BdSAUqFbq+TTDe//wWDuf+muI9LUEjip+ElVodlcvKBRB+CFkGn7kq8LrqirIk kipiP1OMSQzljgqem9tyA9nIVJJ+ahEGkGaooISr7jrV+a2jReRtk5rbzm+zt6wq Ce2ApqX8gCZWo6P6b9Frama1QvZdYALnKFNTbzdpcYkhkCPRfsnli7uuHztK8gnB 43TGvhcG+8V4AB2V9Al/zb8TKXjTKRE1koxP6xKVbgawnJTBGiu0Myki/OZbsOZt iLNKqU43QdPdRG2x2xbs0ad1e4Em4TPUvRW4TV+88g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeiuddgudegkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefluhhnihhoucevucfjrghmrghn ohcuoehgihhtshhtvghrsehpohgsohigrdgtohhmqeenucggtffrrghtthgvrhhnpeelve eifeeiueffueeghfevueeggfefvedvfeelveeuvdefvddufeekhedtfedtgeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehgihhtshhtvghrse hpohgsohigrdgtohhmpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepgh hithhsthgvrhesphhosghogidrtghomh X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 16 Jan 2025 16:36:02 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v4 5/6] oddballs: send usage() help text to standard output Date: Thu, 16 Jan 2025 13:35:52 -0800 Message-ID: <20250116213553.2563751-6-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-210-gaa1682cadd In-Reply-To: <20250116213553.2563751-1-gitster@pobox.com> References: <20250116012524.1557441-1-gitster@pobox.com> <20250116213553.2563751-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_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(...); There are (unnecessarily) being clever ones that 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 like "git var -h" 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 --- * Helper function renamed. Fix fo fetch-pack.c moved from the next step and redone. builtin/credential.c | 3 ++- builtin/fetch-pack.c | 2 ++ builtin/unpack-file.c | 8 ++++++-- builtin/upload-archive.c | 3 ++- builtin/var.c | 1 + 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/builtin/credential.c b/builtin/credential.c index 14c8c6608b..f6fc948123 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_if_asked(argc, argv, usage_msg); + if (argc != 2) usage(usage_msg); op = argv[1]; diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index bed2816c2d..d07eec9e55 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -75,6 +75,8 @@ int cmd_fetch_pack(int argc, list_objects_filter_init(&args.filter_options); args.uploadpack = "git-upload-pack"; + show_usage_if_asked(argc, argv, fetch_pack_usage); + for (i = 1; i < argc && *argv[i] == '-'; i++) { const char *arg = argv[i]; diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c index 6da2825753..fb5fcbc40a 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_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..9d76a31c8f 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_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..46d40d6fba 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_if_asked(argc, argv, var_usage); if (argc != 2) usage(var_usage); From patchwork Thu Jan 16 21:35:53 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: 13942333 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 0CFFD241A02 for ; Thu, 16 Jan 2025 21:36:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063368; cv=none; b=i8r2AECD46yPUcaqRMWJ4jWN14NGNzbVe8qKUlcT9py1kqHQf3jZLjP4hfNQTkMjiMuCgkrIcybvaudFDEobRPRWu+flWlozmHXlFJEwLhDVdiw1WNmxkR0v6NqG7Tgno86WASZsGQ4GNq2/D09Ala3/po6/iHQ4eqtfNjWB9Xg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737063368; c=relaxed/simple; bh=8Vhwawmul1ik1XKrFuu2O4KUvPubkDU6jmQ9o/tFl34=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aDJuKrlIt0b7HVlmRxQmyYjYyOOBAhxIt9MzlW4GyN2DSqwggAF2wNpDjvIrYffbCVlMz8o3XRXcl0FwQ+68lUZQoO2CLW1Jis0sMx2DDyivcTPlh2BQePgKJ+H2g0FHECeYTFtDd2fF9Y+w3JmcQeoKCm+QI8jIApPz1B45b0Y= 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=b78UETAh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fECCTSU2; arc=none smtp.client-ip=103.168.172.155 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="b78UETAh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fECCTSU2" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id 150B411401F4; Thu, 16 Jan 2025 16:36:05 -0500 (EST) Received: from phl-frontend-01 ([10.202.2.160]) by phl-compute-07.internal (MEProxy); Thu, 16 Jan 2025 16:36:05 -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=1737063364; x= 1737149764; bh=aTLfIh4jwy+7KQe8eLYIf7jimvwfjo10SgnHyR9wvqg=; b=b 78UETAhJdg0uAZVPi7pX0C2UjuS1sbedzs36h0jT+puDgLqpgwNbGJUHNhAZZWqn IeNY9YgkoyGohJDjppSe5PbxX3NbObaOfrhuZXECEVHPhdBKqKCSjBJCuBbIqdVK zmTzHxeczbMC2eFOausYyzT+onq1arDgVVMJ1+aI00nkUonQO4PtmUvM7fSPFIEs bf9DkEIzAHAV9FyAqEXod/GRrT9rt9q08SosHuirhhrXw+YuymQAS6I1cgCZ3D86 prduCwr5tUF0vm1T7pO+sC2FaGEG9Q8KeKsDS+ppQpNBc0kodJTQJogdILAfDBoH QWWbl/1DwxY00qKEnh7lg== 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=1737063364; x=1737149764; bh=aTLfIh4jwy+7KQe8eLYIf7jimvwf jo10SgnHyR9wvqg=; b=fECCTSU2dLzWj0PYTAPzdlukHLo3LBYaiMd3xngBRMIC pORQMMs4F68yM4Da5GVQkKATu1Zv4fNkjEujKe5KzLwC06rqKBIrJBQSjRBD2D+Y u3E6HwmylI0ha1zjlwoUFT6Y/AAQ910Y5Z0K5kcb89H9DEEzqSuJKWoIuzgq2V7w n77+F5LU69obzrEtRYHYlmFeIm+aqViZoJj2/B/3MD/0nqI608P2n0V/AkwLqPT8 RRCz8zhgnJG+52oIOgX8Pj88mcDuFCJSDIgGvj9EZ6mTi0wlYeORdiChR/zgyO14 wkKCmC/vVfkVMgLalPJf0fL+S6dzEdrrhIxocEViTw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeiuddgudegjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvuf ffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefluhhnihhoucevucfjrghmrghn ohcuoehgihhtshhtvghrsehpohgsohigrdgtohhmqeenucggtffrrghtthgvrhhnpeelve eifeeiueffueeghfevueeggfefvedvfeelveeuvdefvddufeekhedtfedtgeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehgihhtshhtvghrse hpohgsohigrdgtohhmpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepgh hithhsthgvrhesphhosghogidrtghomh X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 16 Jan 2025 16:36:04 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v4 6/6] builtin: send usage() help text to standard output Date: Thu, 16 Jan 2025 13:35:53 -0800 Message-ID: <20250116213553.2563751-7-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-210-gaa1682cadd In-Reply-To: <20250116213553.2563751-1-gitster@pobox.com> References: <20250116012524.1557441-1-gitster@pobox.com> <20250116213553.2563751-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 --- * Helper function renamed. 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/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/t0012-help.sh | 10 ++-------- 19 files changed, 37 insertions(+), 32 deletions(-) diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c index cef1ffe3ce..5d80afeec0 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_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..99b1749723 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_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..81c0bc8ed7 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_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..e31cc797fe 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_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..2da46fecdc 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_if_asked(argc, argv, fast_import_usage); reset_pack_idx_option(&pack_idx_opts); git_pack_config(); diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c index 6bec0d1854..e4cd1627b4 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_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..d41b126ec0 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_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..264df6259a 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_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..3314fb1336 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_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..97b8a792c7 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_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..abfc060e28 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_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..3febe732f8 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_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..bd2037f27d 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_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..39908546ba 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_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..28f148049f 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_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..428c866c05 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_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..8faa6024b2 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_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 9d76a31c8f..97d7c9522f 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_if_asked(argc, argv, upload_archive_usage); /* * Set up sideband subprocess. 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