Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
git config: reorganize get_color*
author
Felipe Contreras
<felipe.contreras@gmail.com>
Sat, 21 Feb 2009 00:48:57 +0000
(
02:48
+0200)
committer
Junio C Hamano
<gitster@pobox.com>
Sun, 22 Feb 2009 04:37:19 +0000
(20:37 -0800)
In preparation for parseopt.
Also remove some unecessary comments since the usage is described in the
documentation.
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:
b408457
)
diff --git
a/builtin-config.c
b/builtin-config.c
index 5074c6123ecee476460a34198d19ca4de676b349..a2ef5f7c084515f3ed6bfabb86faa862ef5cfd75 100644
(file)
--- a/
builtin-config.c
+++ b/
builtin-config.c
@@
-192,29
+192,8
@@
static int git_get_color_config(const char *var, const char *value, void *cb)
return 0;
}
return 0;
}
-static
int get_color(int argc, const char **argv
)
+static
void get_color(const char *def_color
)
{
{
- /*
- * grab the color setting for the given slot from the configuration,
- * or parse the default value if missing, and return ANSI color
- * escape sequence.
- *
- * e.g.
- * git config --get-color color.diff.whitespace "blue reverse"
- */
- const char *def_color = NULL;
-
- switch (argc) {
- default:
- usage(git_config_set_usage);
- case 2:
- def_color = argv[1];
- /* fallthru */
- case 1:
- get_color_slot = argv[0];
- break;
- }
-
get_color_found = 0;
parsed_color[0] = '\0';
git_config(git_get_color_config, NULL);
get_color_found = 0;
parsed_color[0] = '\0';
git_config(git_get_color_config, NULL);
@@
-223,7
+202,6
@@
static int get_color(int argc, const char **argv)
color_parse(def_color, "command line", parsed_color);
fputs(parsed_color, stdout);
color_parse(def_color, "command line", parsed_color);
fputs(parsed_color, stdout);
- return 0;
}
static int stdout_is_tty;
}
static int stdout_is_tty;
@@
-247,24
+225,10
@@
static int git_get_colorbool_config(const char *var, const char *value,
return 0;
}
return 0;
}
-static int get_colorbool(int
argc, const char **argv
)
+static int get_colorbool(int
print
)
{
{
- /*
- * git config --get-colorbool <slot> [<stdout-is-tty>]
- *
- * returns "true" or "false" depending on how <slot>
- * is configured.
- */
-
- if (argc == 2)
- stdout_is_tty = git_config_bool("command line", argv[1]);
- else if (argc == 1)
- stdout_is_tty = isatty(1);
- else
- usage(git_config_set_usage);
get_colorbool_found = -1;
get_diff_color_found = -1;
get_colorbool_found = -1;
get_diff_color_found = -1;
- get_colorbool_slot = argv[0];
git_config(git_get_colorbool_config, NULL);
if (get_colorbool_found < 0) {
git_config(git_get_colorbool_config, NULL);
if (get_colorbool_found < 0) {
@@
-274,12
+238,11
@@
static int get_colorbool(int argc, const char **argv)
get_colorbool_found = git_use_color_default;
}
get_colorbool_found = git_use_color_default;
}
- if (argc == 1) {
- return get_colorbool_found ? 0 : 1;
- } else {
+ if (print) {
printf("%s\n", get_colorbool_found ? "true" : "false");
return 0;
printf("%s\n", get_colorbool_found ? "true" : "false");
return 0;
- }
+ } else
+ return get_colorbool_found ? 0 : 1;
}
int cmd_config(int argc, const char **argv, const char *unused_prefix)
}
int cmd_config(int argc, const char **argv, const char *unused_prefix)
@@
-363,9
+326,20
@@
int cmd_config(int argc, const char **argv, const char *unused_prefix)
}
return 0;
} else if (!strcmp(argv[1], "--get-color")) {
}
return 0;
} else if (!strcmp(argv[1], "--get-color")) {
- return get_color(argc-2, argv+2);
+ if (argc > 4 || argc < 3)
+ usage(git_config_set_usage);
+ get_color_slot = argv[2];
+ get_color(argv[3]);
+ return 0;
} else if (!strcmp(argv[1], "--get-colorbool")) {
} else if (!strcmp(argv[1], "--get-colorbool")) {
- return get_colorbool(argc-2, argv+2);
+ if (argc == 4)
+ stdout_is_tty = git_config_bool("command line", argv[3]);
+ else if (argc == 3)
+ stdout_is_tty = isatty(1);
+ else
+ usage(git_config_set_usage);
+ get_colorbool_slot = argv[2];
+ return get_colorbool(argc != 3);
} else if (!strcmp(argv[1], "--edit") || !strcmp(argv[1], "-e")) {
if (argc != 2)
usage(git_config_set_usage);
} else if (!strcmp(argv[1], "--edit") || !strcmp(argv[1], "-e")) {
if (argc != 2)
usage(git_config_set_usage);