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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Feb 23, 2026 at 12:26 UTC
096aa6099834ce00401a369b34cbff4868ea5704
1 file changed
+13
-10
builtin/config.c
+13
-10
@@ -86,6 +86,17 @@ struct config_location_options {
86
.respect_includes_opt = -1, \
87
}
88
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
+
100
#define CONFIG_TYPE_OPTIONS(type) \
101
OPT_GROUP(N_("Type")), \
102
OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), \
@@ -111,7 +122,7 @@ struct config_display_options {
122
int show_origin;
123
int show_scope;
124
int show_keys;
114
- int type;
125
+ enum config_type type;
126
char *default_value;
127
/* Populated via `display_options_init()`. */
128
int term;
@@ -122,17 +133,9 @@ struct config_display_options {
133
.term = '\n', \
134
.delim = '=', \
135
.key_delim = ' ', \
136
+ .type = TYPE_NONE, \
137
}
138
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
-
139
#define OPT_CALLBACK_VALUE(s, l, v, h, i) { \
140
.type = OPTION_CALLBACK, \
141
.short_name = (s), \