diff options
author | Jeff King <peff@peff.net> | 2011-08-18 07:03:48 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-08-18 23:48:29 +0200 |
commit | e269eb7946d0a4ba6a4e175133b5479446ac04a5 (patch) | |
tree | 65da98cebb4776458fa7944ba7101c2f4149f1f7 /color.c | |
parent | diff: refactor COLOR_DIFF from a flag into an int (diff) | |
download | git-e269eb7946d0a4ba6a4e175133b5479446ac04a5.tar.xz git-e269eb7946d0a4ba6a4e175133b5479446ac04a5.zip |
git_config_colorbool: refactor stdout_is_tty handling
Usually this function figures out for itself whether stdout
is a tty. However, it has an extra parameter just to allow
git-config to override the auto-detection for its
--get-colorbool option.
Instead of an extra parameter, let's just use a global
variable. This makes calling easier in the common case, and
will make refactoring the colorbool code much simpler.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'color.c')
-rw-r--r-- | color.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -2,6 +2,7 @@ #include "color.h" int git_use_color_default = 0; +int color_stdout_is_tty = -1; /* * The list of available column colors. @@ -157,7 +158,7 @@ bad: die("bad color value '%.*s' for variable '%s'", value_len, value, var); } -int git_config_colorbool(const char *var, const char *value, int stdout_is_tty) +int git_config_colorbool(const char *var, const char *value) { if (value) { if (!strcasecmp(value, "never")) @@ -177,9 +178,9 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty) /* any normal truth value defaults to 'auto' */ auto_color: - if (stdout_is_tty < 0) - stdout_is_tty = isatty(1); - if (stdout_is_tty || (pager_in_use() && pager_use_color)) { + if (color_stdout_is_tty < 0) + color_stdout_is_tty = isatty(1); + if (color_stdout_is_tty || (pager_in_use() && pager_use_color)) { char *term = getenv("TERM"); if (term && strcmp(term, "dumb")) return 1; @@ -190,7 +191,7 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty) int git_color_default_config(const char *var, const char *value, void *cb) { if (!strcmp(var, "color.ui")) { - git_use_color_default = git_config_colorbool(var, value, -1); + git_use_color_default = git_config_colorbool(var, value); return 0; } |