All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 2/7] builtins: always pass prefix to parse_options()
Date: Tue, 28 Mar 2023 16:54:32 -0400	[thread overview]
Message-ID: <20230328205432.GB1754055@coredump.intra.peff.net> (raw)
In-Reply-To: <20230328205253.GA1753925@coredump.intra.peff.net>

Our builtins receive a "prefix" argument as part of their cmd_foo()
function. We should always pass this to parse_options() if we're calling
it, as it may be used for OPT_FILENAME() options.

In the cases here, there's no option that would use it, so we're not
fixing any bug. This is just future-proofing and setting a good example
(plus quelling some -Wunused-parameter warnings).

Note in the case of revert/cherry-pick, that we plumb the prefix through
to run_sequencer(), as those builtins are just thin wrappers around it.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/mktag.c  | 2 +-
 builtin/revert.c | 9 +++++----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/builtin/mktag.c b/builtin/mktag.c
index 42c2457c705..967a4442dee 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -81,7 +81,7 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
 	int tagged_type;
 	struct object_id result;
 
-	argc = parse_options(argc, argv, NULL,
+	argc = parse_options(argc, argv, prefix,
 			     builtin_mktag_options,
 			     builtin_mktag_usage, 0);
 
diff --git a/builtin/revert.c b/builtin/revert.c
index 62986a7b1b0..287721fd37b 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -94,7 +94,8 @@ static void verify_opt_compatible(const char *me, const char *base_opt, ...)
 		die(_("%s: %s cannot be used with %s"), me, this_opt, base_opt);
 }
 
-static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
+static int run_sequencer(int argc, const char **argv, const char *prefix,
+			 struct replay_opts *opts)
 {
 	const char * const * usage_str = revert_or_cherry_pick_usage(opts);
 	const char *me = action_name(opts);
@@ -141,7 +142,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
 		options = parse_options_concat(options, cp_extra);
 	}
 
-	argc = parse_options(argc, argv, NULL, options, usage_str,
+	argc = parse_options(argc, argv, prefix, options, usage_str,
 			PARSE_OPT_KEEP_ARGV0 |
 			PARSE_OPT_KEEP_UNKNOWN_OPT);
 
@@ -246,7 +247,7 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
 
 	opts.action = REPLAY_REVERT;
 	sequencer_init_config(&opts);
-	res = run_sequencer(argc, argv, &opts);
+	res = run_sequencer(argc, argv, prefix, &opts);
 	if (res < 0)
 		die(_("revert failed"));
 	replay_opts_release(&opts);
@@ -260,7 +261,7 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
 
 	opts.action = REPLAY_PICK;
 	sequencer_init_config(&opts);
-	res = run_sequencer(argc, argv, &opts);
+	res = run_sequencer(argc, argv, prefix, &opts);
 	if (res < 0)
 		die(_("cherry-pick failed"));
 	replay_opts_release(&opts);
-- 
2.40.0.675.gb17cd5d94c8


  parent reply	other threads:[~2023-03-28 20:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28 20:52 [PATCH 0/7] unused argc/argv/prefix parameters Jeff King
2023-03-28 20:54 ` [PATCH 1/7] fast-import: fix file access when run from subdir Jeff King
2023-03-28 20:54 ` Jeff King [this message]
2023-03-28 20:55 ` [PATCH 3/7] builtins: annotate always-empty prefix parameters Jeff King
2023-03-28 20:56 ` [PATCH 4/7] builtins: mark unused " Jeff King
2023-03-28 20:57 ` [PATCH 5/7] mark "argv" as unused when we check argc Jeff King
2023-03-28 20:57 ` [PATCH 6/7] t/helper: mark unused argv/argc arguments Jeff King
2023-03-28 20:58 ` [PATCH 7/7] parse-options: drop parse_opt_unknown_cb() Jeff King
2023-03-29 13:17 ` [PATCH 0/7] unused argc/argv/prefix parameters Derrick Stolee
2023-03-29 15:21   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230328205432.GB1754055@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.