builtins: always pass prefix to parse_options()

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 28, 2023 at 16:54 UTC 836c8ceb7a4d26910a70a17ffba5a0d8b87bd1a1
2 files changed +6 -5
builtin/mktag.c
+1 -1
@@ -81,7 +81,7 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
81 int tagged_type;
82 struct object_id result;
83
84 - argc = parse_options(argc, argv, NULL,
84 + argc = parse_options(argc, argv, prefix,
85 builtin_mktag_options,
86 builtin_mktag_usage, 0);
87
builtin/revert.c
+5 -4
@@ -94,7 +94,8 @@ static void verify_opt_compatible(const char *me, const char *base_opt, ...)
94 die(_("%s: %s cannot be used with %s"), me, this_opt, base_opt);
95 }
96
97 -static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
97 +static int run_sequencer(int argc, const char **argv, const char *prefix,
98 + struct replay_opts *opts)
99 {
100 const char * const * usage_str = revert_or_cherry_pick_usage(opts);
101 const char *me = action_name(opts);
@@ -141,7 +142,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
142 options = parse_options_concat(options, cp_extra);
143 }
144
144 - argc = parse_options(argc, argv, NULL, options, usage_str,
145 + argc = parse_options(argc, argv, prefix, options, usage_str,
146 PARSE_OPT_KEEP_ARGV0 |
147 PARSE_OPT_KEEP_UNKNOWN_OPT);
148
@@ -246,7 +247,7 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
247
248 opts.action = REPLAY_REVERT;
249 sequencer_init_config(&opts);
249 - res = run_sequencer(argc, argv, &opts);
250 + res = run_sequencer(argc, argv, prefix, &opts);
251 if (res < 0)
252 die(_("revert failed"));
253 replay_opts_release(&opts);
@@ -260,7 +261,7 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
261
262 opts.action = REPLAY_PICK;
263 sequencer_init_config(&opts);
263 - res = run_sequencer(argc, argv, &opts);
264 + res = run_sequencer(argc, argv, prefix, &opts);
265 if (res < 0)
266 die(_("cherry-pick failed"));
267 replay_opts_release(&opts);