From patchwork Fri Jan 17 21:31:43 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: 13943982 Received: from fout-a7-smtp.messagingengine.com (fout-a7-smtp.messagingengine.com [103.168.172.150]) (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 88AC91D5CCF for ; Fri, 17 Jan 2025 21:31:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737149514; cv=none; b=oUje66akPIjPALwVwPaFQb8JWEhvlFjzY5T+qpvXindxJPds9RI2ZeloE/1WUIV+dQ2x13QqUnIy2ohAKVVWAmlIPHWBCIIwJ8Lu2LafP40C3VbMeB6TRsEgETFUkaTvghhq8Ye2V6gH8XY2P1O8FAjVCJe0SdBop6VBn3hd5Kw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737149514; c=relaxed/simple; bh=Pjp/Akb0yAkDReFNwRziEOlEnjdgi3qrm35LHHDOiEg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dN7KaGcft+yEMgsYcyIS0HpL75FNABqEQv9wemsc3X0JYCKKuDhkkXAilkU0ICCpVbKZmcq9Ak5a36skGtKZnrlvDESIiAmtdBV+XuPBh3HITsvYq21zT4fnto4mAQf/OmMsVHFyBEKOxKWi5wonEX6C5NncEm4EzeeJZqGaTyA= 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=BKkZPCRT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=k7Y5kgAC; arc=none smtp.client-ip=103.168.172.150 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="BKkZPCRT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="k7Y5kgAC" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id AC5891380167; Fri, 17 Jan 2025 16:31:51 -0500 (EST) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-06.internal (MEProxy); Fri, 17 Jan 2025 16:31:51 -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=1737149511; x= 1737235911; bh=DUzw/oduyEmFtRe3OQUnTm5Tg6xmLPqs7CYeTK7vbCI=; b=B KkZPCRTP8GBdRkA5A8wT3DC3V3SGCR9LFNuGX2YvjJ5rVsTjiJo1HmmWOtGUYlta 4hPMurasYwZQC3nX/9Ordak0gOE/f8n0wN3zEgKrVCMJcUWPtEIDfmz4rKWSCZFP 85qvG9nnT6MSZCuaDklE9bbUrgyUKvbzNJNSbjaCSjDqtSYgy7EROYtDrcRt+byV uWxgIHZLG8ZOfsjezRph3k78bEDfP9CTKfVORu0cnNRfaydY4srxAMdznhkMDuYG 0m9ugpyfESLfwyqRRJwlysKUTkikeDQVoq9S1kBPfSKsDwPN1BlPd1huHFIJdAQn IuZxnTyowyUtHboeZxUVw== 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=1737149511; x=1737235911; bh=D Uzw/oduyEmFtRe3OQUnTm5Tg6xmLPqs7CYeTK7vbCI=; b=k7Y5kgACukE5ImBau tl0Tri6GzdJbpXkYk4mTKX781iuRgAB3MwuaT2oXazJErAOlq+iQyOpgrkTE5gPx uDVU8PbgCCXDdgvftKf1mZplHPZ1nOPQ+Ds3wTjX+ldhwtylY01x2Htgh/QbLSCC uti+GPVJwMQUcWChHM+4+UZ2efGdQjNCzzgV7k5KLUqo7VAOQnLJL99hlhPvFBSb kw9UlMoz/rRDPfBErciNngdqBX+9vACMnyJy7F0C7j/zfcwKwk8BPXBfmuDj3wHN As4eGWMWptCWWD1/+fR9A7G/ifogiEssvCjCJlYrZXAIeirstIUqbQqyPwaOMKSJ DlfXQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeifedgudegkecutefuodetggdotefrod 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; Fri, 17 Jan 2025 16:31:51 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH v5 1/6] t0012: optionally check that "-h" output goes to stdout Date: Fri, 17 Jan 2025 13:31:43 -0800 Message-ID: <20250117213148.3974552-2-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-218-gc7e8be6a8f In-Reply-To: <20250117213148.3974552-1-gitster@pobox.com> References: <20250116213553.2563751-1-gitster@pobox.com> <20250117213148.3974552-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: 13943983 Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38CDB1DB362 for ; Fri, 17 Jan 2025 21:31:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737149516; cv=none; b=oR0G9jBDUBmA7rqoRedmnzAUbfycr7s3AK3bVNEtX3DtF0k3bK525e0KXSb9QpKNqEDeoHXxisqIUh/hvh4ZLGMNgANt2t3Nh34ps04SDyap3F8Mr0cAjC7o39W0l7sLZIFhDai5Cms3esEx9SrxiQfQ2NgjRsfuCK5Osxyrq2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737149516; c=relaxed/simple; bh=9uulPGrHHdtkCYu2fZxrPHrpN9b11UJTWlRAvTOSy6E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W2tA4ZyU3goFNnqzFnNKc+GUqbX1P7Mbm+CzhShyanBMMyytuN3mepBpHhoKe7bfR0lodsLKCh0GcOkEEvuyppk7qK7dyTYVg206BT2IRuTFG4s8+QpkD+4erfbcQj12cAHwdOORlt2U3IbZGJyikVI5AI/g5ss6A/347bDeESk= 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=v06Ih7vR; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QF1h6La9; arc=none smtp.client-ip=103.168.172.153 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="v06Ih7vR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QF1h6La9" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 33B7011400DC; Fri, 17 Jan 2025 16:31:53 -0500 (EST) Received: from phl-frontend-01 ([10.202.2.160]) by phl-compute-01.internal (MEProxy); Fri, 17 Jan 2025 16:31:53 -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=1737149513; x= 1737235913; bh=LnBE1ZWpZ236dUuCQuTgvAE/zV59EjrGeOkzAU5+1sw=; b=v 06Ih7vR6C6a1owAL0CV45kydMlcER+CLaN/3nvYtOP0xDA9h5atC9rywCWAryhaY gnAW15sd3SRxfLZKb9JJMhk2+v0+T5DHawfbz3VI4mI3eo+CT5at9Le6l+umkBlp ILVm2TNEiUr6oFe3J5QAiO3La+UpZOAh8CJQeXd2PDXNcxidQtV1oFXkrLGimKPV 3FohaPtNve/OxG4DWb8OMhM23Y14FvyUMe5fZdpzoU0K+fYd47oOP/v7vOymsylV 84cKgVY05SclY3RMRD8FQbTO+mYLkcNKs14khd6ES45kVaRsIAMhoLzIiHhK1ztR BUO1dsSbiz2HOco1ZWJZg== 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=1737149513; x=1737235913; bh=L nBE1ZWpZ236dUuCQuTgvAE/zV59EjrGeOkzAU5+1sw=; b=QF1h6La9ebknkoAEg srgqJ5Kh6UnHcMSMqxY9fAJLkScieuIeMzyY2gBSJfKBZ8TZbwSlZGFY+iMMnIK5 3BsdpZ28FxzIrNc5upgiTmx/AVaIF9MGES36YoOwInve39xe8xIq2XUjP2GwzSZq SsPT2Q7pFvaml0ioXpU175jbCUTQ7/ig2L9N3Css0kQty9UxnSsHkBIMJNDk18r2 nES8SxBVstAgBvBRxDavVQVqnCLqmBBIorgHoFG6arGC0HXrf41iswsHjbHunblr gmSCIJxQBPfKbZNqnrEJg41S8JhJgZzCnykRVrZ+uxoAj1liD4OtvyMBDlFuKqcS d7YFA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeifedgudegkecutefuodetggdotefrod 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; Fri, 17 Jan 2025 16:31:52 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH v5 2/6] parse-options: add show_usage_with_options_if_asked() Date: Fri, 17 Jan 2025 13:31:44 -0800 Message-ID: <20250117213148.3974552-3-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-218-gc7e8be6a8f In-Reply-To: <20250117213148.3974552-1-gitster@pobox.com> References: <20250116213553.2563751-1-gitster@pobox.com> <20250117213148.3974552-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 --- 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 Fri Jan 17 21:31:45 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: 13943984 Received: from fout-a7-smtp.messagingengine.com (fout-a7-smtp.messagingengine.com [103.168.172.150]) (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 836751DDC02 for ; Fri, 17 Jan 2025 21:31:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737149517; cv=none; b=MyjmCG2GbSFxuwR3z7Jg1xaSSYzbvaZYur4QmxN43R7DJwvGSIQJldVQJoeNqKjzXJqxYEQWpB2Uy6ezCDlJ97XOe0tQ5MgqWEHf0Uyqc4hoiqG0PoiFlRRj7B0Qgwk2T+72YQ+dfDsD/zhWNPEc3DmWY0OBDb7TlyXyz19DmYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737149517; c=relaxed/simple; bh=ydnERI537sfl3Gc29Q+s3HB+/67xH10+UmdqNaWpGxg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HFpNrXtss3syaZsvk+D8iDZhOKSZBU9egUhcyJJgVh8CGrtEvIos6Bay26YugxasD+vLr08pEQ4SeCRNXq4RRDi2Yk4Ysq7kk9YPCbYn7p2voqcV86A72YqIMVT2x3btOFOFXuig6hd/b+gebsb5x0VCvca0Aor6BL+68DMQCBk= 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=VtGsdUD2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mLq+Orvj; arc=none smtp.client-ip=103.168.172.150 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="VtGsdUD2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mLq+Orvj" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id 99EC21380128; Fri, 17 Jan 2025 16:31:54 -0500 (EST) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-11.internal (MEProxy); Fri, 17 Jan 2025 16:31:54 -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=1737149514; x= 1737235914; bh=CB5M3NoCtHJJzl/NCWOJSxUzzqzTbSddWKxOZBAXLFE=; b=V tGsdUD2H7EvyUNZLgWw0GdccVXoTanuuaJbYBmqxAoE7SM4e6WwWMdEjbEu9BrSN Fhh9MbhshOUtv+r39d90gadQ0GMcbAtMeoLeeEzAEUlR/r1qrfXrHIQeWibykma9 aMXNzEm6bLREEodkNAEgpMfKYqMZEgy77avmPjpnvzoHIWYtviD+DXG3DlCI4wph L1yNB8c+eEJx7T9lr00Fhn+WwdZ075aT3EddEQBkqrT9HiHIE5A7zF0w4Nkw/BEf CBoUGeO5qSpp+8DCnj/6r/DVtrKpu8rYqqwlUSjqWzlUTioF2iPFdD7NbWgYHAOd T/G2hisGgZpQBe3zE3Ukw== 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=1737149514; x=1737235914; bh=C B5M3NoCtHJJzl/NCWOJSxUzzqzTbSddWKxOZBAXLFE=; b=mLq+Orvj007Mi2lLA lubyiDwkFeeoLUneJXUc7xI11m5tY+61xooEvIx7FaNNVejGemOa0f6d9TFPJZdP STUnIftFSFxqjJBj+0yh689hdYu+JpdIgWliSMPGA4dOZs9qBH/Sl+tNfgCnGKxx 12cDJXDxKik02LoBu4gUHmdaxw/wc/VNd3VsMCDhSLANmoE1DoWB09y5GINJb2bz ay77MGBuqV3yYtdRP2gmkVD1RpDyVRR2dNxr+ca60TLrsBdgIJezgY4FUFSY/Opi iuTVbnmue/67RQPG0VL8jKdrWRlydQ+bCdUORHixHWYkEv/HUZKePin+iQEBLJH7 TO2Xw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeifedgudegjecutefuodetggdotefrod 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; Fri, 17 Jan 2025 16:31:54 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH v5 3/6] usage: add show_usage_if_asked() Date: Fri, 17 Jan 2025 13:31:45 -0800 Message-ID: <20250117213148.3974552-4-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-218-gc7e8be6a8f In-Reply-To: <20250117213148.3974552-1-gitster@pobox.com> References: <20250116213553.2563751-1-gitster@pobox.com> <20250117213148.3974552-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. Helped-by: Jeff King Signed-off-by: Junio C Hamano --- git-compat-util.h | 2 ++ usage.c | 27 ++++++++++++++++++++++++--- 2 files changed, 26 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..38b46bbbfe 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 vfreportf(FILE *f, const char *prefix, const char *err, va_list params) { char msg[4096]; char *p, *pend = msg + sizeof(msg); @@ -32,8 +32,13 @@ 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); + fflush(f); + write_in_full(fileno(f), msg, p - msg); +} + +static void vreportf(const char *prefix, const char *err, va_list params) +{ + vfreportf(stderr, prefix, err, params); } static NORETURN void usage_builtin(const char *err, va_list params) @@ -173,6 +178,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); + vfreportf(stdout, _("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 Fri Jan 17 21:31:46 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: 13943985 Received: from fout-a7-smtp.messagingengine.com (fout-a7-smtp.messagingengine.com [103.168.172.150]) (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 E6AF11DE3B3 for ; Fri, 17 Jan 2025 21:31:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737149518; cv=none; b=o1KGzUCqIqnEND7/pyIOd7RtnZyfYFqKMZ7dSsqgj6kswiMzJTmb57xrCmdwsn9OVrnc6yHjhd7ySUPXuNVNA2plCtQUhS6lT+XxBVgm54UDzQGen1DGt4YENEKWurpcX/LmfnaAWgHxxb5uhvclks77iCGwl31dx6J8zFoFfu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737149518; c=relaxed/simple; bh=WayQ5amF0hGtkeqItxLsQawB5S9haoXrnwPFFh43qRM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=POEBnCyEmFSOQhLuvswaKJXQwwp3NjhzbTWKp14puPM3xnAJMY6PeC6mGIYv9yhE8VeVijMx+8YrEdTZGQNISGu7Sv7+ihB5eAcjTyM/F4GtZS4zYzRgXh+fjxYDhgdgpI5Kfxa+45PpW4x/ei7WaOfz/+sNEM5MSnnuZUv7XuM= 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=y0fHKIrb; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=sjZsW7oy; arc=none smtp.client-ip=103.168.172.150 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="y0fHKIrb"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="sjZsW7oy" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 1C6FA1380167; Fri, 17 Jan 2025 16:31:56 -0500 (EST) Received: from phl-frontend-01 ([10.202.2.160]) by phl-compute-05.internal (MEProxy); Fri, 17 Jan 2025 16:31:56 -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=1737149516; x= 1737235916; bh=pGBQ91OtwTz0DI52ftKwhVC0SaQznSAd2g+C0jmaFQ4=; b=y 0fHKIrbuiI+l6oyr/yEdiRKXGsFwsneOyRmYaZ/FOnorv8t0FbG5qsVxd4mlZoez ILkHMRnotHQuc2Wd3JgrKBQVS+hvAepNRsqDmNqkdhIWrAi6uc9QSYJJuQuvPHZe vPpawEK+xMG/R1+vGYNp208ylmo36mKaBDnvZHddUSYhZYBGDC+YnfDOWiSsrr/1 7y8/WVEFEyfWRUu6a3RGcK0bF1biDjBuZuCPPgaH0CYWMjhTwxSOni0EHyglap6g 24jdMUOr/2rUmr4tBSsE9aTTLuoQi9Vxqs5PGcY5FQcuQOkv8K0hzRJHh2t6en7d za3vK0iBEZVQ31bPi2eVg== 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=1737149516; x=1737235916; bh=p GBQ91OtwTz0DI52ftKwhVC0SaQznSAd2g+C0jmaFQ4=; b=sjZsW7oyPNAcudZGn uC+o3PlBHVKCLKbpeWC7a1HsIIsVGeGjRPcVFqk5q+zvBKvXkApZASR7+bW6lPpy YGJmYKc4yy8CHsGt9l3Z3CLKvSXd1uDvumr8/xDx3phhAeZtgBupGZDAgIbGQwxx gAcbOgq3KSZOaCeW5XDQkW+0uk4OcpSIWEB0tgbs1FxoZzp5LuH6lsNG0fYZuqYN f+u9s2k9UCeoA4XnovHle4PCnpC/FWFisPiX5w2Sff6emmlXjea1C/r3ZGVV4rRm iqmf9ZIfcSUUNEQL5UBuw+dr2oux16wktDZqSUCU2blioioBU2g4YqFA5lWcHc/3 Ee86A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeifedgudegkecutefuodetggdotefrod 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; Fri, 17 Jan 2025 16:31:55 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH v5 4/6] builtins: send usage_with_options() help text to standard output Date: Fri, 17 Jan 2025 13:31:46 -0800 Message-ID: <20250117213148.3974552-5-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-218-gc7e8be6a8f In-Reply-To: <20250117213148.3974552-1-gitster@pobox.com> References: <20250116213553.2563751-1-gitster@pobox.com> <20250117213148.3974552-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. Acked-by: Jeff King 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/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 Fri Jan 17 21:31:47 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: 13943986 Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A80C91DE895 for ; Fri, 17 Jan 2025 21:31:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737149520; cv=none; b=Vj4ZLz1ifq4ImesBI6OxO7dTEKKNJ/EbPSgqapQrmezz1NtHWcbPSCeBFKaUxo468gqiuc+OurLZQqDAb1I25kkr5BOh3e6Q530RztDva3vKHcRglAsmVA0zaPJHygcrW/jDCt4o2RKZFrJ6EzqYbW6q8wrQ82vOqhOKK3lzG2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737149520; c=relaxed/simple; bh=vJdZi6Lfu784JIUdqNygl8j9ZHcGYk4oEylkU5S13s4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B/+LNlDb08O/HthS4K+hIwUkINN7kiE6y2ZgL0gdPiKtRNxOmiXXO9ue8eOOgqFST1lfivwVpGrKP7TRW5yMYs8YVrCozsQRCdSsLqY5rNxgDSITt83aKwxAPpZWaTRj4EALLsXfuu5QHpUkLyR7Thwp8LvbdD/2fvBOuMwbeDw= 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=lUQtdZ4e; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=aR8Gw75Y; arc=none smtp.client-ip=103.168.172.153 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="lUQtdZ4e"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="aR8Gw75Y" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id 9F7AA114010A; Fri, 17 Jan 2025 16:31:57 -0500 (EST) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-03.internal (MEProxy); Fri, 17 Jan 2025 16:31: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=1737149517; x= 1737235917; bh=yK57puxiPTX1CvrxDKA/0e1qHVUGTjdkFTAKSmubZE4=; b=l UQtdZ4eRaiDMXg7iANE6UAjl8wZPbLYo7SNi+K2RP90D55YKZ+Ro/5s6gOk59RQQ Ukqlfb4PG67ClFe+cFwIOQxTSogSV/7wSpMe7KE8NH7tSH+IRvegW93uriDBH4q9 Tdqtz4fRB+t/oGSgCTC2l9j52boYVrA6YXfuH/331Y4Cj9YXRXfrAjxCkBxi/U9L RJLPRkII+cEwV07Ww7o9fCR5sN0NzxiNJnmtvO7e1H2kYUygTZfjkoexKSfzqi8C jehLR+zarhd3M3c3Q86h+92vvjhb0ix6DnK39tvMElbdTtWv0VjAfwD57GjmTpoL AIC6pEYrgo547NyB/6Xag== 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=1737149517; x=1737235917; bh=y K57puxiPTX1CvrxDKA/0e1qHVUGTjdkFTAKSmubZE4=; b=aR8Gw75YNEDWR+MX0 9SIhyWK2WRJNiUcouBpjaiOmBTvt44ALOcDNlBHLJ2NnejGZFTeBoXg1W1Lvke6n O1fixGAI/HgpTDEA5VQLlhkFPuVjLbxCDQVcYdDk/3elL2uV3bCktb4jy0UiFu1T 8QO9koXJeut+NzX3BjOYL5KOTLita8wHtrbIejbSq2AdH6niYR+kjxzwv10zX0FI zeRFVAy5JXHJg1rTvtC8TBKX8eoOgy1m+OLZlYVrYefJ56wtfFhJuKkZAb5F5bRn PgaIgUF9aafYG5Yf15fBfHEhC+etc5DjcosPP8BIMuDMh2op/s2QrfX/kH1wVZRL lRftQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeifedgudegkecutefuodetggdotefrod 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; Fri, 17 Jan 2025 16:31:57 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH v5 5/6] oddballs: send usage() help text to standard output Date: Fri, 17 Jan 2025 13:31:47 -0800 Message-ID: <20250117213148.3974552-6-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-218-gc7e8be6a8f In-Reply-To: <20250117213148.3974552-1-gitster@pobox.com> References: <20250116213553.2563751-1-gitster@pobox.com> <20250117213148.3974552-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. Acked-by: Jeff King Signed-off-by: Junio C Hamano --- 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 Fri Jan 17 21:31: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: 13943987 Received: from fout-a7-smtp.messagingengine.com (fout-a7-smtp.messagingengine.com [103.168.172.150]) (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 057B91DED4C for ; Fri, 17 Jan 2025 21:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737149522; cv=none; b=jrJwihfsBf5jb5EbbJtmezP8NJ3T+BhZCrTotPjDGGzx1WkC3NARrkOpoa5BDP1U7lGiy5svjrwtjuCUc3sfwQYqvpWLSMunJ/k7rnqnUPAVODIo29K/nlTNJmhIwZ6uMT3thhCms+L6OszxvYB5/eZRRaCrA6KoaagNxxZfXKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737149522; c=relaxed/simple; bh=qdWBTvEsyhnISynpVtWPFBlLczrfQ2zXNVJuEe5MHwc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N85CAO4Lqi0nZ1Zq1P+O2TQ7f+K3yTrfNiEZ1gU3t1H0ZxdvigxjTfaBZaOdkaMMl9spEMaC/yc57wycSFuXeHxI1Fmk/M67fls5j7HgjFBbZjJMjfBsOZ/WwTpPLwOUioX557qIJWrSwCrJp5OvCtL+o0McffkMxWhgOoshI6E= 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=Elb2+/7k; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KECdoSdx; arc=none smtp.client-ip=103.168.172.150 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="Elb2+/7k"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KECdoSdx" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id 16F101380128; Fri, 17 Jan 2025 16:31:59 -0500 (EST) Received: from phl-frontend-01 ([10.202.2.160]) by phl-compute-06.internal (MEProxy); Fri, 17 Jan 2025 16:31:59 -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=1737149519; x= 1737235919; bh=U54O6BJq0xfeYopK+8UYDX75HmRsuOKw91nQZGy6fzg=; b=E lb2+/7kq2W00LmfAKRSVDBBh9T2JY6A70PDjfJZL3LLDGKwwTNhzEB7MBopVsiy0 ++b6dv1Gztq5gEz0uO39SugYwvuqevWIRFzZLqrddyQftQugKlmrGjus2YyQp/7M Tqq8LC/qzZP4R4kEmTaV5QXYletKFYi9Q2Jz04oNLJn5iBwzzDejeA3lscxBHd9f kWvrLacRN7af1KwK2G3Ia9erYyV06zaf87Wc0Tdh5fsxjedMOH4YPI+vyF3AFvfi i3eQ2Ez2+TiOiXojhTpx26abZE+Tib74Adyk7PbmzRhcuJldwLc0/BoQC1nJoxZ7 yzJh7AFQx3j3hb+ihXIww== 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=1737149519; x=1737235919; bh=U 54O6BJq0xfeYopK+8UYDX75HmRsuOKw91nQZGy6fzg=; b=KECdoSdxk5AOS+SvV 6MHvbMLiCGo2CQdiWKSL6rnaPOKRHvgNVC5MLoOScOerQSPnSi7714mXmI/ZB+Ss qbBBiRNWBi1QKwLf+IW2Zee5ulmVoXYMXyLp6usbjW/NNQZxZDePvXQzDVFCFt2/ p7aTrDzg/rv4ZlFKu+0xPoQtY78XxGILHNUOYxxA4Fw0S6T7JiBx6ohvcrNk0n3A ILq73wilIxQPau4A/U0IXXnBhTWpJOBWhqpaVOMiS3/6onf1dA07cKBu5wDmaII9 aEfDAh0d6V1Zl5OXg5KAx+dJfe87visQdbtiTkCds+bQqgOhehW7aQVpWoN7m89n papkg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeifedgudegkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomheplfhunhhiohcuvecujfgrmhgr nhhouceoghhithhsthgvrhesphhosghogidrtghomheqnecuggftrfgrthhtvghrnhepvd fflefhueetgfektedthfduleffudetleefieeulefhvdduieeukefhtddvudeknecuvehl uhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepghhithhsthgvrh esphhosghogidrtghomhdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhht pdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhope hpvghffhesphgvfhhfrdhnvghtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidr tghomh X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 Jan 2025 16:31:58 -0500 (EST) From: Junio C Hamano To: git@vger.kernel.org Cc: Jeff King Subject: [PATCH v5 6/6] builtin: send usage() help text to standard output Date: Fri, 17 Jan 2025 13:31:48 -0800 Message-ID: <20250117213148.3974552-7-gitster@pobox.com> X-Mailer: git-send-email 2.48.1-218-gc7e8be6a8f In-Reply-To: <20250117213148.3974552-1-gitster@pobox.com> References: <20250116213553.2563751-1-gitster@pobox.com> <20250117213148.3974552-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. Acked-by: Jeff King 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/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