git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
MMMichel Marti <mma@objectxp.com>
Date
Jul 6, 2007, 15:35 UTC
Message-ID
<468E612E.2070903@objectxp.com>

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
Next: Matthias Lederhofer
Message 1 of 2 in “git-diff: don't use colors when stdout is not a tty.”
  1. git-diff: don't use colors when stdout is not a tty.Michel Marti, Jul 6, 2007
  2. Matthias LederhoferJul 6, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.