From c9bfb953489e559d513c1627150aa16f8d42d6c5 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 17 Aug 2011 22:05:35 -0700 Subject: want_color: automatically fallback to color.ui All of the "do we want color" flags default to -1 to indicate that we don't have any color configured. This value is handled in one of two ways: 1. In porcelain, we check early on whether the value is still -1 after reading the config, and set it to the value of color.ui (which defaults to 0). 2. In plumbing, it stays untouched as -1, and want_color defaults it to off. This works fine, but means that every porcelain has to check and reassign its color flag. Now that want_color gives us a place to put this check in a single spot, we can do that, simplifying the calling code. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- color.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'color.c') diff --git a/color.c b/color.c index ec96fe104..e8e26818b 100644 --- a/color.c +++ b/color.c @@ -1,7 +1,7 @@ #include "cache.h" #include "color.h" -int git_use_color_default = 0; +static int git_use_color_default = 0; int color_stdout_is_tty = -1; /* @@ -196,12 +196,15 @@ int want_color(int var) { static int want_auto = -1; + if (var < 0) + var = git_use_color_default; + if (var == GIT_COLOR_AUTO) { if (want_auto < 0) want_auto = check_auto_color(); return want_auto; } - return var > 0; + return var; } int git_color_config(const char *var, const char *value, void *cb) -- cgit v1.2.1