Skip to content

Commit f62470c

Browse files
pcloudsgitster
authored andcommitted
parse-options: add OPT_BITOP()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent baa4adc commit f62470c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

parse-options.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ static int get_value(struct parse_opt_ctx_t *p,
109109
*(int *)opt->value &= ~opt->defval;
110110
return 0;
111111

112+
case OPTION_BITOP:
113+
if (unset)
114+
BUG("BITOP can't have unset form");
115+
*(int *)opt->value &= ~opt->extra;
116+
*(int *)opt->value |= opt->defval;
117+
return 0;
118+
112119
case OPTION_COUNTUP:
113120
if (*(int *)opt->value < 0)
114121
*(int *)opt->value = 0;

parse-options.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ enum parse_opt_type {
1010
/* options with no arguments */
1111
OPTION_BIT,
1212
OPTION_NEGBIT,
13+
OPTION_BITOP,
1314
OPTION_COUNTUP,
1415
OPTION_SET_INT,
1516
OPTION_CMDMODE,
@@ -118,6 +119,7 @@ struct option {
118119
int flags;
119120
parse_opt_cb *callback;
120121
intptr_t defval;
122+
intptr_t extra;
121123
};
122124

123125
#define OPT_BIT_F(s, l, v, h, b, f) { OPTION_BIT, (s), (l), (v), NULL, (h), \
@@ -133,6 +135,9 @@ struct option {
133135
(h), PARSE_OPT_NOARG}
134136
#define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }
135137
#define OPT_BIT(s, l, v, h, b) OPT_BIT_F(s, l, v, h, b, 0)
138+
#define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \
139+
PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, \
140+
(set), (clear) }
136141
#define OPT_NEGBIT(s, l, v, h, b) { OPTION_NEGBIT, (s), (l), (v), NULL, \
137142
(h), PARSE_OPT_NOARG, NULL, (b) }
138143
#define OPT_COUNTUP(s, l, v, h) OPT_COUNTUP_F(s, l, v, h, 0)

0 commit comments

Comments
 (0)