Message ID | 20230831071845.GC3197751@coredump.intra.peff.net (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | more unused parameters in parseopt callbacks | expand |
Jeff King <peff@peff.net> writes: > The option_parse_strategy() callback does not look at opt->value; > instead it calls append_strategy(), which manipulates the global > use_strategies array directly. But the OPT_CALLBACK declaration assigns > "&use_strategies" to opt->value. > > One could argue this is good, as it tells the reader what we generally > expect the callback to do. But it is also bad, because it can mislead > you into thinking that swapping out "&use_strategies" there might have > any effect. Let's switch it to pass NULL (which is what every other > "does not bother to look at opt->value" callback does). If you want to > know what the callback does, it's easy to read the function itself. Good. It is not like we have two options and each of them affect its own list of strategies. There is a single use_strategies list that is populated not just by the parse options callback but by other callers. So I agree that the new way is less confusing. > > Signed-off-by: Jeff King <peff@peff.net> > --- > builtin/merge.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/builtin/merge.c b/builtin/merge.c > index 0436986dab..545da0c8a1 100644 > --- a/builtin/merge.c > +++ b/builtin/merge.c > @@ -264,7 +264,7 @@ static struct option builtin_merge_options[] = { > OPT_RERERE_AUTOUPDATE(&allow_rerere_auto), > OPT_BOOL(0, "verify-signatures", &verify_signatures, > N_("verify that the named commit has a valid GPG signature")), > - OPT_CALLBACK('s', "strategy", &use_strategies, N_("strategy"), > + OPT_CALLBACK('s', "strategy", NULL, N_("strategy"), > N_("merge strategy to use"), option_parse_strategy), > OPT_STRVEC('X', "strategy-option", &xopts, N_("option=value"), > N_("option for selected merge strategy")),
diff --git a/builtin/merge.c b/builtin/merge.c index 0436986dab..545da0c8a1 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -264,7 +264,7 @@ static struct option builtin_merge_options[] = { OPT_RERERE_AUTOUPDATE(&allow_rerere_auto), OPT_BOOL(0, "verify-signatures", &verify_signatures, N_("verify that the named commit has a valid GPG signature")), - OPT_CALLBACK('s', "strategy", &use_strategies, N_("strategy"), + OPT_CALLBACK('s', "strategy", NULL, N_("strategy"), N_("merge strategy to use"), option_parse_strategy), OPT_STRVEC('X', "strategy-option", &xopts, N_("option=value"), N_("option for selected merge strategy")),
The option_parse_strategy() callback does not look at opt->value; instead it calls append_strategy(), which manipulates the global use_strategies array directly. But the OPT_CALLBACK declaration assigns "&use_strategies" to opt->value. One could argue this is good, as it tells the reader what we generally expect the callback to do. But it is also bad, because it can mislead you into thinking that swapping out "&use_strategies" there might have any effect. Let's switch it to pass NULL (which is what every other "does not bother to look at opt->value" callback does). If you want to know what the callback does, it's easy to read the function itself. Signed-off-by: Jeff King <peff@peff.net> --- builtin/merge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)