From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] die_for_incompatible_opts(): accept more than four options
Date: Thu, 27 Aug 2026 07:35:38 -0700 [thread overview]
Message-ID: <xmqqv78vbphh.fsf@gitster.g> (raw)
In-Reply-To: <20260827045515.GA176544@coredump.intra.peff.net> (Jeff King's message of "Thu, 27 Aug 2026 00:55:15 -0400")
Jeff King <peff@peff.net> writes:
> It took me a minute to understand why we would even want to have an
> arbitrary-sized input if we are capping at 4 anyway. The answer is that
> we are capping at 4 options _that the user actually specified_. But the
> input can be the total set of conflicting options, which is greater. OK.
>
> Really we could cap at 2 if we wanted to be technically correct, but it
> might annoy the user to find each pair iteratively.
>
> So that makes sense. Of course the follow-on question is whether any
> callers actually want to pass more than 4 options. I don't see any
> patches adding new calls.
There isn't. While I was writing [*], I wondered if the two calls
next to each other for opt3 and opt4 want to be combined to opt7.
* https://lore.kernel.org/git/xmqq1pbkefh0.fsf@gitster.g/
>> -void die_for_incompatible_opt4(const char *opt1_name, int opt1,
>> - const char *opt2_name, int opt2,
>> - const char *opt3_name, int opt3,
>> - const char *opt4_name, int opt4)
>
> One nice thing about foo4() without varargs is that the compiler will
> tell you if you messed it up. The obvious downside being that you have
> to count in order to avoid messing it up. ;)
Yes. I like that and that is why the static inlines are kept to
cover the most common cases.
I think I can do without [1/2], by the way.
- die_for_incompatible_optN() (2 <= N <= 4) will keep accepting N
pairs of <int, const char *>
- die_for_incompatible_opts() will take pairs of <int, const char *>,
expects "int" to be 0 (not set), 1 (set), or EOF==-1 (sentinel).
- static inline void die_for_incompatible_opt2() emulation layer
will call die_for_incompatible_opts(!!opt1, opt1_name, !!opt2,
opt2_name, EOF). Similarly for opt3() and opt4() variants.
> Using ARRAY_SIZE() is nice, because we could in theory bump this 4
> later. Though sadly here:
>
>> switch (count) {
>> case 4:
>> die(_("options '%s', '%s', '%s', and '%s' cannot be used together"),
>> - opt1_name, opt2_name, opt3_name, opt4_name);
>> + options[0], options[1], options[2], options[3]);
>
> we still hard-code various count values. It probably would be fine to
> allocate a buffer for the message, though I guess that pushes
> translators into lego-land.
Very true.
We could switch to dynamic allocations immediately after we see
option[] filled, as we are committed to die() at that point and can
afford to waste cycles. That way, for die_for_incompatible_opt10()
when the end-user uses 7 of them, we can fill option[4], switch to
dynamic allocation to collect all 7 of them and report.
The reason I chose not to is primarily because we cannot use the
existing message templates in that case, hurting i18n/l10n.
next prev parent reply other threads:[~2026-08-27 14:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 23:31 [PATCH 0/2] die_for_incompatible_opts(): unbounded number of options Junio C Hamano
2026-08-26 23:31 ` [PATCH 1/2] die_for_incompatible_optN: swap the order of arguments Junio C Hamano
2026-08-26 23:31 ` [PATCH 2/2] die_for_incompatible_opts(): accept more than four options Junio C Hamano
2026-08-27 1:19 ` Elijah Newren
2026-08-27 14:22 ` Junio C Hamano
2026-08-27 4:55 ` Jeff King
2026-08-27 14:35 ` Junio C Hamano [this message]
2026-08-27 17:28 ` [PATCH v2] die_for_incompatible_opts(): unbounded number of options 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=xmqqv78vbphh.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox