All of lore.kernel.org
 help / color / mirror / Atom feed
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: Sat, 29 Aug 2026 10:51:28 -0700	[thread overview]
Message-ID: <87a4q4u867.fsf@gitster.g> (raw)
In-Reply-To: <20260829111418.GA40814@coredump.intra.peff.net> (Jeff King's message of "Sat, 29 Aug 2026 07:14:18 -0400")

Jeff King <peff@peff.net> writes:

> On Thu, Aug 27, 2026 at 07:35:38AM -0700, Junio C Hamano wrote:
>
>> > 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.
>
> OK. I wonder if we're approaching churn here, but I don't have a strong
> feeling.

A quiz that I may probably fail if I were asked in a job interview:

- Using die_for_incompatible_opt[234]() functions, find a way for
  any arbitrary N (4 < N) to ensure that no more than two of N
  options are not set at the same time.

  For example, die_for_incompatible_opt5() can be written like so:

    void die_for_incompatible_opt5(int opt1, const char *name1,
				   int opt2, const char *name2,
				   int opt3, const char *name3,
				   int opt4, const char *name4,
				   int opt5, const char *name5)
    {
	die_for_incompatible_opt4(opt1, name1, opt2, name2,
				  opt3, name3, opt4, name4);
	die_for_incompatible_opt4(opt5, name5, opt2, name2,
				  opt3, name3, opt4, name4);
	die_for_incompatible_opt2(opt5, name5, opt1, name1);
    }
	
but can't we do better?  ;-)

> Yeah, but then you can't get good compiler support, since I don't think
> there is an integer equivalent to LAST_ARG_MUST_BE_NULL.

Ah, I missed that.  It certainly makes sense to flip the order of
these <set, name> pairs.  I suspect that nobody was thinking that
these eventually need to support vararg form when they first added
die_for_incompatible_opt2() and then later extended it to forms that
can support 3 and 4 options; otherwise we would certainly have
chosen the <nameN, setN> order to allow NULL termination.


  reply	other threads:[~2026-08-29 17:51 UTC|newest]

Thread overview: 13+ 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
2026-08-29 11:14       ` Jeff King
2026-08-29 17:51         ` Junio C Hamano [this message]
2026-08-29 18:04         ` René Scharfe
2026-08-27 17:28 ` [PATCH v2] die_for_incompatible_opts(): unbounded number of options Junio C Hamano
2026-08-29 11:15   ` Jeff King
2026-08-30 20:55     ` 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=87a4q4u867.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 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.