* [PATCH] No color diff when redirecting to file
@ 2011-01-23 13:10 Sascha Peilicke
2011-01-23 14:47 ` Johannes Sixt
0 siblings, 1 reply; 7+ messages in thread
From: Sascha Peilicke @ 2011-01-23 13:10 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: Text/Plain, Size: 961 bytes --]
Previously, when having color diffs enabled and redirecting 'git diff'
into a file, one ends up with a messed up file containing termcap color
stuff. This change disables color when diff output is redirected into a
file.
Signed-off-by: Sascha Peilicke <saschpe@gmx.de>
---
diff.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/diff.c b/diff.c
index 5422c43..cd1ecb0 100644
--- a/diff.c
+++ b/diff.c
@@ -2854,6 +2854,11 @@ void diff_setup(struct diff_options *options)
DIFF_OPT_SET(options, COLOR_DIFF);
options->detect_rename = diff_detect_rename_default;
+ struct stat buf;
+ if (fstat(fileno(options->file), &buf) != -1 && S_ISREG(buf.st_mode)) {
+ DIFF_OPT_CLR(options, COLOR_DIFF);
+ }
+
if (diff_no_prefix) {
options->a_prefix = options->b_prefix = "";
} else if (!diff_mnemonic_prefix) {
--
1.7.3.4
--
Mit freundlichen Grüßen,
Sascha Peilicke
http://saschpe.wordpress.com
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] No color diff when redirecting to file
2011-01-23 13:10 [PATCH] No color diff when redirecting to file Sascha Peilicke
@ 2011-01-23 14:47 ` Johannes Sixt
2011-01-23 17:29 ` Matthieu Moy
2011-01-24 8:56 ` Sascha Peilicke
0 siblings, 2 replies; 7+ messages in thread
From: Johannes Sixt @ 2011-01-23 14:47 UTC (permalink / raw)
To: Sascha Peilicke; +Cc: git
The subject line reads as if you want that color markup appears in a file.
On Sonntag, 23. Januar 2011, Sascha Peilicke wrote:
> Previously, when having color diffs enabled and redirecting 'git diff'
> into a file, one ends up with a messed up file containing termcap color
> stuff. This change disables color when diff output is redirected into a
> file.
But this description and the patch read as if you don't want it.
That said, I cannot reproduce. Perhaps your configuration says
color.ui=always? If so, then this is expected behavior and not a bug, IMO.
-- Hannes
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] No color diff when redirecting to file
2011-01-23 14:47 ` Johannes Sixt
@ 2011-01-23 17:29 ` Matthieu Moy
2011-01-23 23:32 ` Junio C Hamano
2011-01-24 8:59 ` Sascha Peilicke
2011-01-24 8:56 ` Sascha Peilicke
1 sibling, 2 replies; 7+ messages in thread
From: Matthieu Moy @ 2011-01-23 17:29 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Sascha Peilicke, git
Johannes Sixt <j6t@kdbg.org> writes:
> That said, I cannot reproduce. Perhaps your configuration says
> color.ui=always? If so, then this is expected behavior and not a bug, IMO.
I think you're right.
I tested this (without the patch):
git diff
=> I get color, because I have color.ui = auto
git diff | cat
=> I don't get color
git diff --color=auto | cat
=> no color
git diff --color=always | cat
=> colors, because I've asked
this seems to be just the right behavior.
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] No color diff when redirecting to file
2011-01-23 17:29 ` Matthieu Moy
@ 2011-01-23 23:32 ` Junio C Hamano
2011-01-24 8:59 ` Sascha Peilicke
1 sibling, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2011-01-23 23:32 UTC (permalink / raw)
To: Matthieu Moy; +Cc: Johannes Sixt, Sascha Peilicke, git
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
> Johannes Sixt <j6t@kdbg.org> writes:
>
>> That said, I cannot reproduce. Perhaps your configuration says
>> color.ui=always? If so, then this is expected behavior and not a bug, IMO.
>
> I think you're right.
>
> I tested this (without the patch):
>
> git diff
> => I get color, because I have color.ui = auto
>
> git diff | cat
> => I don't get color
>
> git diff --color=auto | cat
> => no color
>
> git diff --color=always | cat
> => colors, because I've asked
>
> this seems to be just the right behavior.
Overall I agree with the above observation, but the original poster says
"redirecting into a _file_".
Another possibility is that the mysterious platform the original poster
did not mention has a broken istty() that mistakes a file descriptor going
to a file (instead of a pipe to another process) as connected to a tty.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] No color diff when redirecting to file
2011-01-23 14:47 ` Johannes Sixt
2011-01-23 17:29 ` Matthieu Moy
@ 2011-01-24 8:56 ` Sascha Peilicke
1 sibling, 0 replies; 7+ messages in thread
From: Sascha Peilicke @ 2011-01-24 8:56 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 749 bytes --]
On Sunday 23 January 2011 15:47:17 you wrote:
> The subject line reads as if you want that color markup appears in a file.
>
> On Sonntag, 23. Januar 2011, Sascha Peilicke wrote:
> > Previously, when having color diffs enabled and redirecting 'git diff'
> > into a file, one ends up with a messed up file containing termcap color
> > stuff. This change disables color when diff output is redirected into a
> > file.
>
> But this description and the patch read as if you don't want it.
>
> That said, I cannot reproduce. Perhaps your configuration says
> color.ui=always? If so, then this is expected behavior and not a bug, IMO.
Nope, it's color.ui=auto
--
Mit freundlichen Grüßen,
Sascha Peilicke
http://saschpe.wordpress.com
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] No color diff when redirecting to file
2011-01-23 17:29 ` Matthieu Moy
2011-01-23 23:32 ` Junio C Hamano
@ 2011-01-24 8:59 ` Sascha Peilicke
2011-01-24 9:38 ` Matthieu Moy
1 sibling, 1 reply; 7+ messages in thread
From: Sascha Peilicke @ 2011-01-24 8:59 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: Text/Plain, Size: 752 bytes --]
On Sunday 23 January 2011 18:29:52 you wrote:
> Johannes Sixt <j6t@kdbg.org> writes:
> > That said, I cannot reproduce. Perhaps your configuration says
> > color.ui=always? If so, then this is expected behavior and not a bug,
> > IMO.
>
> I think you're right.
>
> I tested this (without the patch):
>
> git diff
> => I get color, because I have color.ui = auto
>
> git diff | cat
> => I don't get color
>
> git diff --color=auto | cat
> => no color
>
> git diff --color=always | cat
> => colors, because I've asked
>
> this seems to be just the right behavior.
try the same with
git diff > foo
works when
git diff --no-color > foo
--
Mit freundlichen Grüßen,
Sascha Peilicke
http://saschpe.wordpress.com
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] No color diff when redirecting to file
2011-01-24 8:59 ` Sascha Peilicke
@ 2011-01-24 9:38 ` Matthieu Moy
0 siblings, 0 replies; 7+ messages in thread
From: Matthieu Moy @ 2011-01-24 9:38 UTC (permalink / raw)
To: Sascha Peilicke; +Cc: git
Sascha Peilicke <saschpe@gmx.de> writes:
> try the same with
>
> git diff > foo
git diff > foo && cat foo
=> no color.
git diff --no-color > foo && cat foo
=> no color either
git diff --color=always > foo && cat foo
=> colors.
Again, just the expected behavior.
If it helps:
$ uname -a
Linux bauges 2.6.36-686 #1 SMP PREEMPT Fri Nov 5 10:35:38 CET 2010 i686 GNU/Linux
$ git --version
git version 1.7.4.rc1.17.ge7ece
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-01-24 9:38 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-23 13:10 [PATCH] No color diff when redirecting to file Sascha Peilicke
2011-01-23 14:47 ` Johannes Sixt
2011-01-23 17:29 ` Matthieu Moy
2011-01-23 23:32 ` Junio C Hamano
2011-01-24 8:59 ` Sascha Peilicke
2011-01-24 9:38 ` Matthieu Moy
2011-01-24 8:56 ` Sascha Peilicke
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).