Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
git config: don't allow multiple variable types
author
Felipe Contreras
<felipe.contreras@gmail.com>
Sat, 21 Feb 2009 00:49:27 +0000
(
02:49
+0200)
committer
Junio C Hamano
<gitster@pobox.com>
Sun, 22 Feb 2009 04:37:45 +0000
(20:37 -0800)
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>
builtin-config.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
67052c9
)
diff --git
a/builtin-config.c
b/builtin-config.c
index d037e4745c139b1491e5cd344ebf1f24cd8111c0..6dc205d1f439e8fb25129513ad7be0361df94df7 100644
(file)
--- a/
builtin-config.c
+++ b/
builtin-config.c
@@
-19,11
+19,10
@@
static int seen;
static char delim = '=';
static char key_delim = ' ';
static char term = '\n';
static char delim = '=';
static char key_delim = ' ';
static char term = '\n';
-static enum { T_RAW, T_INT, T_BOOL, T_BOOL_OR_INT } type = T_RAW;
static int use_global_config, use_system_config;
static const char *given_config_file;
static int use_global_config, use_system_config;
static const char *given_config_file;
-static int actions;
+static int actions
, types
;
static const char *get_color_slot, *get_colorbool_slot;
static int end_null;
static const char *get_color_slot, *get_colorbool_slot;
static int end_null;
@@
-43,6
+42,10
@@
static int end_null;
#define ACTION_GET_COLOR (1<<13)
#define ACTION_GET_COLORBOOL (1<<14)
#define ACTION_GET_COLOR (1<<13)
#define ACTION_GET_COLORBOOL (1<<14)
+#define TYPE_BOOL (1<<0)
+#define TYPE_INT (1<<1)
+#define TYPE_BOOL_OR_INT (1<<2)
+
static struct option builtin_config_options[] = {
OPT_GROUP("Config file location"),
OPT_BOOLEAN(0, "global", &use_global_config, "use global config file"),
static struct option builtin_config_options[] = {
OPT_GROUP("Config file location"),
OPT_BOOLEAN(0, "global", &use_global_config, "use global config file"),
@@
-63,9
+66,9
@@
static struct option builtin_config_options[] = {
OPT_STRING(0, "get-color", &get_color_slot, "slot", "find the color configured: [default]"),
OPT_STRING(0, "get-colorbool", &get_colorbool_slot, "slot", "find the color setting: [stdout-is-tty]"),
OPT_GROUP("Type"),
OPT_STRING(0, "get-color", &get_color_slot, "slot", "find the color configured: [default]"),
OPT_STRING(0, "get-colorbool", &get_colorbool_slot, "slot", "find the color setting: [stdout-is-tty]"),
OPT_GROUP("Type"),
- OPT_
SET_INT(0, "bool", &type, "value is \"true\" or \"false\"", T
_BOOL),
- OPT_
SET_INT(0, "int", &type, "value is decimal number", T
_INT),
- OPT_
SET_INT(0, "bool-or-int", &type, NULL, T
_BOOL_OR_INT),
+ OPT_
BIT(0, "bool", &types, "value is \"true\" or \"false\"", TYPE
_BOOL),
+ OPT_
BIT(0, "int", &types, "value is decimal number", TYPE
_INT),
+ OPT_
BIT(0, "bool-or-int", &types, NULL, TYPE
_BOOL_OR_INT),
OPT_GROUP("Other"),
OPT_BOOLEAN('z', "null", &end_null, "terminate values with NUL byte"),
OPT_END(),
OPT_GROUP("Other"),
OPT_BOOLEAN('z', "null", &end_null, "terminate values with NUL byte"),
OPT_END(),
@@
-109,11
+112,11
@@
static int show_config(const char *key_, const char *value_, void *cb)
}
if (seen && !do_all)
dup_error = 1;
}
if (seen && !do_all)
dup_error = 1;
- if (type
== T
_INT)
+ if (type
s == TYPE
_INT)
sprintf(value, "%d", git_config_int(key_, value_?value_:""));
sprintf(value, "%d", git_config_int(key_, value_?value_:""));
- else if (type
== T
_BOOL)
+ else if (type
s == TYPE
_BOOL)
vptr = git_config_bool(key_, value_) ? "true" : "false";
vptr = git_config_bool(key_, value_) ? "true" : "false";
- else if (type
== T
_BOOL_OR_INT) {
+ else if (type
s == TYPE
_BOOL_OR_INT) {
int is_bool, v;
v = git_config_bool_or_int(key_, value_, &is_bool);
if (is_bool)
int is_bool, v;
v = git_config_bool_or_int(key_, value_, &is_bool);
if (is_bool)
@@
-212,18
+215,18
@@
static char *normalize_value(const char *key, const char *value)
if (!value)
return NULL;
if (!value)
return NULL;
- if (type
== T_RAW
)
+ if (type
s == 0
)
normalized = xstrdup(value);
else {
normalized = xmalloc(64);
normalized = xstrdup(value);
else {
normalized = xmalloc(64);
- if (type
== T
_INT) {
+ if (type
s == TYPE
_INT) {
int v = git_config_int(key, value);
sprintf(normalized, "%d", v);
}
int v = git_config_int(key, value);
sprintf(normalized, "%d", v);
}
- else if (type
== T
_BOOL)
+ else if (type
s == TYPE
_BOOL)
sprintf(normalized, "%s",
git_config_bool(key, value) ? "true" : "false");
sprintf(normalized, "%s",
git_config_bool(key, value) ? "true" : "false");
- else if (type
== T
_BOOL_OR_INT) {
+ else if (type
s == TYPE
_BOOL_OR_INT) {
int is_bool, v;
v = git_config_bool_or_int(key, value, &is_bool);
if (!is_bool)
int is_bool, v;
v = git_config_bool_or_int(key, value, &is_bool);
if (!is_bool)
@@
-347,6
+350,11
@@
int cmd_config(int argc, const char **argv, const char *unused_prefix)
key_delim = '\n';
}
key_delim = '\n';
}
+ if (HAS_MULTI_BITS(types)) {
+ error("only one type at a time.");
+ usage_with_options(builtin_config_usage, builtin_config_options);
+ }
+
if (get_color_slot)
actions |= ACTION_GET_COLOR;
if (get_colorbool_slot)
if (get_color_slot)
actions |= ACTION_GET_COLOR;
if (get_colorbool_slot)