Git development
 help / color / mirror / Atom feed
* [PATCH 0/2] die_for_incompatible_opts(): unbounded number of options
@ 2026-08-26 23:31 Junio C Hamano
  2026-08-26 23:31 ` [PATCH 1/2] die_for_incompatible_optN: swap the order of arguments Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Junio C Hamano @ 2026-08-26 23:31 UTC (permalink / raw)
  To: git

We have die_for_incompatible_optN() (for 2 <= N <= 4) to check and
complain when two or more among N mutually incompatible options are
used.

What should a developer do if there are more than four options that
cannot be used at once?

Introduce die_for_incompatible_opts(), which can handle an arbitrary
number of mutually exclusive options.  This is done in two steps:

 - The API for existing functions takes N pairs (for 2 <= N <= 4) of
   'int set, const char *name' parameters that signal which options
   are set.  This parameter order is inconvenient for varargs, where
   a sentinel value marks the end of the argument list (and there is
   no clear sentinel value of type 'int').  The first patch rewrites
   all implementations and callers of die_for_incompatible_optN() to
   swap the parameter order to pairs of 'const char *name, int set'.

 - The second patch then introduces die_for_incompatible_opts(),
   which takes an arbitrary number of 'const char *name, int set'
   pairs terminated by a NULL sentinel.

We could do without the first step and use the 'const char *, int'
order only in die_for_incompatible_opts(), leaving the traditional
die_for_incompatible_opt[234]() functions using the
'int, const char *' order, but using a consistent ordering is
likely easier in the long run.

 1/2: die_for_incompatible_optN: swap the order of arguments
 2/2: die_for_incompatible_opts(): accept more than four options

 builtin/add.c          |  6 +++---
 builtin/clone.c        |  8 ++++----
 builtin/commit.c       | 24 ++++++++++++------------
 builtin/difftool.c     |  6 +++---
 builtin/gc.c           |  8 ++++----
 builtin/grep.c         |  6 +++---
 builtin/log.c          |  6 +++---
 builtin/merge-tree.c   |  8 ++++----
 builtin/pack-objects.c | 21 ++++++++++-----------
 builtin/push.c         |  8 ++++----
 builtin/repack.c       | 12 +++++++-----
 builtin/replay.c       | 18 +++++++++---------
 builtin/rev-list.c     |  6 +++---
 builtin/show-ref.c     |  7 ++++---
 parse-options.c        | 26 ++++++++++++++------------
 parse-options.h        | 40 +++++++++++++++++++++++-----------------
 revision.c             | 26 +++++++++++++-------------
 17 files changed, 123 insertions(+), 113 deletions(-)

-- 
2.55.0-862-g3c6f97f7b9


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-08-29 11:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-27 17:28 ` [PATCH v2] die_for_incompatible_opts(): unbounded number of options Junio C Hamano
2026-08-29 11:15   ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox