Skip to content

Commit 3c32c03

Browse files
committed
config: use an enum for type
The --type=<X> option for 'git config' has previously been defined using macros, but using a typed enum is better for tracking the possible values. Move the definition up to make sure it is defined before a macro uses some of its terms. Update the initializer for config_display_options to explicitly set 'type' to TYPE_NONE even though this is implied by a zero value. This assists in knowing that the switch statement added in the previous change has a complete set of cases for a properly-valued enum. Signed-off-by: Derrick Stolee <stolee@gmail.com>
1 parent 76fc767 commit 3c32c03

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

builtin/config.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ struct config_location_options {
8686
.respect_includes_opt = -1, \
8787
}
8888

89+
enum config_type {
90+
TYPE_NONE = 0,
91+
TYPE_BOOL,
92+
TYPE_INT,
93+
TYPE_BOOL_OR_INT,
94+
TYPE_PATH,
95+
TYPE_EXPIRY_DATE,
96+
TYPE_COLOR,
97+
TYPE_BOOL_OR_STR,
98+
};
99+
89100
#define CONFIG_TYPE_OPTIONS(type) \
90101
OPT_GROUP(N_("Type")), \
91102
OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), \
@@ -111,7 +122,7 @@ struct config_display_options {
111122
int show_origin;
112123
int show_scope;
113124
int show_keys;
114-
int type;
125+
enum config_type type;
115126
char *default_value;
116127
/* Populated via `display_options_init()`. */
117128
int term;
@@ -122,17 +133,9 @@ struct config_display_options {
122133
.term = '\n', \
123134
.delim = '=', \
124135
.key_delim = ' ', \
136+
.type = TYPE_NONE, \
125137
}
126138

127-
#define TYPE_NONE 0
128-
#define TYPE_BOOL 1
129-
#define TYPE_INT 2
130-
#define TYPE_BOOL_OR_INT 3
131-
#define TYPE_PATH 4
132-
#define TYPE_EXPIRY_DATE 5
133-
#define TYPE_COLOR 6
134-
#define TYPE_BOOL_OR_STR 7
135-
136139
#define OPT_CALLBACK_VALUE(s, l, v, h, i) { \
137140
.type = OPTION_CALLBACK, \
138141
.short_name = (s), \

0 commit comments

Comments
 (0)