]> git.ipfire.org Git - thirdparty/git.git/commitdiff
parse-options: add OPT_BITOP()
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sun, 27 Jan 2019 00:35:25 +0000 (07:35 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 28 Jan 2019 00:28:18 +0000 (16:28 -0800)
This is needed for diff_opt_parse() where we do

   value = (value & ~mask) | some_more;

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
parse-options.c
parse-options.h

index 779034e1fd86ad7cbd987d859656abd4c3f782d6..62d94ca2e0323c5d543f9290610fdc52c243ca6a 100644 (file)
@@ -109,6 +109,13 @@ static int get_value(struct parse_opt_ctx_t *p,
                        *(int *)opt->value &= ~opt->defval;
                return 0;
 
+       case OPTION_BITOP:
+               if (unset)
+                       BUG("BITOP can't have unset form");
+               *(int *)opt->value &= ~opt->extra;
+               *(int *)opt->value |= opt->defval;
+               return 0;
+
        case OPTION_COUNTUP:
                if (*(int *)opt->value < 0)
                        *(int *)opt->value = 0;
index d663b839734771e159090095d09e43258ecf0829..c97324f576a01e5ffe79c1f6aaa9728d28a1c5da 100644 (file)
@@ -10,6 +10,7 @@ enum parse_opt_type {
        /* options with no arguments */
        OPTION_BIT,
        OPTION_NEGBIT,
+       OPTION_BITOP,
        OPTION_COUNTUP,
        OPTION_SET_INT,
        OPTION_CMDMODE,
@@ -118,6 +119,7 @@ struct option {
        int flags;
        parse_opt_cb *callback;
        intptr_t defval;
+       intptr_t extra;
 };
 
 #define OPT_BIT_F(s, l, v, h, b, f) { OPTION_BIT, (s), (l), (v), NULL, (h), \
@@ -133,6 +135,9 @@ struct option {
                                      (h), PARSE_OPT_NOARG}
 #define OPT_GROUP(h)                { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }
 #define OPT_BIT(s, l, v, h, b)      OPT_BIT_F(s, l, v, h, b, 0)
+#define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \
+                                           PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, \
+                                           (set), (clear) }
 #define OPT_NEGBIT(s, l, v, h, b)   { OPTION_NEGBIT, (s), (l), (v), NULL, \
                                      (h), PARSE_OPT_NOARG, NULL, (b) }
 #define OPT_COUNTUP(s, l, v, h)     OPT_COUNTUP_F(s, l, v, h, 0)