X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;ds=sidebyside;f=color.c;h=7f66c29fae57abceda30b1257c2a66626f3be0b2;hb=a41acc63badf20cbb22cca61039dca9309deaa19;hp=124ba331c7f798b9b922fc8482dbc215202b99a6;hpb=c4316674c48708ca62876470c615101ab8fee2e0;p=git.git diff --git a/color.c b/color.c index 124ba331c..7f66c29fa 100644 --- a/color.c +++ b/color.c @@ -116,23 +116,31 @@ bad: die("bad config value '%s' for variable '%s'", value, var); } -int git_config_colorbool(const char *var, const char *value) +int git_config_colorbool(const char *var, const char *value, int stdout_is_tty) { - if (!value) - return 1; - if (!strcasecmp(value, "auto")) { - if (isatty(1) || (pager_in_use && pager_use_color)) { - char *term = getenv("TERM"); - if (term && strcmp(term, "dumb")) - return 1; - } - return 0; + if (value) { + if (!strcasecmp(value, "never")) + return 0; + if (!strcasecmp(value, "always")) + return 1; + if (!strcasecmp(value, "auto")) + goto auto_color; } - if (!strcasecmp(value, "never")) + + /* Missing or explicit false to turn off colorization */ + if (!git_config_bool(var, value)) return 0; - if (!strcasecmp(value, "always")) - return 1; - return git_config_bool(var, value); + + /* 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)) { + char *term = getenv("TERM"); + if (term && strcmp(term, "dumb")) + return 1; + } + return 0; } static int color_vfprintf(FILE *fp, const char *color, const char *fmt,