login
Header Space

 
 

[PATCH] git-diff: don't use colors when stdout is not a tty.

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Git Mailing List <git@...>
Date: Friday, July 6, 2007 - 11:35 am

Currently, with diff-coloring enabled, git-diff outputs color escape
sequences even if stdout is redirected (not a tty). This is rather annoying
when trying to further process the output. This patch teaches the diff command
to only do its coloring stuff when a pager is in use or stdout is a tty.

Signed-off-by: Michel Marti <mma@objectxp.com>
---
 diff.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/diff.c b/diff.c
index 1958970..988e741 100644
--- a/diff.c
+++ b/diff.c
@@ -451,7 +451,7 @@ static void free_diff_words_data(struct emit_callback *ecbdata)

 const char *diff_get_color(int diff_use_color, enum color_diff ix)
 {
-       if (diff_use_color)
+       if (diff_use_color && (pager_in_use || isatty(STDOUT_FILENO)))
                return diff_colors[ix];
        return "";
 }
--
1.5.2.2

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] git-diff: don't use colors when stdout is not a tty., Michel Marti, (Fri Jul 6, 11:35 am)
Re: [PATCH] git-diff: don't use colors when stdout is not a ..., Matthias Lederhofer, (Fri Jul 6, 12:37 pm)
speck-geostationary