git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] die_for_incompatible_opts(): accept more than four options

From
Elijah Newren <newren@gmail.com>
Date
Aug 27, 2026, 01:19 UTC
Message-ID
<CABPp-BG2PJ7AyC2ctPuX0bmkFd_cGmNz+XtbjdjCbMrH4_d99A@mail.gmail.com>
In-Reply-To
<20260826233152.1703497-3-gitster@pobox.com>
On Wed, Aug 26, 2026 at 4:32 PM Junio C Hamano <gitster@pobox.com> wrote:
>
[...]
Show 34 quoted lines
> +void die_for_incompatible_opts(const char *opt1_name, int opt1, ...)
>  {
> -       int count = 0;
> +       unsigned count = 0;
>         const char *options[4];
> +       va_list ap;
> +
> +       va_start(ap, opt1);
>
>         if (opt1)
>                 options[count++] = opt1_name;
> -       if (opt2)
> -               options[count++] = opt2_name;
> -       if (opt3)
> -               options[count++] = opt3_name;
> -       if (opt4)
> -               options[count++] = opt4_name;
> +       while (count < ARRAY_SIZE(options)) {
> +               const char *name = va_arg(ap, const char *);
> +               if (!name)
> +                       break;
> +               if (va_arg(ap, int))
> +                       options[count++] = name;
> +       }
> +
>         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]);
>                 break;
>         case 3:
>                 die(_("options '%s', '%s', and '%s' cannot be used together"),
> diff --git a/parse-options.h b/parse-options.h
va_start() without a va_end()?
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 13 in “die_for_incompatible_opts(): unbounded number of options”
  1. 0/2 die_for_incompatible_opts(): unbounded number of optionsJunio C Hamano, Aug 26, 2026
  2. 1/2 die_for_incompatible_optN: swap the order of argumentsJunio C Hamano, Aug 26, 2026
  3. 2/2 die_for_incompatible_opts(): accept more than four optionsJunio C Hamano, Aug 26, 2026
  4. Elijah NewrenAug 27, 2026
  5. Junio C HamanoAug 27, 2026
  6. Jeff KingAug 27, 2026
  7. Junio C HamanoAug 27, 2026
  8. Jeff KingAug 29, 2026
  9. Junio C HamanoAug 29, 2026
  10. René ScharfeAug 29, 2026
  11. die_for_incompatible_opts(): unbounded number of optionsJunio C Hamano, Aug 27, 2026
  12. Jeff KingAug 29, 2026
  13. Junio C HamanoAug 30, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.