From: Sascha Peilicke <saschpe@gmx.de>
To: git@vger.kernel.org
Subject: [PATCH] No color diff when redirecting to file
Date: Sun, 23 Jan 2011 14:10:35 +0100 [thread overview]
Message-ID: <201101231410.48528.saschpe@gmx.de> (raw)
[-- 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 --]
next reply other threads:[~2011-01-23 13:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-23 13:10 Sascha Peilicke [this message]
2011-01-23 14:47 ` [PATCH] No color diff when redirecting to file 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201101231410.48528.saschpe@gmx.de \
--to=saschpe@gmx.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).