Code

Teach git-fetch to grab a tag at the same time as a commit
[git.git] / color.c
diff --git a/color.c b/color.c
index 97cfbda31ac02b7e4fe747052c28821a34ee0165..12a6453f90eb4ce2b39f85762bf3acd1cff2b9f2 100644 (file)
--- a/color.c
+++ b/color.c
@@ -3,6 +3,8 @@
 
 #define COLOR_RESET "\033[m"
 
+int git_use_color_default = 0;
+
 static int parse_color(const char *name, int len)
 {
        static const char * const color_names[] = {
@@ -17,7 +19,7 @@ static int parse_color(const char *name, int len)
                        return i - 1;
        }
        i = strtol(name, &end, 10);
-       if (*name && !*end && i >= -1 && i <= 255)
+       if (end - name == len && i >= -1 && i <= 255)
                return i;
        return -2;
 }
@@ -116,7 +118,7 @@ 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) {
                if (!strcasecmp(value, "never"))
@@ -133,7 +135,9 @@ int git_config_colorbool(const char *var, const char *value)
 
        /* any normal truth value defaults to 'auto' */
  auto_color:
-       if (isatty(1) || (pager_in_use && pager_use_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;
@@ -141,6 +145,16 @@ int git_config_colorbool(const char *var, const char *value)
        return 0;
 }
 
+int git_color_default_config(const char *var, const char *value)
+{
+       if (!strcmp(var, "color.ui")) {
+               git_use_color_default = git_config_colorbool(var, value, -1);
+               return 0;
+       }
+
+       return git_default_config(var, value);
+}
+
 static int color_vfprintf(FILE *fp, const char *color, const char *fmt,
                va_list args, const char *trail)
 {