{"thread":{"id":"8898","subject":"[PATCH] git-diff: don't use colors when stdout is not a tty.","startedAt":"2007-07-06T15:35:10Z","lastAt":"2007-07-06T16:37:59Z","messageCount":2,"participants":["Michel Marti","Matthias Lederhofer"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"46641","messageId":"468E612E.2070903@objectxp.com","threadId":"8898","inReplyTo":null,"subject":"[PATCH] git-diff: don't use colors when stdout is not a tty.","fromName":"Michel Marti","fromEmail":"mma@objectxp.com","sentAt":"2007-07-06T15:35:10Z","receivedAt":"2007-07-06T15:35:10Z","isPatch":true,"sender":{"key":"mma@objectxp.com","avatar":null},"body":"Currently, with diff-coloring enabled, git-diff outputs color escape\nsequences even if stdout is redirected (not a tty). This is rather annoying\nwhen trying to further process the output. This patch teaches the diff command\nto only do its coloring stuff when a pager is in use or stdout is a tty.\n\nSigned-off-by: Michel Marti <mma@objectxp.com>\n---\n diff.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 1958970..988e741 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -451,7 +451,7 @@ static void free_diff_words_data(struct emit_callback *ecbdata)\n\n const char *diff_get_color(int diff_use_color, enum color_diff ix)\n {\n-       if (diff_use_color)\n+       if (diff_use_color && (pager_in_use || isatty(STDOUT_FILENO)))\n                return diff_colors[ix];\n        return \"\";\n }\n--\n1.5.2.2\n"},{"id":"46647","messageId":"20070706163759.GA26670@moooo.ath.cx","threadId":"8898","inReplyTo":"468E612E.2070903@objectxp.com","subject":"Re: [PATCH] git-diff: don't use colors when stdout is not a tty.","fromName":"Matthias Lederhofer","fromEmail":"matled@gmx.net","sentAt":"2007-07-06T16:37:59Z","receivedAt":"2007-07-06T16:37:59Z","isPatch":true,"sender":{"key":"matled@gmx.net","avatar":null},"body":"Michel Marti <mma@objectxp.com> wrote:\n> Currently, with diff-coloring enabled, git-diff outputs color escape\n> sequences even if stdout is redirected (not a tty). This is rather annoying\n> when trying to further process the output. This patch teaches the diff command\n> to only do its coloring stuff when a pager is in use or stdout is a tty.\n\nSet color.diff to auto instead of true.\n"}]}