Thread (13 messages) flat view 13 messages, 4 authors, 14d ago

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

From: Elijah Newren <hidden>
Date: 2026-08-27 01:19:35

On Wed, Aug 26, 2026 at 4:32 PM Junio C Hamano [off-list ref] wrote:
[...]
quoted hunk ↗ jump to hunk
+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()?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help