@matheusbsbs / matheus-bagliano / commits / 16c1e93985
Fork 0

git config: don't allow multiple variable types

Only --bool, --int, or --bool-or-int can be used, but not any combination of them. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Feb 21, 2009 at 02:49 UTC 16c1e939856f6ced97c60beb64936d564d198be3
1 file changed +20 -12
builtin-config.c
+20 -12
@@ -19,11 +19,10 @@ static int seen;
19 static char delim = '=';
20 static char key_delim = ' ';
21 static char term = '\n';
22 -static enum { T_RAW, T_INT, T_BOOL, T_BOOL_OR_INT } type = T_RAW;
22
23 static int use_global_config, use_system_config;
24 static const char *given_config_file;
26 -static int actions;
25 +static int actions, types;
26 static const char *get_color_slot, *get_colorbool_slot;
27 static int end_null;
28
@@ -43,6 +42,10 @@ static int end_null;
42 #define ACTION_GET_COLOR (1<<13)
43 #define ACTION_GET_COLORBOOL (1<<14)
44
45 +#define TYPE_BOOL (1<<0)
46 +#define TYPE_INT (1<<1)
47 +#define TYPE_BOOL_OR_INT (1<<2)
48 +
49 static struct option builtin_config_options[] = {
50 OPT_GROUP("Config file location"),
51 OPT_BOOLEAN(0, "global", &use_global_config, "use global config file"),
@@ -63,9 +66,9 @@ static struct option builtin_config_options[] = {
66 OPT_STRING(0, "get-color", &get_color_slot, "slot", "find the color configured: [default]"),
67 OPT_STRING(0, "get-colorbool", &get_colorbool_slot, "slot", "find the color setting: [stdout-is-tty]"),
68 OPT_GROUP("Type"),
66 - OPT_SET_INT(0, "bool", &type, "value is \"true\" or \"false\"", T_BOOL),
67 - OPT_SET_INT(0, "int", &type, "value is decimal number", T_INT),
68 - OPT_SET_INT(0, "bool-or-int", &type, NULL, T_BOOL_OR_INT),
69 + OPT_BIT(0, "bool", &types, "value is \"true\" or \"false\"", TYPE_BOOL),
70 + OPT_BIT(0, "int", &types, "value is decimal number", TYPE_INT),
71 + OPT_BIT(0, "bool-or-int", &types, NULL, TYPE_BOOL_OR_INT),
72 OPT_GROUP("Other"),
73 OPT_BOOLEAN('z', "null", &end_null, "terminate values with NUL byte"),
74 OPT_END(),
@@ -109,11 +112,11 @@ static int show_config(const char *key_, const char *value_, void *cb)
112 }
113 if (seen && !do_all)
114 dup_error = 1;
112 - if (type == T_INT)
115 + if (types == TYPE_INT)
116 sprintf(value, "%d", git_config_int(key_, value_?value_:""));
114 - else if (type == T_BOOL)
117 + else if (types == TYPE_BOOL)
118 vptr = git_config_bool(key_, value_) ? "true" : "false";
116 - else if (type == T_BOOL_OR_INT) {
119 + else if (types == TYPE_BOOL_OR_INT) {
120 int is_bool, v;
121 v = git_config_bool_or_int(key_, value_, &is_bool);
122 if (is_bool)
@@ -212,18 +215,18 @@ static char *normalize_value(const char *key, const char *value)
215 if (!value)
216 return NULL;
217
215 - if (type == T_RAW)
218 + if (types == 0)
219 normalized = xstrdup(value);
220 else {
221 normalized = xmalloc(64);
219 - if (type == T_INT) {
222 + if (types == TYPE_INT) {
223 int v = git_config_int(key, value);
224 sprintf(normalized, "%d", v);
225 }
223 - else if (type == T_BOOL)
226 + else if (types == TYPE_BOOL)
227 sprintf(normalized, "%s",
228 git_config_bool(key, value) ? "true" : "false");
226 - else if (type == T_BOOL_OR_INT) {
229 + else if (types == TYPE_BOOL_OR_INT) {
230 int is_bool, v;
231 v = git_config_bool_or_int(key, value, &is_bool);
232 if (!is_bool)
@@ -347,6 +350,11 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
350 key_delim = '\n';
351 }
352
353 + if (HAS_MULTI_BITS(types)) {
354 + error("only one type at a time.");
355 + usage_with_options(builtin_config_usage, builtin_config_options);
356 + }
357 +
358 if (get_color_slot)
359 actions |= ACTION_GET_COLOR;
360 if (get_colorbool_slot)