{"thread":{"id":"26323","subject":"[PATCH] No color diff when redirecting to file","startedAt":"2011-01-23T13:10:35Z","lastAt":"2011-01-24T09:38:05Z","messageCount":7,"participants":["Sascha Peilicke","Johannes Sixt","Matthieu Moy","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"159798","messageId":"201101231410.48528.saschpe@gmx.de","threadId":"26323","inReplyTo":null,"subject":"[PATCH] No color diff when redirecting to file","fromName":"Sascha Peilicke","fromEmail":"saschpe@gmx.de","sentAt":"2011-01-23T13:10:35Z","receivedAt":"2011-01-23T13:10:35Z","isPatch":true,"sender":{"key":"saschpe@gmx.de","avatar":"https://gravatar.com/avatar/f20b78ad0e6b88e3c15fe9d115ddfabcffa6b83e9f2475cafbcac576730e7682?d=mp&s=160"},"body":"Previously, when having color diffs enabled and redirecting 'git diff'\ninto a file, one ends up with a messed up file containing termcap color\nstuff. This change disables color when diff output is redirected into a\nfile.\n\nSigned-off-by: Sascha Peilicke <saschpe@gmx.de>\n---\n diff.c |    5 +++++\n 1 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 5422c43..cd1ecb0 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2854,6 +2854,11 @@ void diff_setup(struct diff_options *options)\n \t\tDIFF_OPT_SET(options, COLOR_DIFF);\n \toptions->detect_rename = diff_detect_rename_default;\n \n+\tstruct stat buf;\n+\tif (fstat(fileno(options->file), &buf) != -1 && S_ISREG(buf.st_mode)) {\n+\t\tDIFF_OPT_CLR(options, COLOR_DIFF);\n+\t}\n+\n \tif (diff_no_prefix) {\n \t\toptions->a_prefix = options->b_prefix = \"\";\n \t} else if (!diff_mnemonic_prefix) {\n-- \n1.7.3.4\n\n-- \nMit freundlichen Grüßen,\nSascha Peilicke\nhttp://saschpe.wordpress.com\n"},{"id":"159800","messageId":"201101231547.18529.j6t@kdbg.org","threadId":"26323","inReplyTo":"201101231410.48528.saschpe@gmx.de","subject":"Re: [PATCH] No color diff when redirecting to file","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2011-01-23T14:47:17Z","receivedAt":"2011-01-23T14:47:17Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"The subject line reads as if you want that color markup appears in a file.\n\nOn Sonntag, 23. Januar 2011, Sascha Peilicke wrote:\n> Previously, when having color diffs enabled and redirecting 'git diff'\n> into a file, one ends up with a messed up file containing termcap color\n> stuff. This change disables color when diff output is redirected into a\n> file.\n\nBut this description and the patch read as if you don't want it.\n\nThat said, I cannot reproduce. Perhaps your configuration says \ncolor.ui=always? If so, then this is expected behavior and not a bug, IMO.\n\n-- Hannes\n"},{"id":"159801","messageId":"vpq39oj4jfz.fsf@bauges.imag.fr","threadId":"26323","inReplyTo":"201101231547.18529.j6t@kdbg.org","subject":"Re: [PATCH] No color diff when redirecting to file","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2011-01-23T17:29:52Z","receivedAt":"2011-01-23T17:29:52Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Johannes Sixt <j6t@kdbg.org> writes:\n\n> That said, I cannot reproduce. Perhaps your configuration says \n> color.ui=always? If so, then this is expected behavior and not a bug, IMO.\n\nI think you're right.\n\nI tested this (without the patch):\n\ngit diff\n=> I get color, because I have color.ui = auto\n\ngit diff | cat\n=> I don't get color\n\ngit diff --color=auto | cat\n=> no color\n\ngit diff --color=always | cat\n=> colors, because I've asked\n\nthis seems to be just the right behavior.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"159804","messageId":"7voc77mc1v.fsf@alter.siamese.dyndns.org","threadId":"26323","inReplyTo":"vpq39oj4jfz.fsf@bauges.imag.fr","subject":"Re: [PATCH] No color diff when redirecting to file","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-01-23T23:32:12Z","receivedAt":"2011-01-23T23:32:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:\n\n> Johannes Sixt <j6t@kdbg.org> writes:\n>\n>> That said, I cannot reproduce. Perhaps your configuration says \n>> color.ui=always? If so, then this is expected behavior and not a bug, IMO.\n>\n> I think you're right.\n>\n> I tested this (without the patch):\n>\n> git diff\n> => I get color, because I have color.ui = auto\n>\n> git diff | cat\n> => I don't get color\n>\n> git diff --color=auto | cat\n> => no color\n>\n> git diff --color=always | cat\n> => colors, because I've asked\n>\n> this seems to be just the right behavior.\n\nOverall I agree with the above observation, but the original poster says\n\"redirecting into a _file_\".\n\nAnother possibility is that the mysterious platform the original poster\ndid not mention has a broken istty() that mistakes a file descriptor going\nto a file (instead of a pipe to another process) as connected to a tty.\n"},{"id":"159813","messageId":"201101240956.27579.saschpe@gmx.de","threadId":"26323","inReplyTo":"201101231547.18529.j6t@kdbg.org","subject":"Re: [PATCH] No color diff when redirecting to file","fromName":"Sascha Peilicke","fromEmail":"saschpe@gmx.de","sentAt":"2011-01-24T08:56:27Z","receivedAt":"2011-01-24T08:56:27Z","isPatch":true,"sender":{"key":"saschpe@gmx.de","avatar":"https://gravatar.com/avatar/f20b78ad0e6b88e3c15fe9d115ddfabcffa6b83e9f2475cafbcac576730e7682?d=mp&s=160"},"body":"On Sunday 23 January 2011 15:47:17 you wrote:\n> The subject line reads as if you want that color markup appears in a file.\n> \n> On Sonntag, 23. Januar 2011, Sascha Peilicke wrote:\n> > Previously, when having color diffs enabled and redirecting 'git diff'\n> > into a file, one ends up with a messed up file containing termcap color\n> > stuff. This change disables color when diff output is redirected into a\n> > file.\n> \n> But this description and the patch read as if you don't want it.\n> \n> That said, I cannot reproduce. Perhaps your configuration says\n> color.ui=always? If so, then this is expected behavior and not a bug, IMO.\nNope, it's color.ui=auto\n-- \nMit freundlichen Grüßen,\nSascha Peilicke\nhttp://saschpe.wordpress.com\n"},{"id":"159814","messageId":"201101240959.02852.saschpe@gmx.de","threadId":"26323","inReplyTo":"vpq39oj4jfz.fsf@bauges.imag.fr","subject":"Re: [PATCH] No color diff when redirecting to file","fromName":"Sascha Peilicke","fromEmail":"saschpe@gmx.de","sentAt":"2011-01-24T08:59:02Z","receivedAt":"2011-01-24T08:59:02Z","isPatch":true,"sender":{"key":"saschpe@gmx.de","avatar":"https://gravatar.com/avatar/f20b78ad0e6b88e3c15fe9d115ddfabcffa6b83e9f2475cafbcac576730e7682?d=mp&s=160"},"body":"On Sunday 23 January 2011 18:29:52 you wrote:\n> Johannes Sixt <j6t@kdbg.org> writes:\n> > That said, I cannot reproduce. Perhaps your configuration says\n> > color.ui=always? If so, then this is expected behavior and not a bug,\n> > IMO.\n> \n> I think you're right.\n> \n> I tested this (without the patch):\n> \n> git diff\n> => I get color, because I have color.ui = auto\n> \n> git diff | cat\n> => I don't get color\n> \n> git diff --color=auto | cat\n> => no color\n> \n> git diff --color=always | cat\n> => colors, because I've asked\n> \n> this seems to be just the right behavior.\n\ntry the same with\n\ngit diff > foo\n\nworks when\n\ngit diff --no-color > foo\n-- \nMit freundlichen Grüßen,\nSascha Peilicke\nhttp://saschpe.wordpress.com\n"},{"id":"159815","messageId":"vpqtygyhcaq.fsf@bauges.imag.fr","threadId":"26323","inReplyTo":"201101240959.02852.saschpe@gmx.de","subject":"Re: [PATCH] No color diff when redirecting to file","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2011-01-24T09:38:05Z","receivedAt":"2011-01-24T09:38:05Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Sascha Peilicke <saschpe@gmx.de> writes:\n\n> try the same with\n>\n> git diff > foo\n\ngit diff > foo && cat foo\n=> no color.\n\ngit diff --no-color > foo && cat foo\n=> no color either\n\ngit diff --color=always > foo && cat foo\n=> colors.\n\nAgain, just the expected behavior.\n\nIf it helps:\n\n$ uname -a\nLinux bauges 2.6.36-686 #1 SMP PREEMPT Fri Nov 5 10:35:38 CET 2010 i686 GNU/Linux\n$ git --version\ngit version 1.7.4.rc1.17.ge7ece\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"}]}