From MAILER-DAEMON Tue Mar 03 09:57:25 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YSoGD-0005gR-J6
	for mharc-bug-diffutils@gnu.org; Tue, 03 Mar 2015 09:57:25 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:35780)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSbOV-00006A-0I
	for bug-diffutils@gnu.org; Mon, 02 Mar 2015 20:13:07 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSbOR-00015Z-0P
	for bug-diffutils@gnu.org; Mon, 02 Mar 2015 20:13:06 -0500
Received: from debbugs.gnu.org ([140.186.70.43]:34661)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSbOQ-00015V-U1
	for bug-diffutils@gnu.org; Mon, 02 Mar 2015 20:13:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSbOQ-0005Mn-KF
	for bug-diffutils@gnu.org; Mon, 02 Mar 2015 20:13:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Ben Boeckel <mathstuf@gmail.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 03 Mar 2015 01:13:02 +0000
Resent-Message-ID: <handler.19984.B.142534514220579@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: report 19984
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: 19984@debbugs.gnu.org
X-Debbugs-Original-To: bug-diffutils@gnu.org
Received: via spool by submit@debbugs.gnu.org id=B.142534514220579
	(code B ref -1); Tue, 03 Mar 2015 01:13:02 +0000
Received: (at submit) by debbugs.gnu.org; 3 Mar 2015 01:12:22 +0000
Received: from localhost ([127.0.0.1]:33229 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YSbNl-0005Lq-Ei
	for submit@debbugs.gnu.org; Mon, 02 Mar 2015 20:12:21 -0500
Received: from eggs.gnu.org ([208.118.235.92]:33955)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <mathstuf@gmail.com>) id 1YSbNj-0005Ld-Ah
	for submit@debbugs.gnu.org; Mon, 02 Mar 2015 20:12:19 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mathstuf@gmail.com>) id 1YSbNd-0000vV-9H
	for submit@debbugs.gnu.org; Mon, 02 Mar 2015 20:12:14 -0500
Received: from lists.gnu.org ([2001:4830:134:3::11]:47848)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mathstuf@gmail.com>) id 1YSbNd-0000vQ-6G
	for submit@debbugs.gnu.org; Mon, 02 Mar 2015 20:12:13 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:35677)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mathstuf@gmail.com>) id 1YSbNc-0007Ts-2C
	for bug-diffutils@gnu.org; Mon, 02 Mar 2015 20:12:13 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <mathstuf@gmail.com>) id 1YSbNY-0000ur-3M
	for bug-diffutils@gnu.org; Mon, 02 Mar 2015 20:12:11 -0500
Received: from mail-yh0-x229.google.com ([2607:f8b0:4002:c01::229]:45403)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <mathstuf@gmail.com>) id 1YSbNX-0000uf-VO
	for bug-diffutils@gnu.org; Mon, 02 Mar 2015 20:12:08 -0500
Received: by yhai57 with SMTP id i57so16643880yha.12
	for <bug-diffutils@gnu.org>; Mon, 02 Mar 2015 17:12:06 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=date:from:to:subject:message-id:reply-to:mime-version:content-type
	:content-disposition:user-agent;
	bh=Q5BDIDE12uja/J/3sjeUpvkgUHQk6jlrsKycBvYbQ+g=;
	b=TnfILGz5tbZIORCfZxyIjLJLkl2AjfLsIfptCiSgm/SfQsJQ5eeHGPkw31f1up3YSh
	RG3xHRQmGGFMJZMuiHrYoxI6uqWAtNucHIsNRwKArOocdm1Fzwhx8/32uYgnfB49BqrI
	d0DQ/CaiZregmPYKTw20FXlQT/ZOm7B91OZQ7tKxC8VbKHsWbmhuYs1kZrfOlOOqcQH6
	BnY54dY/b0+E6Wis98DRBhXucfbV/SLMrucJeLaNgKasSB3YP1QKvi9PjauQ/cA+CACh
	g4EaoECYZtaToPaUTSrOthGII2D7zX7+592agT3+jOTPF3HuVCziGVpPPLMPdXJ5TrP5
	yxCg==
X-Received: by 10.236.28.199 with SMTP id g47mr22986518yha.7.1425345126505;
	Mon, 02 Mar 2015 17:12:06 -0800 (PST)
Received: from bronto-burt (233.sub-70-209-128.myvzw.com. [70.209.128.233])
	by mx.google.com with ESMTPSA id y9sm11396983yhc.49.2015.03.02.17.12.03
	for <bug-diffutils@gnu.org>
	(version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
	Mon, 02 Mar 2015 17:12:04 -0800 (PST)
Date: Mon, 2 Mar 2015 20:12:00 -0500
From: Ben Boeckel <mathstuf@gmail.com>
Message-ID: <20150303011200.GA521@bronto-burt.dev.benboeckel.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
User-Agent: Mutt/1.5.23 (2014-03-12)
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
	(bad octet value).
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
	(bad octet value).
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
X-Mailman-Approved-At: Tue, 03 Mar 2015 09:57:24 -0500
Subject: [bug-diffutils] bug#19984: Diff and symlinks
X-BeenThere: bug-diffutils@gnu.org
Reply-To: mathstuf@gmail.com
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Mar 2015 01:13:08 -0000

Hi,

When making recursive diffs, diff resolves symlinks. This creates
invalid patches since patch refuses to patch through a symlink. A -L
option to either turn on or off symlink resolution would be nice to
have.

See patch failure here:

    https://kojipkgs.fedoraproject.org//work/tasks/5157/9125157/build.log

Thanks,

--Ben




From MAILER-DAEMON Tue Mar 03 10:07:15 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YSoPj-0000OP-Nd
	for mharc-bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:07:15 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:46294)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSoPd-0000G0-2E
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:07:15 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSoPW-0002tX-IC
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:07:08 -0500
Received: from debbugs.gnu.org ([140.186.70.43]:35473)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSoPW-0002tQ-EM
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:07:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSoPV-0001bQ-Us
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:07:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 03 Mar 2015 15:07:01 +0000
Resent-Message-ID: <handler.19984.B19984.14253951866101@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 19984
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: mathstuf@gmail.com
Received: via spool by 19984-submit@debbugs.gnu.org id=B19984.14253951866101
	(code B ref 19984); Tue, 03 Mar 2015 15:07:01 +0000
Received: (at 19984) by debbugs.gnu.org; 3 Mar 2015 15:06:26 +0000
Received: from localhost ([127.0.0.1]:34041 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YSoOv-0001aK-Gz
	for submit@debbugs.gnu.org; Tue, 03 Mar 2015 10:06:25 -0500
Received: from mail-ob0-f174.google.com ([209.85.214.174]:45217)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <andreas.gruenbacher@gmail.com>) id 1YSoOt-0001a7-6w
	for 19984@debbugs.gnu.org; Tue, 03 Mar 2015 10:06:23 -0500
Received: by obcuz6 with SMTP id uz6so154521obc.12
	for <19984@debbugs.gnu.org>; Tue, 03 Mar 2015 07:06:17 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:date:message-id:subject
	:from:to:cc:content-type;
	bh=OkKD/FdIWNbBwyMUmPCJE/nETTbEToEL3xQHZYLsXds=;
	b=SSPf1Mdxp2xolZyPNeiIvvu0Z1zPWSTy99Z+SDnIGGIkxq5Erzs3iRAHsejDEfYhYX
	wzJSm61kRXEKHVYCQrkrkD1c4ZJOxY9Czph4Vv3re5isUmYyi4RknQcryWMOF/l8xDQ/
	vjgcI9Ja/0ppz5GU7GyXKDhmWNI+8cmSVssaawie+1VXhILw70B8BrJoIH76hyf7kUh+
	HD0pPb8NUNzPHvnC+968qclPvSY9Iv9GsoqkHv+0YfzR6ddUIz4So2rQ7iZrH8sWm1X+
	muk1uxqL4SBuNDpp+MI0K0dWMOzGCwSFSmbn+Ln1/juJwpngFqK0Fo/ylHCYbzXHlOyG
	oESg==
MIME-Version: 1.0
X-Received: by 10.60.47.42 with SMTP id a10mr23284884oen.75.1425395177636;
	Tue, 03 Mar 2015 07:06:17 -0800 (PST)
Received: by 10.182.95.229 with HTTP; Tue, 3 Mar 2015 07:06:17 -0800 (PST)
In-Reply-To: <20150303011200.GA521@bronto-burt.dev.benboeckel.net>
References: <20150303011200.GA521@bronto-burt.dev.benboeckel.net>
Date: Tue, 3 Mar 2015 16:06:17 +0100
X-Google-Sender-Auth: ZQFZm2y-YO2xTMAx2k6EKZH8O5M
Message-ID: <CAHpGcMLZuvGxy-fm860CeKeJonLbGzWMB_=8OMvoy=w5nKrwig@mail.gmail.com>
From: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Content-Type: text/plain; charset=UTF-8
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 19984@debbugs.gnu.org
Subject: [bug-diffutils] bug#19984:  bug#19984: Diff and symlinks
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Mar 2015 15:07:15 -0000

Well, diff has a --no-dereference option for not following symlinks,
and patch has a --follow-symlinks option that will replace symlinks
with patched files. What else do you have in mind?

It's unfortunate that diff doesn't support git-style patches; this
would solve such ambiguities.

Andreas




From MAILER-DAEMON Tue Mar 03 10:10:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YSoSX-0002d9-SE
	for mharc-bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:10:09 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:47003)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSoSV-0002Z6-RK
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:10:08 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSoSQ-00044n-SN
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:10:07 -0500
Received: from debbugs.gnu.org ([140.186.70.43]:35478)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSoSQ-00044c-Oi
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:10:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSoSQ-0001fs-EJ
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:10:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Ben Boeckel <mathstuf@gmail.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 03 Mar 2015 15:10:02 +0000
Resent-Message-ID: <handler.19984.B19984.14253953896412@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 19984
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Received: via spool by 19984-submit@debbugs.gnu.org id=B19984.14253953896412
	(code B ref 19984); Tue, 03 Mar 2015 15:10:02 +0000
Received: (at 19984) by debbugs.gnu.org; 3 Mar 2015 15:09:49 +0000
Received: from localhost ([127.0.0.1]:34046 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YSoSD-0001fL-7X
	for submit@debbugs.gnu.org; Tue, 03 Mar 2015 10:09:49 -0500
Received: from mail-ig0-f171.google.com ([209.85.213.171]:37561)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <mathstuf@gmail.com>) id 1YSoSB-0001f8-Gi
	for 19984@debbugs.gnu.org; Tue, 03 Mar 2015 10:09:47 -0500
Received: by igbhn18 with SMTP id hn18so28469140igb.2
	for <19984@debbugs.gnu.org>; Tue, 03 Mar 2015 07:09:42 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=date:from:to:cc:subject:message-id:reply-to:references:mime-version
	:content-type:content-disposition:content-transfer-encoding
	:in-reply-to:user-agent;
	bh=tEkbzfNp0HSOjsbmDhlU3iAl0+uVixoa0TU9xL6aPF8=;
	b=IloFBAtzux/kp930GmzlDc+DKXjZFqASFFAsVYqpHy9xRKZAA1R6MMYQ8G0wNuQCDT
	4Z8BdFZ8o0vfgsNx81gBI9O88PH+cBW6TDpRhEer2UMSozGyTVAqaWCdXMturNcgIkVv
	9Hv5ZwMAxIwSFA5Pz1PSXa/RXqNGTRDtcDHX21NCK50QYK2znEHBSY0i2GvPQ/aHNvpq
	svrdnikB855VgA1GfZ7jklZG8pfFPYivBtfaJHSsGSEA67ypFQqhbW2Buu6iQ5Im6sqg
	ArpTS6v/qwEWIfQUZxwJ0Vecd6N5ds7xv5d8+BnmVqV185WepkyKKbkh5543QXupE1Nd
	jx5g==
X-Received: by 10.50.79.229 with SMTP id m5mr28861703igx.23.1425395382036;
	Tue, 03 Mar 2015 07:09:42 -0800 (PST)
Received: from megas (tripoint.kitware.com. [66.194.253.20])
	by mx.google.com with ESMTPSA id w31sm1113872ioi.32.2015.03.03.07.09.39
	(version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
	Tue, 03 Mar 2015 07:09:41 -0800 (PST)
Date: Tue, 3 Mar 2015 10:09:38 -0500
From: Ben Boeckel <mathstuf@gmail.com>
Message-ID: <20150303150938.GA30948@megas.kitwarein.com>
References: <20150303011200.GA521@bronto-burt.dev.benboeckel.net>
	<CAHpGcMLZuvGxy-fm860CeKeJonLbGzWMB_=8OMvoy=w5nKrwig@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <CAHpGcMLZuvGxy-fm860CeKeJonLbGzWMB_=8OMvoy=w5nKrwig@mail.gmail.com>
User-Agent: Mutt/1.5.23 (2014-03-12)
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 19984@debbugs.gnu.org
Subject: [bug-diffutils] bug#19984:  bug#19984: Diff and symlinks
X-BeenThere: bug-diffutils@gnu.org
Reply-To: mathstuf@gmail.com
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Mar 2015 15:10:08 -0000

On Tue, Mar 03, 2015 at 16:06:17 +0100, Andreas Grünbacher wrote:
> Well, diff has a --no-dereference option for not following symlinks,
> and patch has a --follow-symlinks option that will replace symlinks
> with patched files. What else do you have in mind?

Ah, I had missed that option. I had searched for 'symlinks' and didn't
see anything. *adds to Fedora patch alias*

Thanks,

--Ben




From MAILER-DAEMON Tue Mar 03 10:19:10 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YSobF-0003Xu-W4
	for mharc-bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:19:10 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49402)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSobE-0003W0-7B
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:19:08 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSob8-00005P-Q3
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:19:08 -0500
Received: from debbugs.gnu.org ([140.186.70.43]:35482)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSob8-00005G-Lx
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:19:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSob8-0001ss-6s
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:19:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 03 Mar 2015 15:19:02 +0000
Resent-Message-ID: <handler.19984.B19984.14253959067197@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 19984
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: mathstuf@gmail.com
Received: via spool by 19984-submit@debbugs.gnu.org id=B19984.14253959067197
	(code B ref 19984); Tue, 03 Mar 2015 15:19:02 +0000
Received: (at 19984) by debbugs.gnu.org; 3 Mar 2015 15:18:26 +0000
Received: from localhost ([127.0.0.1]:34050 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YSoaY-0001s0-F6
	for submit@debbugs.gnu.org; Tue, 03 Mar 2015 10:18:26 -0500
Received: from mail-oi0-f46.google.com ([209.85.218.46]:37190)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <andreas.gruenbacher@gmail.com>) id 1YSoaW-0001rl-DE
	for 19984@debbugs.gnu.org; Tue, 03 Mar 2015 10:18:24 -0500
Received: by oigi138 with SMTP id i138so15714oig.4
	for <19984@debbugs.gnu.org>; Tue, 03 Mar 2015 07:18:18 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:date:message-id:subject
	:from:to:cc:content-type;
	bh=YMDIVdxUmnazzKkkPYRTqNgecM+gDw8V/McdM45TrCg=;
	b=hoKxia9ZjYYEwVjUHvZs8VSHfMcHs5OPFlNHx1PcEO+aKRqhDEDmLYBfEK9I1BZE0i
	CQ2cRchpdFU7O6BfoSqCpAEEsT4MFaxK48Qf4uIt0IZRd5h0lm+qnE4fwrzMM1OGruUO
	/2+/+1coITZeN9BFXnwhnBcxmnNuGqb2C1nMIQnluMWs7RBEx7itYLYGkQADQqgS49C3
	AOaO6VuRCPcunVVie8Bdx1OPzF8YBt4GURC298mArzalLte8VIOjNOW5akDF5DUprqmf
	dxWb2XxBA0TysbNaW8CNXjnedgNtrzwaeAVwzQ1NkFozEgiDoo1PzYPruOHGqDs1h3m+
	WYGA==
MIME-Version: 1.0
X-Received: by 10.202.226.198 with SMTP id z189mr22172329oig.64.1425395898926; 
	Tue, 03 Mar 2015 07:18:18 -0800 (PST)
Received: by 10.182.95.229 with HTTP; Tue, 3 Mar 2015 07:18:18 -0800 (PST)
In-Reply-To: <20150303150938.GA30948@megas.kitwarein.com>
References: <20150303011200.GA521@bronto-burt.dev.benboeckel.net>
	<CAHpGcMLZuvGxy-fm860CeKeJonLbGzWMB_=8OMvoy=w5nKrwig@mail.gmail.com>
	<20150303150938.GA30948@megas.kitwarein.com>
Date: Tue, 3 Mar 2015 16:18:18 +0100
X-Google-Sender-Auth: 1bGWo7Mzn_p7OYefzxC4Itq_rfE
Message-ID: <CAHpGcMLOMgkWQn5WHoKWhe73BXdF+VshM6Dy64EUc+9bq108yg@mail.gmail.com>
From: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Content-Type: text/plain; charset=UTF-8
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 19984@debbugs.gnu.org
Subject: [bug-diffutils] bug#19984:  bug#19984: Diff and symlinks
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Mar 2015 15:19:09 -0000

2015-03-03 16:09 GMT+01:00 Ben Boeckel <mathstuf@gmail.com>:
> Ah, I had missed that option. I had searched for 'symlinks' and didn't
> see anything. *adds to Fedora patch alias*

Be careful with that option and don't even think about adding it globally
for all packages -- the resulting semantics are weird and it breaks
symlinks in git-style diffs.

Andreas




From MAILER-DAEMON Tue Mar 03 10:21:10 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YSodC-0005Tf-PH
	for mharc-bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:21:10 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49934)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSodA-0005Px-9P
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:21:08 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSod4-0001G9-R8
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:21:08 -0500
Received: from debbugs.gnu.org ([140.186.70.43]:35486)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSod4-0001G5-OP
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:21:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSod4-0001w1-Et
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:21:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Ben Boeckel <mathstuf@gmail.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 03 Mar 2015 15:21:02 +0000
Resent-Message-ID: <handler.19984.B19984.14253960167369@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 19984
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Received: via spool by 19984-submit@debbugs.gnu.org id=B19984.14253960167369
	(code B ref 19984); Tue, 03 Mar 2015 15:21:02 +0000
Received: (at 19984) by debbugs.gnu.org; 3 Mar 2015 15:20:16 +0000
Received: from localhost ([127.0.0.1]:34054 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YSocJ-0001un-Tj
	for submit@debbugs.gnu.org; Tue, 03 Mar 2015 10:20:16 -0500
Received: from mail-ie0-f169.google.com ([209.85.223.169]:37619)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <mathstuf@gmail.com>) id 1YSocH-0001uY-Oy
	for 19984@debbugs.gnu.org; Tue, 03 Mar 2015 10:20:14 -0500
Received: by iecrl12 with SMTP id rl12so59075448iec.4
	for <19984@debbugs.gnu.org>; Tue, 03 Mar 2015 07:20:08 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=date:from:to:cc:subject:message-id:reply-to:references:mime-version
	:content-type:content-disposition:content-transfer-encoding
	:in-reply-to:user-agent;
	bh=yjV9uX7LaNcN9mFb2nuwGy36rS824NCIT+IuLiGhx4w=;
	b=Cg02Wkt7dkgltpRnUdlDTGKKMh5q1RFHAI4w3UF7yZv46qdnNlN8s3UeDz88dcTRKf
	wryDu1HfCwaCMPA8ILHuG5LrbsyU4fzRWzFRhSIRvBi+2scid7C4jt4HJF92TpD8/yWq
	A5GC6uvAab8OJeDfKBjTIPF64eAWLE82wkWxyqZBo+/FKWTxuX1ZB/RlshMmNIB/rCSw
	+ZuL625iLqmjmsHHRWO2Xmi2SMwrir+SwXKw2MyHzqT5L4vc11LzXyaeB3mMV2yDcMLa
	RCi+6oLvuEW+De1Oja+ie97GQAPOLdeaJGo/8T+ewIKmWc+aX1BadQXblPD4wsCO/FmS
	82xg==
X-Received: by 10.50.49.43 with SMTP id r11mr29659198ign.18.1425396007931;
	Tue, 03 Mar 2015 07:20:07 -0800 (PST)
Received: from megas (tripoint.kitware.com. [66.194.253.20])
	by mx.google.com with ESMTPSA id
	a196sm1120574ioe.41.2015.03.03.07.20.06
	(version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
	Tue, 03 Mar 2015 07:20:07 -0800 (PST)
Date: Tue, 3 Mar 2015 10:20:04 -0500
From: Ben Boeckel <mathstuf@gmail.com>
Message-ID: <20150303152004.GA31611@megas.kitwarein.com>
References: <20150303011200.GA521@bronto-burt.dev.benboeckel.net>
	<CAHpGcMLZuvGxy-fm860CeKeJonLbGzWMB_=8OMvoy=w5nKrwig@mail.gmail.com>
	<20150303150938.GA30948@megas.kitwarein.com>
	<CAHpGcMLOMgkWQn5WHoKWhe73BXdF+VshM6Dy64EUc+9bq108yg@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <CAHpGcMLOMgkWQn5WHoKWhe73BXdF+VshM6Dy64EUc+9bq108yg@mail.gmail.com>
User-Agent: Mutt/1.5.23 (2014-03-12)
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 19984@debbugs.gnu.org
Subject: [bug-diffutils] bug#19984:  bug#19984: Diff and symlinks
X-BeenThere: bug-diffutils@gnu.org
Reply-To: mathstuf@gmail.com
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Mar 2015 15:21:09 -0000

On Tue, Mar 03, 2015 at 16:18:18 +0100, Andreas Grünbacher wrote:
> Be careful with that option and don't even think about adding it globally
> for all packages -- the resulting semantics are weird and it breaks
> symlinks in git-style diffs.

It's for making patches for Fedora packages, so it looks like:

    alias fdiff="diff -r -U5 --no-dereference"

--Ben




From MAILER-DAEMON Tue Mar 03 10:25:17 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YSohB-0000Gt-6A
	for mharc-bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:25:17 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:51386)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSoh6-00009B-7b
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:25:15 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSogx-0002kM-Vk
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:25:12 -0500
Received: from debbugs.gnu.org ([140.186.70.43]:35492)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSogx-0002jB-TS
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:25:03 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YSogx-00021r-2j
	for bug-diffutils@gnu.org; Tue, 03 Mar 2015 10:25:03 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 03 Mar 2015 15:25:03 +0000
Resent-Message-ID: <handler.19984.B19984.14253962737754@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 19984
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: mathstuf@gmail.com
Received: via spool by 19984-submit@debbugs.gnu.org id=B19984.14253962737754
	(code B ref 19984); Tue, 03 Mar 2015 15:25:03 +0000
Received: (at 19984) by debbugs.gnu.org; 3 Mar 2015 15:24:33 +0000
Received: from localhost ([127.0.0.1]:34060 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YSogS-00020z-Oq
	for submit@debbugs.gnu.org; Tue, 03 Mar 2015 10:24:33 -0500
Received: from mail-ob0-f182.google.com ([209.85.214.182]:38650)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <andreas.gruenbacher@gmail.com>) id 1YSogR-00020o-DQ
	for 19984@debbugs.gnu.org; Tue, 03 Mar 2015 10:24:31 -0500
Received: by obcwo20 with SMTP id wo20so337807obc.5
	for <19984@debbugs.gnu.org>; Tue, 03 Mar 2015 07:24:26 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:date:message-id:subject
	:from:to:cc:content-type;
	bh=2H0bLSZKyjjYJiQFW48WnxcLNlrr/uHo8KoOStHyexw=;
	b=KGNaSraLnxLodM63CWAVQNoLr8IXV9JxtXVq7Jgg/ZK4GFrBAUsl5A5WzpSCNHyH3F
	7bFyB/mX8HaPQlLNjEYVMz2oDJdPZmaZlLtBChoyPwGQ4kYKn9riMQDjTJbQQ1hisNad
	w5RRMMA6TkgsyTyC65gLI7FSx3kQ9MT7M0RZu2Wvn93ish3TSz8wrRrzKFt41uPArxw9
	Q4fRKs0on/DE5vm4Hx+FuuGADR1JS71GO2oay+nr7b/IPUFHgEH6/sxQpl0OLnHbc7ED
	epl3LI69pjToLxP3U9cH6dP5wutT3xzoGV8nAeA9k1s2oPmkyEXWNQeLE/npYQMBJBm/
	k+Bw==
MIME-Version: 1.0
X-Received: by 10.202.185.198 with SMTP id j189mr22187365oif.72.1425396265882; 
	Tue, 03 Mar 2015 07:24:25 -0800 (PST)
Received: by 10.182.95.229 with HTTP; Tue, 3 Mar 2015 07:24:25 -0800 (PST)
In-Reply-To: <20150303152004.GA31611@megas.kitwarein.com>
References: <20150303011200.GA521@bronto-burt.dev.benboeckel.net>
	<CAHpGcMLZuvGxy-fm860CeKeJonLbGzWMB_=8OMvoy=w5nKrwig@mail.gmail.com>
	<20150303150938.GA30948@megas.kitwarein.com>
	<CAHpGcMLOMgkWQn5WHoKWhe73BXdF+VshM6Dy64EUc+9bq108yg@mail.gmail.com>
	<20150303152004.GA31611@megas.kitwarein.com>
Date: Tue, 3 Mar 2015 16:24:25 +0100
X-Google-Sender-Auth: S3YFeIKAXEHk-YNbD4uxU_Lp4oc
Message-ID: <CAHpGcMJKj=6SMbS3BayBUn-n_BGyOKumVo0=2Lj9vC1v5p-jFw@mail.gmail.com>
From: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Content-Type: text/plain; charset=UTF-8
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 19984@debbugs.gnu.org
Subject: [bug-diffutils] bug#19984:  bug#19984: Diff and symlinks
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Mar 2015 15:25:15 -0000

Okay, this is safe, diff will just fail when it encounters symlinks
that don't point to the same file.

Andreas




From MAILER-DAEMON Fri Mar 06 16:58:53 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YU0Gj-0001tg-Ek
	for mharc-bug-diffutils@gnu.org; Fri, 06 Mar 2015 16:58:53 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:60027)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YTxgI-0007Bk-1o
	for bug-diffutils@gnu.org; Fri, 06 Mar 2015 14:13:10 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YTxgE-0008EN-Pv
	for bug-diffutils@gnu.org; Fri, 06 Mar 2015 14:13:05 -0500
Received: from debbugs.gnu.org ([140.186.70.43]:39250)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YTxgE-0008E9-50
	for bug-diffutils@gnu.org; Fri, 06 Mar 2015 14:13:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YTxgD-0007cI-SX
	for bug-diffutils@gnu.org; Fri, 06 Mar 2015 14:13:01 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: H0PE <planeth0pe@yahoo.com.au>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Fri, 06 Mar 2015 19:13:01 +0000
Resent-Message-ID: <handler.20018.B.142566915729230@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: report 20018
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: 20018@debbugs.gnu.org
X-Debbugs-Original-To: "bug-diffutils@gnu.org" <bug-diffutils@gnu.org>
Received: via spool by submit@debbugs.gnu.org id=B.142566915729230
	(code B ref -1); Fri, 06 Mar 2015 19:13:01 +0000
Received: (at submit) by debbugs.gnu.org; 6 Mar 2015 19:12:37 +0000
Received: from localhost ([127.0.0.1]:37816 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YTxfo-0007bM-3i
	for submit@debbugs.gnu.org; Fri, 06 Mar 2015 14:12:37 -0500
Received: from eggs.gnu.org ([208.118.235.92]:48695)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <planeth0pe@yahoo.com.au>) id 1YTwzJ-0006UK-CY
	for submit@debbugs.gnu.org; Fri, 06 Mar 2015 13:28:42 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <planeth0pe@yahoo.com.au>) id 1YTwzC-0004HI-HI
	for submit@debbugs.gnu.org; Fri, 06 Mar 2015 13:28:35 -0500
Received: from lists.gnu.org ([2001:4830:134:3::11]:49400)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <planeth0pe@yahoo.com.au>) id 1YTwzC-0004HE-DP
	for submit@debbugs.gnu.org; Fri, 06 Mar 2015 13:28:34 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:50415)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <planeth0pe@yahoo.com.au>) id 1YTwzA-0002I1-Qi
	for bug-diffutils@gnu.org; Fri, 06 Mar 2015 13:28:34 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <planeth0pe@yahoo.com.au>) id 1YTwz5-0004FR-QV
	for bug-diffutils@gnu.org; Fri, 06 Mar 2015 13:28:32 -0500
Received: from nm23.bullet.mail.gq1.yahoo.com ([98.136.217.6]:34351)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <planeth0pe@yahoo.com.au>) id 1YTwz5-0004F7-B7
	for bug-diffutils@gnu.org; Fri, 06 Mar 2015 13:28:27 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com.au; s=s2048; 
	t=1425666506; bh=ohWFE0hy86U5fWpVanNow0QU+xucrs/20IJLdUFjLlo=; 
	h=Date:From:Reply-To:To:Subject:From:Subject;
	b=DnSWxW5BS1W9x1hqiaGiyuOxNSdSocCYYEpuS6f9EHcLOPrJHDKfPtv+keTlpY6akcJ3ds3EYpasNyKViVIU3ILpPfwJ3mHqvBIVzG0WarWrjP5jfgsEw1wnAMHyG5m6zaiMuDTSlq/DMLHwLnOMjT4FtuaeV1VD4m6JDTW9lK0ZB60ihML2OqtNYbMJeXK1X/oEAKYPQha9OLSPjp5jYNGoi/HsdeEvExFAUSMeWu7Y1yLNW2rix2lOxxLL7C37vHHYXZ9DOIuchSwK6INWDq/YcZDPi+6wyCAbIos5G//9UQy57ordjgq3+CUWiwgJbCZ4/ehyaOvisfZwVYtSIg==
Received: from [98.137.12.190] by nm23.bullet.mail.gq1.yahoo.com with NNFMP;
	06 Mar 2015 18:28:26 -0000
Received: from [98.138.89.165] by tm11.bullet.mail.gq1.yahoo.com with NNFMP;
	06 Mar 2015 18:28:26 -0000
Received: from [127.0.0.1] by omp1021.mail.ne1.yahoo.com with NNFMP;
	06 Mar 2015 18:28:26 -0000
X-Yahoo-Newman-Property: ymail-3
X-Yahoo-Newman-Id: 196244.59858.bm@omp1021.mail.ne1.yahoo.com
X-YMail-OSG: w_I1yy4VM1l.4LdmXVFueFgjAIOtuaIsbiSIQ9hM4eCj.89bmozRnjwsJbH5IIL
	WwUQXmcLqNcYIDX82wYzGKq4bbinYrzr2J8eANcoPg5_RgfxkUVPyjo8VKIpZ8Ai1GNbKnYTjjpa
	wWeUCsknedAodAQ_v7Dp0msh7tRLHqWFmQXxUpLDCGnC.2eU5WhmKoFiCWPr9tToZ6zVklXXj7uK
	BKvH_1h7SWJKdt3ZWFYjixS_DnzJaDVGSPVUddAEneUpV.qWv13y.J8REzTd7sY_zDeWliLQBxQt
	V580m0GfCGs3qNWtyB4ecuka0S_W1v3OqJacBQuUmXq6K60H4wPHRhtYMEKgxU8RZGlgd9JX4SuF
	tZLb8z4NtfqekPZliKzloE2HFvaOXF0z7y1izaMlgfFu9gk2DfHVA_bmzmExeLx2KafpMRt5OFyh
	Q3UwbzoVzrovvDYK.0rXYyAT5MWC7QhIYlzB_F.Ku_.U_jYtupWDKek3GyadTq6UI8bUTDk0Gq1e
	zCy_dI975vw--
Received: by 98.138.101.163; Fri, 06 Mar 2015 18:28:25 +0000 
Date: Fri, 6 Mar 2015 18:28:24 +0000 (UTC)
From: H0PE <planeth0pe@yahoo.com.au>
Message-ID: <1312962410.4159685.1425666504352.JavaMail.yahoo@mail.yahoo.com>
MIME-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_4159684_290986130.1425666504338"
Content-Length: 17869
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
	(bad octet value).
X-Mailman-Approved-At: Fri, 06 Mar 2015 14:12:34 -0500
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
X-Mailman-Approved-At: Fri, 06 Mar 2015 16:58:52 -0500
Subject: [bug-diffutils] bug#20018: Question: Two txt file difference to a
	new txt file?
X-BeenThere: bug-diffutils@gnu.org
Reply-To: H0PE <planeth0pe@yahoo.com.au>
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 06 Mar 2015 19:13:11 -0000

------=_Part_4159684_290986130.1425666504338
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi guys,


=C2=A0
I'm having hard timewith diffutils and I need your help. What I've done is:

-I've created a regsnapshot before installing an app (with regedit's export=
 function from the fullregistry)

-After installing theapp I've taken another snapshot from the registry (sam=
e way as above)


=C2=A0
What I would like to dois to put the new information (difference) from the =
second.reg file to anotherfile with diffutils.


=C2=A0
So far I've figured thisout to get the cleanest way:


=C2=A0
diff -n -a before.txtafter.txt >diff.txt


=C2=A0
I've renamed the two regfile to txt but I doubt this would matter.


=C2=A0
But my problem when Iopen diff.txt is this:

Quote from diff.txt:

"3424a3425,3429

> =C2=A0[ H K E Y _ L O C A L _ M A C H I N E\ S O F T W A R E \ C l a s s =
e s \ * \ s h e l l e x \ C o n t e x t M e n u Ha n d l e r s \ D e s k t =
o p D o c k S h e l l E x t ]=C2=A0

=C2=A0

> =C2=A0

=C2=A0

> =C2=A0[ H K E Y _ L O C A L _ M A C H I N E\ S O F T W A R E \ C l a s s =
e s \ * \ s h e l l e x \ C o n t e x t M e n u Ha n d l e r s \ F e n c e =
s S h e l l E x t ]=C2=A0

=C2=A0

> =C2=A0@ =3D " { 1 9 8 4 D D 4 5 - 5 2 CF - 4 9 c d - A B 7 7 - 1 8 F 3 7 =
8 F E A 2 6 4 } "=C2=A0

=C2=A0

> =C2=A0

=C2=A0

15782a15788,15799

> =C2=A0[ H K E Y _ L O C A L _ M A C H I N E\ S O F T W A R E \ C l a s s =
e s \ C L S I D \ { 1 9 8 4 D D 4 5 - 5 2 C F - 49 c d - A B 7 7 - 1 8 F 3 =
7 8 F E A 2 6 4 } ]=C2=A0

=C2=A0

> =C2=A0@ =3D " F e n c e s S h l E x t=C2=A0 C l a s s "=C2=A0

=C2=A0

> =C2=A0" D i s a b l e P r o c e s s Is o l a t i o n " =3D d w o r d : 0 =
0 0 0 0 0 0 1=C2=A0

=C2=A0

> =C2=A0" L o c a l i z e d S t r i n g" =3D " F e n c e s "=C2=A0

=C2=A0

> =C2=A0

=C2=A0

> =C2=A0[ H K E Y _ L O C A L _ M A C H I N E\ S O F T W A R E \ C l a s s =
e s \ C L S I D \ { 1 9 8 4 D D 4 5 - 5 2 C F - 49 c d - A B 7 7 - 1 8 F 3 =
7 8 F E A 2 6 4 } \ D e f a u l t I c o n ]=C2=A0

=C2=A0

> =C2=A0@ =3D " C : \ \ P r o g r a m=C2=A0 F i l e s \ \ S t a r d o c k \=
 \ F e n c e s \ \ F e n c e s M e n u .d l l , 0 "=C2=A0

=C2=A0

> =C2=A0

=C2=A0

> =C2=A0[ H K E Y _ L O C A L _ M A C H I N E\ S O F T W A R E \ C l a s s =
e s \ C L S I D \ { 1 9 8 4 D D 4 5 - 5 2 C F - 49 c d - A B 7 7 - 1 8 F 3 =
7 8 F E A 2 6 4 } \ I n p r o c S e r v e r 3 2]=C2=A0

=C2=A0

> =C2=A0@ =3D " C : \ \ P r o g r a m=C2=A0 F i l e s \ \ S t a r d o c k \=
 \ F e n c e s \ \ F e n c e s M e n u .d l l "=C2=A0

=C2=A0

> =C2=A0" T h r e a d i n g M o d e l" =3D " A p a r t m e n t "=C2=A0

=C2=A0

> =C2=A0

=C2=A0"


=C2=A0
Issues I got -and Ican't figure out-:

1.)How to get rid ofthe=C2=A0> =C2=A0characters from the beginning -so diff=
util wouldn't evenwrite it to there in the first place-?

2.)I dont want toinclude diffutil difference notes to the file (e.g.:=C2=A0=
3424a3425,3429)

3.)Why diffutil addspaces after every damn character? I can't figure out ho=
w to get rid of this-so diffutil wouldn't add a space after every character=
-


=C2=A0
What I really need is totake the difference, put it in a new file, without =
changing anything, so I canuse that information later through a reg file (d=
elete, add, whatever)?


=C2=A0
Waiting for youranswers,

H0PE


------=_Part_4159684_290986130.1425666504338
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif;font-size:10px"><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">Hi guys,<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class=""><o:p class="" style="">&nbsp;</o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">I'm having hard time
with diffutils and I need your help. What I've done is:<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">-I've created a reg
snapshot before installing an app (with regedit's export function from the full
registry)<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">-After installing the
app I've taken another snapshot from the registry (same way as above)<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class=""><o:p class="" style="">&nbsp;</o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">What I would like to do
is to put the new information (difference) from the second.reg file to another
file with diffutils.<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class=""><o:p class="" style="">&nbsp;</o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">So far I've figured this
out to get the cleanest way:<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class=""><o:p class="" style="">&nbsp;</o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">diff -n -a before.txt
after.txt &gt;diff.txt<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class=""><o:p class="" style="">&nbsp;</o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">I've renamed the two reg
file to txt but I doubt this would matter.<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class=""><o:p class="" style="">&nbsp;</o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">But my problem when I
open diff.txt is this:<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">Quote from diff.txt:<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">"3424a3425,3429<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;[ H K E Y _ L O C A L _ M A C H I N E
\ S O F T W A R E \ C l a s s e s \ * \ s h e l l e x \ C o n t e x t M e n u H
a n d l e r s \ D e s k t o p D o c k S h e l l E x t ]&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;[ H K E Y _ L O C A L _ M A C H I N E
\ S O F T W A R E \ C l a s s e s \ * \ s h e l l e x \ C o n t e x t M e n u H
a n d l e r s \ F e n c e s S h e l l E x t ]&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;@ = " { 1 9 8 4 D D 4 5 - 5 2 C
F - 4 9 c d - A B 7 7 - 1 8 F 3 7 8 F E A 2 6 4 } "&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">15782a15788,15799<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;[ H K E Y _ L O C A L _ M A C H I N E
\ S O F T W A R E \ C l a s s e s \ C L S I D \ { 1 9 8 4 D D 4 5 - 5 2 C F - 4
9 c d - A B 7 7 - 1 8 F 3 7 8 F E A 2 6 4 } ]&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;@ = " F e n c e s S h l E x t
&nbsp; C l a s s "&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;" D i s a b l e P r o c e s s I
s o l a t i o n " = d w o r d : 0 0 0 0 0 0 0 1&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;" L o c a l i z e d S t r i n g
" = " F e n c e s "&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11235"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11079"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="" id="yui_3_16_0_1_1425665645627_11134">&gt; &nbsp;[ H K E Y _ L O C A L _ M A C H I N E
\ S O F T W A R E \ C l a s s e s \ C L S I D \ { 1 9 8 4 D D 4 5 - 5 2 C F - 4
9 c d - A B 7 7 - 1 8 F 3 7 8 F E A 2 6 4 } \ D e f a u l t I c o n ]&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11093"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11460"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;@ = " C : \ \ P r o g r a m
&nbsp; F i l e s \ \ S t a r d o c k \ \ F e n c e s \ \ F e n c e s M e n u .
d l l , 0 "&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11469"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11478"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11487"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11497"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="" id="yui_3_16_0_1_1425665645627_11496">&gt; &nbsp;[ H K E Y _ L O C A L _ M A C H I N E
\ S O F T W A R E \ C l a s s e s \ C L S I D \ { 1 9 8 4 D D 4 5 - 5 2 C F - 4
9 c d - A B 7 7 - 1 8 F 3 7 8 F E A 2 6 4 } \ I n p r o c S e r v e r 3 2
]&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11522"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11539"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;@ = " C : \ \ P r o g r a m
&nbsp; F i l e s \ \ S t a r d o c k \ \ F e n c e s \ \ F e n c e s M e n u .
d l l "&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11556"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11565"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;" T h r e a d i n g M o d e l
" = " A p a r t m e n t "&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11586"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&gt; &nbsp;<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 9pt; font-family: Arial, sans-serif;" class="">&nbsp;"<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class=""><o:p class="" style="">&nbsp;</o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">Issues I got -and I
can't figure out-:<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">1.)How to get rid of
the&nbsp;&gt; &nbsp;characters from the beginning -so diffutil wouldn't even
write it to there in the first place-?<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11840"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">2.)I dont want to
include diffutil difference notes to the file (e.g.:&nbsp;3424a3425,3429)<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11842"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="" id="yui_3_16_0_1_1425665645627_11841">3.)Why diffutil add
spaces after every damn character? I can't figure out how to get rid of this
-so diffutil wouldn't add a space after every character-<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11851"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class=""><o:p class="" style="">&nbsp;</o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11861"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="" id="yui_3_16_0_1_1425665645627_11860">What I really need is to
take the difference, put it in a new file, without changing anything, so I can
use that information later through a reg file (delete, add, whatever)?<o:p class="" style=""></o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11870"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class=""><o:p class="" style="">&nbsp;</o:p></span></div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11883"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">Waiting for your
answers,<o:p class="" style=""></o:p></span></div><div id="yui_3_16_0_1_1425665645627_8063" dir="ltr">

























































































































</div><div class="" style="margin-bottom: 0.0001pt;" id="yui_3_16_0_1_1425665645627_11896"><span style="font-size: 12pt; font-family: Arial, sans-serif;" class="">H0PE<o:p class="" style=""></o:p></span></div></div></body></html>
------=_Part_4159684_290986130.1425666504338--




From MAILER-DAEMON Fri Mar 06 19:05:12 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YU2Ey-0004Of-AA
	for mharc-bug-diffutils@gnu.org; Fri, 06 Mar 2015 19:05:12 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:52780)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YU2Ev-0004Mq-Iv
	for bug-diffutils@gnu.org; Fri, 06 Mar 2015 19:05:10 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YU2Ep-0001gC-RO
	for bug-diffutils@gnu.org; Fri, 06 Mar 2015 19:05:09 -0500
Received: from debbugs.gnu.org ([140.186.70.43]:39399)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YU2Ep-0001fw-Og
	for bug-diffutils@gnu.org; Fri, 06 Mar 2015 19:05:03 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YU2Ep-0006Qv-IQ
	for bug-diffutils@gnu.org; Fri, 06 Mar 2015 19:05:03 -0500
Resent-From: Eric Blake <eblake@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-To: bug-diffutils@gnu.org
Resent-Date: Sat, 07 Mar 2015 00:05:03 +0000
Resent-Message-ID: <handler.20018.D20018.142568669024692.done@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: cc-closed 20018
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: notabug
To: H0PE <planeth0pe@yahoo.com.au>, 20018-done@debbugs.gnu.org
Mail-Followup-To: 20018@debbugs.gnu.org, eblake@redhat.com,
	planeth0pe@yahoo.com.au
Received: via spool by 20018-done@debbugs.gnu.org id=D20018.142568669024692
	(code D ref 20018); Sat, 07 Mar 2015 00:05:03 +0000
Received: (at 20018-done) by debbugs.gnu.org; 7 Mar 2015 00:04:50 +0000
Received: from localhost ([127.0.0.1]:37963 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YU2Eb-0006Q6-9N
	for submit@debbugs.gnu.org; Fri, 06 Mar 2015 19:04:49 -0500
Received: from mx1.redhat.com ([209.132.183.28]:41341)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eblake@redhat.com>)
	id 1YU2EY-0006Ps-6B; Fri, 06 Mar 2015 19:04:47 -0500
Received: from int-mx11.intmail.prod.int.phx2.redhat.com
	(int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2704irM003916
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL); Fri, 6 Mar 2015 19:04:44 -0500
Received: from [10.3.113.113] (ovpn-113-113.phx2.redhat.com [10.3.113.113])
	by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2704iKE012679; Fri, 6 Mar 2015 19:04:44 -0500
Message-ID: <54FA409B.1090609@redhat.com>
Date: Fri, 06 Mar 2015 17:04:43 -0700
From: Eric Blake <eblake@redhat.com>
Organization: Red Hat, Inc.
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
References: <1312962410.4159685.1425666504352.JavaMail.yahoo@mail.yahoo.com>
In-Reply-To: <1312962410.4159685.1425666504352.JavaMail.yahoo@mail.yahoo.com>
OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature";
	boundary="eD29OWcM9NT49wST09aJeOf9b4bsJEed4"
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Subject: [bug-diffutils] bug#20018: bug#20018: Question: Two txt file
	difference to a new txt file?
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 07 Mar 2015 00:05:10 -0000

This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--eD29OWcM9NT49wST09aJeOf9b4bsJEed4
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

tag 20018 notabug
thanks

On 03/06/2015 11:28 AM, H0PE wrote:
> Hi guys,
>=20
>=20
> =20
> I'm having hard timewith diffutils and I need your help. What I've done=
 is:

[Your mail is hard to read in plain text, due to missing spaces in
various places.  Writing html mail is frowned upon in technical lists,
and doing the mail in plain text to begin with can avoid some
embarrassment when the list automatically converts your html into plain
text.]

> =20
> diff -n -a before.txtafter.txt >diff.txt

This creates a binary diff in ed-script format.

> Issues I got -and Ican't figure out-:
>=20
> 1.)How to get rid ofthe >  characters from the beginning -so diffutil w=
ouldn't evenwrite it to there in the first place-?

You don't.  The output is correct for what you asked for.  Rather, it
sounds like you DON'T want to do a binary diff, but instead want to do a
content-specific diff.  That is, using diffutils is the wrong tool for
what you appear to want.

There are other tools, such as hivex (low-level) and virt-win-reg (built
on top of hivex, which formats a hive file into a registry file), that
are better equipped to read registry files _as structured data_, rather
than diffutils' approach of a raw binary byte stream.  Using tools like
this can generate usable registry scripts that represent the difference
between two hive files.  For a demonstration, read Rich Jones' blog:
https://rwmj.wordpress.com/2011/06/05/tip-using-a-backing-file-to-record-=
file-and-registry-changes-part-3/

>=20
> 2.)I dont want toinclude diffutil difference notes to the file (e.g.: 3=
424a3425,3429)

Again, it sounds like you are using the wrong tool.

>=20
> 3.)Why diffutil addspaces after every damn character? I can't figure ou=
t how to get rid of this-so diffutil wouldn't add a space after every cha=
racter-

That's because the hive format uses UTF-16 characters (where ASCII
characters are represented by the two-byte sequence of the ASCII byte
and a NUL byte, which your viewer is rendering as a space).  When using
diffutils to compare hive files, you are seeing raw UTF-16 streams, and
NOT the typical registry files (which can be written in pure ASCII).

As you have not demonstrated any bug in diffutils, I'm closing this bug
report.  Hopefully, by pointing you at higher level tools more suited to
your task, I've helped you figure out the difference between binary
diffs (diffutils' specialty) and structured diffs (hivex' specialty).
Good luck, and feel free to ask more questions on the topic even though
the bug is closed, although the answer on this list may merely be
redirecting you over to the hivex list.

--=20
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


--eD29OWcM9NT49wST09aJeOf9b4bsJEed4
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJU+kCbAAoJEKeha0olJ0NqnY4H/3Ctzwn5A38090iKH8JdAkqw
4rnZskiTpzZj40VA7lPYv2Kapko6U7ZdvDrxhO2PKnyYYFihziLm1fZx39C1CB70
L+8uSkR0oE5yhEPuezDw0zUETz86TAuaaNizXU+d8rTKx0ZX3kLKZhnqkUEUmiv/
VAVGl+CpiQ1d0nkqv3sQnN/O138vAw45kNgEZNXdq/vpf76LmbvYGPqePP7Pg1Pm
S3wQdYzElGn2TwZavvIL2O8wCAxzoMH0YXGMcQdPz0kKb4NQ3xp8A5r6wbljG1A+
ztQhlMd1IedGsk1vhbTetvH9tA1OiLtQ5Ey0cxxD211p3Q76b4x5DxXmWIrla7w=
=h4rL
-----END PGP SIGNATURE-----

--eD29OWcM9NT49wST09aJeOf9b4bsJEed4--




From MAILER-DAEMON Sun Mar 08 19:09:12 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YUkJs-0000uc-OB
	for mharc-bug-diffutils@gnu.org; Sun, 08 Mar 2015 19:09:12 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:52834)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YUjC5-0001uc-On
	for bug-diffutils@gnu.org; Sun, 08 Mar 2015 17:57:07 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YUjC2-0006VD-Gg
	for bug-diffutils@gnu.org; Sun, 08 Mar 2015 17:57:05 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:41258)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YUjC2-0006V7-DN
	for bug-diffutils@gnu.org; Sun, 08 Mar 2015 17:57:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YUjC2-0005mn-5S
	for bug-diffutils@gnu.org; Sun, 08 Mar 2015 17:57:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Sun, 08 Mar 2015 21:57:02 +0000
Resent-Message-ID: <handler.20062.B.142585181622228@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: report 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: 20062@debbugs.gnu.org
X-Debbugs-Original-To: bug-diffutils@gnu.org
Received: via spool by submit@debbugs.gnu.org id=B.142585181622228
	(code B ref -1); Sun, 08 Mar 2015 21:57:02 +0000
Received: (at submit) by debbugs.gnu.org; 8 Mar 2015 21:56:56 +0000
Received: from localhost ([127.0.0.1]:39826 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YUjBv-0005mR-1l
	for submit@debbugs.gnu.org; Sun, 08 Mar 2015 17:56:55 -0400
Received: from eggs.gnu.org ([208.118.235.92]:51087)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YUjBs-0005mB-6u
	for submit@debbugs.gnu.org; Sun, 08 Mar 2015 17:56:53 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <gscrivan@redhat.com>) id 1YUjBk-0006Su-V8
	for submit@debbugs.gnu.org; Sun, 08 Mar 2015 17:56:46 -0400
Received: from lists.gnu.org ([2001:4830:134:3::11]:46465)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <gscrivan@redhat.com>) id 1YUjBk-0006Sp-Rw
	for submit@debbugs.gnu.org; Sun, 08 Mar 2015 17:56:44 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:52797)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <gscrivan@redhat.com>) id 1YUjBi-0001su-VK
	for bug-diffutils@gnu.org; Sun, 08 Mar 2015 17:56:44 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <gscrivan@redhat.com>) id 1YUjBf-0006RF-NO
	for bug-diffutils@gnu.org; Sun, 08 Mar 2015 17:56:42 -0400
Received: from mx1.redhat.com ([209.132.183.28]:46754)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <gscrivan@redhat.com>) id 1YUjBf-0006RA-FO
	for bug-diffutils@gnu.org; Sun, 08 Mar 2015 17:56:39 -0400
Received: from int-mx09.intmail.prod.int.phx2.redhat.com
	(int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t28LucA7030153
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL)
	for <bug-diffutils@gnu.org>; Sun, 8 Mar 2015 17:56:38 -0400
Received: from localhost.localdomain (vpn1-7-152.ams2.redhat.com [10.36.7.152])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t28LuaYN026868
	for <bug-diffutils@gnu.org>; Sun, 8 Mar 2015 17:56:37 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Sun,  8 Mar 2015 22:56:31 +0100
Message-Id: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
	(bad octet value).
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
X-Mailman-Approved-At: Sun, 08 Mar 2015 19:09:11 -0400
Subject: [bug-diffutils] bug#20062: [PATCH] diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 08 Mar 2015 21:57:07 -0000

* doc/diffutils.texi (diff Options): Add documentation for --color.
Copied from coreutils ls --color.
* src/context.c (pr_unidiff_hunk): Add calls to set_color_context.
* src/diff.h (enum colors): New enum to register the current color to use.
(enum colors_style): New enum to record when to use colors.
(colors_style): New variable to memorize the argument value.
(set_color_context): Add function definition.
* src/diff.c (specify_colors_style): New function.
(BINARY_OPTION): Add COLOR_OPTION.
(longopts): Add --color.
(main): Handle --color argument.
(option_help_msgid): Add usage string for --color.
* src/normal.c (print_normal_hunk): Add calls to set_color_context
* src/side.c (print_1sdiff_line): Add calls to set_color_context.
* src/util.c (colors_enabled): New boolean variable.
(check_color_output): New function.
(begin_output): Call check_color_output every time the output file is changed.
(set_color_context): New function.  If colors are enabled, print the right
command for the terminal to change the color.
---

I got so used to having colors in git diff that I become unable to
quickly spot differences in the plain diff output.  This patch fills
the gap between the two versions.

doc/diffutils.texi | 22 ++++++++++++++++++++++
 src/context.c      |  4 ++++
 src/diff.c         | 27 ++++++++++++++++++++++++++-
 src/diff.h         | 30 ++++++++++++++++++++++++++++++
 src/normal.c       | 16 ++++++++++++----
 src/side.c         | 15 +++++++++++++++
 src/util.c         | 36 ++++++++++++++++++++++++++++++++++++
 7 files changed, 145 insertions(+), 5 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 3e25807..bc7169a 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3745,6 +3745,28 @@ Read and write data in binary mode.  @xref{Binary}.
 Use the context output format, showing three lines of context.
 @xref{Context Format}.
 
+@item --color [=@var{when}]
+@cindex color, distinguishing file types with
+Specify whether to use color for distinguishing file types.  @var{when}
+may be omitted, or one of:
+@itemize @bullet
+@item none
+@vindex none @r{color option}
+- Do not use color at all.  This is the default.
+@item auto
+@vindex auto @r{color option}
+@cindex terminal, using color iff
+- Only use color if standard output is a terminal.
+@item always
+@vindex always @r{color option}
+- Always use color.
+@end itemize
+Specifying @option{--color} and no @var{when} is equivalent to
+@option{--color=always}.
+Piping a colorized listing through a pager like @command{more} or
+@command{less} usually produces unreadable results.  However, using
+@code{more -f} does seem to work.
+
 @item -C @var{lines}
 @itemx --context@r{[}=@var{lines}@r{]}
 Use the context output format, showing @var{lines} (an integer) lines of
diff --git a/src/context.c b/src/context.c
index e0f21c4..88ddfde 100644
--- a/src/context.c
+++ b/src/context.c
@@ -366,10 +366,12 @@ pr_unidiff_hunk (struct change *hunk)
 	  while (k--)
 	    {
 	      char const * const *line = &files[0].linbuf[i++];
+              set_color_context (DELETE);
 	      putc ('-', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
 	      print_1_line (NULL, line);
+              set_color_context (RESET);
 	    }
 
 	  /* Then output the inserted part. */
@@ -378,10 +380,12 @@ pr_unidiff_hunk (struct change *hunk)
 	  while (k--)
 	    {
 	      char const * const *line = &files[1].linbuf[j++];
+              set_color_context (ADD);
 	      putc ('+', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
 	      print_1_line (NULL, line);
+              set_color_context (RESET);
 	    }
 
 	  /* We're done with this hunk, so on to the next! */
diff --git a/src/diff.c b/src/diff.c
index ff28377..7d14877 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -70,6 +70,7 @@ static void add_regexp (struct regexp_list *, char const *);
 static void summarize_regexp_list (struct regexp_list *);
 static void specify_style (enum output_style);
 static void specify_value (char const **, char const *, char const *);
+static void specify_colors_style (char const *);
 static void try_help (char const *, char const *) __attribute__((noreturn));
 static void check_stdout (void);
 static void usage (void);
@@ -136,7 +137,9 @@ enum
   UNCHANGED_GROUP_FORMAT_OPTION,
   OLD_GROUP_FORMAT_OPTION,
   NEW_GROUP_FORMAT_OPTION,
-  CHANGED_GROUP_FORMAT_OPTION
+  CHANGED_GROUP_FORMAT_OPTION,
+
+  COLOR_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -159,6 +162,7 @@ static struct option const longopts[] =
   {"binary", 0, 0, BINARY_OPTION},
   {"brief", 0, 0, 'q'},
   {"changed-group-format", 1, 0, CHANGED_GROUP_FORMAT_OPTION},
+  {"color", 2, 0, COLOR_OPTION},
   {"context", 2, 0, 'C'},
   {"ed", 0, 0, 'e'},
   {"exclude", 1, 0, 'x'},
@@ -627,6 +631,10 @@ main (int argc, char **argv)
 	  specify_value (&group_format[c], optarg, group_format_option[c]);
 	  break;
 
+        case COLOR_OPTION:
+          specify_colors_style (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
@@ -940,6 +948,8 @@ static char const * const option_help_msgid[] = {
   N_("-d, --minimal            try hard to find a smaller set of changes"),
   N_("    --horizon-lines=NUM  keep NUM lines of the common prefix and suffix"),
   N_("    --speed-large-files  assume large files and many scattered small changes"),
+  N_("    --color[=WHEN]         colorize the output; WHEN can be 'never', 'auto',"),
+  N_("                             or 'always' (the default); more info below"),
   "",
   N_("    --help               display this help and exit"),
   N_("-v, --version            output version information and exit"),
@@ -1008,6 +1018,21 @@ specify_style (enum output_style style)
       output_style = style;
     }
 }
+
+/* Set the color mode.  */
+static void
+specify_colors_style (char const *value)
+{
+  if (value == NULL || STREQ (value, "always"))
+    colors_style = ALWAYS;
+  else if (STREQ (value, "never"))
+    colors_style = NEVER;
+  else if (STREQ (value, "auto"))
+    colors_style = AUTO;
+  else
+    try_help ("invalid color '%s'", value);
+}
+
 
 /* Set the last-modified time of *ST to be the current time.  */
 
diff --git a/src/diff.h b/src/diff.h
index 465e4bc..cad961b 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -38,6 +38,32 @@ enum changes
   /* Both deletes and inserts: a hunk containing both old and new lines.  */
   CHANGED
 };
+
+/* What kind of changes a hunk contains.  */
+enum colors
+{
+  /* Reset to the default color.  */
+  RESET,
+
+  /* Delete lines.  Show output in red.  */
+  DELETE,
+
+  /* Added lines.  Show them in green.  */
+  ADD,
+};
+
+/* What kind of changes a hunk contains.  */
+enum colors_style
+{
+  /* Never output colors.  */
+  NEVER,
+
+  /* Output colors if the output is a terminal.  */
+  AUTO,
+
+  /* Always output colors.  */
+  ALWAYS,
+};
 
 /* Variables for command line options */
 
@@ -83,6 +109,9 @@ enum output_style
 
 XTERN enum output_style output_style;
 
+/* True if colors are printed.  */
+XTERN enum colors_style colors_style;
+
 /* Nonzero if output cannot be generated for identical files.  */
 XTERN bool no_diff_means_no_output;
 
@@ -390,3 +419,4 @@ extern void print_script (struct change *, struct change * (*) (struct change *)
 extern void setup_output (char const *, char const *, bool);
 extern void translate_range (struct file_data const *, lin, lin,
                              long int *, long int *);
+extern void set_color_context (enum colors);
diff --git a/src/normal.c b/src/normal.c
index 721fd1a..c5211cb 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -56,14 +56,22 @@ print_normal_hunk (struct change *hunk)
 
   /* Print the lines that the first file has.  */
   if (changes & OLD)
-    for (i = first0; i <= last0; i++)
-      print_1_line ("<", &files[0].linbuf[i]);
+    {
+      set_color_context (DELETE);
+      for (i = first0; i <= last0; i++)
+        print_1_line ("<", &files[0].linbuf[i]);
+      set_color_context (RESET);
+    }
 
   if (changes == CHANGED)
     fputs ("---\n", outfile);
 
   /* Print the lines that the second file has.  */
   if (changes & NEW)
-    for (i = first1; i <= last1; i++)
-      print_1_line (">", &files[1].linbuf[i]);
+    {
+      set_color_context (ADD);
+      for (i = first1; i <= last1; i++)
+        print_1_line (">", &files[1].linbuf[i]);
+      set_color_context (RESET);
+    }
 }
diff --git a/src/side.c b/src/side.c
index 155512c..e52454e 100644
--- a/src/side.c
+++ b/src/side.c
@@ -206,6 +206,18 @@ print_1sdiff_line (char const *const *left, char sep,
   size_t c2o = sdiff_column2_offset;
   size_t col = 0;
   bool put_newline = false;
+  bool color_to_reset = false;
+
+  if (sep == '<')
+    {
+      set_color_context (DELETE);
+      color_to_reset = true;
+    }
+  else if (sep == '>')
+    {
+      set_color_context (ADD);
+      color_to_reset = true;
+    }
 
   if (left)
     {
@@ -233,6 +245,9 @@ print_1sdiff_line (char const *const *left, char sep,
 
   if (put_newline)
     putc ('\n', out);
+
+  if (color_to_reset)
+    set_color_context (RESET);
 }
 
 /* Print lines common to both files in side-by-side format.  */
diff --git a/src/util.c b/src/util.c
index 2d6d3fc..3687b5e 100644
--- a/src/util.c
+++ b/src/util.c
@@ -153,6 +153,17 @@ print_message_queue (void)
 static char const *current_name0;
 static char const *current_name1;
 static bool currently_recursive;
+static bool colors_enabled;
+
+static void
+check_color_output (void)
+{
+  if (! outfile)
+    return;
+
+  colors_enabled = (colors_style == ALWAYS)
+    || (colors_style == AUTO && isatty (fileno (outfile)));
+}
 
 void
 setup_output (char const *name0, char const *name1, bool recursive)
@@ -313,6 +324,7 @@ begin_output (void)
 	    outfile = fdopen (pipes[1], "w");
 	    if (!outfile)
 	      pfatal_with_name ("fdopen");
+            check_color_output ();
 	  }
 #else
 	char *command = system_quote_argv (SCI_SYSTEM, (char **) argv);
@@ -320,6 +332,7 @@ begin_output (void)
 	outfile = popen (command, "w");
 	if (!outfile)
 	  pfatal_with_name (command);
+        check_color_output ();
 	free (command);
 #endif
       }
@@ -330,6 +343,7 @@ begin_output (void)
       /* If -l was not specified, output the diff straight to 'stdout'.  */
 
       outfile = stdout;
+      check_color_output ();
 
       /* If handling multiple files (because scanning a directory),
 	 print which files the following output is about.  */
@@ -717,6 +731,28 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
     }
 }
 
+void
+set_color_context (enum colors con)
+{
+  if (! colors_enabled)
+    return;
+
+  switch (con)
+    {
+    case DELETE:
+      fprintf (outfile, "\x1B[31m");
+      break;
+
+    case ADD:
+      fprintf (outfile, "\x1B[32m");
+      break;
+
+    case RESET:
+      fprintf(outfile, "\x1b[0m");
+      break;
+    }
+}
+
 char const change_letter[] = { 0, 'd', 'a', 'c' };
 
 /* Translate an internal line number (an index into diff's table of lines)
-- 
2.1.0





From MAILER-DAEMON Mon Mar 09 10:52:10 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YUz2Q-0003Wv-S4
	for mharc-bug-diffutils@gnu.org; Mon, 09 Mar 2015 10:52:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:52696)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YUz2O-0003Vg-97
	for bug-diffutils@gnu.org; Mon, 09 Mar 2015 10:52:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YUz2I-0001em-KQ
	for bug-diffutils@gnu.org; Mon, 09 Mar 2015 10:52:08 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:42263)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YUz2I-0001ef-HY
	for bug-diffutils@gnu.org; Mon, 09 Mar 2015 10:52:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YUz2I-0003xu-1z
	for bug-diffutils@gnu.org; Mon, 09 Mar 2015 10:52:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Eric Blake <eblake@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Mon, 09 Mar 2015 14:52:02 +0000
Resent-Message-ID: <handler.20062.B20062.142591266815168@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>, 20062@debbugs.gnu.org
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142591266815168
	(code B ref 20062); Mon, 09 Mar 2015 14:52:02 +0000
Received: (at 20062) by debbugs.gnu.org; 9 Mar 2015 14:51:08 +0000
Received: from localhost ([127.0.0.1]:40831 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YUz1P-0003wa-Sv
	for submit@debbugs.gnu.org; Mon, 09 Mar 2015 10:51:08 -0400
Received: from mx1.redhat.com ([209.132.183.28]:49280)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eblake@redhat.com>) id 1YUz1N-0003wC-Bw
	for 20062@debbugs.gnu.org; Mon, 09 Mar 2015 10:51:06 -0400
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t29Ep0ZU004525
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL)
	for <20062@debbugs.gnu.org>; Mon, 9 Mar 2015 10:51:01 -0400
Received: from [10.3.113.117] (ovpn-113-117.phx2.redhat.com [10.3.113.117])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t29Ep0gi025256; Mon, 9 Mar 2015 10:51:00 -0400
Message-ID: <54FDB353.8060801@redhat.com>
Date: Mon, 09 Mar 2015 08:50:59 -0600
From: Eric Blake <eblake@redhat.com>
Organization: Red Hat, Inc.
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
In-Reply-To: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature";
	boundary="qamsl7gvFmNFeHBP2D8AlGSJC4LM3LSt3"
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Subject: [bug-diffutils] bug#20062: bug#20062: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 09 Mar 2015 14:52:09 -0000

This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--qamsl7gvFmNFeHBP2D8AlGSJC4LM3LSt3
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

On 03/08/2015 03:56 PM, Giuseppe Scrivano wrote:
> * doc/diffutils.texi (diff Options): Add documentation for --color.
> Copied from coreutils ls --color.

Cool!

> +@item --color [=3D@var{when}]
> +@cindex color, distinguishing file types with
> +Specify whether to use color for distinguishing file types.  @var{when=
}
> +may be omitted, or one of:
> +@itemize @bullet
> +@item none
> +@vindex none @r{color option}
> +- Do not use color at all.  This is the default.

At first, I was worried that this meant that '--color' =3D=3D
'--color=3Dnone'; so maybe you want this to read "This is the default whe=
n
no --color option is present"

> +@item auto
> +@vindex auto @r{color option}
> +@cindex terminal, using color iff
> +- Only use color if standard output is a terminal.
> +@item always
> +@vindex always @r{color option}
> +- Always use color.
> +@end itemize
> +Specifying @option{--color} and no @var{when} is equivalent to
> +@option{--color=3Dalways}.

Is this the right default?  Some GNU programs default --color to
--color=3Dauto; others to --color=3Dalways.  I'm 50:50 on which default i=
s
better, but it's worth thinking about rather than just blindly picking
one, as we have both GNU styles as precedent.

--=20
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


--qamsl7gvFmNFeHBP2D8AlGSJC4LM3LSt3
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJU/bNTAAoJEKeha0olJ0NqhiwH/0ePqTyuvASiwCNjQhbeZmzF
+7DMxkAiKW0IMXABzatM1eAY5YGTyk41L72uipYpPrS4zVyMP54JABaSHmXbi8Hr
REvyQ59jRkUMzqyjPMNQba5WdEThb0Fm3Mybo5HANqo6wgCTNfrRsBFbHPl6xLvo
JaQBG661RDxtRGFk7hsOkPABM+l4uUA+lfs9DoNEST2SuP59nmZqOVJT3Ic5Ip/t
S54afWjSFIQkbloVPWYEZJvLqz51NFKEB9eyK3QfWlcUYdO8oWiXGdVeFPaLHvUp
7WjiXZsusKtYZKe0yMPIMvb+XfKVKtTMIEshE3vuSYUrkwRl6F8fcpjpiFPQGi8=
=W1q4
-----END PGP SIGNATURE-----

--qamsl7gvFmNFeHBP2D8AlGSJC4LM3LSt3--




From MAILER-DAEMON Mon Mar 09 17:23:12 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YV58q-0000hd-Q8
	for mharc-bug-diffutils@gnu.org; Mon, 09 Mar 2015 17:23:12 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41695)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YV58l-0000gT-9H
	for bug-diffutils@gnu.org; Mon, 09 Mar 2015 17:23:11 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YV58g-0006tS-Re
	for bug-diffutils@gnu.org; Mon, 09 Mar 2015 17:23:07 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:42407)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YV58g-0006tM-Ns
	for bug-diffutils@gnu.org; Mon, 09 Mar 2015 17:23:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YV58g-0006vl-EO
	for bug-diffutils@gnu.org; Mon, 09 Mar 2015 17:23:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Mon, 09 Mar 2015 21:23:02 +0000
Resent-Message-ID: <handler.20062.B20062.142593612526543@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Eric Blake <eblake@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142593612526543
	(code B ref 20062); Mon, 09 Mar 2015 21:23:02 +0000
Received: (at 20062) by debbugs.gnu.org; 9 Mar 2015 21:22:05 +0000
Received: from localhost ([127.0.0.1]:40975 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YV57k-0006u3-Ko
	for submit@debbugs.gnu.org; Mon, 09 Mar 2015 17:22:04 -0400
Received: from mx1.redhat.com ([209.132.183.28]:58597)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YV57i-0006tg-R7
	for 20062@debbugs.gnu.org; Mon, 09 Mar 2015 17:22:03 -0400
Received: from int-mx13.intmail.prod.int.phx2.redhat.com
	(int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t29LLx2t010736
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL)
	for <20062@debbugs.gnu.org>; Mon, 9 Mar 2015 17:22:00 -0400
Received: from foobarbaz (vpn1-4-214.ams2.redhat.com [10.36.4.214])
	by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t29LLu2d014993
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Mon, 9 Mar 2015 17:21:58 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com>
Date: Mon, 09 Mar 2015 22:21:55 +0100
In-Reply-To: <54FDB353.8060801@redhat.com> (Eric Blake's message of "Mon, 09
	Mar 2015 08:50:59 -0600")
Message-ID: <87fv9dj28c.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 09 Mar 2015 21:23:11 -0000

Eric Blake <eblake@redhat.com> writes:

>> +@item auto
>> +@vindex auto @r{color option}
>> +@cindex terminal, using color iff
>> +- Only use color if standard output is a terminal.
>> +@item always
>> +@vindex always @r{color option}
>> +- Always use color.
>> +@end itemize
>> +Specifying @option{--color} and no @var{when} is equivalent to
>> +@option{--color=always}.
>
> Is this the right default?  Some GNU programs default --color to
> --color=auto; others to --color=always.  I'm 50:50 on which default is
> better, but it's worth thinking about rather than just blindly picking
> one, as we have both GNU styles as precedent.

I thought about it as well, and then I decided to go for the same
default as ls but I still believe that auto would be a better one.

If it is fine for everyone, I can rework the patch and change the
default to auto.

Regards,
Giuseppe




From MAILER-DAEMON Tue Mar 10 06:12:10 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YVH90-0001ln-6B
	for mharc-bug-diffutils@gnu.org; Tue, 10 Mar 2015 06:12:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:54480)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVH8v-0001kj-TT
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 06:12:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVH8s-0000zP-LG
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 06:12:05 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:42622)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVH8s-0000zL-I0
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 06:12:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVH8r-0005vL-US
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 06:12:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 10 Mar 2015 10:12:01 +0000
Resent-Message-ID: <handler.20062.B20062.142598226222690@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Eric Blake <eblake@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142598226222690
	(code B ref 20062); Tue, 10 Mar 2015 10:12:01 +0000
Received: (at 20062) by debbugs.gnu.org; 10 Mar 2015 10:11:02 +0000
Received: from localhost ([127.0.0.1]:41190 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YVH7t-0005ta-6h
	for submit@debbugs.gnu.org; Tue, 10 Mar 2015 06:11:02 -0400
Received: from mx1.redhat.com ([209.132.183.28]:47894)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YVH7q-0005tO-J6
	for 20062@debbugs.gnu.org; Tue, 10 Mar 2015 06:11:00 -0400
Received: from int-mx13.intmail.prod.int.phx2.redhat.com
	(int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2AAAuWf001427
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL)
	for <20062@debbugs.gnu.org>; Tue, 10 Mar 2015 06:10:56 -0400
Received: from foobarbaz (vpn1-7-177.ams2.redhat.com [10.36.7.177])
	by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2AAAq6W028502
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Tue, 10 Mar 2015 06:10:54 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
Date: Tue, 10 Mar 2015 11:10:51 +0100
In-Reply-To: <87fv9dj28c.fsf@redhat.com> (Giuseppe Scrivano's message of "Mon, 
	09 Mar 2015 22:21:55 +0100")
Message-ID: <874mptgo2c.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 10 Mar 2015 10:12:08 -0000

Giuseppe Scrivano <gscrivan@redhat.com> writes:

> Eric Blake <eblake@redhat.com> writes:
>
>>> +@item auto
>>> +@vindex auto @r{color option}
>>> +@cindex terminal, using color iff
>>> +- Only use color if standard output is a terminal.
>>> +@item always
>>> +@vindex always @r{color option}
>>> +- Always use color.
>>> +@end itemize
>>> +Specifying @option{--color} and no @var{when} is equivalent to
>>> +@option{--color=always}.
>>
>> Is this the right default?  Some GNU programs default --color to
>> --color=auto; others to --color=always.  I'm 50:50 on which default is
>> better, but it's worth thinking about rather than just blindly picking
>> one, as we have both GNU styles as precedent.
>
> I thought about it as well, and then I decided to go for the same
> default as ls but I still believe that auto would be a better one.
>
> If it is fine for everyone, I can rework the patch and change the
> default to auto.

This new version changes the default for --color to auto:

>From 7c8c9a6258eb37e6d5832362309fef1906f9a939 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Sun, 8 Mar 2015 22:45:11 +0100
Subject: [PATCH] diff: add support for --color

* doc/diffutils.texi (diff Options): Add documentation for --color.
Copied from coreutils ls --color.
* src/context.c (pr_unidiff_hunk): Add calls to set_color_context.
* src/diff.h (enum colors): New enum to register the current color to use.
(enum colors_style): New enum to record when to use colors.
(colors_style): New variable to memorize the argument value.
(set_color_context): Add function definition.
* src/diff.c (specify_colors_style): New function.
(BINARY_OPTION): Add COLOR_OPTION.
(longopts): Add --color.
(main): Handle --color argument.
(option_help_msgid): Add usage string for --color.
* src/normal.c (print_normal_hunk): Add calls to set_color_context
* src/side.c (print_1sdiff_line): Add calls to set_color_context.
* src/util.c (colors_enabled): New boolean variable.
(check_color_output): New function.
(begin_output): Call check_color_output every time the output file is changed.
(set_color_context): New function.  If colors are enabled, print the right
command for the terminal to change the color.
---
 doc/diffutils.texi | 23 +++++++++++++++++++++++
 src/context.c      |  4 ++++
 src/diff.c         | 27 ++++++++++++++++++++++++++-
 src/diff.h         | 30 ++++++++++++++++++++++++++++++
 src/normal.c       | 16 ++++++++++++----
 src/side.c         | 15 +++++++++++++++
 src/util.c         | 36 ++++++++++++++++++++++++++++++++++++
 7 files changed, 146 insertions(+), 5 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 3e25807..f5e1804 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3745,6 +3745,29 @@ Read and write data in binary mode.  @xref{Binary}.
 Use the context output format, showing three lines of context.
 @xref{Context Format}.
 
+@item --color [=@var{when}]
+@cindex color, distinguishing file types with
+Specify whether to use color for distinguishing file types.  @var{when}
+may be omitted, or one of:
+@itemize @bullet
+@item none
+@vindex none @r{color option}
+- Do not use color at all.  This is the default when no --color option
+is present.
+@item auto
+@vindex auto @r{color option}
+@cindex terminal, using color iff
+- Only use color if standard output is a terminal.
+@item always
+@vindex always @r{color option}
+- Always use color.
+@end itemize
+Specifying @option{--color} and no @var{when} is equivalent to
+@option{--color=auto}.
+Piping a colorized listing through a pager like @command{more} or
+@command{less} usually produces unreadable results.  However, using
+@code{more -f} does seem to work.
+
 @item -C @var{lines}
 @itemx --context@r{[}=@var{lines}@r{]}
 Use the context output format, showing @var{lines} (an integer) lines of
diff --git a/src/context.c b/src/context.c
index e0f21c4..88ddfde 100644
--- a/src/context.c
+++ b/src/context.c
@@ -366,10 +366,12 @@ pr_unidiff_hunk (struct change *hunk)
 	  while (k--)
 	    {
 	      char const * const *line = &files[0].linbuf[i++];
+              set_color_context (DELETE);
 	      putc ('-', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
 	      print_1_line (NULL, line);
+              set_color_context (RESET);
 	    }
 
 	  /* Then output the inserted part. */
@@ -378,10 +380,12 @@ pr_unidiff_hunk (struct change *hunk)
 	  while (k--)
 	    {
 	      char const * const *line = &files[1].linbuf[j++];
+              set_color_context (ADD);
 	      putc ('+', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
 	      print_1_line (NULL, line);
+              set_color_context (RESET);
 	    }
 
 	  /* We're done with this hunk, so on to the next! */
diff --git a/src/diff.c b/src/diff.c
index ff28377..5874646 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -70,6 +70,7 @@ static void add_regexp (struct regexp_list *, char const *);
 static void summarize_regexp_list (struct regexp_list *);
 static void specify_style (enum output_style);
 static void specify_value (char const **, char const *, char const *);
+static void specify_colors_style (char const *);
 static void try_help (char const *, char const *) __attribute__((noreturn));
 static void check_stdout (void);
 static void usage (void);
@@ -136,7 +137,9 @@ enum
   UNCHANGED_GROUP_FORMAT_OPTION,
   OLD_GROUP_FORMAT_OPTION,
   NEW_GROUP_FORMAT_OPTION,
-  CHANGED_GROUP_FORMAT_OPTION
+  CHANGED_GROUP_FORMAT_OPTION,
+
+  COLOR_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -159,6 +162,7 @@ static struct option const longopts[] =
   {"binary", 0, 0, BINARY_OPTION},
   {"brief", 0, 0, 'q'},
   {"changed-group-format", 1, 0, CHANGED_GROUP_FORMAT_OPTION},
+  {"color", 2, 0, COLOR_OPTION},
   {"context", 2, 0, 'C'},
   {"ed", 0, 0, 'e'},
   {"exclude", 1, 0, 'x'},
@@ -627,6 +631,10 @@ main (int argc, char **argv)
 	  specify_value (&group_format[c], optarg, group_format_option[c]);
 	  break;
 
+        case COLOR_OPTION:
+          specify_colors_style (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
@@ -940,6 +948,8 @@ static char const * const option_help_msgid[] = {
   N_("-d, --minimal            try hard to find a smaller set of changes"),
   N_("    --horizon-lines=NUM  keep NUM lines of the common prefix and suffix"),
   N_("    --speed-large-files  assume large files and many scattered small changes"),
+  N_("    --color[=WHEN]         colorize the output; WHEN can be 'never', 'always',"),
+  N_("                             or 'auto' (the default)"),
   "",
   N_("    --help               display this help and exit"),
   N_("-v, --version            output version information and exit"),
@@ -1008,6 +1018,21 @@ specify_style (enum output_style style)
       output_style = style;
     }
 }
+
+/* Set the color mode.  */
+static void
+specify_colors_style (char const *value)
+{
+  if (value == NULL || STREQ (value, "auto"))
+    colors_style = AUTO;
+  else if (STREQ (value, "always"))
+    colors_style = ALWAYS;
+  else if (STREQ (value, "never"))
+    colors_style = NEVER;
+  else
+    try_help ("invalid color '%s'", value);
+}
+
 
 /* Set the last-modified time of *ST to be the current time.  */
 
diff --git a/src/diff.h b/src/diff.h
index 465e4bc..cad961b 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -38,6 +38,32 @@ enum changes
   /* Both deletes and inserts: a hunk containing both old and new lines.  */
   CHANGED
 };
+
+/* What kind of changes a hunk contains.  */
+enum colors
+{
+  /* Reset to the default color.  */
+  RESET,
+
+  /* Delete lines.  Show output in red.  */
+  DELETE,
+
+  /* Added lines.  Show them in green.  */
+  ADD,
+};
+
+/* What kind of changes a hunk contains.  */
+enum colors_style
+{
+  /* Never output colors.  */
+  NEVER,
+
+  /* Output colors if the output is a terminal.  */
+  AUTO,
+
+  /* Always output colors.  */
+  ALWAYS,
+};
 
 /* Variables for command line options */
 
@@ -83,6 +109,9 @@ enum output_style
 
 XTERN enum output_style output_style;
 
+/* True if colors are printed.  */
+XTERN enum colors_style colors_style;
+
 /* Nonzero if output cannot be generated for identical files.  */
 XTERN bool no_diff_means_no_output;
 
@@ -390,3 +419,4 @@ extern void print_script (struct change *, struct change * (*) (struct change *)
 extern void setup_output (char const *, char const *, bool);
 extern void translate_range (struct file_data const *, lin, lin,
                              long int *, long int *);
+extern void set_color_context (enum colors);
diff --git a/src/normal.c b/src/normal.c
index 721fd1a..c5211cb 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -56,14 +56,22 @@ print_normal_hunk (struct change *hunk)
 
   /* Print the lines that the first file has.  */
   if (changes & OLD)
-    for (i = first0; i <= last0; i++)
-      print_1_line ("<", &files[0].linbuf[i]);
+    {
+      set_color_context (DELETE);
+      for (i = first0; i <= last0; i++)
+        print_1_line ("<", &files[0].linbuf[i]);
+      set_color_context (RESET);
+    }
 
   if (changes == CHANGED)
     fputs ("---\n", outfile);
 
   /* Print the lines that the second file has.  */
   if (changes & NEW)
-    for (i = first1; i <= last1; i++)
-      print_1_line (">", &files[1].linbuf[i]);
+    {
+      set_color_context (ADD);
+      for (i = first1; i <= last1; i++)
+        print_1_line (">", &files[1].linbuf[i]);
+      set_color_context (RESET);
+    }
 }
diff --git a/src/side.c b/src/side.c
index 155512c..e52454e 100644
--- a/src/side.c
+++ b/src/side.c
@@ -206,6 +206,18 @@ print_1sdiff_line (char const *const *left, char sep,
   size_t c2o = sdiff_column2_offset;
   size_t col = 0;
   bool put_newline = false;
+  bool color_to_reset = false;
+
+  if (sep == '<')
+    {
+      set_color_context (DELETE);
+      color_to_reset = true;
+    }
+  else if (sep == '>')
+    {
+      set_color_context (ADD);
+      color_to_reset = true;
+    }
 
   if (left)
     {
@@ -233,6 +245,9 @@ print_1sdiff_line (char const *const *left, char sep,
 
   if (put_newline)
     putc ('\n', out);
+
+  if (color_to_reset)
+    set_color_context (RESET);
 }
 
 /* Print lines common to both files in side-by-side format.  */
diff --git a/src/util.c b/src/util.c
index 2d6d3fc..3687b5e 100644
--- a/src/util.c
+++ b/src/util.c
@@ -153,6 +153,17 @@ print_message_queue (void)
 static char const *current_name0;
 static char const *current_name1;
 static bool currently_recursive;
+static bool colors_enabled;
+
+static void
+check_color_output (void)
+{
+  if (! outfile)
+    return;
+
+  colors_enabled = (colors_style == ALWAYS)
+    || (colors_style == AUTO && isatty (fileno (outfile)));
+}
 
 void
 setup_output (char const *name0, char const *name1, bool recursive)
@@ -313,6 +324,7 @@ begin_output (void)
 	    outfile = fdopen (pipes[1], "w");
 	    if (!outfile)
 	      pfatal_with_name ("fdopen");
+            check_color_output ();
 	  }
 #else
 	char *command = system_quote_argv (SCI_SYSTEM, (char **) argv);
@@ -320,6 +332,7 @@ begin_output (void)
 	outfile = popen (command, "w");
 	if (!outfile)
 	  pfatal_with_name (command);
+        check_color_output ();
 	free (command);
 #endif
       }
@@ -330,6 +343,7 @@ begin_output (void)
       /* If -l was not specified, output the diff straight to 'stdout'.  */
 
       outfile = stdout;
+      check_color_output ();
 
       /* If handling multiple files (because scanning a directory),
 	 print which files the following output is about.  */
@@ -717,6 +731,28 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
     }
 }
 
+void
+set_color_context (enum colors con)
+{
+  if (! colors_enabled)
+    return;
+
+  switch (con)
+    {
+    case DELETE:
+      fprintf (outfile, "\x1B[31m");
+      break;
+
+    case ADD:
+      fprintf (outfile, "\x1B[32m");
+      break;
+
+    case RESET:
+      fprintf(outfile, "\x1b[0m");
+      break;
+    }
+}
+
 char const change_letter[] = { 0, 'd', 'a', 'c' };
 
 /* Translate an internal line number (an index into diff's table of lines)
-- 
2.1.0





From MAILER-DAEMON Tue Mar 10 12:23:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YVMw1-0002gk-6Z
	for mharc-bug-diffutils@gnu.org; Tue, 10 Mar 2015 12:23:09 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:34066)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVMvy-0002cD-S7
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 12:23:07 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVMvv-0004TE-Ai
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 12:23:06 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:43297)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVMvv-0004T9-8L
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 12:23:03 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVMvu-0003cz-Nm
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 12:23:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Paul Eggert <eggert@cs.ucla.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 10 Mar 2015 16:23:02 +0000
Resent-Message-ID: <handler.20062.B20062.142600457313924@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>,  Eric Blake <eblake@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142600457313924
	(code B ref 20062); Tue, 10 Mar 2015 16:23:02 +0000
Received: (at 20062) by debbugs.gnu.org; 10 Mar 2015 16:22:53 +0000
Received: from localhost ([127.0.0.1]:41865 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YVMvh-0003cL-E4
	for submit@debbugs.gnu.org; Tue, 10 Mar 2015 12:22:51 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:56173)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1YVMve-0003bz-6P
	for 20062@debbugs.gnu.org; Tue, 10 Mar 2015 12:22:46 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
	by smtp.cs.ucla.edu (Postfix) with ESMTP id 1A87DA6000C;
	Tue, 10 Mar 2015 09:22:40 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
	by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id ID4ARNYzrTWW; Tue, 10 Mar 2015 09:22:39 -0700 (PDT)
Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200])
	by smtp.cs.ucla.edu (Postfix) with ESMTPSA id E40B6A60007;
	Tue, 10 Mar 2015 09:22:39 -0700 (PDT)
Message-ID: <54FF1A4C.6080104@cs.ucla.edu>
Date: Tue, 10 Mar 2015 09:22:36 -0700
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>	<54FDB353.8060801@redhat.com>
	<87fv9dj28c.fsf@redhat.com> <874mptgo2c.fsf@redhat.com>
In-Reply-To: <874mptgo2c.fsf@redhat.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 10 Mar 2015 16:23:07 -0000

What happens if I type Control-C while colored output is streaming by my 
terminal?  Can it leave the terminal in a funny colored state?




From MAILER-DAEMON Tue Mar 10 18:20:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YVSVV-0000Yz-UD
	for mharc-bug-diffutils@gnu.org; Tue, 10 Mar 2015 18:20:09 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:55965)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVSVT-0000UP-PN
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 18:20:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVSVO-0007QO-US
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 18:20:07 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:43442)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVSVO-0007Q7-Qf
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 18:20:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVSVO-00052n-5r
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 18:20:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 10 Mar 2015 22:20:02 +0000
Resent-Message-ID: <handler.20062.B20062.142602598119357@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Paul Eggert <eggert@cs.ucla.edu>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142602598119357
	(code B ref 20062); Tue, 10 Mar 2015 22:20:02 +0000
Received: (at 20062) by debbugs.gnu.org; 10 Mar 2015 22:19:41 +0000
Received: from localhost ([127.0.0.1]:42010 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YVSV2-000528-SG
	for submit@debbugs.gnu.org; Tue, 10 Mar 2015 18:19:41 -0400
Received: from mx1.redhat.com ([209.132.183.28]:53456)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YVSV0-00051z-8j
	for 20062@debbugs.gnu.org; Tue, 10 Mar 2015 18:19:39 -0400
Received: from int-mx13.intmail.prod.int.phx2.redhat.com
	(int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2AMJUUB025349
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL); Tue, 10 Mar 2015 18:19:30 -0400
Received: from foobarbaz (vpn1-7-177.ams2.redhat.com [10.36.7.177])
	by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2AMJQ6F019268
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Tue, 10 Mar 2015 18:19:28 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com> <54FF1A4C.6080104@cs.ucla.edu>
Date: Tue, 10 Mar 2015 23:19:26 +0100
In-Reply-To: <54FF1A4C.6080104@cs.ucla.edu> (Paul Eggert's message of "Tue, 10
	Mar 2015 09:22:36 -0700")
Message-ID: <87k2yoebrl.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 10 Mar 2015 22:20:08 -0000

Paul Eggert <eggert@cs.ucla.edu> writes:

> What happens if I type Control-C while colored output is streaming by
> my terminal?  Can it leave the terminal in a funny colored state?

No, the Control-C would leave the terminal in a funny state.  Thanks to
have pointed it out, I completely missed the ls.c code that handles
that.

What about amending the previous version with the patch below?

Regards,
Giuseppe


diff --git a/src/util.c b/src/util.c
index 3687b5e..5b28a07 100644
--- a/src/util.c
+++ b/src/util.c
@@ -24,6 +24,7 @@
 #include <system-quote.h>
 #include <xalloc.h>
 #include "xvasprintf.h"
+#include <signal.h>
 
 char const pr_program[] = PR_PROGRAM;
 
@@ -731,24 +732,56 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
     }
 }
 
+static sigset_t old_sigproc_set;
 void
 set_color_context (enum colors con)
 {
+  int j;
+  sigset_t set;
+  static int const sig[] =
+    {
+      SIGTSTP,
+      SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,
+#ifdef SIGPOLL
+      SIGPOLL,
+#endif
+#ifdef SIGPROF
+      SIGPROF,
+#endif
+#ifdef SIGVTALRM
+      SIGVTALRM,
+#endif
+#ifdef SIGXCPU
+      SIGXCPU,
+#endif
+#ifdef SIGXFSZ
+      SIGXFSZ,
+#endif
+    };
+
   if (! colors_enabled)
     return;
 
+  sigemptyset (&set);
+  for (j = 0; j < (sizeof (sig) / sizeof (*sig)); j++)
+    sigaddset (&set, sig[j]);
+
   switch (con)
     {
     case DELETE:
+      sigprocmask (SIG_BLOCK, &set, &old_sigproc_set);
       fprintf (outfile, "\x1B[31m");
       break;
 
     case ADD:
+      sigprocmask (SIG_BLOCK, &set, &old_sigproc_set);
       fprintf (outfile, "\x1B[32m");
       break;
 
     case RESET:
-      fprintf(outfile, "\x1b[0m");
+      fprintf (outfile, "\x1b[0m");
+      fflush (outfile);
+      sigprocmask (SIG_SETMASK, &old_sigproc_set, NULL);
       break;
     }
 }




From MAILER-DAEMON Tue Mar 10 19:00:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YVT8D-0000kn-9t
	for mharc-bug-diffutils@gnu.org; Tue, 10 Mar 2015 19:00:09 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:34721)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVT8B-0000iH-Gb
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 19:00:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVT88-0004W2-BL
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 19:00:07 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:43452)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVT88-0004Uj-8x
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 19:00:04 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVT87-0007YI-CM
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 19:00:03 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Paul Eggert <eggert@cs.ucla.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 10 Mar 2015 23:00:03 +0000
Resent-Message-ID: <handler.20062.B20062.142602836828943@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142602836828943
	(code B ref 20062); Tue, 10 Mar 2015 23:00:03 +0000
Received: (at 20062) by debbugs.gnu.org; 10 Mar 2015 22:59:28 +0000
Received: from localhost ([127.0.0.1]:42020 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YVT7X-0007Wl-K1
	for submit@debbugs.gnu.org; Tue, 10 Mar 2015 18:59:28 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:47842)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1YVT7V-0007WW-Et
	for 20062@debbugs.gnu.org; Tue, 10 Mar 2015 18:59:26 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
	by smtp.cs.ucla.edu (Postfix) with ESMTP id 064F9A60018;
	Tue, 10 Mar 2015 15:59:19 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
	by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id F-p5+bXJ+hY2; Tue, 10 Mar 2015 15:59:18 -0700 (PDT)
Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net
	[100.32.155.148])
	by smtp.cs.ucla.edu (Postfix) with ESMTPSA id A2511A60007;
	Tue, 10 Mar 2015 15:59:18 -0700 (PDT)
Message-ID: <54FF7742.6050500@cs.ucla.edu>
Date: Tue, 10 Mar 2015 15:59:14 -0700
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>	<54FDB353.8060801@redhat.com>
	<87fv9dj28c.fsf@redhat.com>	<874mptgo2c.fsf@redhat.com>
	<54FF1A4C.6080104@cs.ucla.edu> <87k2yoebrl.fsf@redhat.com>
In-Reply-To: <87k2yoebrl.fsf@redhat.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 10 Mar 2015 23:00:08 -0000

Giuseppe Scrivano wrote:

> +  sigemptyset (&set);
> +  for (j = 0; j < (sizeof (sig) / sizeof (*sig)); j++)
> +    sigaddset (&set, sig[j]);

Shouldn't the above part be done just once?  Also, it has redundant parentheses.

> +      sigprocmask (SIG_BLOCK, &set, &old_sigproc_set);

The sigprocmask module needs to be added to bootstrap.conf.

Can the proposed implementation block signals for an unbounded amount of time? 
That would be bad.  ls.c attempts to avoid this problem, and 'diff' should too.

Also, 'diff --color' needn't mess with signal handling unless isatty (fileno 
(outfile)).

Also, surely --color is incompatible with --paginate, in the sense that signals 
arriving while paginating will put outfile into a weird state if outfile is a 
tty, so I expect that combination of options should be rejected.

> What about amending the previous version with the patch below?

Yes, we do need the patch to be amended something along these lines.




From MAILER-DAEMON Tue Mar 10 19:45:10 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YVTpm-00086Y-A4
	for mharc-bug-diffutils@gnu.org; Tue, 10 Mar 2015 19:45:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:42910)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVTpk-00084a-JQ
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 19:45:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVTph-0002sa-86
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 19:45:08 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:43466)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVTph-0002rv-4O
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 19:45:05 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVTpg-0000MV-Jb
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 19:45:04 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 10 Mar 2015 23:45:04 +0000
Resent-Message-ID: <handler.20062.B20062.14260310461303@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Paul Eggert <eggert@cs.ucla.edu>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.14260310461303
	(code B ref 20062); Tue, 10 Mar 2015 23:45:04 +0000
Received: (at 20062) by debbugs.gnu.org; 10 Mar 2015 23:44:06 +0000
Received: from localhost ([127.0.0.1]:42034 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YVToj-0000Kw-UQ
	for submit@debbugs.gnu.org; Tue, 10 Mar 2015 19:44:06 -0400
Received: from mx1.redhat.com ([209.132.183.28]:59629)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YVToh-0000KX-Fu
	for 20062@debbugs.gnu.org; Tue, 10 Mar 2015 19:44:04 -0400
Received: from int-mx13.intmail.prod.int.phx2.redhat.com
	(int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2ANi1ZJ013360
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL); Tue, 10 Mar 2015 19:44:01 -0400
Received: from foobarbaz (vpn1-7-177.ams2.redhat.com [10.36.7.177])
	by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2ANhvbG018974
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Tue, 10 Mar 2015 19:43:59 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com> <54FF1A4C.6080104@cs.ucla.edu>
	<87k2yoebrl.fsf@redhat.com> <54FF7742.6050500@cs.ucla.edu>
Date: Wed, 11 Mar 2015 00:43:57 +0100
In-Reply-To: <54FF7742.6050500@cs.ucla.edu> (Paul Eggert's message of "Tue, 10
	Mar 2015 15:59:14 -0700")
Message-ID: <87egowctaa.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 10 Mar 2015 23:45:09 -0000

Paul Eggert <eggert@cs.ucla.edu> writes:

> Giuseppe Scrivano wrote:
>
>> +  sigemptyset (&set);
>> +  for (j = 0; j < (sizeof (sig) / sizeof (*sig)); j++)
>> +    sigaddset (&set, sig[j]);
>
> Shouldn't the above part be done just once?  Also, it has redundant parentheses.
>
>> +      sigprocmask (SIG_BLOCK, &set, &old_sigproc_set);
>
> The sigprocmask module needs to be added to bootstrap.conf.
>
> Can the proposed implementation block signals for an unbounded amount
> of time? That would be bad.  ls.c attempts to avoid this problem, and
> 'diff' should too.

The change of color context is done per line (except in normal.c where
at the moment it is per hunk but I will change it to be per line) so the
most it can hang is the time needed to print a single line.


> Also, 'diff --color' needn't mess with signal handling unless isatty
> (fileno (outfile)).

Should this also be done if --color=always is used?

Thanks,
Giuseppe




From MAILER-DAEMON Tue Mar 10 20:07:10 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YVUB4-0004Fn-9G
	for mharc-bug-diffutils@gnu.org; Tue, 10 Mar 2015 20:07:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:46134)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVUB1-0004EB-F1
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 20:07:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVUAx-0001wi-E4
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 20:07:07 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:43474)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVUAx-0001wV-Aw
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 20:07:03 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVUAw-0000yr-Ro
	for bug-diffutils@gnu.org; Tue, 10 Mar 2015 20:07:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Paul Eggert <eggert@cs.ucla.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Wed, 11 Mar 2015 00:07:02 +0000
Resent-Message-ID: <handler.20062.B20062.14260324093747@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.14260324093747
	(code B ref 20062); Wed, 11 Mar 2015 00:07:02 +0000
Received: (at 20062) by debbugs.gnu.org; 11 Mar 2015 00:06:49 +0000
Received: from localhost ([127.0.0.1]:42042 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YVUAj-0000yM-8k
	for submit@debbugs.gnu.org; Tue, 10 Mar 2015 20:06:49 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:50870)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1YVUAh-0000y8-55
	for 20062@debbugs.gnu.org; Tue, 10 Mar 2015 20:06:47 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
	by smtp.cs.ucla.edu (Postfix) with ESMTP id 2CC3EA60018;
	Tue, 10 Mar 2015 17:06:41 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
	by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id z9FIEP4+P6Sy; Tue, 10 Mar 2015 17:06:41 -0700 (PDT)
Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net
	[100.32.155.148])
	by smtp.cs.ucla.edu (Postfix) with ESMTPSA id DC685A60007;
	Tue, 10 Mar 2015 17:06:40 -0700 (PDT)
Message-ID: <54FF870C.5000902@cs.ucla.edu>
Date: Tue, 10 Mar 2015 17:06:36 -0700
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>	<54FDB353.8060801@redhat.com>
	<87fv9dj28c.fsf@redhat.com>	<874mptgo2c.fsf@redhat.com>
	<54FF1A4C.6080104@cs.ucla.edu>	<87k2yoebrl.fsf@redhat.com>
	<54FF7742.6050500@cs.ucla.edu> <87egowctaa.fsf@redhat.com>
In-Reply-To: <87egowctaa.fsf@redhat.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 11 Mar 2015 00:07:08 -0000

Giuseppe Scrivano wrote:
> the
> most it can hang is the time needed to print a single line.

There's no limit on line length though, right?  Other than available memory.  So 
this could be a problem.  ('ls' doesn't have a similar problem, if I understand 
it correctly, as OSes typically have reasonably short limits on file name length.)

>> >Also, 'diff --color' needn't mess with signal handling unless isatty
>> >(fileno (outfile)).
> Should this also be done if --color=always is used?

Yes.  diff needs to mess with signal handling only if both (1) diff is 
outputting colors and (2) the output is a terminal.  This is independent of why 
diff is doing (1).




From MAILER-DAEMON Wed Mar 11 16:29:19 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YVnFn-0002Z3-29
	for mharc-bug-diffutils@gnu.org; Wed, 11 Mar 2015 16:29:19 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49092)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVnFe-0002Wb-N0
	for bug-diffutils@gnu.org; Wed, 11 Mar 2015 16:29:18 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVnFW-00042T-FI
	for bug-diffutils@gnu.org; Wed, 11 Mar 2015 16:29:10 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:44607)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVnFW-00042P-BS
	for bug-diffutils@gnu.org; Wed, 11 Mar 2015 16:29:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVnFW-0004Nr-3i
	for bug-diffutils@gnu.org; Wed, 11 Mar 2015 16:29:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Wed, 11 Mar 2015 20:29:02 +0000
Resent-Message-ID: <handler.20062.B20062.142610571016782@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Paul Eggert <eggert@cs.ucla.edu>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142610571016782
	(code B ref 20062); Wed, 11 Mar 2015 20:29:02 +0000
Received: (at 20062) by debbugs.gnu.org; 11 Mar 2015 20:28:30 +0000
Received: from localhost ([127.0.0.1]:43172 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YVnEy-0004MU-Vs
	for submit@debbugs.gnu.org; Wed, 11 Mar 2015 16:28:30 -0400
Received: from mx1.redhat.com ([209.132.183.28]:47398)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YVnEv-0004MH-Iw
	for 20062@debbugs.gnu.org; Wed, 11 Mar 2015 16:28:27 -0400
Received: from int-mx13.intmail.prod.int.phx2.redhat.com
	(int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2BKSMfD025864
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL); Wed, 11 Mar 2015 16:28:23 -0400
Received: from foobarbaz (vpn1-5-126.ams2.redhat.com [10.36.5.126])
	by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2BJwFe9002165
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Wed, 11 Mar 2015 15:58:17 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com> <54FF1A4C.6080104@cs.ucla.edu>
	<87k2yoebrl.fsf@redhat.com> <54FF7742.6050500@cs.ucla.edu>
	<87egowctaa.fsf@redhat.com> <54FF870C.5000902@cs.ucla.edu>
Date: Wed, 11 Mar 2015 20:58:15 +0100
In-Reply-To: <54FF870C.5000902@cs.ucla.edu> (Paul Eggert's message of "Tue, 10
	Mar 2015 17:06:36 -0700")
Message-ID: <878uf3b92g.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 11 Mar 2015 20:29:18 -0000

Paul Eggert <eggert@cs.ucla.edu> writes:

> There's no limit on line length though, right?  Other than available
> memory.  So this could be a problem.  ('ls' doesn't have a similar
> problem, if I understand it correctly, as OSes typically have
> reasonably short limits on file name length.)
>
>>> >Also, 'diff --color' needn't mess with signal handling unless isatty
>>> >(fileno (outfile)).
>> Should this also be done if --color=always is used?
>
> Yes.  diff needs to mess with signal handling only if both (1) diff is
> outputting colors and (2) the output is a terminal.  This is
> independent of why diff is doing (1).

ok, thanks for the explanation.  I've addressed your comments in the
version below.

Now I make sure that we don't write more than "max_chunk" bytes in
output_1_line and unblock/block the signals.

Regards,
Giuseppe


>From 41b868be5adb8c3de2c57c235693d1f2ec426b12 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Sun, 8 Mar 2015 22:45:11 +0100
Subject: [PATCH] diff: add support for --color

* bootstrap.conf (gnulib_modules): Add "sigprocmask".
* doc/diffutils.texi (diff Options): Add documentation for --color.
Copied from coreutils ls --color.
* src/context.c (pr_unidiff_hunk): Add calls to set_color_context.
* src/diff.h (enum colors): New enum to register the current color to use.
(enum colors_style): New enum to record when to use colors.
(colors_style): New variable to memorize the argument value.
(set_color_context): Add function definition.
* src/diff.c: : Define COLOR_OPTION.
(specify_colors_style): New function.
(longopts): Add --color.
(main): Handle --color argument.
(option_help_msgid): Add usage string for --color.
* src/normal.c (print_normal_hunk): Add calls to set_color_context
* src/side.c (print_1sdiff_line): Add calls to set_color_context.
* src/util.c (colors_enabled): New boolean variable.
(colors_enabled): New boolean variable.
(check_color_output): New function.
(begin_output): Call check_color_output every time the output file is changed.
(set_color_context): New function.  If colors are enabled, print the right
command for the terminal to change the color.
---
 bootstrap.conf     |   1 +
 doc/diffutils.texi |  20 +++++++++
 src/context.c      |   4 ++
 src/diff.c         |  30 +++++++++++++-
 src/diff.h         |  34 +++++++++++++++
 src/normal.c       |  20 +++++++--
 src/side.c         |  15 +++++++
 src/util.c         | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 8 files changed, 234 insertions(+), 10 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 9b2de22..63be732 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -61,6 +61,7 @@ readme-release
 regex
 sh-quote
 signal
+sigprocmask
 stat
 stat-macros
 stat-time
diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 3e25807..92a7243 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3745,6 +3745,26 @@ Read and write data in binary mode.  @xref{Binary}.
 Use the context output format, showing three lines of context.
 @xref{Context Format}.
 
+@item --color [=@var{when}]
+@cindex color, distinguishing file types with
+Specify whether to use color for distinguishing file types.  @var{when}
+may be omitted, or one of:
+@itemize @bullet
+@item none
+@vindex none @r{color option}
+- Do not use color at all.  This is the default when no --color option
+is present.
+@item auto
+@vindex auto @r{color option}
+@cindex terminal, using color iff
+- Only use color if standard output is a terminal.
+@item always
+@vindex always @r{color option}
+- Always use color.
+@end itemize
+Specifying @option{--color} and no @var{when} is equivalent to
+@option{--color=auto}.
+
 @item -C @var{lines}
 @itemx --context@r{[}=@var{lines}@r{]}
 Use the context output format, showing @var{lines} (an integer) lines of
diff --git a/src/context.c b/src/context.c
index e0f21c4..88ddfde 100644
--- a/src/context.c
+++ b/src/context.c
@@ -366,10 +366,12 @@ pr_unidiff_hunk (struct change *hunk)
 	  while (k--)
 	    {
 	      char const * const *line = &files[0].linbuf[i++];
+              set_color_context (DELETE);
 	      putc ('-', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
 	      print_1_line (NULL, line);
+              set_color_context (RESET);
 	    }
 
 	  /* Then output the inserted part. */
@@ -378,10 +380,12 @@ pr_unidiff_hunk (struct change *hunk)
 	  while (k--)
 	    {
 	      char const * const *line = &files[1].linbuf[j++];
+              set_color_context (ADD);
 	      putc ('+', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
 	      print_1_line (NULL, line);
+              set_color_context (RESET);
 	    }
 
 	  /* We're done with this hunk, so on to the next! */
diff --git a/src/diff.c b/src/diff.c
index ff28377..07fcb57 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -70,6 +70,7 @@ static void add_regexp (struct regexp_list *, char const *);
 static void summarize_regexp_list (struct regexp_list *);
 static void specify_style (enum output_style);
 static void specify_value (char const **, char const *, char const *);
+static void specify_colors_style (char const *);
 static void try_help (char const *, char const *) __attribute__((noreturn));
 static void check_stdout (void);
 static void usage (void);
@@ -136,7 +137,9 @@ enum
   UNCHANGED_GROUP_FORMAT_OPTION,
   OLD_GROUP_FORMAT_OPTION,
   NEW_GROUP_FORMAT_OPTION,
-  CHANGED_GROUP_FORMAT_OPTION
+  CHANGED_GROUP_FORMAT_OPTION,
+
+  COLOR_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -159,6 +162,7 @@ static struct option const longopts[] =
   {"binary", 0, 0, BINARY_OPTION},
   {"brief", 0, 0, 'q'},
   {"changed-group-format", 1, 0, CHANGED_GROUP_FORMAT_OPTION},
+  {"color", 2, 0, COLOR_OPTION},
   {"context", 2, 0, 'C'},
   {"ed", 0, 0, 'e'},
   {"exclude", 1, 0, 'x'},
@@ -627,6 +631,10 @@ main (int argc, char **argv)
 	  specify_value (&group_format[c], optarg, group_format_option[c]);
 	  break;
 
+        case COLOR_OPTION:
+          specify_colors_style (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
@@ -645,6 +653,9 @@ main (int argc, char **argv)
 	specify_style (OUTPUT_NORMAL);
     }
 
+  if (colors_style != NEVER && paginate)
+    error (EXIT_TROUBLE, 0, _("Cannot specify both --color and --paginate."));
+
   if (output_style != OUTPUT_CONTEXT || hard_locale (LC_TIME))
     {
 #if (defined STAT_TIMESPEC || defined STAT_TIMESPEC_NS \
@@ -940,6 +951,8 @@ static char const * const option_help_msgid[] = {
   N_("-d, --minimal            try hard to find a smaller set of changes"),
   N_("    --horizon-lines=NUM  keep NUM lines of the common prefix and suffix"),
   N_("    --speed-large-files  assume large files and many scattered small changes"),
+  N_("    --color[=WHEN]         colorize the output; WHEN can be 'never', 'always',"),
+  N_("                             or 'auto' (the default)"),
   "",
   N_("    --help               display this help and exit"),
   N_("-v, --version            output version information and exit"),
@@ -1008,6 +1021,21 @@ specify_style (enum output_style style)
       output_style = style;
     }
 }
+
+/* Set the color mode.  */
+static void
+specify_colors_style (char const *value)
+{
+  if (value == NULL || STREQ (value, "auto"))
+    colors_style = AUTO;
+  else if (STREQ (value, "always"))
+    colors_style = ALWAYS;
+  else if (STREQ (value, "never"))
+    colors_style = NEVER;
+  else
+    try_help ("invalid color '%s'", value);
+}
+
 
 /* Set the last-modified time of *ST to be the current time.  */
 
diff --git a/src/diff.h b/src/diff.h
index 465e4bc..0291fdd 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -38,6 +38,36 @@ enum changes
   /* Both deletes and inserts: a hunk containing both old and new lines.  */
   CHANGED
 };
+
+/* What kind of changes a hunk contains.  */
+enum colors
+{
+  /* Reset to the default color.  */
+  RESET,
+
+  /* Delete lines.  Show output in red.  */
+  DELETE,
+
+  /* Added lines.  Show them in green.  */
+  ADD,
+
+  /* Does not modify the context.  Use it to periodically process pending
+     signals.  */
+  SAME,
+};
+
+/* What kind of changes a hunk contains.  */
+enum colors_style
+{
+  /* Never output colors.  */
+  NEVER,
+
+  /* Output colors if the output is a terminal.  */
+  AUTO,
+
+  /* Always output colors.  */
+  ALWAYS,
+};
 
 /* Variables for command line options */
 
@@ -83,6 +113,9 @@ enum output_style
 
 XTERN enum output_style output_style;
 
+/* True if colors are printed.  */
+XTERN enum colors_style colors_style;
+
 /* Nonzero if output cannot be generated for identical files.  */
 XTERN bool no_diff_means_no_output;
 
@@ -390,3 +423,4 @@ extern void print_script (struct change *, struct change * (*) (struct change *)
 extern void setup_output (char const *, char const *, bool);
 extern void translate_range (struct file_data const *, lin, lin,
                              long int *, long int *);
+extern void set_color_context (enum colors);
diff --git a/src/normal.c b/src/normal.c
index 721fd1a..0d53033 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -56,14 +56,26 @@ print_normal_hunk (struct change *hunk)
 
   /* Print the lines that the first file has.  */
   if (changes & OLD)
-    for (i = first0; i <= last0; i++)
-      print_1_line ("<", &files[0].linbuf[i]);
+    {
+      for (i = first0; i <= last0; i++)
+        {
+          set_color_context (DELETE);
+          print_1_line ("<", &files[0].linbuf[i]);
+          set_color_context (RESET);
+        }
+    }
 
   if (changes == CHANGED)
     fputs ("---\n", outfile);
 
   /* Print the lines that the second file has.  */
   if (changes & NEW)
-    for (i = first1; i <= last1; i++)
-      print_1_line (">", &files[1].linbuf[i]);
+    {
+      for (i = first1; i <= last1; i++)
+        {
+          set_color_context (ADD);
+          print_1_line (">", &files[1].linbuf[i]);
+          set_color_context (RESET);
+        }
+    }
 }
diff --git a/src/side.c b/src/side.c
index 155512c..e52454e 100644
--- a/src/side.c
+++ b/src/side.c
@@ -206,6 +206,18 @@ print_1sdiff_line (char const *const *left, char sep,
   size_t c2o = sdiff_column2_offset;
   size_t col = 0;
   bool put_newline = false;
+  bool color_to_reset = false;
+
+  if (sep == '<')
+    {
+      set_color_context (DELETE);
+      color_to_reset = true;
+    }
+  else if (sep == '>')
+    {
+      set_color_context (ADD);
+      color_to_reset = true;
+    }
 
   if (left)
     {
@@ -233,6 +245,9 @@ print_1sdiff_line (char const *const *left, char sep,
 
   if (put_newline)
     putc ('\n', out);
+
+  if (color_to_reset)
+    set_color_context (RESET);
 }
 
 /* Print lines common to both files in side-by-side format.  */
diff --git a/src/util.c b/src/util.c
index 2d6d3fc..dcb3a59 100644
--- a/src/util.c
+++ b/src/util.c
@@ -24,6 +24,7 @@
 #include <system-quote.h>
 #include <xalloc.h>
 #include "xvasprintf.h"
+#include <signal.h>
 
 char const pr_program[] = PR_PROGRAM;
 
@@ -153,6 +154,20 @@ print_message_queue (void)
 static char const *current_name0;
 static char const *current_name1;
 static bool currently_recursive;
+static bool colors_enabled;
+static bool output_is_tty;
+
+static void
+check_color_output (void)
+{
+  if (! outfile)
+    return;
+
+  output_is_tty = isatty (fileno (outfile));
+
+  colors_enabled = (colors_style == ALWAYS)
+    || (colors_style == AUTO && output_is_tty);
+}
 
 void
 setup_output (char const *name0, char const *name1, bool recursive)
@@ -313,6 +328,7 @@ begin_output (void)
 	    outfile = fdopen (pipes[1], "w");
 	    if (!outfile)
 	      pfatal_with_name ("fdopen");
+            check_color_output ();
 	  }
 #else
 	char *command = system_quote_argv (SCI_SYSTEM, (char **) argv);
@@ -320,6 +336,7 @@ begin_output (void)
 	outfile = popen (command, "w");
 	if (!outfile)
 	  pfatal_with_name (command);
+        check_color_output ();
 	free (command);
 #endif
       }
@@ -330,6 +347,7 @@ begin_output (void)
       /* If -l was not specified, output the diff straight to 'stdout'.  */
 
       outfile = stdout;
+      check_color_output ();
 
       /* If handling multiple files (because scanning a directory),
 	 print which files the following output is about.  */
@@ -672,8 +690,20 @@ void
 output_1_line (char const *base, char const *limit, char const *flag_format,
 	       char const *line_flag)
 {
+  /* Try to avoid to block for too long and write more than MAX_CHUNK bytes before
+     checking for pending signals.  */
+  const size_t max_chunk = 4096;
   if (!expand_tabs)
-    fwrite (base, sizeof (char), limit - base, outfile);
+    {
+      size_t left = limit - base;
+      while (left)
+        {
+          size_t len = MIN (left, max_chunk);
+          fwrite (base, sizeof (char), len, outfile);
+          set_color_context (SAME);
+          left -= len;
+        }
+    }
   else
     {
       register FILE *out = outfile;
@@ -681,6 +711,7 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
       register char const *t = base;
       register size_t column = 0;
       size_t tab_size = tabsize;
+      size_t written = 0;
 
       while (t < limit)
 	switch ((c = *t++))
@@ -690,7 +721,9 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
 	      size_t spaces = tab_size - column % tab_size;
 	      column += spaces;
 	      do
-		putc (' ', out);
+                {
+                  written += putc (' ', out);
+                }
 	      while (--spaces);
 	    }
 	    break;
@@ -698,7 +731,7 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
 	  case '\r':
 	    putc (c, out);
 	    if (flag_format && t < limit && *t != '\n')
-	      fprintf (out, flag_format, line_flag);
+	      written += fprintf (out, flag_format, line_flag);
 	    column = 0;
 	    break;
 
@@ -706,17 +739,94 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
 	    if (column == 0)
 	      continue;
 	    column--;
-	    putc (c, out);
+	    written += putc (c, out);
 	    break;
 
 	  default:
 	    column += isprint (c) != 0;
-	    putc (c, out);
+	    written += putc (c, out);
+            if (written >= max_chunk)
+              {
+                set_color_context (SAME);
+                written = 0;
+              }
 	    break;
 	  }
     }
 }
 
+static sigset_t old_sigproc_set;
+void
+set_color_context (enum colors con)
+{
+  int j;
+  static sigset_t set;
+  static bool set_initialized;
+  static enum colors last_color_context = RESET;
+  static int const sig[] =
+    {
+      SIGTSTP,
+      SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,
+#ifdef SIGPOLL
+      SIGPOLL,
+#endif
+#ifdef SIGPROF
+      SIGPROF,
+#endif
+#ifdef SIGVTALRM
+      SIGVTALRM,
+#endif
+#ifdef SIGXCPU
+      SIGXCPU,
+#endif
+#ifdef SIGXFSZ
+      SIGXFSZ,
+#endif
+    };
+
+  if (!colors_enabled || (con == SAME && !output_is_tty))
+    return;
+
+  if (output_is_tty && !set_initialized)
+    {
+      sigemptyset (&set);
+      for (j = 0; j < sizeof (sig) / sizeof (*sig); j++)
+        sigaddset (&set, sig[j]);
+      set_initialized = true;
+    }
+
+repeat:
+  switch (con)
+    {
+    case DELETE:
+      if (output_is_tty)
+        sigprocmask (SIG_BLOCK, &set, &old_sigproc_set);
+      fprintf (outfile, "\x1B[31m");
+      break;
+
+    case ADD:
+      if (output_is_tty)
+        sigprocmask (SIG_BLOCK, &set, &old_sigproc_set);
+      fprintf (outfile, "\x1B[32m");
+      break;
+
+    case SAME:
+    case RESET:
+      fprintf (outfile, "\x1b[0m");
+      fflush (outfile);
+      if (output_is_tty)
+        sigprocmask (SIG_SETMASK, &old_sigproc_set, NULL);
+      if (con == SAME)
+        {
+          con = last_color_context;
+          goto repeat;
+        }
+      break;
+    }
+
+  last_color_context = con;
+}
+
 char const change_letter[] = { 0, 'd', 'a', 'c' };
 
 /* Translate an internal line number (an index into diff's table of lines)
-- 
2.1.0





From MAILER-DAEMON Wed Mar 11 19:19:10 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YVpuA-00052r-2S
	for mharc-bug-diffutils@gnu.org; Wed, 11 Mar 2015 19:19:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:57515)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVpu7-00052R-G7
	for bug-diffutils@gnu.org; Wed, 11 Mar 2015 19:19:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVpu2-0008To-BC
	for bug-diffutils@gnu.org; Wed, 11 Mar 2015 19:19:07 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:44687)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVpu2-0008TT-7W
	for bug-diffutils@gnu.org; Wed, 11 Mar 2015 19:19:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVpu1-0000aY-Nt
	for bug-diffutils@gnu.org; Wed, 11 Mar 2015 19:19:01 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Paul Eggert <eggert@cs.ucla.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Wed, 11 Mar 2015 23:19:01 +0000
Resent-Message-ID: <handler.20062.B20062.14261159232233@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.14261159232233
	(code B ref 20062); Wed, 11 Mar 2015 23:19:01 +0000
Received: (at 20062) by debbugs.gnu.org; 11 Mar 2015 23:18:43 +0000
Received: from localhost ([127.0.0.1]:43255 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YVpti-0000Zx-F3
	for submit@debbugs.gnu.org; Wed, 11 Mar 2015 19:18:42 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:47925)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1YVptg-0000Zi-BO
	for 20062@debbugs.gnu.org; Wed, 11 Mar 2015 19:18:41 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
	by smtp.cs.ucla.edu (Postfix) with ESMTP id 0FA00A60031;
	Wed, 11 Mar 2015 16:18:34 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
	by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Y2p4JhVNSzz2; Wed, 11 Mar 2015 16:18:33 -0700 (PDT)
Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net
	[100.32.155.148])
	by smtp.cs.ucla.edu (Postfix) with ESMTPSA id B3A58A6002D;
	Wed, 11 Mar 2015 16:18:33 -0700 (PDT)
Message-ID: <5500CD49.1060505@cs.ucla.edu>
Date: Wed, 11 Mar 2015 16:18:33 -0700
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>	<54FDB353.8060801@redhat.com>
	<87fv9dj28c.fsf@redhat.com>	<874mptgo2c.fsf@redhat.com>
	<54FF1A4C.6080104@cs.ucla.edu>	<87k2yoebrl.fsf@redhat.com>
	<54FF7742.6050500@cs.ucla.edu>	<87egowctaa.fsf@redhat.com>
	<54FF870C.5000902@cs.ucla.edu> <878uf3b92g.fsf@redhat.com>
In-Reply-To: <878uf3b92g.fsf@redhat.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 11 Mar 2015 23:19:08 -0000

Giuseppe Scrivano wrote:

>   signal
> +sigprocmask
>   stat

Your mailer is inserting spaces at the start of lines, making the patch hard to 
read.  Perhaps attach the patch instead next time?

> +- Do not use color at all.  This is the default when no --color option
> +is present.

That leading "-" doesn't look right.  I'd remove it.  (Similarly elsewhere.)

+  if (! outfile)
+    return;
+
+  output_is_tty = isatty (fileno (outfile));
+
+  colors_enabled = (colors_style == ALWAYS)
+    || (colors_style == AUTO && output_is_tty);

The indenting and parentheses should be something like this:

    colors_enabled = (colors_style == ALWAYS
                      || (colors_style == AUTO && output_is_tty));

More important, don't call isatty unless it's needed, as isatty can be somewhat 
expensive on some hosts.  It's not needed if COLORS_STYLE == NEVER.

+            check_color_output ();
...
+        check_color_output ();
...
        outfile = stdout;
+      check_color_output ();

The first two calls to check_color_output do unnecessary work, since 'outfile' 
must be a pipe in that case, so there's no need to call isatty.  Only in the 
last case might isatty be needed.

+      size_t left = limit - base;
+      while (left)
+        {
+          size_t len = MIN (left, max_chunk);
+          fwrite (base, sizeof (char), len, outfile);
+          set_color_context (SAME);
+          left -= len;
+        }
+    }

I'm afraid this won't work in general, as set_color_context (SAME) sends bytes 
to stdout if stdout is a tty, whereas it shouldn't output anything in the normal 
case.  For example, it might try to change color in the middle of a multibyte 
character, and that's a no-no.

Also, I'm a bit dubious about all those calls to sigprocmask.  Can't we solve 
this without having to execute a sigmask-related system call for each buffer? 
How about using the method that 'ls' uses instead?  Install a signal handler 
that merely sets a static variable.  Perhaps the relevant 'ls' code should be 
Gnulib-ized, so that it can be shared between 'ls' and 'diff'.

+      fprintf (outfile, "\x1b[0m");
+      fflush (outfile);
+      if (output_is_tty)
+        sigprocmask (SIG_SETMASK, &old_sigproc_set, NULL);

No need to call fflush if output is not a tty.




From MAILER-DAEMON Thu Mar 12 05:15:12 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YVzCy-0001BX-38
	for mharc-bug-diffutils@gnu.org; Thu, 12 Mar 2015 05:15:12 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:46647)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVzCs-00018p-Sp
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 05:15:10 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVzCo-0002HB-Ni
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 05:15:06 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:44872)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVzCo-0002GX-L4
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 05:15:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YVzCo-0006wK-5C
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 05:15:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Thu, 12 Mar 2015 09:15:01 +0000
Resent-Message-ID: <handler.20062.B20062.142615165926606@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Paul Eggert <eggert@cs.ucla.edu>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142615165926606
	(code B ref 20062); Thu, 12 Mar 2015 09:15:01 +0000
Received: (at 20062) by debbugs.gnu.org; 12 Mar 2015 09:14:19 +0000
Received: from localhost ([127.0.0.1]:43440 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YVzC7-0006v4-Bl
	for submit@debbugs.gnu.org; Thu, 12 Mar 2015 05:14:19 -0400
Received: from mx1.redhat.com ([209.132.183.28]:55483)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YVzC4-0006uq-CA
	for 20062@debbugs.gnu.org; Thu, 12 Mar 2015 05:14:17 -0400
Received: from int-mx09.intmail.prod.int.phx2.redhat.com
	(int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2C9E7OI007078
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL); Thu, 12 Mar 2015 05:14:07 -0400
Received: from foobarbaz (vpn1-4-71.ams2.redhat.com [10.36.4.71])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2C9E4dc019196
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Thu, 12 Mar 2015 05:14:06 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com> <54FF1A4C.6080104@cs.ucla.edu>
	<87k2yoebrl.fsf@redhat.com> <54FF7742.6050500@cs.ucla.edu>
	<87egowctaa.fsf@redhat.com> <54FF870C.5000902@cs.ucla.edu>
	<878uf3b92g.fsf@redhat.com> <5500CD49.1060505@cs.ucla.edu>
Date: Thu, 12 Mar 2015 10:14:03 +0100
In-Reply-To: <5500CD49.1060505@cs.ucla.edu> (Paul Eggert's message of "Wed, 11
	Mar 2015 16:18:33 -0700")
Message-ID: <87twxqa884.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 12 Mar 2015 09:15:11 -0000

Hi Paul,

Paul Eggert <eggert@cs.ucla.edu> writes:

> Also, I'm a bit dubious about all those calls to sigprocmask.  Can't
> we solve this without having to execute a sigmask-related system call
> for each buffer? How about using the method that 'ls' uses instead?
> Install a signal handler that merely sets a static variable.  Perhaps
> the relevant 'ls' code should be Gnulib-ized, so that it can be shared
> between 'ls' and 'diff'.

is it ok for now to keep these calls to sigprocmask and fix all the
other issues you reported (until the ls.c code is Gnulib-ized)?
They won't affect any existing use-case anyway as they will be used only
when --color is used on a tty.

Thanks for the detailed review.

Giuseppe




From MAILER-DAEMON Thu Mar 12 10:46:12 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YW4NI-0006pC-8u
	for mharc-bug-diffutils@gnu.org; Thu, 12 Mar 2015 10:46:12 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:45614)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YW4NC-0006oD-87
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 10:46:10 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YW4N8-0006m5-6p
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 10:46:06 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:45492)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YW4N8-0006m1-3a
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 10:46:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YW4N7-0008Iy-UA
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 10:46:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Paul Eggert <eggert@cs.ucla.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Thu, 12 Mar 2015 14:46:01 +0000
Resent-Message-ID: <handler.20062.B20062.142617150831843@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142617150831843
	(code B ref 20062); Thu, 12 Mar 2015 14:46:01 +0000
Received: (at 20062) by debbugs.gnu.org; 12 Mar 2015 14:45:08 +0000
Received: from localhost ([127.0.0.1]:44060 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YW4MF-0008HW-Tw
	for submit@debbugs.gnu.org; Thu, 12 Mar 2015 10:45:08 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:49801)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1YW4MC-0008Gh-AC
	for 20062@debbugs.gnu.org; Thu, 12 Mar 2015 10:45:05 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
	by smtp.cs.ucla.edu (Postfix) with ESMTP id 32933A6001B;
	Thu, 12 Mar 2015 07:44:57 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
	by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id DoQfiRwDVbUp; Thu, 12 Mar 2015 07:44:57 -0700 (PDT)
Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net
	[100.32.155.148])
	by smtp.cs.ucla.edu (Postfix) with ESMTPSA id E04CB39E8018;
	Thu, 12 Mar 2015 07:44:56 -0700 (PDT)
Message-ID: <5501A668.5050104@cs.ucla.edu>
Date: Thu, 12 Mar 2015 07:44:56 -0700
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>	<54FDB353.8060801@redhat.com>
	<87fv9dj28c.fsf@redhat.com>	<874mptgo2c.fsf@redhat.com>
	<54FF1A4C.6080104@cs.ucla.edu>	<87k2yoebrl.fsf@redhat.com>
	<54FF7742.6050500@cs.ucla.edu>	<87egowctaa.fsf@redhat.com>
	<54FF870C.5000902@cs.ucla.edu>	<878uf3b92g.fsf@redhat.com>
	<5500CD49.1060505@cs.ucla.edu> <87twxqa884.fsf@redhat.com>
In-Reply-To: <87twxqa884.fsf@redhat.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 12 Mar 2015 14:46:10 -0000

Giuseppe Scrivano wrote:
> is it ok for now to keep these calls to sigprocmask and fix all the
> other issues you reported (until the ls.c code is Gnulib-ized)?

Sure, if removing sigprocmask calls is merely an efficiency thing.  (It may be 
that the cost of the sigprocmask calls is not significant, so we can leave them 
in.)  Correctness is the bigger problem here.

Another possibility is to refuse to output colors to a terminal.  That would 
simplify a lot of things; we wouldn't need to worry about signals at all.

A third possibility is to have a signal handler that resets the terminal (using 
'write' not 'fwrite', to make it async-signal-safe).  That should remove the 
need for sigprocmask.




From MAILER-DAEMON Thu Mar 12 12:22:17 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YW5sH-0000tb-Bn
	for mharc-bug-diffutils@gnu.org; Thu, 12 Mar 2015 12:22:17 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:60929)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YW5II-0008Hh-PJ
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 11:45:12 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YW5IF-0007Gs-Dm
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 11:45:06 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:45538)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YW5IF-0007GP-8N
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 11:45:03 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YW5IE-0001MO-VI
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 11:45:03 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Gisle Vanem <gvanem@yahoo.no>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Thu, 12 Mar 2015 15:45:02 +0000
Resent-Message-ID: <handler.20062.B.14261750675166@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: 20062@debbugs.gnu.org
X-Debbugs-Original-To: bug-diffutils@gnu.org
Received: via spool by submit@debbugs.gnu.org id=B.14261750675166
	(code B ref -1); Thu, 12 Mar 2015 15:45:02 +0000
Received: (at submit) by debbugs.gnu.org; 12 Mar 2015 15:44:27 +0000
Received: from localhost ([127.0.0.1]:44106 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YW5He-0001LG-K7
	for submit@debbugs.gnu.org; Thu, 12 Mar 2015 11:44:27 -0400
Received: from eggs.gnu.org ([208.118.235.92]:58197)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gvanem@yahoo.no>) id 1YVySM-0005kT-8g
	for submit@debbugs.gnu.org; Thu, 12 Mar 2015 04:27:03 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <gvanem@yahoo.no>) id 1YVySC-0000hl-Vx
	for submit@debbugs.gnu.org; Thu, 12 Mar 2015 04:26:56 -0400
Received: from lists.gnu.org ([2001:4830:134:3::11]:51777)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <gvanem@yahoo.no>) id 1YVySC-0000hh-TU
	for submit@debbugs.gnu.org; Thu, 12 Mar 2015 04:26:52 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:59901)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <gvanem@yahoo.no>) id 1YVyS8-0001Ly-4i
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 04:26:52 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <gvanem@yahoo.no>) id 1YVyS4-0000bl-1m
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 04:26:48 -0400
Received: from nm29-vm8.bullet.mail.gq1.yahoo.com ([98.136.216.183]:48168)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <gvanem@yahoo.no>) id 1YVyS3-0000bU-P6
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 04:26:43 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.no; s=s2048;
	t=1426148802; bh=PrukXXLV91aMpq41fdqG7rze4XGvzOvozAC7lAGxvSU=;
	h=Date:From:To:Subject:References:In-Reply-To:From:Subject;
	b=WqgFogjPuE7jwRQzEPl8Z9FGMewTEDFSdHkVRGVN5X6/L1Pc/T0IQ/0Z9343YZjNtspY63r6Zvgq8FM+lcaTWeB0xJYpsCsxnMfUlEbW+hcX+jmILUIyVdugEQCuMYtTX5DxVRhxwEFShplcAwqqxYTeFqWeUz6RakAZ4ADYqsvCAlArpnSNyenTUA9hfmGg52ghl6LSrwdZKtmj06gsiCpM+QZe2HbZyMTCR/LWwGbWa3rn1/cgtFhXMaxM+svBxmsJYMgTgsczOYIWUvNOcKOC8Wl1M+b4mJdaWIAssxfS4yLnzauwPyakJT9POXCGWbRC40mxllDiRYWffcov9g==
Received: from [98.137.12.59] by nm29.bullet.mail.gq1.yahoo.com with NNFMP;
	12 Mar 2015 08:26:42 -0000
Received: from [46.228.39.75] by tm4.bullet.mail.gq1.yahoo.com with NNFMP;
	12 Mar 2015 08:26:42 -0000
Received: from [127.0.0.1] by smtp112.mail.ir2.yahoo.com with NNFMP;
	12 Mar 2015 08:26:41 -0000
X-Yahoo-Newman-Id: 744691.63501.bm@smtp112.mail.ir2.yahoo.com
X-Yahoo-Newman-Property: ymail-3
X-YMail-OSG: VxG7GiQVM1nJg_VZ22OLCQ6cEJGtl1Mgw.IF.B8bOExQm0H
	_x_Dl50Nb0TwnTUhQKbyX2WLsPAFDSdKUCIsyM8jt2u3MxF9oXwDFJNqqW6E
	Ig8JlMhT.tHQ4e699iiOMy5DzQEL3CX81Q.4rAkFL.eq0Z85BeOVFYz_mliE
	7ZxnmmV86Q98cTmmpDMXJ.rVycWWH5SJlrXxwDHe7ejPcqbpmoirifKGGH6v
	F29F_MJpt6bI.R5FmnsRw7CRUKY3qjS_ixkFy6JtPNNW93aARQrj8_f0Ig2r
	xCQgjts2j8GjnOmWWLvPLcfcFIu1vBoP5kIMf5iXtJGphkzZsbE1l57iAR1I
	OWw5X8ZLGnSowGYCaJxP_PuxaexHQRzeX.vuu8Y.iLTgvjRo1x_QDMCR2NT.
	T84rFV.xg6l9a0G8SYz5bXiYZ.T4ZmeQ3FEmulB7ezOBFzckoFqzJAUgWCxP
	ha2C6.DskVJpIYNTxFlAlWysvCGE_UzDr3rGtfkILOZM.QeGTUVFKIn_BV_a
	fEeH1Bj1g3jB939Tg0mz04w--
X-Yahoo-SMTP: 8zhYLGyswBB3AGU8c4pvFIFOfA--
Message-ID: <55014DC7.3050602@yahoo.no>
Date: Thu, 12 Mar 2015 09:26:47 +0100
From: Gisle Vanem <gvanem@yahoo.no>
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64;
	rv:35.0) Gecko/20100101 Firefox/35.0 SeaMonkey/2.32.1
MIME-Version: 1.0
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>	<54FDB353.8060801@redhat.com>	<87fv9dj28c.fsf@redhat.com>	<874mptgo2c.fsf@redhat.com>	<54FF1A4C.6080104@cs.ucla.edu>	<87k2yoebrl.fsf@redhat.com>	<54FF7742.6050500@cs.ucla.edu>	<87egowctaa.fsf@redhat.com>	<54FF870C.5000902@cs.ucla.edu>
	<878uf3b92g.fsf@redhat.com> <5500CD49.1060505@cs.ucla.edu>
In-Reply-To: <5500CD49.1060505@cs.ucla.edu>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
	(bad octet value).
X-Mailman-Approved-At: Thu, 12 Mar 2015 11:44:24 -0400
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
X-Mailman-Approved-At: Thu, 12 Mar 2015 12:22:16 -0400
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062: [PATCH]
	diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 12 Mar 2015 15:45:12 -0000

Paul Eggert wrote:

> +      fprintf (outfile, "\x1b[0m");
> +      fflush (outfile);
> +      if (output_is_tty)
> +        sigprocmask (SIG_SETMASK, &old_sigproc_set, NULL);
>
> No need to call fflush if output is not a tty.

And what support do GnuLib have for parsing ANSI-codes
and showing colours on Windows? None I guess.

But I've written a simple ANSI-color decoder elsewhere I could
contribute. Or we could replace those "\x1b[0m" with calls to
SetConsoleTextAttribute() instead.

-- 
--gv




From MAILER-DAEMON Thu Mar 12 17:19:10 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YWAVa-0005e1-5n
	for mharc-bug-diffutils@gnu.org; Thu, 12 Mar 2015 17:19:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:34803)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWAVW-0005aL-EJ
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 17:19:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWAVS-0001nZ-9E
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 17:19:06 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:45737)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWAVS-0001nS-5M
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 17:19:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWAVR-0005nj-NM
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 17:19:01 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Thu, 12 Mar 2015 21:19:01 +0000
Resent-Message-ID: <handler.20062.B20062.142619511122258@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Paul Eggert <eggert@cs.ucla.edu>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142619511122258
	(code B ref 20062); Thu, 12 Mar 2015 21:19:01 +0000
Received: (at 20062) by debbugs.gnu.org; 12 Mar 2015 21:18:31 +0000
Received: from localhost ([127.0.0.1]:44305 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YWAUv-0005mt-TT
	for submit@debbugs.gnu.org; Thu, 12 Mar 2015 17:18:31 -0400
Received: from mx1.redhat.com ([209.132.183.28]:57460)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YWAUs-0005mi-1I
	for 20062@debbugs.gnu.org; Thu, 12 Mar 2015 17:18:28 -0400
Received: from int-mx14.intmail.prod.int.phx2.redhat.com
	(int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2CLIN1I014178
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL); Thu, 12 Mar 2015 17:18:23 -0400
Received: from foobarbaz (vpn1-6-98.ams2.redhat.com [10.36.6.98])
	by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2CLIIUb032492
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Thu, 12 Mar 2015 17:18:20 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com> <54FF1A4C.6080104@cs.ucla.edu>
	<87k2yoebrl.fsf@redhat.com> <54FF7742.6050500@cs.ucla.edu>
	<87egowctaa.fsf@redhat.com> <54FF870C.5000902@cs.ucla.edu>
	<878uf3b92g.fsf@redhat.com> <5500CD49.1060505@cs.ucla.edu>
	<87twxqa884.fsf@redhat.com> <5501A668.5050104@cs.ucla.edu>
Date: Thu, 12 Mar 2015 22:18:18 +0100
In-Reply-To: <5501A668.5050104@cs.ucla.edu> (Paul Eggert's message of "Thu, 12
	Mar 2015 07:44:56 -0700")
Message-ID: <87pp8d9ap1.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 12 Mar 2015 21:19:09 -0000

--=-=-=
Content-Type: text/plain

Paul Eggert <eggert@cs.ucla.edu> writes:

> Giuseppe Scrivano wrote:
>> is it ok for now to keep these calls to sigprocmask and fix all the
>> other issues you reported (until the ls.c code is Gnulib-ized)?
>
> Sure, if removing sigprocmask calls is merely an efficiency thing.
> (It may be that the cost of the sigprocmask calls is not significant,
> so we can leave them in.)  Correctness is the bigger problem here.

I've attached a new version where I leave sigprocmask when colors are
used on a tty.

Regards,
Giuseppe


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=0001-diff-add-support-for-color.patch

>From 68c9ac2ba4c3baf8ce3202c59fa931367a0ec215 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Sun, 8 Mar 2015 22:45:11 +0100
Subject: [PATCH] diff: add support for --color

* bootstrap.conf (gnulib_modules): Add "sigprocmask" and "mbiter".
* doc/diffutils.texi (diff Options): Add documentation for --color.
Copied from coreutils ls --color.
* src/context.c (pr_unidiff_hunk): Add calls to set_color_context.
* src/diff.h (enum colors): New enum to register the current color to use.
(enum colors_style): New enum to record when to use colors.
(colors_style): New variable to memorize the argument value.
(set_color_context): Add function definition.
* src/diff.c: : Define COLOR_OPTION.
(specify_colors_style): New function.
(longopts): Add --color.
(main): Handle --color argument.
(option_help_msgid): Add usage string for --color.
* src/normal.c (print_normal_hunk): Add calls to set_color_context
* src/side.c (print_1sdiff_line): Add calls to set_color_context.
* src/util.c (colors_enabled): New boolean variable.
(colors_enabled): New boolean variable.
(check_color_output): New function.
(begin_output): Call check_color_output every time the output file is changed.
(set_color_context): New function.  If colors are enabled, print the right
command for the terminal to change the color.
---
 bootstrap.conf     |   2 +
 doc/diffutils.texi |  20 ++++++++
 src/context.c      |   4 ++
 src/diff.c         |  30 +++++++++++-
 src/diff.h         |  34 ++++++++++++++
 src/normal.c       |  20 ++++++--
 src/side.c         |  15 ++++++
 src/util.c         | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 8 files changed, 251 insertions(+), 10 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 9b2de22..4825401 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -51,6 +51,7 @@ largefile
 lstat
 maintainer-makefile
 manywarnings
+mbiter
 mbrtowc
 mkstemp
 mktime
@@ -61,6 +62,7 @@ readme-release
 regex
 sh-quote
 signal
+sigprocmask
 stat
 stat-macros
 stat-time
diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 3e25807..0a2f1fc 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3745,6 +3745,26 @@ Read and write data in binary mode.  @xref{Binary}.
 Use the context output format, showing three lines of context.
 @xref{Context Format}.
 
+@item --color [=@var{when}]
+@cindex color, distinguishing file types with
+Specify whether to use color for distinguishing file types.  @var{when}
+may be omitted, or one of:
+@itemize @bullet
+@item none
+@vindex none @r{color option}
+Do not use color at all.  This is the default when no --color option
+is present.
+@item auto
+@vindex auto @r{color option}
+@cindex terminal, using color iff
+Only use color if standard output is a terminal.
+@item always
+@vindex always @r{color option}
+Always use color.
+@end itemize
+Specifying @option{--color} and no @var{when} is equivalent to
+@option{--color=auto}.
+
 @item -C @var{lines}
 @itemx --context@r{[}=@var{lines}@r{]}
 Use the context output format, showing @var{lines} (an integer) lines of
diff --git a/src/context.c b/src/context.c
index e0f21c4..88ddfde 100644
--- a/src/context.c
+++ b/src/context.c
@@ -366,10 +366,12 @@ pr_unidiff_hunk (struct change *hunk)
 	  while (k--)
 	    {
 	      char const * const *line = &files[0].linbuf[i++];
+              set_color_context (DELETE);
 	      putc ('-', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
 	      print_1_line (NULL, line);
+              set_color_context (RESET);
 	    }
 
 	  /* Then output the inserted part. */
@@ -378,10 +380,12 @@ pr_unidiff_hunk (struct change *hunk)
 	  while (k--)
 	    {
 	      char const * const *line = &files[1].linbuf[j++];
+              set_color_context (ADD);
 	      putc ('+', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
 	      print_1_line (NULL, line);
+              set_color_context (RESET);
 	    }
 
 	  /* We're done with this hunk, so on to the next! */
diff --git a/src/diff.c b/src/diff.c
index ff28377..07fcb57 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -70,6 +70,7 @@ static void add_regexp (struct regexp_list *, char const *);
 static void summarize_regexp_list (struct regexp_list *);
 static void specify_style (enum output_style);
 static void specify_value (char const **, char const *, char const *);
+static void specify_colors_style (char const *);
 static void try_help (char const *, char const *) __attribute__((noreturn));
 static void check_stdout (void);
 static void usage (void);
@@ -136,7 +137,9 @@ enum
   UNCHANGED_GROUP_FORMAT_OPTION,
   OLD_GROUP_FORMAT_OPTION,
   NEW_GROUP_FORMAT_OPTION,
-  CHANGED_GROUP_FORMAT_OPTION
+  CHANGED_GROUP_FORMAT_OPTION,
+
+  COLOR_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -159,6 +162,7 @@ static struct option const longopts[] =
   {"binary", 0, 0, BINARY_OPTION},
   {"brief", 0, 0, 'q'},
   {"changed-group-format", 1, 0, CHANGED_GROUP_FORMAT_OPTION},
+  {"color", 2, 0, COLOR_OPTION},
   {"context", 2, 0, 'C'},
   {"ed", 0, 0, 'e'},
   {"exclude", 1, 0, 'x'},
@@ -627,6 +631,10 @@ main (int argc, char **argv)
 	  specify_value (&group_format[c], optarg, group_format_option[c]);
 	  break;
 
+        case COLOR_OPTION:
+          specify_colors_style (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
@@ -645,6 +653,9 @@ main (int argc, char **argv)
 	specify_style (OUTPUT_NORMAL);
     }
 
+  if (colors_style != NEVER && paginate)
+    error (EXIT_TROUBLE, 0, _("Cannot specify both --color and --paginate."));
+
   if (output_style != OUTPUT_CONTEXT || hard_locale (LC_TIME))
     {
 #if (defined STAT_TIMESPEC || defined STAT_TIMESPEC_NS \
@@ -940,6 +951,8 @@ static char const * const option_help_msgid[] = {
   N_("-d, --minimal            try hard to find a smaller set of changes"),
   N_("    --horizon-lines=NUM  keep NUM lines of the common prefix and suffix"),
   N_("    --speed-large-files  assume large files and many scattered small changes"),
+  N_("    --color[=WHEN]         colorize the output; WHEN can be 'never', 'always',"),
+  N_("                             or 'auto' (the default)"),
   "",
   N_("    --help               display this help and exit"),
   N_("-v, --version            output version information and exit"),
@@ -1008,6 +1021,21 @@ specify_style (enum output_style style)
       output_style = style;
     }
 }
+
+/* Set the color mode.  */
+static void
+specify_colors_style (char const *value)
+{
+  if (value == NULL || STREQ (value, "auto"))
+    colors_style = AUTO;
+  else if (STREQ (value, "always"))
+    colors_style = ALWAYS;
+  else if (STREQ (value, "never"))
+    colors_style = NEVER;
+  else
+    try_help ("invalid color '%s'", value);
+}
+
 
 /* Set the last-modified time of *ST to be the current time.  */
 
diff --git a/src/diff.h b/src/diff.h
index 465e4bc..0291fdd 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -38,6 +38,36 @@ enum changes
   /* Both deletes and inserts: a hunk containing both old and new lines.  */
   CHANGED
 };
+
+/* What kind of changes a hunk contains.  */
+enum colors
+{
+  /* Reset to the default color.  */
+  RESET,
+
+  /* Delete lines.  Show output in red.  */
+  DELETE,
+
+  /* Added lines.  Show them in green.  */
+  ADD,
+
+  /* Does not modify the context.  Use it to periodically process pending
+     signals.  */
+  SAME,
+};
+
+/* What kind of changes a hunk contains.  */
+enum colors_style
+{
+  /* Never output colors.  */
+  NEVER,
+
+  /* Output colors if the output is a terminal.  */
+  AUTO,
+
+  /* Always output colors.  */
+  ALWAYS,
+};
 
 /* Variables for command line options */
 
@@ -83,6 +113,9 @@ enum output_style
 
 XTERN enum output_style output_style;
 
+/* True if colors are printed.  */
+XTERN enum colors_style colors_style;
+
 /* Nonzero if output cannot be generated for identical files.  */
 XTERN bool no_diff_means_no_output;
 
@@ -390,3 +423,4 @@ extern void print_script (struct change *, struct change * (*) (struct change *)
 extern void setup_output (char const *, char const *, bool);
 extern void translate_range (struct file_data const *, lin, lin,
                              long int *, long int *);
+extern void set_color_context (enum colors);
diff --git a/src/normal.c b/src/normal.c
index 721fd1a..0d53033 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -56,14 +56,26 @@ print_normal_hunk (struct change *hunk)
 
   /* Print the lines that the first file has.  */
   if (changes & OLD)
-    for (i = first0; i <= last0; i++)
-      print_1_line ("<", &files[0].linbuf[i]);
+    {
+      for (i = first0; i <= last0; i++)
+        {
+          set_color_context (DELETE);
+          print_1_line ("<", &files[0].linbuf[i]);
+          set_color_context (RESET);
+        }
+    }
 
   if (changes == CHANGED)
     fputs ("---\n", outfile);
 
   /* Print the lines that the second file has.  */
   if (changes & NEW)
-    for (i = first1; i <= last1; i++)
-      print_1_line (">", &files[1].linbuf[i]);
+    {
+      for (i = first1; i <= last1; i++)
+        {
+          set_color_context (ADD);
+          print_1_line (">", &files[1].linbuf[i]);
+          set_color_context (RESET);
+        }
+    }
 }
diff --git a/src/side.c b/src/side.c
index 155512c..e52454e 100644
--- a/src/side.c
+++ b/src/side.c
@@ -206,6 +206,18 @@ print_1sdiff_line (char const *const *left, char sep,
   size_t c2o = sdiff_column2_offset;
   size_t col = 0;
   bool put_newline = false;
+  bool color_to_reset = false;
+
+  if (sep == '<')
+    {
+      set_color_context (DELETE);
+      color_to_reset = true;
+    }
+  else if (sep == '>')
+    {
+      set_color_context (ADD);
+      color_to_reset = true;
+    }
 
   if (left)
     {
@@ -233,6 +245,9 @@ print_1sdiff_line (char const *const *left, char sep,
 
   if (put_newline)
     putc ('\n', out);
+
+  if (color_to_reset)
+    set_color_context (RESET);
 }
 
 /* Print lines common to both files in side-by-side format.  */
diff --git a/src/util.c b/src/util.c
index 2d6d3fc..e7161d2 100644
--- a/src/util.c
+++ b/src/util.c
@@ -24,6 +24,8 @@
 #include <system-quote.h>
 #include <xalloc.h>
 #include "xvasprintf.h"
+#include <signal.h>
+#include <mbiter.h>
 
 char const pr_program[] = PR_PROGRAM;
 
@@ -153,6 +155,21 @@ print_message_queue (void)
 static char const *current_name0;
 static char const *current_name1;
 static bool currently_recursive;
+static bool colors_enabled;
+static bool output_is_tty;
+
+static void
+check_color_output (bool is_pipe)
+{
+  if (! outfile)
+    return;
+
+  output_is_tty = (colors_style != NEVER && !is_pipe
+                   && isatty (fileno (outfile)));
+
+  colors_enabled = (colors_style == ALWAYS
+                    || (colors_style == AUTO && output_is_tty));
+}
 
 void
 setup_output (char const *name0, char const *name1, bool recursive)
@@ -313,6 +330,7 @@ begin_output (void)
 	    outfile = fdopen (pipes[1], "w");
 	    if (!outfile)
 	      pfatal_with_name ("fdopen");
+            check_color_output (true);
 	  }
 #else
 	char *command = system_quote_argv (SCI_SYSTEM, (char **) argv);
@@ -320,6 +338,7 @@ begin_output (void)
 	outfile = popen (command, "w");
 	if (!outfile)
 	  pfatal_with_name (command);
+        check_color_output (true);
 	free (command);
 #endif
       }
@@ -330,6 +349,7 @@ begin_output (void)
       /* If -l was not specified, output the diff straight to 'stdout'.  */
 
       outfile = stdout;
+      check_color_output (false);
 
       /* If handling multiple files (because scanning a directory),
 	 print which files the following output is about.  */
@@ -672,8 +692,32 @@ void
 output_1_line (char const *base, char const *limit, char const *flag_format,
 	       char const *line_flag)
 {
+  /* Try to avoid to block for too long and write more than MAX_CHUNK bytes before
+     checking for pending signals.  */
+  const size_t max_chunk = 4096;
   if (!expand_tabs)
-    fwrite (base, sizeof (char), limit - base, outfile);
+    {
+      if (!colors_enabled || !output_is_tty)
+        {
+          fwrite (base, sizeof (char), limit - base, outfile);
+        }
+      else
+        {
+          size_t written = 0;
+          mbi_iterator_t iter;
+          for (mbi_init (iter, base, limit - base); mbi_avail (iter); mbi_advance (iter))
+            {
+              size_t mbi_len = mb_len (mbi_cur (iter));
+              fwrite (mbi_cur_ptr (iter), mbi_len, 1, outfile);
+              written += mbi_len;
+              if (written >= max_chunk)
+                {
+                  set_color_context (SAME);
+                  written = 0;
+                }
+            }
+        }
+    }
   else
     {
       register FILE *out = outfile;
@@ -681,6 +725,7 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
       register char const *t = base;
       register size_t column = 0;
       size_t tab_size = tabsize;
+      size_t written = 0;
 
       while (t < limit)
 	switch ((c = *t++))
@@ -690,7 +735,9 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
 	      size_t spaces = tab_size - column % tab_size;
 	      column += spaces;
 	      do
-		putc (' ', out);
+                {
+                  written += putc (' ', out);
+                }
 	      while (--spaces);
 	    }
 	    break;
@@ -698,7 +745,7 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
 	  case '\r':
 	    putc (c, out);
 	    if (flag_format && t < limit && *t != '\n')
-	      fprintf (out, flag_format, line_flag);
+	      written += fprintf (out, flag_format, line_flag);
 	    column = 0;
 	    break;
 
@@ -706,17 +753,96 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
 	    if (column == 0)
 	      continue;
 	    column--;
-	    putc (c, out);
+	    written += putc (c, out);
 	    break;
 
 	  default:
 	    column += isprint (c) != 0;
-	    putc (c, out);
+	    written += putc (c, out);
+            if (written >= max_chunk)
+              {
+                set_color_context (SAME);
+                written = 0;
+              }
 	    break;
 	  }
     }
 }
 
+static sigset_t old_sigproc_set;
+void
+set_color_context (enum colors con)
+{
+  int j;
+  static sigset_t set;
+  static bool set_initialized;
+  static enum colors last_color_context = RESET;
+  static int const sig[] =
+    {
+      SIGTSTP,
+      SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,
+#ifdef SIGPOLL
+      SIGPOLL,
+#endif
+#ifdef SIGPROF
+      SIGPROF,
+#endif
+#ifdef SIGVTALRM
+      SIGVTALRM,
+#endif
+#ifdef SIGXCPU
+      SIGXCPU,
+#endif
+#ifdef SIGXFSZ
+      SIGXFSZ,
+#endif
+    };
+
+  if (!colors_enabled || (con == SAME && !output_is_tty))
+    return;
+
+  if (output_is_tty && !set_initialized)
+    {
+      sigemptyset (&set);
+      for (j = 0; j < sizeof (sig) / sizeof (*sig); j++)
+        sigaddset (&set, sig[j]);
+      set_initialized = true;
+    }
+
+repeat:
+  switch (con)
+    {
+    case DELETE:
+      if (output_is_tty)
+        sigprocmask (SIG_BLOCK, &set, &old_sigproc_set);
+      fprintf (outfile, "\x1B[31m");
+      break;
+
+    case ADD:
+      if (output_is_tty)
+        sigprocmask (SIG_BLOCK, &set, &old_sigproc_set);
+      fprintf (outfile, "\x1B[32m");
+      break;
+
+    case SAME:
+    case RESET:
+      fprintf (outfile, "\x1b[0m");
+      if (output_is_tty)
+        {
+          fflush (outfile);
+          sigprocmask (SIG_SETMASK, &old_sigproc_set, NULL);
+        }
+      if (con == SAME)
+        {
+          con = last_color_context;
+          goto repeat;
+        }
+      break;
+    }
+
+  last_color_context = con;
+}
+
 char const change_letter[] = { 0, 'd', 'a', 'c' };
 
 /* Translate an internal line number (an index into diff's table of lines)
-- 
2.1.0


--=-=-=--




From MAILER-DAEMON Thu Mar 12 17:47:10 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YWAwg-0004Zo-5Y
	for mharc-bug-diffutils@gnu.org; Thu, 12 Mar 2015 17:47:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:40174)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWAwd-0004Zi-O3
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 17:47:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWAwY-0005uJ-KV
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 17:47:07 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:45750)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWAwY-0005uC-GR
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 17:47:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWAwY-0006Sb-7Z
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 17:47:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Paul Eggert <eggert@cs.ucla.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Thu, 12 Mar 2015 21:47:02 +0000
Resent-Message-ID: <handler.20062.B20062.142619679824804@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142619679824804
	(code B ref 20062); Thu, 12 Mar 2015 21:47:02 +0000
Received: (at 20062) by debbugs.gnu.org; 12 Mar 2015 21:46:38 +0000
Received: from localhost ([127.0.0.1]:44318 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YWAw9-0006S0-RV
	for submit@debbugs.gnu.org; Thu, 12 Mar 2015 17:46:38 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:43172)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1YWAw7-0006Ro-HF
	for 20062@debbugs.gnu.org; Thu, 12 Mar 2015 17:46:36 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
	by smtp.cs.ucla.edu (Postfix) with ESMTP id 4EE42A60031;
	Thu, 12 Mar 2015 14:46:29 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
	by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Qt3ba84lnywJ; Thu, 12 Mar 2015 14:46:29 -0700 (PDT)
Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200])
	by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 09490A6002D;
	Thu, 12 Mar 2015 14:46:29 -0700 (PDT)
Message-ID: <55020934.8080505@cs.ucla.edu>
Date: Thu, 12 Mar 2015 14:46:28 -0700
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>	<54FDB353.8060801@redhat.com>
	<87fv9dj28c.fsf@redhat.com>	<874mptgo2c.fsf@redhat.com>
	<54FF1A4C.6080104@cs.ucla.edu>	<87k2yoebrl.fsf@redhat.com>
	<54FF7742.6050500@cs.ucla.edu>	<87egowctaa.fsf@redhat.com>
	<54FF870C.5000902@cs.ucla.edu>	<878uf3b92g.fsf@redhat.com>
	<5500CD49.1060505@cs.ucla.edu>	<87twxqa884.fsf@redhat.com>
	<5501A668.5050104@cs.ucla.edu> <87pp8d9ap1.fsf@redhat.com>
In-Reply-To: <87pp8d9ap1.fsf@redhat.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 12 Mar 2015 21:47:08 -0000

On 03/12/2015 02:18 PM, Giuseppe Scrivano wrote:

 > +mbiter

Ouch.  I was hoping we didn't need to do that.  I expect the use of 
mbiter to hurt performance significantly.  I hope there's a better way, 
one that doesn't require counting individual multibyte characters.  It 
may be time to think about having a signal handler that resets the 
output tty.

 >            char const * const *line = &files[0].linbuf[i++];
 > +              set_color_context (DELETE);

Please use the same indenting (if the original uses tabs, do that), so 
that it's easier to read the diffs.

 > +    error (EXIT_TROUBLE, 0, _("Cannot specify both --color and 
--paginate."));

"cannot", not "Cannot", and no period at the end (it's not a sentence).

 > +              fwrite (mbi_cur_ptr (iter), mbi_len, 1, outfile);
 > +              written += mbi_len;

fwrite may write fewer than mbi_len characters.

 > -        putc (' ', out);
 > +                {
 > +                  written += putc (' ', out);
 > +                }

No need for {} here.  On the other hand, putc does not return 1-or-0 so 
this usage is problematic.

 > +          written += fprintf (out, flag_format, line_flag);

fprintf might return -1.

 > +        written += putc (c, out);
 > ...
 > +        written += putc (c, out);

Again, putc might return values other than 0 and 1.

 > +  if (output_is_tty && !set_initialized)
 > +    {
 > +      sigemptyset (&set);
 > +      for (j = 0; j < sizeof (sig) / sizeof (*sig); j++)
 > +        sigaddset (&set, sig[j]);
 > +      set_initialized = true;
 > +    }

This stuff can be done once, by 'main', with no need for a
set_initialized var.

 > +repeat:

Let's rephrase it without the goto; it'll be easier to understand that 
way, and just as efficient I expect.





From MAILER-DAEMON Thu Mar 12 20:30:13 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YWDUT-0006zm-9g
	for mharc-bug-diffutils@gnu.org; Thu, 12 Mar 2015 20:30:13 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:55076)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWDUQ-0006zR-3N
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 20:30:12 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWDUK-00049q-9w
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 20:30:10 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:45827)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWDUK-00049E-5n
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 20:30:04 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWDUJ-0004je-GJ
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 20:30:03 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Fri, 13 Mar 2015 00:30:03 +0000
Resent-Message-ID: <handler.20062.B20062.142620656118080@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Paul Eggert <eggert@cs.ucla.edu>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142620656118080
	(code B ref 20062); Fri, 13 Mar 2015 00:30:03 +0000
Received: (at 20062) by debbugs.gnu.org; 13 Mar 2015 00:29:21 +0000
Received: from localhost ([127.0.0.1]:44395 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YWDTb-0004hV-Vu
	for submit@debbugs.gnu.org; Thu, 12 Mar 2015 20:29:21 -0400
Received: from mx1.redhat.com ([209.132.183.28]:59697)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YWDTZ-0004hF-0v
	for 20062@debbugs.gnu.org; Thu, 12 Mar 2015 20:29:19 -0400
Received: from int-mx11.intmail.prod.int.phx2.redhat.com
	(int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2D0TDLr028708
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL); Thu, 12 Mar 2015 20:29:14 -0400
Received: from foobarbaz (vpn1-6-98.ams2.redhat.com [10.36.6.98])
	by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2D0T9xG005655
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Thu, 12 Mar 2015 20:29:10 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com> <54FF1A4C.6080104@cs.ucla.edu>
	<87k2yoebrl.fsf@redhat.com> <54FF7742.6050500@cs.ucla.edu>
	<87egowctaa.fsf@redhat.com> <54FF870C.5000902@cs.ucla.edu>
	<878uf3b92g.fsf@redhat.com> <5500CD49.1060505@cs.ucla.edu>
	<87twxqa884.fsf@redhat.com> <5501A668.5050104@cs.ucla.edu>
	<87pp8d9ap1.fsf@redhat.com> <55020934.8080505@cs.ucla.edu>
Date: Fri, 13 Mar 2015 01:29:09 +0100
In-Reply-To: <55020934.8080505@cs.ucla.edu> (Paul Eggert's message of "Thu, 12
	Mar 2015 14:46:28 -0700")
Message-ID: <87h9tp91uy.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 13 Mar 2015 00:30:12 -0000

--=-=-=
Content-Type: text/plain

Paul Eggert <eggert@cs.ucla.edu> writes:

> On 03/12/2015 02:18 PM, Giuseppe Scrivano wrote:
>
>> +mbiter
>
> Ouch.  I was hoping we didn't need to do that.  I expect the use of
> mbiter to hurt performance significantly.  I hope there's a better
> way, one that doesn't require counting individual multibyte
> characters.  It may be time to think about having a signal handler
> that resets the output tty.

Thanks once again for your prompt and detailed review.

I have dropped that and implemented the solution you suggested: now the
signal handler directly write(2) to reset the tty if needed and then
restore the default handler.  It contributes to simplify the code in
util.c as the output throttling is not required anymore.

Giuseppe


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=0001-diff-add-support-for-color.patch

>From 45372bec9789e0ec3879c8710dc0e4c799dd0950 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Sun, 8 Mar 2015 22:45:11 +0100
Subject: [PATCH] diff: add support for --color

* bootstrap.conf (gnulib_modules): Add "sigprocmask".
* doc/diffutils.texi (diff Options): Add documentation for --color.
Copied from coreutils ls --color.
* src/context.c (pr_unidiff_hunk): Add calls to set_color_context.
* src/diff.h (enum colors): New enum to register the current color to use.
(enum colors_style): New enum to record when to use colors.
(colors_style): New variable to memorize the argument value.
(set_color_context): Add function definition.
* src/diff.c: : Define COLOR_OPTION.
(specify_colors_style): New function.
(longopts): Add --color.
(main): Call install_signal_handlers.  Handle --color argument.
(option_help_msgid): Add usage string for --color.
* src/normal.c (print_normal_hunk): Add calls to set_color_context
* src/side.c (print_1sdiff_line): Add calls to set_color_context.
* src/util.c (colors_enabled): New boolean variable.
(colors_enabled): New boolean variable.
(check_color_output): New function.
(install_signal_handlers): New function.
(signal_handler): New function.
(begin_output): Call check_color_output every time the output file is changed.
(set_color_context): New function.  If colors are enabled, print the right
command for the terminal to change the color.
---
 bootstrap.conf     |   1 +
 doc/diffutils.texi |  20 +++++++++++
 src/context.c      |   4 +++
 src/diff.c         |  32 ++++++++++++++++-
 src/diff.h         |  31 +++++++++++++++++
 src/normal.c       |  20 ++++++++---
 src/side.c         |  15 ++++++++
 src/util.c         | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 218 insertions(+), 5 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 9b2de22..63be732 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -61,6 +61,7 @@ readme-release
 regex
 sh-quote
 signal
+sigprocmask
 stat
 stat-macros
 stat-time
diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 3e25807..0a2f1fc 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3745,6 +3745,26 @@ Read and write data in binary mode.  @xref{Binary}.
 Use the context output format, showing three lines of context.
 @xref{Context Format}.
 
+@item --color [=@var{when}]
+@cindex color, distinguishing file types with
+Specify whether to use color for distinguishing file types.  @var{when}
+may be omitted, or one of:
+@itemize @bullet
+@item none
+@vindex none @r{color option}
+Do not use color at all.  This is the default when no --color option
+is present.
+@item auto
+@vindex auto @r{color option}
+@cindex terminal, using color iff
+Only use color if standard output is a terminal.
+@item always
+@vindex always @r{color option}
+Always use color.
+@end itemize
+Specifying @option{--color} and no @var{when} is equivalent to
+@option{--color=auto}.
+
 @item -C @var{lines}
 @itemx --context@r{[}=@var{lines}@r{]}
 Use the context output format, showing @var{lines} (an integer) lines of
diff --git a/src/context.c b/src/context.c
index e0f21c4..f07a581 100644
--- a/src/context.c
+++ b/src/context.c
@@ -366,10 +366,12 @@ pr_unidiff_hunk (struct change *hunk)
 	  while (k--)
 	    {
 	      char const * const *line = &files[0].linbuf[i++];
+	      set_color_context (DELETE, false);
 	      putc ('-', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
 	      print_1_line (NULL, line);
+	      set_color_context (RESET, false);
 	    }
 
 	  /* Then output the inserted part. */
@@ -378,10 +380,12 @@ pr_unidiff_hunk (struct change *hunk)
 	  while (k--)
 	    {
 	      char const * const *line = &files[1].linbuf[j++];
+	      set_color_context (ADD, false);
 	      putc ('+', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
 	      print_1_line (NULL, line);
+	      set_color_context (RESET, false);
 	    }
 
 	  /* We're done with this hunk, so on to the next! */
diff --git a/src/diff.c b/src/diff.c
index ff28377..637f716 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -70,6 +70,7 @@ static void add_regexp (struct regexp_list *, char const *);
 static void summarize_regexp_list (struct regexp_list *);
 static void specify_style (enum output_style);
 static void specify_value (char const **, char const *, char const *);
+static void specify_colors_style (char const *);
 static void try_help (char const *, char const *) __attribute__((noreturn));
 static void check_stdout (void);
 static void usage (void);
@@ -136,7 +137,9 @@ enum
   UNCHANGED_GROUP_FORMAT_OPTION,
   OLD_GROUP_FORMAT_OPTION,
   NEW_GROUP_FORMAT_OPTION,
-  CHANGED_GROUP_FORMAT_OPTION
+  CHANGED_GROUP_FORMAT_OPTION,
+
+  COLOR_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -159,6 +162,7 @@ static struct option const longopts[] =
   {"binary", 0, 0, BINARY_OPTION},
   {"brief", 0, 0, 'q'},
   {"changed-group-format", 1, 0, CHANGED_GROUP_FORMAT_OPTION},
+  {"color", 2, 0, COLOR_OPTION},
   {"context", 2, 0, 'C'},
   {"ed", 0, 0, 'e'},
   {"exclude", 1, 0, 'x'},
@@ -285,6 +289,8 @@ main (int argc, char **argv)
   re_set_syntax (RE_SYNTAX_GREP | RE_NO_POSIX_BACKTRACKING);
   excluded = new_exclude ();
 
+  install_signal_handlers ();
+
   /* Decode the options.  */
 
   while ((c = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1)
@@ -627,6 +633,10 @@ main (int argc, char **argv)
 	  specify_value (&group_format[c], optarg, group_format_option[c]);
 	  break;
 
+        case COLOR_OPTION:
+          specify_colors_style (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
@@ -645,6 +655,9 @@ main (int argc, char **argv)
 	specify_style (OUTPUT_NORMAL);
     }
 
+  if (colors_style != NEVER && paginate)
+    error (EXIT_TROUBLE, 0, _("cannot specify both --color and --paginate"));
+
   if (output_style != OUTPUT_CONTEXT || hard_locale (LC_TIME))
     {
 #if (defined STAT_TIMESPEC || defined STAT_TIMESPEC_NS \
@@ -940,6 +953,8 @@ static char const * const option_help_msgid[] = {
   N_("-d, --minimal            try hard to find a smaller set of changes"),
   N_("    --horizon-lines=NUM  keep NUM lines of the common prefix and suffix"),
   N_("    --speed-large-files  assume large files and many scattered small changes"),
+  N_("    --color[=WHEN]         colorize the output; WHEN can be 'never', 'always',"),
+  N_("                             or 'auto' (the default)"),
   "",
   N_("    --help               display this help and exit"),
   N_("-v, --version            output version information and exit"),
@@ -1008,6 +1023,21 @@ specify_style (enum output_style style)
       output_style = style;
     }
 }
+
+/* Set the color mode.  */
+static void
+specify_colors_style (char const *value)
+{
+  if (value == NULL || STREQ (value, "auto"))
+    colors_style = AUTO;
+  else if (STREQ (value, "always"))
+    colors_style = ALWAYS;
+  else if (STREQ (value, "never"))
+    colors_style = NEVER;
+  else
+    try_help ("invalid color '%s'", value);
+}
+
 
 /* Set the last-modified time of *ST to be the current time.  */
 
diff --git a/src/diff.h b/src/diff.h
index 465e4bc..c18786e 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -38,6 +38,32 @@ enum changes
   /* Both deletes and inserts: a hunk containing both old and new lines.  */
   CHANGED
 };
+
+/* What kind of changes a hunk contains.  */
+enum colors
+{
+  /* Reset to the default color.  */
+  RESET,
+
+  /* Delete lines.  Show output in red.  */
+  DELETE,
+
+  /* Added lines.  Show them in green.  */
+  ADD,
+};
+
+/* What kind of changes a hunk contains.  */
+enum colors_style
+{
+  /* Never output colors.  */
+  NEVER,
+
+  /* Output colors if the output is a terminal.  */
+  AUTO,
+
+  /* Always output colors.  */
+  ALWAYS,
+};
 
 /* Variables for command line options */
 
@@ -83,6 +109,9 @@ enum output_style
 
 XTERN enum output_style output_style;
 
+/* True if colors are printed.  */
+XTERN enum colors_style colors_style;
+
 /* Nonzero if output cannot be generated for identical files.  */
 XTERN bool no_diff_means_no_output;
 
@@ -390,3 +419,5 @@ extern void print_script (struct change *, struct change * (*) (struct change *)
 extern void setup_output (char const *, char const *, bool);
 extern void translate_range (struct file_data const *, lin, lin,
                              long int *, long int *);
+extern void set_color_context (enum colors, bool force);
+extern void install_signal_handlers (void);
diff --git a/src/normal.c b/src/normal.c
index 721fd1a..41a97b9 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -56,14 +56,26 @@ print_normal_hunk (struct change *hunk)
 
   /* Print the lines that the first file has.  */
   if (changes & OLD)
-    for (i = first0; i <= last0; i++)
-      print_1_line ("<", &files[0].linbuf[i]);
+    {
+      for (i = first0; i <= last0; i++)
+        {
+          set_color_context (DELETE, false);
+          print_1_line ("<", &files[0].linbuf[i]);
+          set_color_context (RESET, false);
+        }
+    }
 
   if (changes == CHANGED)
     fputs ("---\n", outfile);
 
   /* Print the lines that the second file has.  */
   if (changes & NEW)
-    for (i = first1; i <= last1; i++)
-      print_1_line (">", &files[1].linbuf[i]);
+    {
+      for (i = first1; i <= last1; i++)
+        {
+          set_color_context (ADD, false);
+          print_1_line (">", &files[1].linbuf[i]);
+          set_color_context (RESET, false);
+        }
+    }
 }
diff --git a/src/side.c b/src/side.c
index 155512c..4d04942 100644
--- a/src/side.c
+++ b/src/side.c
@@ -206,6 +206,18 @@ print_1sdiff_line (char const *const *left, char sep,
   size_t c2o = sdiff_column2_offset;
   size_t col = 0;
   bool put_newline = false;
+  bool color_to_reset = false;
+
+  if (sep == '<')
+    {
+      set_color_context (DELETE, false);
+      color_to_reset = true;
+    }
+  else if (sep == '>')
+    {
+      set_color_context (ADD, false);
+      color_to_reset = true;
+    }
 
   if (left)
     {
@@ -233,6 +245,9 @@ print_1sdiff_line (char const *const *left, char sep,
 
   if (put_newline)
     putc ('\n', out);
+
+  if (color_to_reset)
+    set_color_context (RESET, false);
 }
 
 /* Print lines common to both files in side-by-side format.  */
diff --git a/src/util.c b/src/util.c
index 2d6d3fc..4cbd402 100644
--- a/src/util.c
+++ b/src/util.c
@@ -24,6 +24,7 @@
 #include <system-quote.h>
 #include <xalloc.h>
 #include "xvasprintf.h"
+#include <signal.h>
 
 char const pr_program[] = PR_PROGRAM;
 
@@ -153,6 +154,21 @@ print_message_queue (void)
 static char const *current_name0;
 static char const *current_name1;
 static bool currently_recursive;
+static bool colors_enabled;
+static bool output_is_tty;
+
+static void
+check_color_output (bool is_pipe)
+{
+  if (! outfile)
+    return;
+
+  output_is_tty = (colors_style != NEVER && !is_pipe
+                   && isatty (fileno (outfile)));
+
+  colors_enabled = (colors_style == ALWAYS
+                    || (colors_style == AUTO && output_is_tty));
+}
 
 void
 setup_output (char const *name0, char const *name1, bool recursive)
@@ -313,6 +329,7 @@ begin_output (void)
 	    outfile = fdopen (pipes[1], "w");
 	    if (!outfile)
 	      pfatal_with_name ("fdopen");
+	    check_color_output (true);
 	  }
 #else
 	char *command = system_quote_argv (SCI_SYSTEM, (char **) argv);
@@ -320,6 +337,7 @@ begin_output (void)
 	outfile = popen (command, "w");
 	if (!outfile)
 	  pfatal_with_name (command);
+	check_color_output (true);
 	free (command);
 #endif
       }
@@ -330,6 +348,7 @@ begin_output (void)
       /* If -l was not specified, output the diff straight to 'stdout'.  */
 
       outfile = stdout;
+      check_color_output (false);
 
       /* If handling multiple files (because scanning a directory),
 	 print which files the following output is about.  */
@@ -717,6 +736,87 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
     }
 }
 
+static void
+signal_handler (int signal)
+{
+  struct sigaction act;
+
+  if (output_is_tty)
+    set_color_context (RESET, true);
+
+  /* Restore the default handler, and report the signal again.  */
+  sigaction (signal, NULL, &act);
+  act.sa_handler = SIG_DFL;
+  sigaction (signal, &act, NULL);
+  raise (signal);
+}
+
+void
+install_signal_handlers (void)
+{
+  int j;
+  struct sigaction act;
+  int const sig[] =
+    {
+      SIGTSTP,
+      SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,
+#ifdef SIGPOLL
+      SIGPOLL,
+#endif
+#ifdef SIGPROF
+      SIGPROF,
+#endif
+#ifdef SIGVTALRM
+      SIGVTALRM,
+#endif
+#ifdef SIGXCPU
+      SIGXCPU,
+#endif
+#ifdef SIGXFSZ
+      SIGXFSZ,
+#endif
+    };
+
+  for (j = 0; j < sizeof (sig) / sizeof (*sig); j++)
+    {
+      sigaction (sig[j], NULL, &act);
+      if (act.sa_handler != SIG_IGN)
+        {
+          act.sa_handler = signal_handler;
+          sigaction (sig[j], &act, NULL);
+        }
+    }
+}
+
+void
+set_color_context (enum colors con, bool force)
+{
+  const char *const reset_sequence = "\x1b[0m";
+  if (! colors_enabled)
+    return;
+  switch (con)
+    {
+    case DELETE:
+      fprintf (outfile, "\x1B[31m");
+      break;
+
+    case ADD:
+      fprintf (outfile, "\x1B[32m");
+      break;
+
+    case RESET:
+      if (! force)
+        fprintf (outfile, "%s", reset_sequence);
+      else
+        {
+          if (write (fileno (outfile), reset_sequence,
+                     strlen (reset_sequence)) < 0)
+            error (EXIT_TROUBLE, 0, "%s", _("write failed"));
+        }
+      break;
+    }
+}
+
 char const change_letter[] = { 0, 'd', 'a', 'c' };
 
 /* Translate an internal line number (an index into diff's table of lines)
-- 
2.1.0


--=-=-=--




From MAILER-DAEMON Thu Mar 12 21:09:08 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YWE68-0007xu-EO
	for mharc-bug-diffutils@gnu.org; Thu, 12 Mar 2015 21:09:08 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:36381)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWE65-0007xm-Sx
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 21:09:06 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWE62-0000lE-Lq
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 21:09:05 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:45848)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWE62-0000l9-Ha
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 21:09:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWE62-0006JM-1k
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 21:09:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Paul Eggert <eggert@cs.ucla.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Fri, 13 Mar 2015 01:09:01 +0000
Resent-Message-ID: <handler.20062.B20062.142620888224109@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142620888224109
	(code B ref 20062); Fri, 13 Mar 2015 01:09:01 +0000
Received: (at 20062) by debbugs.gnu.org; 13 Mar 2015 01:08:02 +0000
Received: from localhost ([127.0.0.1]:44416 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YWE52-0006Gb-Tf
	for submit@debbugs.gnu.org; Thu, 12 Mar 2015 21:08:01 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:51616)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1YWE50-0006GD-2h
	for 20062@debbugs.gnu.org; Thu, 12 Mar 2015 21:07:59 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
	by smtp.cs.ucla.edu (Postfix) with ESMTP id D7730A6004B;
	Thu, 12 Mar 2015 18:07:51 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
	by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id QPsVpGIIQ3nF; Thu, 12 Mar 2015 18:07:51 -0700 (PDT)
Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net
	[100.32.155.148])
	by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 6EB74A60047;
	Thu, 12 Mar 2015 18:07:51 -0700 (PDT)
Message-ID: <55023863.6000407@cs.ucla.edu>
Date: Thu, 12 Mar 2015 18:07:47 -0700
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>	<54FDB353.8060801@redhat.com>
	<87fv9dj28c.fsf@redhat.com>	<874mptgo2c.fsf@redhat.com>
	<54FF1A4C.6080104@cs.ucla.edu>	<87k2yoebrl.fsf@redhat.com>
	<54FF7742.6050500@cs.ucla.edu>	<87egowctaa.fsf@redhat.com>
	<54FF870C.5000902@cs.ucla.edu>	<878uf3b92g.fsf@redhat.com>
	<5500CD49.1060505@cs.ucla.edu>	<87twxqa884.fsf@redhat.com>
	<5501A668.5050104@cs.ucla.edu>	<87pp8d9ap1.fsf@redhat.com>
	<55020934.8080505@cs.ucla.edu> <87h9tp91uy.fsf@redhat.com>
In-Reply-To: <87h9tp91uy.fsf@redhat.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 13 Mar 2015 01:09:07 -0000

Giuseppe Scrivano wrote:

 > +sigprocmask

This part of the change isn't needed any more.

 > +        case COLOR_OPTION:
 > +          specify_colors_style (optarg);
 > +	  break;

Please be consistent about tabs vs spaces.

 > +  if (colors_style != NEVER && paginate)
 > +    error (EXIT_TROUBLE, 0, _("cannot specify both --color and --paginate"));

This part isn't needed any more, if I understand aright.

 > +/* What kind of changes a hunk contains.  */
 > +enum colors_style

The comment doesn't match the code.

 > +/* True if colors are printed.  */
 > +XTERN enum colors_style colors_style;

The comment doesn't match the code (it's not a boolean).

 > -    for (i = first0; i <= last0; i++)
 > -      print_1_line ("<", &files[0].linbuf[i]);
 > +    {
 > +      for (i = first0; i <= last0; i++)
 > +        {
 > +          set_color_context (DELETE, false);
 > +          print_1_line ("<", &files[0].linbuf[i]);
 > +          set_color_context (RESET, false);
 > +        }
 > +    }
 > ...
 >    if (changes & NEW)
 > -    for (i = first1; i <= last1; i++)
 > -      print_1_line (">", &files[1].linbuf[i]);
 > +    {
 > +      for (i = first1; i <= last1; i++)
 > +        {
 > +          set_color_context (ADD, false);
 > +          print_1_line (">", &files[1].linbuf[i]);
 > +          set_color_context (RESET, false);
 > +        }
 > +    }

No need for the outer braces (twice).

 > +  /* Restore the default handler, and report the signal again.  */
 > +  sigaction (signal, NULL, &act);
 > +  act.sa_handler = SIG_DFL;
 > +  sigaction (signal, &act, NULL);
 > +  raise (signal);

This assumes sigaction, but GNU diff is portable to hosts that lack sigaction. 
Please see the code in sdiff.c, which uses sigaction only if available.  You may 
want to steal and/or librarize it, instead of using the ls.c-inspired code.

 > +  const char *const reset_sequence = "\x1b[0m";

This should be:

    static char const reset_sequence[] = "\x1b[0m";

(I prefer putting the 'const' after the type, for consistency with "char *const 
*".)  That is, there's no need for the pointer variable here, and you can use 
'sizeof reset_sequence - 1' instead of 'strlen (reset_sequence)'.

 > +void
 > +set_color_context (enum colors con, bool force)

This would be a bit clearer as separate functions for each combination of 
arguments that are used.  In particular, the separate function that can be 
called from a signal handler should be commented as such, as it has more 
constraints on its actions.

 > +      fprintf (outfile, "\x1B[31m");
 > ...
 > +      fprintf (outfile, "\x1B[32m");
 > ...
 > +        fprintf (outfile, "%s", reset_sequence);

Use fputs instead of fprintf.

 > +          if (write (fileno (outfile), reset_sequence,
 > +                     strlen (reset_sequence)) < 0)
 > +            error (EXIT_TROUBLE, 0, "%s", _("write failed"));

We can't use 'fileno' or 'error' inside a signal handler; they're not 
async-signal-safe.  And we can't use 'outfile', as it's not volatile.

Instead, I suggest redoing begin_output so that 'outfile' is always stdout and 
its file descriptor is 1; that way, 'write' can use STDOUT_FILENO instead of 
fileno (stdout).  (You can use dup2 to arrange for this after the pipe calls.) 
Do not call 'error'; just return and let the signal handler re-raise the signal 
and exit.

Also, don't assume that 'write' will write out the whole string; it might be a 
partial write.

Also, what happens if a signal occurs when 'diff' is outputting an escape 
sequence?  E.g., suppose 'diff' is in the middle of outputting "\x1B[31m" and 
gets interrupted after the '[', so that it outputs "\x1B[\x1b[0m".  Is this 
guaranteed to reset the terminal?  If not, what sequence of bytes is guaranteed 
to reset the terminal color even if the sequence is output immediately after a 
truncated escape sequence?

 > +static void
 > +signal_handler (int signal)
 > +{
 > +  struct sigaction act;
 > +
 > +  if (output_is_tty)
 > +    set_color_context (RESET, true);

Don't have the signal handler inspect output_is_tty, as that would mean 
output_is_tty would have to be volatile.  Instead, install the signal handler 
only if output_is_tty; that way, the handler itself can assume output_is_tty 
without having to check it.

Isn't signal-handling fun?

By the way, are you running "./configure --enable-gcc-warnings"?  If not, please 
do that.




From MAILER-DAEMON Thu Mar 12 21:25:10 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YWELe-0002xF-27
	for mharc-bug-diffutils@gnu.org; Thu, 12 Mar 2015 21:25:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41877)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWELc-0002uj-35
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 21:25:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWELW-0007FZ-VO
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 21:25:08 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:45860)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWELW-0007FP-S5
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 21:25:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWELW-0008N3-Ce
	for bug-diffutils@gnu.org; Thu, 12 Mar 2015 21:25:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Paul Eggert <eggert@cs.ucla.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Fri, 13 Mar 2015 01:25:02 +0000
Resent-Message-ID: <handler.20062.B20062.142620989532154@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142620989532154
	(code B ref 20062); Fri, 13 Mar 2015 01:25:02 +0000
Received: (at 20062) by debbugs.gnu.org; 13 Mar 2015 01:24:55 +0000
Received: from localhost ([127.0.0.1]:44428 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YWELP-0008MW-AL
	for submit@debbugs.gnu.org; Thu, 12 Mar 2015 21:24:55 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:52048)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1YWELM-0008M9-IM
	for 20062@debbugs.gnu.org; Thu, 12 Mar 2015 21:24:53 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
	by smtp.cs.ucla.edu (Postfix) with ESMTP id DE0FAA6004B;
	Thu, 12 Mar 2015 18:24:46 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
	by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id kAS+Pxw3T+Fq; Thu, 12 Mar 2015 18:24:46 -0700 (PDT)
Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net
	[100.32.155.148])
	by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 86AEEA60047;
	Thu, 12 Mar 2015 18:24:46 -0700 (PDT)
Message-ID: <55023C5E.3030600@cs.ucla.edu>
Date: Thu, 12 Mar 2015 18:24:46 -0700
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>	<54FDB353.8060801@redhat.com>
	<87fv9dj28c.fsf@redhat.com>	<874mptgo2c.fsf@redhat.com>
	<54FF1A4C.6080104@cs.ucla.edu>	<87k2yoebrl.fsf@redhat.com>
	<54FF7742.6050500@cs.ucla.edu>	<87egowctaa.fsf@redhat.com>
	<54FF870C.5000902@cs.ucla.edu>	<878uf3b92g.fsf@redhat.com>
	<5500CD49.1060505@cs.ucla.edu>	<87twxqa884.fsf@redhat.com>
	<5501A668.5050104@cs.ucla.edu>	<87pp8d9ap1.fsf@redhat.com>
	<55020934.8080505@cs.ucla.edu> <87h9tp91uy.fsf@redhat.com>
	<55023863.6000407@cs.ucla.edu>
In-Reply-To: <55023863.6000407@cs.ucla.edu>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 13 Mar 2015 01:25:08 -0000

One other thing.  This:

+  sigaction (signal, NULL, &act);
+  act.sa_handler = SIG_DFL;
+  sigaction (signal, &act, NULL);

can be done more simply as 'signal (sig, SIG_DFL)' (assuming you change the 
local variable's name from 'signal' to 'sig').




From MAILER-DAEMON Fri Mar 13 07:12:17 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YWNVp-0007YL-AB
	for mharc-bug-diffutils@gnu.org; Fri, 13 Mar 2015 07:12:17 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41217)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWNVi-0006Cb-Hf
	for bug-diffutils@gnu.org; Fri, 13 Mar 2015 07:12:13 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWNI2-00059U-Be
	for bug-diffutils@gnu.org; Fri, 13 Mar 2015 06:58:06 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:46022)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWNI2-00059L-8n
	for bug-diffutils@gnu.org; Fri, 13 Mar 2015 06:58:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWNI1-0008IN-Tf
	for bug-diffutils@gnu.org; Fri, 13 Mar 2015 06:58:01 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Fri, 13 Mar 2015 10:58:01 +0000
Resent-Message-ID: <handler.20062.B20062.142624424731848@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Paul Eggert <eggert@cs.ucla.edu>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142624424731848
	(code B ref 20062); Fri, 13 Mar 2015 10:58:01 +0000
Received: (at 20062) by debbugs.gnu.org; 13 Mar 2015 10:57:27 +0000
Received: from localhost ([127.0.0.1]:44590 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YWNHS-0008Ha-Tx
	for submit@debbugs.gnu.org; Fri, 13 Mar 2015 06:57:27 -0400
Received: from mx1.redhat.com ([209.132.183.28]:47993)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YWNHQ-0008HR-47
	for 20062@debbugs.gnu.org; Fri, 13 Mar 2015 06:57:25 -0400
Received: from int-mx09.intmail.prod.int.phx2.redhat.com
	(int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2DAvFtr003474
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL); Fri, 13 Mar 2015 06:57:15 -0400
Received: from foobarbaz (vpn1-5-157.ams2.redhat.com [10.36.5.157])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2DAvCnh015505
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Fri, 13 Mar 2015 06:57:13 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com> <54FF1A4C.6080104@cs.ucla.edu>
	<87k2yoebrl.fsf@redhat.com> <54FF7742.6050500@cs.ucla.edu>
	<87egowctaa.fsf@redhat.com> <54FF870C.5000902@cs.ucla.edu>
	<878uf3b92g.fsf@redhat.com> <5500CD49.1060505@cs.ucla.edu>
	<87twxqa884.fsf@redhat.com> <5501A668.5050104@cs.ucla.edu>
	<87pp8d9ap1.fsf@redhat.com> <55020934.8080505@cs.ucla.edu>
	<87h9tp91uy.fsf@redhat.com> <55023863.6000407@cs.ucla.edu>
Date: Fri, 13 Mar 2015 11:57:11 +0100
In-Reply-To: <55023863.6000407@cs.ucla.edu> (Paul Eggert's message of "Thu, 12
	Mar 2015 18:07:47 -0700")
Message-ID: <87wq2l6u7s.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 13 Mar 2015 11:12:14 -0000

Paul Eggert <eggert@cs.ucla.edu> writes:

> We can't use 'fileno' or 'error' inside a signal handler; they're not
> async-signal-safe.  And we can't use 'outfile', as it's not volatile.
>
> Instead, I suggest redoing begin_output so that 'outfile' is always
> stdout and its file descriptor is 1; that way, 'write' can use
> STDOUT_FILENO instead of fileno (stdout).  (You can use dup2 to
> arrange for this after the pipe calls.) Do not call 'error'; just
> return and let the signal handler re-raise the signal and exit.

we can do it right now I think, as anyway we use signals only when we
are outputting to a terminal so it doesn't cover the pipe case.

> Also, what happens if a signal occurs when 'diff' is outputting an
> escape sequence?  E.g., suppose 'diff' is in the middle of outputting
> "\x1B[31m" and gets interrupted after the '[', so that it outputs
> "\x1B[\x1b[0m".  Is this guaranteed to reset the terminal?  If not,
> what sequence of bytes is guaranteed to reset the terminal color even
> if the sequence is output immediately after a truncated escape
> sequence?

I could not find any immediate answer, neither in the ncurses, but on
the terminals I have tried it is enough to reset even in the middle of
another sequence.  We could play safe and output it twice, but IMHO it
doesn't seem to be needed.

I'll send an updated version later today.

Thanks,
Giuseppe




From MAILER-DAEMON Fri Mar 13 14:09:11 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YWU1H-0006iR-G7
	for mharc-bug-diffutils@gnu.org; Fri, 13 Mar 2015 14:09:11 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:37945)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWU1D-0006i0-PB
	for bug-diffutils@gnu.org; Fri, 13 Mar 2015 14:09:10 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWU18-0006gV-IL
	for bug-diffutils@gnu.org; Fri, 13 Mar 2015 14:09:07 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:46837)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWU18-0006gL-D6
	for bug-diffutils@gnu.org; Fri, 13 Mar 2015 14:09:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWU17-00073f-Qb
	for bug-diffutils@gnu.org; Fri, 13 Mar 2015 14:09:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Fri, 13 Mar 2015 18:09:01 +0000
Resent-Message-ID: <handler.20062.B20062.142627011527091@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Paul Eggert <eggert@cs.ucla.edu>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142627011527091
	(code B ref 20062); Fri, 13 Mar 2015 18:09:01 +0000
Received: (at 20062) by debbugs.gnu.org; 13 Mar 2015 18:08:35 +0000
Received: from localhost ([127.0.0.1]:45405 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YWU0g-00072s-Cl
	for submit@debbugs.gnu.org; Fri, 13 Mar 2015 14:08:35 -0400
Received: from mx1.redhat.com ([209.132.183.28]:43553)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YWU0d-00072h-C7
	for 20062@debbugs.gnu.org; Fri, 13 Mar 2015 14:08:33 -0400
Received: from int-mx09.intmail.prod.int.phx2.redhat.com
	(int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2DI8SqV005313
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL); Fri, 13 Mar 2015 14:08:28 -0400
Received: from foobarbaz (vpn1-5-157.ams2.redhat.com [10.36.5.157])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2DI8OaW006298
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Fri, 13 Mar 2015 14:08:26 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com> <54FF1A4C.6080104@cs.ucla.edu>
	<87k2yoebrl.fsf@redhat.com> <54FF7742.6050500@cs.ucla.edu>
	<87egowctaa.fsf@redhat.com> <54FF870C.5000902@cs.ucla.edu>
	<878uf3b92g.fsf@redhat.com> <5500CD49.1060505@cs.ucla.edu>
	<87twxqa884.fsf@redhat.com> <5501A668.5050104@cs.ucla.edu>
	<87pp8d9ap1.fsf@redhat.com> <55020934.8080505@cs.ucla.edu>
	<87h9tp91uy.fsf@redhat.com> <55023863.6000407@cs.ucla.edu>
	<87wq2l6u7s.fsf@redhat.com>
Date: Fri, 13 Mar 2015 19:08:24 +0100
In-Reply-To: <87wq2l6u7s.fsf@redhat.com> (Giuseppe Scrivano's message of "Fri, 
	13 Mar 2015 11:57:11 +0100")
Message-ID: <87oanw7otj.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 13 Mar 2015 18:09:10 -0000

--=-=-=
Content-Type: text/plain

Giuseppe Scrivano <gscrivan@redhat.com> writes:

> I'll send an updated version later today.

and here it is, I've attached the patch.

Regards,
Giuseppe


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=0001-diff-add-support-for-color.patch

>From 749a7466adc192c230b1dde963be18a2c9f408e2 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Sun, 8 Mar 2015 22:45:11 +0100
Subject: [PATCH] diff: add support for --color

* doc/diffutils.texi (diff Options): Add documentation for --color.
Copied from coreutils ls --color.
* src/context.c (pr_unidiff_hunk): Add calls to set_color_context.
* src/diff.h (enum colors_style): New enum to record when to use colors.
(colors_style): New variable to memorize the argument value.
(set_add_color_context): Add function definition.
(set_delete_color_context): Likewise.
(reset_color_context): Likewise.
* src/diff.c: : Define COLOR_OPTION.
(specify_colors_style): New function.
(longopts): Add --color.
(main): Handle --color argument.
(option_help_msgid): Add usage string for --color.
* src/normal.c (print_normal_hunk): Add calls to set_color_context
* src/side.c (print_1sdiff_line): Add calls to set_color_context.
* src/util.c (colors_enabled): New boolean variable.
(begin_output): Call check_color_output once the output file is
configured.
(colors_enabled): New boolean variable.
(check_color_output): New function.
(install_signal_handlers): Likewise.
(signal_handler): Likewise.
(set_add_color_context): Likewise.
(set_delete_color_context): Likewise.
(reset_color_context): Likewise.
---
 doc/diffutils.texi |  20 ++++++++++
 src/context.c      |  17 +++++++-
 src/diff.c         |  27 ++++++++++++-
 src/diff.h         |  19 +++++++++
 src/normal.c       |  12 +++++-
 src/side.c         |  15 +++++++
 src/util.c         | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 218 insertions(+), 4 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 3e25807..0a2f1fc 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3745,6 +3745,26 @@ Read and write data in binary mode.  @xref{Binary}.
 Use the context output format, showing three lines of context.
 @xref{Context Format}.
 
+@item --color [=@var{when}]
+@cindex color, distinguishing file types with
+Specify whether to use color for distinguishing file types.  @var{when}
+may be omitted, or one of:
+@itemize @bullet
+@item none
+@vindex none @r{color option}
+Do not use color at all.  This is the default when no --color option
+is present.
+@item auto
+@vindex auto @r{color option}
+@cindex terminal, using color iff
+Only use color if standard output is a terminal.
+@item always
+@vindex always @r{color option}
+Always use color.
+@end itemize
+Specifying @option{--color} and no @var{when} is equivalent to
+@option{--color=auto}.
+
 @item -C @var{lines}
 @itemx --context@r{[}=@var{lines}@r{]}
 Use the context output format, showing @var{lines} (an integer) lines of
diff --git a/src/context.c b/src/context.c
index e0f21c4..65b7485 100644
--- a/src/context.c
+++ b/src/context.c
@@ -360,9 +360,17 @@ pr_unidiff_hunk (struct change *hunk)
 	}
       else
 	{
+          bool reset_context = false;
+
 	  /* For each difference, first output the deleted part. */
 
 	  k = next->deleted;
+          if (k)
+            {
+              reset_context = true;
+              set_delete_color_context ();
+            }
+
 	  while (k--)
 	    {
 	      char const * const *line = &files[0].linbuf[i++];
@@ -375,9 +383,15 @@ pr_unidiff_hunk (struct change *hunk)
 	  /* Then output the inserted part. */
 
 	  k = next->inserted;
+          if (k)
+            {
+              reset_context = true;
+              set_add_color_context ();
+            }
 	  while (k--)
 	    {
 	      char const * const *line = &files[1].linbuf[j++];
+	      set_add_color_context ();
 	      putc ('+', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
@@ -385,7 +399,8 @@ pr_unidiff_hunk (struct change *hunk)
 	    }
 
 	  /* We're done with this hunk, so on to the next! */
-
+          if (reset_context)
+            reset_color_context (false);
 	  next = next->link;
 	}
     }
diff --git a/src/diff.c b/src/diff.c
index ff28377..be6e6e3 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -70,6 +70,7 @@ static void add_regexp (struct regexp_list *, char const *);
 static void summarize_regexp_list (struct regexp_list *);
 static void specify_style (enum output_style);
 static void specify_value (char const **, char const *, char const *);
+static void specify_colors_style (char const *);
 static void try_help (char const *, char const *) __attribute__((noreturn));
 static void check_stdout (void);
 static void usage (void);
@@ -136,7 +137,9 @@ enum
   UNCHANGED_GROUP_FORMAT_OPTION,
   OLD_GROUP_FORMAT_OPTION,
   NEW_GROUP_FORMAT_OPTION,
-  CHANGED_GROUP_FORMAT_OPTION
+  CHANGED_GROUP_FORMAT_OPTION,
+
+  COLOR_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -159,6 +162,7 @@ static struct option const longopts[] =
   {"binary", 0, 0, BINARY_OPTION},
   {"brief", 0, 0, 'q'},
   {"changed-group-format", 1, 0, CHANGED_GROUP_FORMAT_OPTION},
+  {"color", 2, 0, COLOR_OPTION},
   {"context", 2, 0, 'C'},
   {"ed", 0, 0, 'e'},
   {"exclude", 1, 0, 'x'},
@@ -627,6 +631,10 @@ main (int argc, char **argv)
 	  specify_value (&group_format[c], optarg, group_format_option[c]);
 	  break;
 
+	case COLOR_OPTION:
+	  specify_colors_style (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
@@ -940,6 +948,8 @@ static char const * const option_help_msgid[] = {
   N_("-d, --minimal            try hard to find a smaller set of changes"),
   N_("    --horizon-lines=NUM  keep NUM lines of the common prefix and suffix"),
   N_("    --speed-large-files  assume large files and many scattered small changes"),
+  N_("    --color[=WHEN]         colorize the output; WHEN can be 'never', 'always',"),
+  N_("                             or 'auto' (the default)"),
   "",
   N_("    --help               display this help and exit"),
   N_("-v, --version            output version information and exit"),
@@ -1008,6 +1018,21 @@ specify_style (enum output_style style)
       output_style = style;
     }
 }
+
+/* Set the color mode.  */
+static void
+specify_colors_style (char const *value)
+{
+  if (value == NULL || STREQ (value, "auto"))
+    colors_style = AUTO;
+  else if (STREQ (value, "always"))
+    colors_style = ALWAYS;
+  else if (STREQ (value, "never"))
+    colors_style = NEVER;
+  else
+    try_help ("invalid color '%s'", value);
+}
+
 
 /* Set the last-modified time of *ST to be the current time.  */
 
diff --git a/src/diff.h b/src/diff.h
index 465e4bc..abecf2b 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -38,6 +38,19 @@ enum changes
   /* Both deletes and inserts: a hunk containing both old and new lines.  */
   CHANGED
 };
+
+/* What kind of changes a hunk contains.  */
+enum colors_style
+{
+  /* Never output colors.  */
+  NEVER,
+
+  /* Output colors if the output is a terminal.  */
+  AUTO,
+
+  /* Always output colors.  */
+  ALWAYS,
+};
 
 /* Variables for command line options */
 
@@ -83,6 +96,9 @@ enum output_style
 
 XTERN enum output_style output_style;
 
+/* Define the current color context used to print a line.  */
+XTERN enum colors_style colors_style;
+
 /* Nonzero if output cannot be generated for identical files.  */
 XTERN bool no_diff_means_no_output;
 
@@ -390,3 +406,6 @@ extern void print_script (struct change *, struct change * (*) (struct change *)
 extern void setup_output (char const *, char const *, bool);
 extern void translate_range (struct file_data const *, lin, lin,
                              long int *, long int *);
+extern void set_add_color_context (void);
+extern void set_delete_color_context (void);
+extern void reset_color_context (bool from_signal);
diff --git a/src/normal.c b/src/normal.c
index 721fd1a..6fa48be 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -57,7 +57,11 @@ print_normal_hunk (struct change *hunk)
   /* Print the lines that the first file has.  */
   if (changes & OLD)
     for (i = first0; i <= last0; i++)
-      print_1_line ("<", &files[0].linbuf[i]);
+      {
+        set_delete_color_context ();
+        print_1_line ("<", &files[0].linbuf[i]);
+        reset_color_context (false);
+      }
 
   if (changes == CHANGED)
     fputs ("---\n", outfile);
@@ -65,5 +69,9 @@ print_normal_hunk (struct change *hunk)
   /* Print the lines that the second file has.  */
   if (changes & NEW)
     for (i = first1; i <= last1; i++)
-      print_1_line (">", &files[1].linbuf[i]);
+      {
+        set_add_color_context ();
+        print_1_line (">", &files[1].linbuf[i]);
+        reset_color_context (false);
+      }
 }
diff --git a/src/side.c b/src/side.c
index 155512c..8327d11 100644
--- a/src/side.c
+++ b/src/side.c
@@ -206,6 +206,18 @@ print_1sdiff_line (char const *const *left, char sep,
   size_t c2o = sdiff_column2_offset;
   size_t col = 0;
   bool put_newline = false;
+  bool color_to_reset = false;
+
+  if (sep == '<')
+    {
+      set_delete_color_context ();
+      color_to_reset = true;
+    }
+  else if (sep == '>')
+    {
+      set_add_color_context ();
+      color_to_reset = true;
+    }
 
   if (left)
     {
@@ -233,6 +245,9 @@ print_1sdiff_line (char const *const *left, char sep,
 
   if (put_newline)
     putc ('\n', out);
+
+  if (color_to_reset)
+    reset_color_context (false);
 }
 
 /* Print lines common to both files in side-by-side format.  */
diff --git a/src/util.c b/src/util.c
index 2d6d3fc..133e42b 100644
--- a/src/util.c
+++ b/src/util.c
@@ -24,6 +24,7 @@
 #include <system-quote.h>
 #include <xalloc.h>
 #include "xvasprintf.h"
+#include <signal.h>
 
 char const pr_program[] = PR_PROGRAM;
 
@@ -143,6 +144,59 @@ print_message_queue (void)
     }
 }
 
+static void
+signal_handler (int sig)
+{
+  reset_color_context (true);
+
+  /* Restore the default handler, and report the signal again.  */
+  signal (sig, SIG_DFL);
+  raise (sig);
+}
+
+static void
+install_signal_handlers (void)
+{
+  int j;
+#if HAVE_SIGACTION
+  struct sigaction act;
+#endif
+  int const sig[] =
+    {
+      SIGTSTP,
+      SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,
+#ifdef SIGPOLL
+      SIGPOLL,
+#endif
+#ifdef SIGPROF
+      SIGPROF,
+#endif
+#ifdef SIGVTALRM
+      SIGVTALRM,
+#endif
+#ifdef SIGXCPU
+      SIGXCPU,
+#endif
+#ifdef SIGXFSZ
+      SIGXFSZ,
+#endif
+    };
+
+  for (j = 0; j < sizeof (sig) / sizeof (*sig); j++)
+    {
+#if HAVE_SIGACTION
+      sigaction (sig[j], NULL, &act);
+      if (act.sa_handler != SIG_IGN)
+        {
+          act.sa_handler = signal_handler;
+          sigaction (sig[j], &act, NULL);
+        }
+#else
+      signal (sig[j], signal_handler);
+#endif
+    }
+}
+
 /* Call before outputting the results of comparing files NAME0 and NAME1
    to set up OUTFILE, the stdio stream for the output to go to.
 
@@ -153,6 +207,24 @@ print_message_queue (void)
 static char const *current_name0;
 static char const *current_name1;
 static bool currently_recursive;
+static bool colors_enabled;
+static bool output_is_tty;
+
+static void
+check_color_output (bool is_pipe)
+{
+  if (! outfile)
+    return;
+
+  output_is_tty = (colors_style != NEVER && !is_pipe
+                   && isatty (fileno (outfile)));
+
+  colors_enabled = (colors_style == ALWAYS
+                    || (colors_style == AUTO && output_is_tty));
+
+  if (output_is_tty)
+    install_signal_handlers ();
+}
 
 void
 setup_output (char const *name0, char const *name1, bool recursive)
@@ -313,6 +385,7 @@ begin_output (void)
 	    outfile = fdopen (pipes[1], "w");
 	    if (!outfile)
 	      pfatal_with_name ("fdopen");
+	    check_color_output (true);
 	  }
 #else
 	char *command = system_quote_argv (SCI_SYSTEM, (char **) argv);
@@ -320,6 +393,7 @@ begin_output (void)
 	outfile = popen (command, "w");
 	if (!outfile)
 	  pfatal_with_name (command);
+	check_color_output (true);
 	free (command);
 #endif
       }
@@ -330,6 +404,7 @@ begin_output (void)
       /* If -l was not specified, output the diff straight to 'stdout'.  */
 
       outfile = stdout;
+      check_color_output (false);
 
       /* If handling multiple files (because scanning a directory),
 	 print which files the following output is about.  */
@@ -717,6 +792,43 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
     }
 }
 
+void
+set_add_color_context (void)
+{
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[32m");
+}
+
+void
+set_delete_color_context (void)
+{
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[31m");
+}
+
+void
+reset_color_context (bool from_signal)
+{
+  static char const reset_sequence[] = "\x1b[0m";
+  if (! colors_enabled)
+    return;
+
+  if (! from_signal)
+    fputs (reset_sequence, outfile);
+  else
+    {
+      size_t written = 0;
+      while (written < sizeof reset_sequence - 1)
+        {
+          int ret = write (STDOUT_FILENO, reset_sequence + written,
+                           sizeof reset_sequence - 1 - written);
+          if (ret < 0)
+            return;
+          written += ret;
+        }
+    }
+}
+
 char const change_letter[] = { 0, 'd', 'a', 'c' };
 
 /* Translate an internal line number (an index into diff's table of lines)
-- 
2.1.0


--=-=-=--




From MAILER-DAEMON Sat Mar 14 15:00:12 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YWrIC-0007rZ-Qf
	for mharc-bug-diffutils@gnu.org; Sat, 14 Mar 2015 15:00:12 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:59258)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWrIA-0007rT-Ew
	for bug-diffutils@gnu.org; Sat, 14 Mar 2015 15:00:11 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWrI5-0003VN-ED
	for bug-diffutils@gnu.org; Sat, 14 Mar 2015 15:00:10 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:48260)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWrI5-0003Uz-Bv
	for bug-diffutils@gnu.org; Sat, 14 Mar 2015 15:00:05 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWrI4-00023a-RG
	for bug-diffutils@gnu.org; Sat, 14 Mar 2015 15:00:05 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Sat, 14 Mar 2015 19:00:04 +0000
Resent-Message-ID: <handler.20062.B20062.14263595957860@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.14263595957860
	(code B ref 20062); Sat, 14 Mar 2015 19:00:04 +0000
Received: (at 20062) by debbugs.gnu.org; 14 Mar 2015 18:59:55 +0000
Received: from localhost ([127.0.0.1]:46828 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YWrHv-00022g-7c
	for submit@debbugs.gnu.org; Sat, 14 Mar 2015 14:59:55 -0400
Received: from mail-oi0-f50.google.com ([209.85.218.50]:36699)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <andreas.gruenbacher@gmail.com>) id 1YWrHs-00022W-VL
	for 20062@debbugs.gnu.org; Sat, 14 Mar 2015 14:59:53 -0400
Received: by oiaz123 with SMTP id z123so10102496oia.3
	for <20062@debbugs.gnu.org>; Sat, 14 Mar 2015 11:59:52 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:date:message-id:subject
	:from:to:cc:content-type;
	bh=60aAdp2A0Ct7jhowrkKi/3d2R56dQahlD4iZqcYXzMQ=;
	b=HTqsK05xQTUi7RODzq5L7U9Q1w6rKHkwyYuiAT3tDBfqiPDZTKCLyZptsOjs9BtszW
	cqGHTcbSMf6soCUifiN5VrXmVY2aTLcx4wT/+QTWLVeJFOZEOfz2wMmHnToVBAfI6dBQ
	h+qz3JWyaEOMY0kfJj+60zYXLc30UfZ+G2/FEl5ebGkq7pMXp/54QyTExPpTrB7X3XR6
	PIyckN4VL5fpJ6Wwp0p+CdvRplWL8mvqA0ezidn81t5e/64QvzvRF9yYC98PKSDwh722
	THrKhj9veuZm0/+wd1ta5kLonxr2wojiBeTtCsXp7OV/sRfpey783szRGaLhY4/G0Isg
	7y0Q==
MIME-Version: 1.0
X-Received: by 10.60.73.38 with SMTP id i6mr35056459oev.27.1426359592286; Sat,
	14 Mar 2015 11:59:52 -0700 (PDT)
Received: by 10.182.118.66 with HTTP; Sat, 14 Mar 2015 11:59:52 -0700 (PDT)
In-Reply-To: <87oanw7otj.fsf@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com> <54FF1A4C.6080104@cs.ucla.edu>
	<87k2yoebrl.fsf@redhat.com> <54FF7742.6050500@cs.ucla.edu>
	<87egowctaa.fsf@redhat.com> <54FF870C.5000902@cs.ucla.edu>
	<878uf3b92g.fsf@redhat.com> <5500CD49.1060505@cs.ucla.edu>
	<87twxqa884.fsf@redhat.com> <5501A668.5050104@cs.ucla.edu>
	<87pp8d9ap1.fsf@redhat.com> <55020934.8080505@cs.ucla.edu>
	<87h9tp91uy.fsf@redhat.com> <55023863.6000407@cs.ucla.edu>
	<87wq2l6u7s.fsf@redhat.com> <87oanw7otj.fsf@redhat.com>
Date: Sat, 14 Mar 2015 19:59:52 +0100
X-Google-Sender-Auth: Tqo5RpJZ1vL0KKmxNNcgx4IY-Bg
Message-ID: <CAHpGcMJ3em9Ld0cjXfNYWX0uF+2V_nyJxY+oo4KSUgrJ7LAWvg@mail.gmail.com>
From: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Content-Type: text/plain; charset=UTF-8
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062: [PATCH]
	diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 14 Mar 2015 19:00:11 -0000

Giuseppe,

2015-03-13 19:08 GMT+01:00 Giuseppe Scrivano <gscrivan@redhat.com>:
> Giuseppe Scrivano <gscrivan@redhat.com> writes:
>
>> I'll send an updated version later today.

here are some more comments:

 * Please have a look at your changes to doc/diffutils.texi, they make no sense.

 * colors_style is never initialized and defaults to NEVER; it should
default to AUTO.

 * Please colorize the output of non-unified diffs as well.

 * Please use one of the common existing color schemes, not a new one -- for
   example, the one used by vim or "git diff". Those colorize patch
header lines as well.

Thanks,
Andreas




From MAILER-DAEMON Sat Mar 14 16:30:13 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YWshJ-0001af-5z
	for mharc-bug-diffutils@gnu.org; Sat, 14 Mar 2015 16:30:13 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:40415)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWshG-0001aT-TZ
	for bug-diffutils@gnu.org; Sat, 14 Mar 2015 16:30:11 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWshB-0002FI-Tc
	for bug-diffutils@gnu.org; Sat, 14 Mar 2015 16:30:10 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:48268)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWshB-0002Ea-R9
	for bug-diffutils@gnu.org; Sat, 14 Mar 2015 16:30:05 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWshA-0004qF-RZ
	for bug-diffutils@gnu.org; Sat, 14 Mar 2015 16:30:05 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Paul Eggert <eggert@cs.ucla.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Sat, 14 Mar 2015 20:30:04 +0000
Resent-Message-ID: <handler.20062.B20062.142636498618555@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>,
	Giuseppe Scrivano <gscrivan@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142636498618555
	(code B ref 20062); Sat, 14 Mar 2015 20:30:04 +0000
Received: (at 20062) by debbugs.gnu.org; 14 Mar 2015 20:29:46 +0000
Received: from localhost ([127.0.0.1]:46836 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YWsgs-0004pD-I8
	for submit@debbugs.gnu.org; Sat, 14 Mar 2015 16:29:46 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:49579)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1YWsgq-0004p2-0e
	for 20062@debbugs.gnu.org; Sat, 14 Mar 2015 16:29:44 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
	by smtp.cs.ucla.edu (Postfix) with ESMTP id A09A039E801F;
	Sat, 14 Mar 2015 13:29:42 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
	by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id jEiv1VtXryJF; Sat, 14 Mar 2015 13:29:42 -0700 (PDT)
Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net
	[100.32.155.148])
	by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 4ED1139E8017;
	Sat, 14 Mar 2015 13:29:42 -0700 (PDT)
Message-ID: <55049A36.6000603@cs.ucla.edu>
Date: Sat, 14 Mar 2015 13:29:42 -0700
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>	<54FDB353.8060801@redhat.com>	<87fv9dj28c.fsf@redhat.com>	<874mptgo2c.fsf@redhat.com>	<54FF1A4C.6080104@cs.ucla.edu>	<87k2yoebrl.fsf@redhat.com>	<54FF7742.6050500@cs.ucla.edu>	<87egowctaa.fsf@redhat.com>	<54FF870C.5000902@cs.ucla.edu>	<878uf3b92g.fsf@redhat.com>	<5500CD49.1060505@cs.ucla.edu>	<87twxqa884.fsf@redhat.com>	<5501A668.5050104@cs.ucla.edu>	<87pp8d9ap1.fsf@redhat.com>	<55020934.8080505@cs.ucla.edu>	<87h9tp91uy.fsf@redhat.com>	<55023863.6000407@cs.ucla.edu>	<87wq2l6u7s.fsf@redhat.com>	<87oanw7otj.fsf@redhat.com>
	<CAHpGcMJ3em9Ld0cjXfNYWX0uF+2V_nyJxY+oo4KSUgrJ7LAWvg@mail.gmail.com>
In-Reply-To: <CAHpGcMJ3em9Ld0cjXfNYWX0uF+2V_nyJxY+oo4KSUgrJ7LAWvg@mail.gmail.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062: [PATCH]
	diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 14 Mar 2015 20:30:11 -0000

Andreas Grünbacher wrote:
>   * colors_style is never initialized and defaults to NEVER; it should
> default to AUTO.

'grep' and 'ls' default to the equivalent of NEVER; shouldn't 'diff' do the same?




From MAILER-DAEMON Sat Mar 14 16:56:10 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YWt6Q-0008W0-F3
	for mharc-bug-diffutils@gnu.org; Sat, 14 Mar 2015 16:56:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:43624)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWt6N-0008VZ-Sn
	for bug-diffutils@gnu.org; Sat, 14 Mar 2015 16:56:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWt6I-0001De-SV
	for bug-diffutils@gnu.org; Sat, 14 Mar 2015 16:56:07 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:48291)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWt6I-0001Da-PL
	for bug-diffutils@gnu.org; Sat, 14 Mar 2015 16:56:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YWt6I-0005SL-IO
	for bug-diffutils@gnu.org; Sat, 14 Mar 2015 16:56:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Sat, 14 Mar 2015 20:56:02 +0000
Resent-Message-ID: <handler.20062.B20062.142636650720909@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Paul Eggert <eggert@cs.ucla.edu>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142636650720909
	(code B ref 20062); Sat, 14 Mar 2015 20:56:02 +0000
Received: (at 20062) by debbugs.gnu.org; 14 Mar 2015 20:55:07 +0000
Received: from localhost ([127.0.0.1]:46859 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YWt5P-0005R9-5Q
	for submit@debbugs.gnu.org; Sat, 14 Mar 2015 16:55:07 -0400
Received: from mail-ob0-f170.google.com ([209.85.214.170]:34386)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <andreas.gruenbacher@gmail.com>) id 1YWt5M-0005R1-Fl
	for 20062@debbugs.gnu.org; Sat, 14 Mar 2015 16:55:05 -0400
Received: by obbgg8 with SMTP id gg8so11773017obb.1
	for <20062@debbugs.gnu.org>; Sat, 14 Mar 2015 13:55:03 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:date:message-id:subject
	:from:to:cc:content-type;
	bh=4/axFOWh6rkN7uxjCk1K+Tjfv+jYRD77NjmY8LoKSBc=;
	b=buuiIaG8PI0aetHVJuNMcxob1x3B34+UBfqARt4TFI1sjE7DY2Pj8DQ/lLkLPpjt+4
	TJcjPK8RcQFz+cWuS6d1KcqOwk1He0Dglxqx84PvFloGW4p4xDzB3fktE94ldlPnBpTB
	GnAZNIJtrWiMwWPLPjveMUzpo50ULqp9RvLpK/YLs/Ty0Xnbi2m5aNiRV7YUTgzQyRZn
	afaQmdRF1q+cZrvdw48fCPlWlxaalbb5YtFp9iN+Nl6+fBLtE/X80+LGuCLqnIOfXcLP
	d16OzBTw8ZbxkG0LhYxEQSr5srL/0NtkuRYVrxZgHqs4UnU2dxMEesxuMhJkaLR2t0JH
	VdbA==
MIME-Version: 1.0
X-Received: by 10.60.73.38 with SMTP id i6mr35259685oev.27.1426366503824; Sat,
	14 Mar 2015 13:55:03 -0700 (PDT)
Received: by 10.182.118.66 with HTTP; Sat, 14 Mar 2015 13:55:03 -0700 (PDT)
In-Reply-To: <55049A36.6000603@cs.ucla.edu>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com> <54FF1A4C.6080104@cs.ucla.edu>
	<87k2yoebrl.fsf@redhat.com> <54FF7742.6050500@cs.ucla.edu>
	<87egowctaa.fsf@redhat.com> <54FF870C.5000902@cs.ucla.edu>
	<878uf3b92g.fsf@redhat.com> <5500CD49.1060505@cs.ucla.edu>
	<87twxqa884.fsf@redhat.com> <5501A668.5050104@cs.ucla.edu>
	<87pp8d9ap1.fsf@redhat.com> <55020934.8080505@cs.ucla.edu>
	<87h9tp91uy.fsf@redhat.com> <55023863.6000407@cs.ucla.edu>
	<87wq2l6u7s.fsf@redhat.com> <87oanw7otj.fsf@redhat.com>
	<CAHpGcMJ3em9Ld0cjXfNYWX0uF+2V_nyJxY+oo4KSUgrJ7LAWvg@mail.gmail.com>
	<55049A36.6000603@cs.ucla.edu>
Date: Sat, 14 Mar 2015 21:55:03 +0100
X-Google-Sender-Auth: FfVzpk6WBeQNu0MnawACLEF4McQ
Message-ID: <CAHpGcMKkV2LCcnBtWJc9Hrw7f8rRf6Nsrv2wVuJOj4oA_PTspg@mail.gmail.com>
From: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Content-Type: text/plain; charset=UTF-8
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: Giuseppe Scrivano <gscrivan@redhat.com>, 20062 <20062@debbugs.gnu.org>
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062: [PATCH]
	diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 14 Mar 2015 20:56:08 -0000

2015-03-14 21:29 GMT+01:00 Paul Eggert <eggert@cs.ucla.edu>:
> 'grep' and 'ls' default to the equivalent of NEVER; shouldn't 'diff' do the
> same?

I think color terminals are the standard nowadays, but if you think
that the default should be 'never', I could live with that. In any
case, the program help text is wrong, too:

>      --color[=WHEN]         colorize the output; WHEN can be 'never', 'always',
>                               or 'auto' (the default)

The default for WHEN is still 'always', but when the option is not
used at all, the default is either 'auto' (my preference) or 'never'.
Confusing ...

Thanks,
Andreas




From MAILER-DAEMON Sun Mar 15 16:20:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YXF17-0002YQ-U4
	for mharc-bug-diffutils@gnu.org; Sun, 15 Mar 2015 16:20:09 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:36235)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXF15-0002WH-SM
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 16:20:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXF12-00027A-My
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 16:20:07 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:48847)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXF12-000260-KY
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 16:20:04 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXF11-0001Uz-Rl
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 16:20:04 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Sun, 15 Mar 2015 20:20:03 +0000
Resent-Message-ID: <handler.20062.B20062.14264507765711@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.14264507765711
	(code B ref 20062); Sun, 15 Mar 2015 20:20:03 +0000
Received: (at 20062) by debbugs.gnu.org; 15 Mar 2015 20:19:36 +0000
Received: from localhost ([127.0.0.1]:47415 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YXF0a-0001U3-16
	for submit@debbugs.gnu.org; Sun, 15 Mar 2015 16:19:36 -0400
Received: from mx1.redhat.com ([209.132.183.28]:33483)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YXF0X-0001Ts-H0
	for 20062@debbugs.gnu.org; Sun, 15 Mar 2015 16:19:34 -0400
Received: from int-mx09.intmail.prod.int.phx2.redhat.com
	(int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2FKJQES001488
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL); Sun, 15 Mar 2015 16:19:26 -0400
Received: from foobarbaz (vpn1-5-113.ams2.redhat.com [10.36.5.113])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2FKJMI6029434
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Sun, 15 Mar 2015 16:19:24 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com> <54FF1A4C.6080104@cs.ucla.edu>
	<87k2yoebrl.fsf@redhat.com> <54FF7742.6050500@cs.ucla.edu>
	<87egowctaa.fsf@redhat.com> <54FF870C.5000902@cs.ucla.edu>
	<878uf3b92g.fsf@redhat.com> <5500CD49.1060505@cs.ucla.edu>
	<87twxqa884.fsf@redhat.com> <5501A668.5050104@cs.ucla.edu>
	<87pp8d9ap1.fsf@redhat.com> <55020934.8080505@cs.ucla.edu>
	<87h9tp91uy.fsf@redhat.com> <55023863.6000407@cs.ucla.edu>
	<87wq2l6u7s.fsf@redhat.com> <87oanw7otj.fsf@redhat.com>
	<CAHpGcMJ3em9Ld0cjXfNYWX0uF+2V_nyJxY+oo4KSUgrJ7LAWvg@mail.gmail.com>
Date: Sun, 15 Mar 2015 21:19:22 +0100
In-Reply-To: <CAHpGcMJ3em9Ld0cjXfNYWX0uF+2V_nyJxY+oo4KSUgrJ7LAWvg@mail.gmail.com>
	("Andreas \=\?utf-8\?Q\?Gr\=C3\=BCnbacher\=22's\?\= message of "Sat,
	14 Mar 2015 19:59:52 +0100")
Message-ID: <87wq2i3tf9.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062: [PATCH]
	diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 15 Mar 2015 20:20:08 -0000

Andreas Gr=C3=BCnbacher <agruen@gnu.org> writes:

> Giuseppe,
>
> 2015-03-13 19:08 GMT+01:00 Giuseppe Scrivano <gscrivan@redhat.com>:
>> Giuseppe Scrivano <gscrivan@redhat.com> writes:
>>
>>> I'll send an updated version later today.
>
> here are some more comments:
>
>  * Please have a look at your changes to doc/diffutils.texi, they make no=
 sense.

I've basically copied this section from coreutils.  What doesn't make
sense to you?

Thanks,
Giuseppe






From MAILER-DAEMON Sun Mar 15 17:07:07 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YXFkZ-0007el-PZ
	for mharc-bug-diffutils@gnu.org; Sun, 15 Mar 2015 17:07:07 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41300)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXFkY-0007d2-Ct
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 17:07:07 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXFkV-0008Mc-2C
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 17:07:06 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:48869)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXFkU-0008L8-Ve
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 17:07:03 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXFkU-0002ix-2u
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 17:07:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Sun, 15 Mar 2015 21:07:02 +0000
Resent-Message-ID: <handler.20062.B20062.142645358910428@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142645358910428
	(code B ref 20062); Sun, 15 Mar 2015 21:07:02 +0000
Received: (at 20062) by debbugs.gnu.org; 15 Mar 2015 21:06:29 +0000
Received: from localhost ([127.0.0.1]:47437 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YXFjw-0002i5-KR
	for submit@debbugs.gnu.org; Sun, 15 Mar 2015 17:06:29 -0400
Received: from mx1.redhat.com ([209.132.183.28]:37495)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YXFjp-0002ho-Ex
	for 20062@debbugs.gnu.org; Sun, 15 Mar 2015 17:06:27 -0400
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (Postfix) with ESMTPS id 936138EB5B;
	Sun, 15 Mar 2015 21:06:20 +0000 (UTC)
Received: from foobarbaz (vpn1-5-113.ams2.redhat.com [10.36.5.113])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2FL6HIb026774
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Sun, 15 Mar 2015 17:06:18 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<87fv9dj28c.fsf@redhat.com> <874mptgo2c.fsf@redhat.com>
	<54FF1A4C.6080104@cs.ucla.edu> <87k2yoebrl.fsf@redhat.com>
	<54FF7742.6050500@cs.ucla.edu> <87egowctaa.fsf@redhat.com>
	<54FF870C.5000902@cs.ucla.edu> <878uf3b92g.fsf@redhat.com>
	<5500CD49.1060505@cs.ucla.edu> <87twxqa884.fsf@redhat.com>
	<5501A668.5050104@cs.ucla.edu> <87pp8d9ap1.fsf@redhat.com>
	<55020934.8080505@cs.ucla.edu> <87h9tp91uy.fsf@redhat.com>
	<55023863.6000407@cs.ucla.edu> <87wq2l6u7s.fsf@redhat.com>
	<87oanw7otj.fsf@redhat.com>
	<CAHpGcMJ3em9Ld0cjXfNYWX0uF+2V_nyJxY+oo4KSUgrJ7LAWvg@mail.gmail.com>
	<55049A36.6000603@cs.ucla.edu>
	<CAHpGcMKkV2LCcnBtWJc9Hrw7f8rRf6Nsrv2wVuJOj4oA_PTspg@mail.gmail.com>
Date: Sun, 15 Mar 2015 22:06:16 +0100
In-Reply-To: <CAHpGcMKkV2LCcnBtWJc9Hrw7f8rRf6Nsrv2wVuJOj4oA_PTspg@mail.gmail.com>
	("Andreas \=\?utf-8\?Q\?Gr\=C3\=BCnbacher\=22's\?\= message of "Sat,
	14 Mar 2015 21:55:03 +0100")
Message-ID: <87sid63r93.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062 <20062@debbugs.gnu.org>
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062: [PATCH]
	diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 15 Mar 2015 21:07:07 -0000

Andreas Gr=C3=BCnbacher <agruen@gnu.org> writes:

> 2015-03-14 21:29 GMT+01:00 Paul Eggert <eggert@cs.ucla.edu>:
>> 'grep' and 'ls' default to the equivalent of NEVER; shouldn't 'diff' do =
the
>> same?
>
> I think color terminals are the standard nowadays, but if you think
> that the default should be 'never', I could live with that. In any
> case, the program help text is wrong, too:
>
>>      --color[=3DWHEN]         colorize the output; WHEN can be 'never', =
'always',
>>                               or 'auto' (the default)
>
> The default for WHEN is still 'always', but when the option is not
> used at all, the default is either 'auto' (my preference) or 'never'.
> Confusing ...

I think the default for --color should be auto.  Outputting stdout to a
file happens more often with diff than with ls and having the colors
commands in a diff file is to be avoided as much as possible (if people
really want it, then they can force it with always).

grep seems to default to "auto" as well when --color is specified.

Regards,
Giuseppe




From MAILER-DAEMON Sun Mar 15 20:38:39 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YXJ3H-0001Gn-4t
	for mharc-bug-diffutils@gnu.org; Sun, 15 Mar 2015 20:38:39 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:42257)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXIIK-0005yi-U9
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 19:50:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXIIF-0006eO-EY
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 19:50:08 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:49066)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXIIF-0006ck-B3
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 19:50:03 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXIIE-0006sB-BG
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 19:50:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Norihiro Tanaka <noritnk@kcn.ne.jp>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Sun, 15 Mar 2015 23:50:02 +0000
Resent-Message-ID: <handler.20062.B20062.142646337426371@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142646337426371
	(code B ref 20062); Sun, 15 Mar 2015 23:50:02 +0000
Received: (at 20062) by debbugs.gnu.org; 15 Mar 2015 23:49:34 +0000
Received: from localhost ([127.0.0.1]:47634 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YXIHl-0006rH-Iv
	for submit@debbugs.gnu.org; Sun, 15 Mar 2015 19:49:33 -0400
Received: from mailgw04.kcn.ne.jp ([61.86.7.211]:38290)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <noritnk@kcn.ne.jp>) id 1YXIHi-0006r6-Sm
	for 20062@debbugs.gnu.org; Sun, 15 Mar 2015 19:49:32 -0400
Received: from mxs02-s (mailgw2.kcn.ne.jp [61.86.15.234])
	by mailgw04.kcn.ne.jp (Postfix) with ESMTP id C55EB6C14D5
	for <20062@debbugs.gnu.org>; Mon, 16 Mar 2015 08:49:28 +0900 (JST)
X-matriXscan-loop-detect: a722b906f7eaffc6d98a04a8e39711daa887e6cd
Received: from mail03.kcn.ne.jp ([61.86.6.182]) by mxs02-s with ESMTP;
	Mon, 16 Mar 2015 08:49:26 +0900 (JST)
Received: from [10.120.1.73] (i118-21-128-66.s30.a048.ap.plala.or.jp
	[118.21.128.66])
	by mail03.kcn.ne.jp (Postfix) with ESMTPA id BDA17141009C;
	Mon, 16 Mar 2015 08:49:26 +0900 (JST)
Date: Mon, 16 Mar 2015 08:49:29 +0900
From: Norihiro Tanaka <noritnk@kcn.ne.jp>
In-Reply-To: <87sid63r93.fsf@redhat.com>
References: <CAHpGcMKkV2LCcnBtWJc9Hrw7f8rRf6Nsrv2wVuJOj4oA_PTspg@mail.gmail.com>
	<87sid63r93.fsf@redhat.com>
Message-Id: <20150316084928.498A.27F6AC2D@kcn.ne.jp>
MIME-Version: 1.0
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-Mailer: Becky! ver. 2.65.07 [ja]
X-matriXscan-CTCmd-AV: Clean
X-matriXscan-Action: Approve
X-matriXscan: Uncategorized
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
X-Mailman-Approved-At: Sun, 15 Mar 2015 20:38:37 -0400
Cc: 20062 <20062@debbugs.gnu.org>
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062:
	bug#20062: [PATCH] diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 15 Mar 2015 23:50:09 -0000

Giuseppe Scrivano <gscrivan@redhat.com> wrote:

> I think the default for --color should be auto.  Outputting stdout to a
> file happens more often with diff than with ls and having the colors
> commands in a diff file is to be avoided as much as possible (if people
> really want it, then they can force it with always).

I disagree.  I think we should not make difference for default among
diff, ls and grep, and they should not also be neither AUTO nor ALWAYS.

AUTO and ALWAYS are POSIX incompatible, as they change output in byte
level.  So I think that if only users and/or distributors expect it,
they should manually change color option into AUTO or ALWAYS.

> grep seems to default to "auto" as well when --color is specified.

However, grep will suffer from the disadvantage of performance down with
--color option.





From MAILER-DAEMON Sun Mar 15 20:38:43 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YXJ3L-0001Hh-8j
	for mharc-bug-diffutils@gnu.org; Sun, 15 Mar 2015 20:38:43 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:43317)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXIN9-0006sJ-AT
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 19:55:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXIN4-0007x7-Ax
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 19:55:07 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:49096)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXIN4-0007wp-7h
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 19:55:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXIN3-00070a-SE
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 19:55:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Norihiro Tanaka <noritnk@kcn.ne.jp>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Sun, 15 Mar 2015 23:55:01 +0000
Resent-Message-ID: <handler.20062.B20062.142646365226873@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142646365226873
	(code B ref 20062); Sun, 15 Mar 2015 23:55:01 +0000
Received: (at 20062) by debbugs.gnu.org; 15 Mar 2015 23:54:12 +0000
Received: from localhost ([127.0.0.1]:47664 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YXIMF-0006zN-LC
	for submit@debbugs.gnu.org; Sun, 15 Mar 2015 19:54:11 -0400
Received: from mailgw04.kcn.ne.jp ([61.86.7.211]:39337)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <noritnk@kcn.ne.jp>) id 1YXIMD-0006zE-P5
	for 20062@debbugs.gnu.org; Sun, 15 Mar 2015 19:54:10 -0400
Received: from mxs01-s (mailgw1.kcn.ne.jp [61.86.15.233])
	by mailgw04.kcn.ne.jp (Postfix) with ESMTP id 962BF6C16AE
	for <20062@debbugs.gnu.org>; Mon, 16 Mar 2015 08:54:08 +0900 (JST)
X-matriXscan-loop-detect: 0047eac04c330429991ad4fdfbbe6002868c0c6c
Received: from mail07.kcn.ne.jp ([61.86.6.186]) by mxs01-s with ESMTP;
	Mon, 16 Mar 2015 08:54:07 +0900 (JST)
Received: from [10.120.1.73] (i118-21-128-66.s30.a048.ap.plala.or.jp
	[118.21.128.66])
	by mail07.kcn.ne.jp (Postfix) with ESMTPA id 85E92D5002B;
	Mon, 16 Mar 2015 08:54:07 +0900 (JST)
Date: Mon, 16 Mar 2015 08:54:09 +0900
From: Norihiro Tanaka <noritnk@kcn.ne.jp>
In-Reply-To: <20150316084928.498A.27F6AC2D@kcn.ne.jp>
References: <87sid63r93.fsf@redhat.com>
	<20150316084928.498A.27F6AC2D@kcn.ne.jp>
Message-Id: <20150316085409.4996.27F6AC2D@kcn.ne.jp>
MIME-Version: 1.0
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-Mailer: Becky! ver. 2.65.07 [ja]
X-matriXscan-CTCmd-AV: Clean
X-matriXscan-Action: Approve
X-matriXscan: Uncategorized
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
X-Mailman-Approved-At: Sun, 15 Mar 2015 20:38:42 -0400
Cc: 20062 <20062@debbugs.gnu.org>
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062:
	bug#20062: [PATCH] diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 15 Mar 2015 23:55:08 -0000


On Mon, 16 Mar 2015 08:49:29 +0900
Norihiro Tanaka <noritnk@kcn.ne.jp> wrote:

> AUTO and ALWAYS are POSIX incompatible,

In addition, if the default is AUTO, and they are also imcompatible with
previous versions of DIFF by default.





From MAILER-DAEMON Sun Mar 15 20:57:11 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YXJLD-0000Hk-8w
	for mharc-bug-diffutils@gnu.org; Sun, 15 Mar 2015 20:57:11 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:34776)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXJL9-0000HC-0W
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 20:57:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXJL4-0003FD-K5
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 20:57:06 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:49224)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXJL4-0003F9-FR
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 20:57:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXJL4-0001bz-3l
	for bug-diffutils@gnu.org; Sun, 15 Mar 2015 20:57:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Mon, 16 Mar 2015 00:57:02 +0000
Resent-Message-ID: <handler.20062.B20062.14264674076116@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Norihiro Tanaka <noritnk@kcn.ne.jp>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.14264674076116
	(code B ref 20062); Mon, 16 Mar 2015 00:57:02 +0000
Received: (at 20062) by debbugs.gnu.org; 16 Mar 2015 00:56:47 +0000
Received: from localhost ([127.0.0.1]:47792 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YXJKn-0001aY-MC
	for submit@debbugs.gnu.org; Sun, 15 Mar 2015 20:56:46 -0400
Received: from mx1.redhat.com ([209.132.183.28]:38455)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YXJKj-0001aO-QJ
	for 20062@debbugs.gnu.org; Sun, 15 Mar 2015 20:56:43 -0400
Received: from int-mx13.intmail.prod.int.phx2.redhat.com
	(int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26])
	by mx1.redhat.com (Postfix) with ESMTPS id B0F50C6A01;
	Mon, 16 Mar 2015 00:56:40 +0000 (UTC)
Received: from foobarbaz (vpn1-5-113.ams2.redhat.com [10.36.5.113])
	by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2G0uaUe023908
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Sun, 15 Mar 2015 20:56:38 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <87sid63r93.fsf@redhat.com>
	<20150316084928.498A.27F6AC2D@kcn.ne.jp>
	<20150316085409.4996.27F6AC2D@kcn.ne.jp>
Date: Mon, 16 Mar 2015 01:56:36 +0100
In-Reply-To: <20150316085409.4996.27F6AC2D@kcn.ne.jp> (Norihiro Tanaka's
	message of "Mon, 16 Mar 2015 08:54:09 +0900")
Message-ID: <8738554v5n.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062 <20062@debbugs.gnu.org>
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062:
	bug#20062: [PATCH] diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 16 Mar 2015 00:57:09 -0000

--=-=-=
Content-Type: text/plain

Norihiro Tanaka <noritnk@kcn.ne.jp> writes:

> On Mon, 16 Mar 2015 08:49:29 +0900
> Norihiro Tanaka <noritnk@kcn.ne.jp> wrote:
>
>> AUTO and ALWAYS are POSIX incompatible,
>
> In addition, if the default is AUTO, and they are also imcompatible with
> previous versions of DIFF by default.

I meant the default if --color is specified.  That is not incompatible
with any previous version since --color was not present.

Apparently, ls and grep already behaves differently for --color so diff
is not going to make any other difference here.  "ls --color" means "ls
--color=always" while "grep --color" behaves like "grep --color=auto".
Having to choose between these two, --color=auto makes more sense for
diff where redirection to files is a common operation.

I am attaching the latest version of the patch, taking into account
comments from Andreas.  I have added colors for header and line numbers,
following the "git diff" colors scheme.

Thanks,
Giuseppe


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=0001-diff-add-support-for-color.patch

>From 2d7ae3ebba0eaeda9d8f1e2fca6e8646ec187334 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Sun, 8 Mar 2015 22:45:11 +0100
Subject: [PATCH] diff: add support for --color

* doc/diffutils.texi (diff Options): Add documentation for --color.
Copied from coreutils ls --color.
* src/context.c (pr_unidiff_hunk): Set the color context.
(print_context_header): Likewise.
(pr_context_hunk): Likewise.
* src/diff.h (enum colors_style): New enum to record when to use colors.
(colors_style): New variable to memorize the argument value.
(set_add_color_context): Add function definition.
(set_delete_color_context): Likewise.
(set_header_color_context): Likewise.
(set_line_numbers_color_context): Likewise.
(reset_color_context): Likewise.
* src/diff.c: : Define COLOR_OPTION.
(specify_colors_style): New function.
(longopts): Add --color.
(main): Handle --color argument.
(option_help_msgid): Add usage string for --color.
* src/normal.c (print_normal_hunk): Set the color context.
* src/side.c (print_1sdiff_line): Likewise.
* src/util.c (colors_enabled): New boolean variable.
(begin_output): Call check_color_output once the output file is
configured.
(colors_enabled): New boolean variable.
(check_color_output): New function.
(install_signal_handlers): Likewise.
(signal_handler): Likewise.
(set_add_color_context): Likewise.
(set_delete_color_context): Likewise.
(reset_color_context): Likewise.
(set_header_color_context): Likewise.
(set_line_numbers_color_context): Likewise.
---
 doc/diffutils.texi |  20 +++++++++
 src/context.c      |  51 ++++++++++++++++++----
 src/diff.c         |  27 +++++++++++-
 src/diff.h         |  21 +++++++++
 src/normal.c       |  18 ++++++--
 src/side.c         |  15 +++++++
 src/util.c         | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 264 insertions(+), 14 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 3e25807..0a2f1fc 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3745,6 +3745,26 @@ Read and write data in binary mode.  @xref{Binary}.
 Use the context output format, showing three lines of context.
 @xref{Context Format}.
 
+@item --color [=@var{when}]
+@cindex color, distinguishing file types with
+Specify whether to use color for distinguishing file types.  @var{when}
+may be omitted, or one of:
+@itemize @bullet
+@item none
+@vindex none @r{color option}
+Do not use color at all.  This is the default when no --color option
+is present.
+@item auto
+@vindex auto @r{color option}
+@cindex terminal, using color iff
+Only use color if standard output is a terminal.
+@item always
+@vindex always @r{color option}
+Always use color.
+@end itemize
+Specifying @option{--color} and no @var{when} is equivalent to
+@option{--color=auto}.
+
 @item -C @var{lines}
 @itemx --context@r{[}=@var{lines}@r{]}
 Use the context output format, showing @var{lines} (an integer) lines of
diff --git a/src/context.c b/src/context.c
index e0f21c4..9b23d36 100644
--- a/src/context.c
+++ b/src/context.c
@@ -80,6 +80,7 @@ print_context_label (char const *mark,
 void
 print_context_header (struct file_data inf[], char const *const *names, bool unidiff)
 {
+  set_header_color_context ();
   if (unidiff)
     {
       print_context_label ("---", &inf[0], names[0], file_label[0]);
@@ -90,6 +91,7 @@ print_context_header (struct file_data inf[], char const *const *names, bool uni
       print_context_label ("***", &inf[0], names[0], file_label[0]);
       print_context_label ("---", &inf[1], names[1], file_label[1]);
     }
+  reset_color_context (false);
 }
 
 /* Print an edit script in context format.  */
@@ -215,6 +217,7 @@ pr_context_hunk (struct change *hunk)
 
       for (i = first0; i <= last0; i++)
 	{
+          bool reset_context = false;
 	  /* Skip past changes that apply (in file 0)
 	     only to lines before line I.  */
 
@@ -225,12 +228,18 @@ pr_context_hunk (struct change *hunk)
 
 	  prefix = " ";
 	  if (next && next->line0 <= i)
-	    /* The change NEXT covers this line.
-	       If lines were inserted here in file 1, this is "changed".
-	       Otherwise it is "deleted".  */
-	    prefix = (next->inserted > 0 ? "!" : "-");
+            {
+              reset_context = true;
+              set_delete_color_context ();
+              /* The change NEXT covers this line.
+                 If lines were inserted here in file 1, this is "changed".
+                 Otherwise it is "deleted".  */
+              prefix = (next->inserted > 0 ? "!" : "-");
+            }
 
 	  print_1_line (prefix, &files[0].linbuf[i]);
+          if (reset_context)
+            reset_color_context (false);
 	}
     }
 
@@ -244,6 +253,7 @@ pr_context_hunk (struct change *hunk)
 
       for (i = first1; i <= last1; i++)
 	{
+          bool reset_context = false;
 	  /* Skip past changes that apply (in file 1)
 	     only to lines before line I.  */
 
@@ -254,12 +264,17 @@ pr_context_hunk (struct change *hunk)
 
 	  prefix = " ";
 	  if (next && next->line1 <= i)
-	    /* The change NEXT covers this line.
-	       If lines were deleted here in file 0, this is "changed".
-	       Otherwise it is "inserted".  */
-	    prefix = (next->deleted > 0 ? "!" : "+");
-
+            {
+              reset_context = true;
+              set_add_color_context ();
+              /* The change NEXT covers this line.
+                 If lines were deleted here in file 0, this is "changed".
+                 Otherwise it is "inserted".  */
+              prefix = (next->deleted > 0 ? "!" : "+");
+            }
 	  print_1_line (prefix, &files[1].linbuf[i]);
+          if (reset_context)
+            reset_color_context (false);
 	}
     }
 }
@@ -330,11 +345,13 @@ pr_unidiff_hunk (struct change *hunk)
   begin_output ();
   out = outfile;
 
+  set_line_numbers_color_context ();
   fputs ("@@ -", out);
   print_unidiff_number_range (&files[0], first0, last0);
   fputs (" +", out);
   print_unidiff_number_range (&files[1], first1, last1);
   fputs (" @@", out);
+  reset_color_context (false);
 
   if (function)
     print_context_function (out, function);
@@ -360,9 +377,17 @@ pr_unidiff_hunk (struct change *hunk)
 	}
       else
 	{
+          bool reset_context = false;
+
 	  /* For each difference, first output the deleted part. */
 
 	  k = next->deleted;
+          if (k)
+            {
+              reset_context = true;
+              set_delete_color_context ();
+            }
+
 	  while (k--)
 	    {
 	      char const * const *line = &files[0].linbuf[i++];
@@ -375,9 +400,15 @@ pr_unidiff_hunk (struct change *hunk)
 	  /* Then output the inserted part. */
 
 	  k = next->inserted;
+          if (k)
+            {
+              reset_context = true;
+              set_add_color_context ();
+            }
 	  while (k--)
 	    {
 	      char const * const *line = &files[1].linbuf[j++];
+	      set_add_color_context ();
 	      putc ('+', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
@@ -386,6 +417,8 @@ pr_unidiff_hunk (struct change *hunk)
 
 	  /* We're done with this hunk, so on to the next! */
 
+          if (reset_context)
+            reset_color_context (false);
 	  next = next->link;
 	}
     }
diff --git a/src/diff.c b/src/diff.c
index ff28377..be6e6e3 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -70,6 +70,7 @@ static void add_regexp (struct regexp_list *, char const *);
 static void summarize_regexp_list (struct regexp_list *);
 static void specify_style (enum output_style);
 static void specify_value (char const **, char const *, char const *);
+static void specify_colors_style (char const *);
 static void try_help (char const *, char const *) __attribute__((noreturn));
 static void check_stdout (void);
 static void usage (void);
@@ -136,7 +137,9 @@ enum
   UNCHANGED_GROUP_FORMAT_OPTION,
   OLD_GROUP_FORMAT_OPTION,
   NEW_GROUP_FORMAT_OPTION,
-  CHANGED_GROUP_FORMAT_OPTION
+  CHANGED_GROUP_FORMAT_OPTION,
+
+  COLOR_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -159,6 +162,7 @@ static struct option const longopts[] =
   {"binary", 0, 0, BINARY_OPTION},
   {"brief", 0, 0, 'q'},
   {"changed-group-format", 1, 0, CHANGED_GROUP_FORMAT_OPTION},
+  {"color", 2, 0, COLOR_OPTION},
   {"context", 2, 0, 'C'},
   {"ed", 0, 0, 'e'},
   {"exclude", 1, 0, 'x'},
@@ -627,6 +631,10 @@ main (int argc, char **argv)
 	  specify_value (&group_format[c], optarg, group_format_option[c]);
 	  break;
 
+	case COLOR_OPTION:
+	  specify_colors_style (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
@@ -940,6 +948,8 @@ static char const * const option_help_msgid[] = {
   N_("-d, --minimal            try hard to find a smaller set of changes"),
   N_("    --horizon-lines=NUM  keep NUM lines of the common prefix and suffix"),
   N_("    --speed-large-files  assume large files and many scattered small changes"),
+  N_("    --color[=WHEN]         colorize the output; WHEN can be 'never', 'always',"),
+  N_("                             or 'auto' (the default)"),
   "",
   N_("    --help               display this help and exit"),
   N_("-v, --version            output version information and exit"),
@@ -1008,6 +1018,21 @@ specify_style (enum output_style style)
       output_style = style;
     }
 }
+
+/* Set the color mode.  */
+static void
+specify_colors_style (char const *value)
+{
+  if (value == NULL || STREQ (value, "auto"))
+    colors_style = AUTO;
+  else if (STREQ (value, "always"))
+    colors_style = ALWAYS;
+  else if (STREQ (value, "never"))
+    colors_style = NEVER;
+  else
+    try_help ("invalid color '%s'", value);
+}
+
 
 /* Set the last-modified time of *ST to be the current time.  */
 
diff --git a/src/diff.h b/src/diff.h
index 465e4bc..553bad1 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -38,6 +38,19 @@ enum changes
   /* Both deletes and inserts: a hunk containing both old and new lines.  */
   CHANGED
 };
+
+/* What kind of changes a hunk contains.  */
+enum colors_style
+{
+  /* Never output colors.  */
+  NEVER,
+
+  /* Output colors if the output is a terminal.  */
+  AUTO,
+
+  /* Always output colors.  */
+  ALWAYS,
+};
 
 /* Variables for command line options */
 
@@ -83,6 +96,9 @@ enum output_style
 
 XTERN enum output_style output_style;
 
+/* Define the current color context used to print a line.  */
+XTERN enum colors_style colors_style;
+
 /* Nonzero if output cannot be generated for identical files.  */
 XTERN bool no_diff_means_no_output;
 
@@ -390,3 +406,8 @@ extern void print_script (struct change *, struct change * (*) (struct change *)
 extern void setup_output (char const *, char const *, bool);
 extern void translate_range (struct file_data const *, lin, lin,
                              long int *, long int *);
+extern void set_header_color_context (void);
+extern void set_add_color_context (void);
+extern void set_delete_color_context (void);
+extern void reset_color_context (bool from_signal);
+extern void set_line_numbers_color_context (void);
diff --git a/src/normal.c b/src/normal.c
index 721fd1a..0ce01ee 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -49,21 +49,31 @@ print_normal_hunk (struct change *hunk)
   begin_output ();
 
   /* Print out the line number header for this hunk */
+  set_line_numbers_color_context ();
   print_number_range (',', &files[0], first0, last0);
   fputc (change_letter[changes], outfile);
   print_number_range (',', &files[1], first1, last1);
   fputc ('\n', outfile);
+  reset_color_context (false);
 
   /* Print the lines that the first file has.  */
   if (changes & OLD)
-    for (i = first0; i <= last0; i++)
-      print_1_line ("<", &files[0].linbuf[i]);
+    {
+      set_delete_color_context ();
+      for (i = first0; i <= last0; i++)
+        print_1_line ("<", &files[0].linbuf[i]);
+      reset_color_context (false);
+    }
 
   if (changes == CHANGED)
     fputs ("---\n", outfile);
 
   /* Print the lines that the second file has.  */
   if (changes & NEW)
-    for (i = first1; i <= last1; i++)
-      print_1_line (">", &files[1].linbuf[i]);
+    {
+      set_add_color_context ();
+      for (i = first1; i <= last1; i++)
+        print_1_line (">", &files[1].linbuf[i]);
+      reset_color_context (false);
+    }
 }
diff --git a/src/side.c b/src/side.c
index 155512c..8327d11 100644
--- a/src/side.c
+++ b/src/side.c
@@ -206,6 +206,18 @@ print_1sdiff_line (char const *const *left, char sep,
   size_t c2o = sdiff_column2_offset;
   size_t col = 0;
   bool put_newline = false;
+  bool color_to_reset = false;
+
+  if (sep == '<')
+    {
+      set_delete_color_context ();
+      color_to_reset = true;
+    }
+  else if (sep == '>')
+    {
+      set_add_color_context ();
+      color_to_reset = true;
+    }
 
   if (left)
     {
@@ -233,6 +245,9 @@ print_1sdiff_line (char const *const *left, char sep,
 
   if (put_newline)
     putc ('\n', out);
+
+  if (color_to_reset)
+    reset_color_context (false);
 }
 
 /* Print lines common to both files in side-by-side format.  */
diff --git a/src/util.c b/src/util.c
index 2d6d3fc..0f8f7a8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -24,6 +24,7 @@
 #include <system-quote.h>
 #include <xalloc.h>
 #include "xvasprintf.h"
+#include <signal.h>
 
 char const pr_program[] = PR_PROGRAM;
 
@@ -143,6 +144,59 @@ print_message_queue (void)
     }
 }
 
+static void
+signal_handler (int sig)
+{
+  reset_color_context (true);
+
+  /* Restore the default handler, and report the signal again.  */
+  signal (sig, SIG_DFL);
+  raise (sig);
+}
+
+static void
+install_signal_handlers (void)
+{
+  int j;
+#if HAVE_SIGACTION
+  struct sigaction act;
+#endif
+  int const sig[] =
+    {
+      SIGTSTP,
+      SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,
+#ifdef SIGPOLL
+      SIGPOLL,
+#endif
+#ifdef SIGPROF
+      SIGPROF,
+#endif
+#ifdef SIGVTALRM
+      SIGVTALRM,
+#endif
+#ifdef SIGXCPU
+      SIGXCPU,
+#endif
+#ifdef SIGXFSZ
+      SIGXFSZ,
+#endif
+    };
+
+  for (j = 0; j < sizeof (sig) / sizeof (*sig); j++)
+    {
+#if HAVE_SIGACTION
+      sigaction (sig[j], NULL, &act);
+      if (act.sa_handler != SIG_IGN)
+        {
+          act.sa_handler = signal_handler;
+          sigaction (sig[j], &act, NULL);
+        }
+#else
+      signal (sig[j], signal_handler);
+#endif
+    }
+}
+
 /* Call before outputting the results of comparing files NAME0 and NAME1
    to set up OUTFILE, the stdio stream for the output to go to.
 
@@ -153,6 +207,24 @@ print_message_queue (void)
 static char const *current_name0;
 static char const *current_name1;
 static bool currently_recursive;
+static bool colors_enabled;
+static bool output_is_tty;
+
+static void
+check_color_output (bool is_pipe)
+{
+  if (! outfile)
+    return;
+
+  output_is_tty = (colors_style != NEVER && !is_pipe
+                   && isatty (fileno (outfile)));
+
+  colors_enabled = (colors_style == ALWAYS
+                    || (colors_style == AUTO && output_is_tty));
+
+  if (output_is_tty)
+    install_signal_handlers ();
+}
 
 void
 setup_output (char const *name0, char const *name1, bool recursive)
@@ -313,6 +385,7 @@ begin_output (void)
 	    outfile = fdopen (pipes[1], "w");
 	    if (!outfile)
 	      pfatal_with_name ("fdopen");
+	    check_color_output (true);
 	  }
 #else
 	char *command = system_quote_argv (SCI_SYSTEM, (char **) argv);
@@ -320,6 +393,7 @@ begin_output (void)
 	outfile = popen (command, "w");
 	if (!outfile)
 	  pfatal_with_name (command);
+	check_color_output (true);
 	free (command);
 #endif
       }
@@ -330,6 +404,7 @@ begin_output (void)
       /* If -l was not specified, output the diff straight to 'stdout'.  */
 
       outfile = stdout;
+      check_color_output (false);
 
       /* If handling multiple files (because scanning a directory),
 	 print which files the following output is about.  */
@@ -717,6 +792,57 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
     }
 }
 
+void
+set_header_color_context (void)
+{
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[1;39m");
+}
+
+void
+set_line_numbers_color_context (void)
+{
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[36m");
+}
+
+void
+set_add_color_context (void)
+{
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[32m");
+}
+
+void
+set_delete_color_context (void)
+{
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[31m");
+}
+
+void
+reset_color_context (bool from_signal)
+{
+  static char const reset_sequence[] = "\x1b[0m";
+  if (! colors_enabled)
+    return;
+
+  if (! from_signal)
+    fputs (reset_sequence, outfile);
+  else
+    {
+      size_t written = 0;
+      while (written < sizeof reset_sequence - 1)
+        {
+          int ret = write (STDOUT_FILENO, reset_sequence + written,
+                           sizeof reset_sequence - 1 - written);
+          if (ret < 0)
+            return;
+          written += ret;
+        }
+    }
+}
+
 char const change_letter[] = { 0, 'd', 'a', 'c' };
 
 /* Translate an internal line number (an index into diff's table of lines)
-- 
2.1.0


--=-=-=--




From MAILER-DAEMON Mon Mar 16 09:57:11 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YXVW2-0003zR-Tu
	for mharc-bug-diffutils@gnu.org; Mon, 16 Mar 2015 09:57:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:59764)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXVW0-0003vk-G8
	for bug-diffutils@gnu.org; Mon, 16 Mar 2015 09:57:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXVVv-0006Dl-H9
	for bug-diffutils@gnu.org; Mon, 16 Mar 2015 09:57:08 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:50091)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXVVv-0006Dh-EU
	for bug-diffutils@gnu.org; Mon, 16 Mar 2015 09:57:03 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXVVu-0005g7-Qj
	for bug-diffutils@gnu.org; Mon, 16 Mar 2015 09:57:03 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Norihiro Tanaka <noritnk@kcn.ne.jp>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Mon, 16 Mar 2015 13:57:02 +0000
Resent-Message-ID: <handler.20062.B20062.142651421921815@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142651421921815
	(code B ref 20062); Mon, 16 Mar 2015 13:57:02 +0000
Received: (at 20062) by debbugs.gnu.org; 16 Mar 2015 13:56:59 +0000
Received: from localhost ([127.0.0.1]:48659 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YXVVq-0005fn-MK
	for submit@debbugs.gnu.org; Mon, 16 Mar 2015 09:56:59 -0400
Received: from mailgw01.kcn.ne.jp ([61.86.7.208]:37845)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <noritnk@kcn.ne.jp>) id 1YXVVk-0005fd-AM
	for 20062@debbugs.gnu.org; Mon, 16 Mar 2015 09:56:53 -0400
Received: from mxs02-s (mailgw2.kcn.ne.jp [61.86.15.234])
	by mailgw01.kcn.ne.jp (Postfix) with ESMTP id E356E803A6
	for <20062@debbugs.gnu.org>; Mon, 16 Mar 2015 22:56:49 +0900 (JST)
X-matriXscan-loop-detect: 575294e2d310977090c9f2b1a200879e66ae20e9
Received: from mail08.kcn.ne.jp ([61.86.6.187]) by mxs02-s with ESMTP;
	Mon, 16 Mar 2015 22:56:47 +0900 (JST)
Received: from [10.120.1.36] (i118-21-128-66.s30.a048.ap.plala.or.jp
	[118.21.128.66])
	by mail08.kcn.ne.jp (Postfix) with ESMTPA id E28FF12B8098;
	Mon, 16 Mar 2015 22:56:46 +0900 (JST)
Date: Mon, 16 Mar 2015 22:56:49 +0900
From: Norihiro Tanaka <noritnk@kcn.ne.jp>
In-Reply-To: <8738554v5n.fsf@redhat.com>
References: <20150316085409.4996.27F6AC2D@kcn.ne.jp>
	<8738554v5n.fsf@redhat.com>
Message-Id: <20150316225648.721C.27F6AC2D@kcn.ne.jp>
MIME-Version: 1.0
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-Mailer: Becky! ver. 2.65.07 [ja]
X-matriXscan-CTCmd-AV: Clean
X-matriXscan-Action: Approve
X-matriXscan: Uncategorized
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062 <20062@debbugs.gnu.org>
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062:
	bug#20062: [PATCH] diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 16 Mar 2015 13:57:10 -0000

On Mon, 16 Mar 2015 01:56:36 +0100
Giuseppe Scrivano <gscrivan@redhat.com> wrote:

> Norihiro Tanaka <noritnk@kcn.ne.jp> writes:
> 
> > On Mon, 16 Mar 2015 08:49:29 +0900
> > Norihiro Tanaka <noritnk@kcn.ne.jp> wrote:
> >
> >> AUTO and ALWAYS are POSIX incompatible,
> >
> > In addition, if the default is AUTO, and they are also imcompatible with
> > previous versions of DIFF by default.
> 
> I meant the default if --color is specified.  That is not incompatible
> with any previous version since --color was not present.
> 
> Apparently, ls and grep already behaves differently for --color so diff
> is not going to make any other difference here.  "ls --color" means "ls
> --color=always" while "grep --color" behaves like "grep --color=auto".
> Having to choose between these two, --color=auto makes more sense for
> diff where redirection to files is a common operation.
> 
> I am attaching the latest version of the patch, taking into account
> comments from Andreas.  I have added colors for header and line numbers,
> following the "git diff" colors scheme.
> 
> Thanks,
> Giuseppe

I understood that you said, agree.

Thanks,
Norihiro





From MAILER-DAEMON Mon Mar 16 12:22:10 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YXXmM-0008GE-87
	for mharc-bug-diffutils@gnu.org; Mon, 16 Mar 2015 12:22:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:43042)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXXmJ-0008Ed-Co
	for bug-diffutils@gnu.org; Mon, 16 Mar 2015 12:22:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXXmF-00068q-O2
	for bug-diffutils@gnu.org; Mon, 16 Mar 2015 12:22:07 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:50196)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXXmF-00068k-Ki
	for bug-diffutils@gnu.org; Mon, 16 Mar 2015 12:22:03 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXXmF-0000sG-CR
	for bug-diffutils@gnu.org; Mon, 16 Mar 2015 12:22:03 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Mon, 16 Mar 2015 16:22:03 +0000
Resent-Message-ID: <handler.20062.B20062.14265229043322@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.14265229043322
	(code B ref 20062); Mon, 16 Mar 2015 16:22:03 +0000
Received: (at 20062) by debbugs.gnu.org; 16 Mar 2015 16:21:44 +0000
Received: from localhost ([127.0.0.1]:48762 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YXXlw-0000rV-3u
	for submit@debbugs.gnu.org; Mon, 16 Mar 2015 12:21:44 -0400
Received: from mail-oi0-f54.google.com ([209.85.218.54]:33689)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <andreas.gruenbacher@gmail.com>) id 1YXXlt-0000rN-M5
	for 20062@debbugs.gnu.org; Mon, 16 Mar 2015 12:21:42 -0400
Received: by oibu204 with SMTP id u204so42287730oib.0
	for <20062@debbugs.gnu.org>; Mon, 16 Mar 2015 09:21:41 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:date:message-id:subject
	:from:to:cc:content-type;
	bh=ZHGmT6vsUnldwhEtDXhlqa+fuT+NouVMYeTP88Lv3h8=;
	b=EyN2uiGrowsJaVM3hCPujbO/8oJ+JLJQ9sSBwb3iKywiQRdqqmjnTD3I/B68gkboVG
	SY3MqeYYQj1GE9Q4VJ+y9yeR8nSP4QxKPbWcFo7PxNRSKKwdZh0XrGOEYx82v/3t12XV
	G0FIklHjarCwycPK4Ix8/sRRzIy8MdwAlTIg0Gd8npNecEoQZDfHBleFCONaBkMUV0xx
	5EiWuM1c6zWYd97qNnDazXS3L356SyRJ1moC6Iqk/waIgRhanYz7RnTQS7mUf/Nn1r5b
	kq08b86zLtur/Y+ty2pPJ16dcB4hGxEPxT1Ds/xbwRwTt5Chr9czjiyoBHmhiETEF4O0
	PlKQ==
MIME-Version: 1.0
X-Received: by 10.60.112.65 with SMTP id io1mr39435833oeb.66.1426522900873;
	Mon, 16 Mar 2015 09:21:40 -0700 (PDT)
Received: by 10.182.118.66 with HTTP; Mon, 16 Mar 2015 09:21:40 -0700 (PDT)
In-Reply-To: <87wq2i3tf9.fsf@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com> <54FF1A4C.6080104@cs.ucla.edu>
	<87k2yoebrl.fsf@redhat.com> <54FF7742.6050500@cs.ucla.edu>
	<87egowctaa.fsf@redhat.com> <54FF870C.5000902@cs.ucla.edu>
	<878uf3b92g.fsf@redhat.com> <5500CD49.1060505@cs.ucla.edu>
	<87twxqa884.fsf@redhat.com> <5501A668.5050104@cs.ucla.edu>
	<87pp8d9ap1.fsf@redhat.com> <55020934.8080505@cs.ucla.edu>
	<87h9tp91uy.fsf@redhat.com> <55023863.6000407@cs.ucla.edu>
	<87wq2l6u7s.fsf@redhat.com> <87oanw7otj.fsf@redhat.com>
	<CAHpGcMJ3em9Ld0cjXfNYWX0uF+2V_nyJxY+oo4KSUgrJ7LAWvg@mail.gmail.com>
	<87wq2i3tf9.fsf@redhat.com>
Date: Mon, 16 Mar 2015 17:21:40 +0100
X-Google-Sender-Auth: S0-dOyU2FSZxqLxdCP62n7ETIpI
Message-ID: <CAHpGcMK5VgM=5hp63g8vFCLYBv-qgv_jcErYf2O3kOyEM6eV-A@mail.gmail.com>
From: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Content-Type: text/plain; charset=UTF-8
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062 <20062@debbugs.gnu.org>
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062: [PATCH]
	diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 16 Mar 2015 16:22:08 -0000

2015-03-15 21:19 GMT+01:00 Giuseppe Scrivano <gscrivan@redhat.com>:
> I've basically copied this section from coreutils.  What doesn't make
> sense to you?

+@item --color [=@var{when}]
+@cindex color, distinguishing file types with
+Specify whether to use color for distinguishing file types.  @var{when}
[...]

Color is used to distinguish between file types in ls, but not in
diff. Simply reading what you've copied from coreutils would have been
enough to figure that out.

Andreas




From MAILER-DAEMON Mon Mar 16 14:31:12 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YXZnE-0007H7-5n
	for mharc-bug-diffutils@gnu.org; Mon, 16 Mar 2015 14:31:12 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:51047)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXZnA-0007BN-Is
	for bug-diffutils@gnu.org; Mon, 16 Mar 2015 14:31:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXZn5-0000vJ-Nn
	for bug-diffutils@gnu.org; Mon, 16 Mar 2015 14:31:08 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:50269)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXZn5-0000vF-Kb
	for bug-diffutils@gnu.org; Mon, 16 Mar 2015 14:31:03 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YXZn5-0004DB-DK
	for bug-diffutils@gnu.org; Mon, 16 Mar 2015 14:31:03 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Mon, 16 Mar 2015 18:31:03 +0000
Resent-Message-ID: <handler.20062.B20062.142653063716109@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Andreas =?UTF-8?Q?Gr=C3=BCnbacher?= <agruen@gnu.org>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142653063716109
	(code B ref 20062); Mon, 16 Mar 2015 18:31:03 +0000
Received: (at 20062) by debbugs.gnu.org; 16 Mar 2015 18:30:37 +0000
Received: from localhost ([127.0.0.1]:48829 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YXZmf-0004Bl-1P
	for submit@debbugs.gnu.org; Mon, 16 Mar 2015 14:30:37 -0400
Received: from mx1.redhat.com ([209.132.183.28]:55711)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YXZmb-0004BV-Rd
	for 20062@debbugs.gnu.org; Mon, 16 Mar 2015 14:30:34 -0400
Received: from int-mx11.intmail.prod.int.phx2.redhat.com
	(int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2GIUVi9010996
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL); Mon, 16 Mar 2015 14:30:31 -0400
Received: from foobarbaz (vpn1-4-233.ams2.redhat.com [10.36.4.233])
	by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2GIURlq002181
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Mon, 16 Mar 2015 14:30:29 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<87fv9dj28c.fsf@redhat.com> <874mptgo2c.fsf@redhat.com>
	<54FF1A4C.6080104@cs.ucla.edu> <87k2yoebrl.fsf@redhat.com>
	<54FF7742.6050500@cs.ucla.edu> <87egowctaa.fsf@redhat.com>
	<54FF870C.5000902@cs.ucla.edu> <878uf3b92g.fsf@redhat.com>
	<5500CD49.1060505@cs.ucla.edu> <87twxqa884.fsf@redhat.com>
	<5501A668.5050104@cs.ucla.edu> <87pp8d9ap1.fsf@redhat.com>
	<55020934.8080505@cs.ucla.edu> <87h9tp91uy.fsf@redhat.com>
	<55023863.6000407@cs.ucla.edu> <87wq2l6u7s.fsf@redhat.com>
	<87oanw7otj.fsf@redhat.com>
	<CAHpGcMJ3em9Ld0cjXfNYWX0uF+2V_nyJxY+oo4KSUgrJ7LAWvg@mail.gmail.com>
	<87wq2i3tf9.fsf@redhat.com>
	<CAHpGcMK5VgM=5hp63g8vFCLYBv-qgv_jcErYf2O3kOyEM6eV-A@mail.gmail.com>
Date: Mon, 16 Mar 2015 19:30:27 +0100
In-Reply-To: <CAHpGcMK5VgM=5hp63g8vFCLYBv-qgv_jcErYf2O3kOyEM6eV-A@mail.gmail.com>
	("Andreas \=\?utf-8\?Q\?Gr\=C3\=BCnbacher\=22's\?\= message of "Mon,
	16 Mar 2015 17:21:40 +0100")
Message-ID: <87pp88ztfg.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062 <20062@debbugs.gnu.org>
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062: [PATCH]
	diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 16 Mar 2015 18:31:09 -0000

Andreas Gr=C3=BCnbacher <agruen@gnu.org> writes:

> 2015-03-15 21:19 GMT+01:00 Giuseppe Scrivano <gscrivan@redhat.com>:
>> I've basically copied this section from coreutils.  What doesn't make
>> sense to you?
>
> +@item --color [=3D@var{when}]
> +@cindex color, distinguishing file types with
> +Specify whether to use color for distinguishing file types.  @var{when}
> [...]
>
> Color is used to distinguish between file types in ls, but not in
> diff. Simply reading what you've copied from coreutils would have been
> enough to figure that out.

I see, sorry for that.  I copied it straight without paying much
attention, I had to be more careful.

Thanks,
Giuseppe




From MAILER-DAEMON Wed Mar 18 19:39:11 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1YYNYN-0000eQ-14
	for mharc-bug-diffutils@gnu.org; Wed, 18 Mar 2015 19:39:11 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:39845)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YYNYK-0000eB-0H
	for bug-diffutils@gnu.org; Wed, 18 Mar 2015 19:39:10 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YYNYE-0001Io-SV
	for bug-diffutils@gnu.org; Wed, 18 Mar 2015 19:39:07 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:53507)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YYNYE-0001Ik-Nl
	for bug-diffutils@gnu.org; Wed, 18 Mar 2015 19:39:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1YYNYE-0008W8-BM
	for bug-diffutils@gnu.org; Wed, 18 Mar 2015 19:39:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Wed, 18 Mar 2015 23:39:02 +0000
Resent-Message-ID: <handler.20062.B20062.142672190532694@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Paul Eggert <eggert@cs.ucla.edu>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142672190532694
	(code B ref 20062); Wed, 18 Mar 2015 23:39:02 +0000
Received: (at 20062) by debbugs.gnu.org; 18 Mar 2015 23:38:25 +0000
Received: from localhost ([127.0.0.1]:52075 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YYNXb-0008VE-Sg
	for submit@debbugs.gnu.org; Wed, 18 Mar 2015 19:38:25 -0400
Received: from mx1.redhat.com ([209.132.183.28]:44636)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YYNXZ-0008V4-38
	for 20062@debbugs.gnu.org; Wed, 18 Mar 2015 19:38:23 -0400
Received: from int-mx09.intmail.prod.int.phx2.redhat.com
	(int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22])
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2INcJPB004423
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=FAIL); Wed, 18 Mar 2015 19:38:19 -0400
Received: from foobarbaz (vpn1-6-206.ams2.redhat.com [10.36.6.206])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2INcFIQ022782
	(version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO);
	Wed, 18 Mar 2015 19:38:17 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<54FDB353.8060801@redhat.com> <87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com> <54FF1A4C.6080104@cs.ucla.edu>
	<87k2yoebrl.fsf@redhat.com> <54FF7742.6050500@cs.ucla.edu>
	<87egowctaa.fsf@redhat.com> <54FF870C.5000902@cs.ucla.edu>
	<878uf3b92g.fsf@redhat.com> <5500CD49.1060505@cs.ucla.edu>
	<87twxqa884.fsf@redhat.com> <5501A668.5050104@cs.ucla.edu>
	<87pp8d9ap1.fsf@redhat.com> <55020934.8080505@cs.ucla.edu>
	<87h9tp91uy.fsf@redhat.com> <55023863.6000407@cs.ucla.edu>
	<87wq2l6u7s.fsf@redhat.com> <87oanw7otj.fsf@redhat.com>
	<CAHpGcMJ3em9Ld0cjXfNYWX0uF+2V_nyJxY+oo4KSUgrJ7LAWvg@mail.gmail.com>
	<87wq2i3tf9.fsf@redhat.com>
Date: Thu, 19 Mar 2015 00:38:15 +0100
In-Reply-To: <87wq2i3tf9.fsf@redhat.com> (Giuseppe Scrivano's message of "Sun, 
	15 Mar 2015 21:19:22 +0100")
Message-ID: <87wq2duba0.fsf_-_@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 18 Mar 2015 23:39:10 -0000

--=-=-=
Content-Type: text/plain

Hi Paul,

I've attached the last version of the patch.  Is there anything left
that should be done?

Thanks,
Giuseppe


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=0001-diff-add-support-for-color.patch

>From 8b39f7297c0137af62336ad79044271803b66299 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Sun, 8 Mar 2015 22:45:11 +0100
Subject: [PATCH] diff: add support for --color

* doc/diffutils.texi (diff Options): Add documentation for --color.
Copied from coreutils ls --color.
* src/context.c (pr_unidiff_hunk): Set the color context.
(print_context_header): Likewise.
(pr_context_hunk): Likewise.
* src/diff.h (enum colors_style): New enum to record when to use colors.
(colors_style): New variable to memorize the argument value.
(set_add_color_context): Add function definition.
(set_delete_color_context): Likewise.
(set_header_color_context): Likewise.
(set_line_numbers_color_context): Likewise.
(reset_color_context): Likewise.
* src/diff.c: : Define COLOR_OPTION.
(specify_colors_style): New function.
(longopts): Add --color.
(main): Handle --color argument.
(option_help_msgid): Add usage string for --color.
* src/normal.c (print_normal_hunk): Set the color context.
* src/side.c (print_1sdiff_line): Likewise.
* src/util.c (colors_enabled): New boolean variable.
(begin_output): Call check_color_output once the output file is
configured.
(colors_enabled): New boolean variable.
(check_color_output): New function.
(install_signal_handlers): Likewise.
(signal_handler): Likewise.
(set_add_color_context): Likewise.
(set_delete_color_context): Likewise.
(reset_color_context): Likewise.
(set_header_color_context): Likewise.
(set_line_numbers_color_context): Likewise.
---
 doc/diffutils.texi |  21 +++++++++
 src/context.c      |  51 ++++++++++++++++++----
 src/diff.c         |  27 +++++++++++-
 src/diff.h         |  21 +++++++++
 src/normal.c       |  18 ++++++--
 src/side.c         |  15 +++++++
 src/util.c         | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 265 insertions(+), 14 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 3e25807..dd5a1c6 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3745,6 +3745,27 @@ Read and write data in binary mode.  @xref{Binary}.
 Use the context output format, showing three lines of context.
 @xref{Context Format}.
 
+@item --color [=@var{when}]
+@cindex color, distinguishing different context
+Specify whether to use color for distinguishing different contexts,
+like header, added or removed lines.  @var{when} may be omitted, or
+one of:
+@itemize @bullet
+@item none
+@vindex none @r{color option}
+Do not use color at all.  This is the default when no --color option
+is present.
+@item auto
+@vindex auto @r{color option}
+@cindex terminal, using color iff
+Only use color if standard output is a terminal.
+@item always
+@vindex always @r{color option}
+Always use color.
+@end itemize
+Specifying @option{--color} and no @var{when} is equivalent to
+@option{--color=auto}.
+
 @item -C @var{lines}
 @itemx --context@r{[}=@var{lines}@r{]}
 Use the context output format, showing @var{lines} (an integer) lines of
diff --git a/src/context.c b/src/context.c
index e0f21c4..9b23d36 100644
--- a/src/context.c
+++ b/src/context.c
@@ -80,6 +80,7 @@ print_context_label (char const *mark,
 void
 print_context_header (struct file_data inf[], char const *const *names, bool unidiff)
 {
+  set_header_color_context ();
   if (unidiff)
     {
       print_context_label ("---", &inf[0], names[0], file_label[0]);
@@ -90,6 +91,7 @@ print_context_header (struct file_data inf[], char const *const *names, bool uni
       print_context_label ("***", &inf[0], names[0], file_label[0]);
       print_context_label ("---", &inf[1], names[1], file_label[1]);
     }
+  reset_color_context (false);
 }
 
 /* Print an edit script in context format.  */
@@ -215,6 +217,7 @@ pr_context_hunk (struct change *hunk)
 
       for (i = first0; i <= last0; i++)
 	{
+          bool reset_context = false;
 	  /* Skip past changes that apply (in file 0)
 	     only to lines before line I.  */
 
@@ -225,12 +228,18 @@ pr_context_hunk (struct change *hunk)
 
 	  prefix = " ";
 	  if (next && next->line0 <= i)
-	    /* The change NEXT covers this line.
-	       If lines were inserted here in file 1, this is "changed".
-	       Otherwise it is "deleted".  */
-	    prefix = (next->inserted > 0 ? "!" : "-");
+            {
+              reset_context = true;
+              set_delete_color_context ();
+              /* The change NEXT covers this line.
+                 If lines were inserted here in file 1, this is "changed".
+                 Otherwise it is "deleted".  */
+              prefix = (next->inserted > 0 ? "!" : "-");
+            }
 
 	  print_1_line (prefix, &files[0].linbuf[i]);
+          if (reset_context)
+            reset_color_context (false);
 	}
     }
 
@@ -244,6 +253,7 @@ pr_context_hunk (struct change *hunk)
 
       for (i = first1; i <= last1; i++)
 	{
+          bool reset_context = false;
 	  /* Skip past changes that apply (in file 1)
 	     only to lines before line I.  */
 
@@ -254,12 +264,17 @@ pr_context_hunk (struct change *hunk)
 
 	  prefix = " ";
 	  if (next && next->line1 <= i)
-	    /* The change NEXT covers this line.
-	       If lines were deleted here in file 0, this is "changed".
-	       Otherwise it is "inserted".  */
-	    prefix = (next->deleted > 0 ? "!" : "+");
-
+            {
+              reset_context = true;
+              set_add_color_context ();
+              /* The change NEXT covers this line.
+                 If lines were deleted here in file 0, this is "changed".
+                 Otherwise it is "inserted".  */
+              prefix = (next->deleted > 0 ? "!" : "+");
+            }
 	  print_1_line (prefix, &files[1].linbuf[i]);
+          if (reset_context)
+            reset_color_context (false);
 	}
     }
 }
@@ -330,11 +345,13 @@ pr_unidiff_hunk (struct change *hunk)
   begin_output ();
   out = outfile;
 
+  set_line_numbers_color_context ();
   fputs ("@@ -", out);
   print_unidiff_number_range (&files[0], first0, last0);
   fputs (" +", out);
   print_unidiff_number_range (&files[1], first1, last1);
   fputs (" @@", out);
+  reset_color_context (false);
 
   if (function)
     print_context_function (out, function);
@@ -360,9 +377,17 @@ pr_unidiff_hunk (struct change *hunk)
 	}
       else
 	{
+          bool reset_context = false;
+
 	  /* For each difference, first output the deleted part. */
 
 	  k = next->deleted;
+          if (k)
+            {
+              reset_context = true;
+              set_delete_color_context ();
+            }
+
 	  while (k--)
 	    {
 	      char const * const *line = &files[0].linbuf[i++];
@@ -375,9 +400,15 @@ pr_unidiff_hunk (struct change *hunk)
 	  /* Then output the inserted part. */
 
 	  k = next->inserted;
+          if (k)
+            {
+              reset_context = true;
+              set_add_color_context ();
+            }
 	  while (k--)
 	    {
 	      char const * const *line = &files[1].linbuf[j++];
+	      set_add_color_context ();
 	      putc ('+', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
@@ -386,6 +417,8 @@ pr_unidiff_hunk (struct change *hunk)
 
 	  /* We're done with this hunk, so on to the next! */
 
+          if (reset_context)
+            reset_color_context (false);
 	  next = next->link;
 	}
     }
diff --git a/src/diff.c b/src/diff.c
index ff28377..be6e6e3 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -70,6 +70,7 @@ static void add_regexp (struct regexp_list *, char const *);
 static void summarize_regexp_list (struct regexp_list *);
 static void specify_style (enum output_style);
 static void specify_value (char const **, char const *, char const *);
+static void specify_colors_style (char const *);
 static void try_help (char const *, char const *) __attribute__((noreturn));
 static void check_stdout (void);
 static void usage (void);
@@ -136,7 +137,9 @@ enum
   UNCHANGED_GROUP_FORMAT_OPTION,
   OLD_GROUP_FORMAT_OPTION,
   NEW_GROUP_FORMAT_OPTION,
-  CHANGED_GROUP_FORMAT_OPTION
+  CHANGED_GROUP_FORMAT_OPTION,
+
+  COLOR_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -159,6 +162,7 @@ static struct option const longopts[] =
   {"binary", 0, 0, BINARY_OPTION},
   {"brief", 0, 0, 'q'},
   {"changed-group-format", 1, 0, CHANGED_GROUP_FORMAT_OPTION},
+  {"color", 2, 0, COLOR_OPTION},
   {"context", 2, 0, 'C'},
   {"ed", 0, 0, 'e'},
   {"exclude", 1, 0, 'x'},
@@ -627,6 +631,10 @@ main (int argc, char **argv)
 	  specify_value (&group_format[c], optarg, group_format_option[c]);
 	  break;
 
+	case COLOR_OPTION:
+	  specify_colors_style (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
@@ -940,6 +948,8 @@ static char const * const option_help_msgid[] = {
   N_("-d, --minimal            try hard to find a smaller set of changes"),
   N_("    --horizon-lines=NUM  keep NUM lines of the common prefix and suffix"),
   N_("    --speed-large-files  assume large files and many scattered small changes"),
+  N_("    --color[=WHEN]         colorize the output; WHEN can be 'never', 'always',"),
+  N_("                             or 'auto' (the default)"),
   "",
   N_("    --help               display this help and exit"),
   N_("-v, --version            output version information and exit"),
@@ -1008,6 +1018,21 @@ specify_style (enum output_style style)
       output_style = style;
     }
 }
+
+/* Set the color mode.  */
+static void
+specify_colors_style (char const *value)
+{
+  if (value == NULL || STREQ (value, "auto"))
+    colors_style = AUTO;
+  else if (STREQ (value, "always"))
+    colors_style = ALWAYS;
+  else if (STREQ (value, "never"))
+    colors_style = NEVER;
+  else
+    try_help ("invalid color '%s'", value);
+}
+
 
 /* Set the last-modified time of *ST to be the current time.  */
 
diff --git a/src/diff.h b/src/diff.h
index 465e4bc..553bad1 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -38,6 +38,19 @@ enum changes
   /* Both deletes and inserts: a hunk containing both old and new lines.  */
   CHANGED
 };
+
+/* What kind of changes a hunk contains.  */
+enum colors_style
+{
+  /* Never output colors.  */
+  NEVER,
+
+  /* Output colors if the output is a terminal.  */
+  AUTO,
+
+  /* Always output colors.  */
+  ALWAYS,
+};
 
 /* Variables for command line options */
 
@@ -83,6 +96,9 @@ enum output_style
 
 XTERN enum output_style output_style;
 
+/* Define the current color context used to print a line.  */
+XTERN enum colors_style colors_style;
+
 /* Nonzero if output cannot be generated for identical files.  */
 XTERN bool no_diff_means_no_output;
 
@@ -390,3 +406,8 @@ extern void print_script (struct change *, struct change * (*) (struct change *)
 extern void setup_output (char const *, char const *, bool);
 extern void translate_range (struct file_data const *, lin, lin,
                              long int *, long int *);
+extern void set_header_color_context (void);
+extern void set_add_color_context (void);
+extern void set_delete_color_context (void);
+extern void reset_color_context (bool from_signal);
+extern void set_line_numbers_color_context (void);
diff --git a/src/normal.c b/src/normal.c
index 721fd1a..0ce01ee 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -49,21 +49,31 @@ print_normal_hunk (struct change *hunk)
   begin_output ();
 
   /* Print out the line number header for this hunk */
+  set_line_numbers_color_context ();
   print_number_range (',', &files[0], first0, last0);
   fputc (change_letter[changes], outfile);
   print_number_range (',', &files[1], first1, last1);
   fputc ('\n', outfile);
+  reset_color_context (false);
 
   /* Print the lines that the first file has.  */
   if (changes & OLD)
-    for (i = first0; i <= last0; i++)
-      print_1_line ("<", &files[0].linbuf[i]);
+    {
+      set_delete_color_context ();
+      for (i = first0; i <= last0; i++)
+        print_1_line ("<", &files[0].linbuf[i]);
+      reset_color_context (false);
+    }
 
   if (changes == CHANGED)
     fputs ("---\n", outfile);
 
   /* Print the lines that the second file has.  */
   if (changes & NEW)
-    for (i = first1; i <= last1; i++)
-      print_1_line (">", &files[1].linbuf[i]);
+    {
+      set_add_color_context ();
+      for (i = first1; i <= last1; i++)
+        print_1_line (">", &files[1].linbuf[i]);
+      reset_color_context (false);
+    }
 }
diff --git a/src/side.c b/src/side.c
index 155512c..8327d11 100644
--- a/src/side.c
+++ b/src/side.c
@@ -206,6 +206,18 @@ print_1sdiff_line (char const *const *left, char sep,
   size_t c2o = sdiff_column2_offset;
   size_t col = 0;
   bool put_newline = false;
+  bool color_to_reset = false;
+
+  if (sep == '<')
+    {
+      set_delete_color_context ();
+      color_to_reset = true;
+    }
+  else if (sep == '>')
+    {
+      set_add_color_context ();
+      color_to_reset = true;
+    }
 
   if (left)
     {
@@ -233,6 +245,9 @@ print_1sdiff_line (char const *const *left, char sep,
 
   if (put_newline)
     putc ('\n', out);
+
+  if (color_to_reset)
+    reset_color_context (false);
 }
 
 /* Print lines common to both files in side-by-side format.  */
diff --git a/src/util.c b/src/util.c
index 2d6d3fc..0f8f7a8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -24,6 +24,7 @@
 #include <system-quote.h>
 #include <xalloc.h>
 #include "xvasprintf.h"
+#include <signal.h>
 
 char const pr_program[] = PR_PROGRAM;
 
@@ -143,6 +144,59 @@ print_message_queue (void)
     }
 }
 
+static void
+signal_handler (int sig)
+{
+  reset_color_context (true);
+
+  /* Restore the default handler, and report the signal again.  */
+  signal (sig, SIG_DFL);
+  raise (sig);
+}
+
+static void
+install_signal_handlers (void)
+{
+  int j;
+#if HAVE_SIGACTION
+  struct sigaction act;
+#endif
+  int const sig[] =
+    {
+      SIGTSTP,
+      SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,
+#ifdef SIGPOLL
+      SIGPOLL,
+#endif
+#ifdef SIGPROF
+      SIGPROF,
+#endif
+#ifdef SIGVTALRM
+      SIGVTALRM,
+#endif
+#ifdef SIGXCPU
+      SIGXCPU,
+#endif
+#ifdef SIGXFSZ
+      SIGXFSZ,
+#endif
+    };
+
+  for (j = 0; j < sizeof (sig) / sizeof (*sig); j++)
+    {
+#if HAVE_SIGACTION
+      sigaction (sig[j], NULL, &act);
+      if (act.sa_handler != SIG_IGN)
+        {
+          act.sa_handler = signal_handler;
+          sigaction (sig[j], &act, NULL);
+        }
+#else
+      signal (sig[j], signal_handler);
+#endif
+    }
+}
+
 /* Call before outputting the results of comparing files NAME0 and NAME1
    to set up OUTFILE, the stdio stream for the output to go to.
 
@@ -153,6 +207,24 @@ print_message_queue (void)
 static char const *current_name0;
 static char const *current_name1;
 static bool currently_recursive;
+static bool colors_enabled;
+static bool output_is_tty;
+
+static void
+check_color_output (bool is_pipe)
+{
+  if (! outfile)
+    return;
+
+  output_is_tty = (colors_style != NEVER && !is_pipe
+                   && isatty (fileno (outfile)));
+
+  colors_enabled = (colors_style == ALWAYS
+                    || (colors_style == AUTO && output_is_tty));
+
+  if (output_is_tty)
+    install_signal_handlers ();
+}
 
 void
 setup_output (char const *name0, char const *name1, bool recursive)
@@ -313,6 +385,7 @@ begin_output (void)
 	    outfile = fdopen (pipes[1], "w");
 	    if (!outfile)
 	      pfatal_with_name ("fdopen");
+	    check_color_output (true);
 	  }
 #else
 	char *command = system_quote_argv (SCI_SYSTEM, (char **) argv);
@@ -320,6 +393,7 @@ begin_output (void)
 	outfile = popen (command, "w");
 	if (!outfile)
 	  pfatal_with_name (command);
+	check_color_output (true);
 	free (command);
 #endif
       }
@@ -330,6 +404,7 @@ begin_output (void)
       /* If -l was not specified, output the diff straight to 'stdout'.  */
 
       outfile = stdout;
+      check_color_output (false);
 
       /* If handling multiple files (because scanning a directory),
 	 print which files the following output is about.  */
@@ -717,6 +792,57 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
     }
 }
 
+void
+set_header_color_context (void)
+{
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[1;39m");
+}
+
+void
+set_line_numbers_color_context (void)
+{
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[36m");
+}
+
+void
+set_add_color_context (void)
+{
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[32m");
+}
+
+void
+set_delete_color_context (void)
+{
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[31m");
+}
+
+void
+reset_color_context (bool from_signal)
+{
+  static char const reset_sequence[] = "\x1b[0m";
+  if (! colors_enabled)
+    return;
+
+  if (! from_signal)
+    fputs (reset_sequence, outfile);
+  else
+    {
+      size_t written = 0;
+      while (written < sizeof reset_sequence - 1)
+        {
+          int ret = write (STDOUT_FILENO, reset_sequence + written,
+                           sizeof reset_sequence - 1 - written);
+          if (ret < 0)
+            return;
+          written += ret;
+        }
+    }
+}
+
 char const change_letter[] = { 0, 'd', 'a', 'c' };
 
 /* Translate an internal line number (an index into diff's table of lines)
-- 
2.1.0


--=-=-=--




From MAILER-DAEMON Sat Mar 28 06:14:08 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Ybnkm-0004Ug-5W
	for mharc-bug-diffutils@gnu.org; Sat, 28 Mar 2015 06:14:08 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:47873)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Ybnkk-0004Ua-1h
	for bug-diffutils@gnu.org; Sat, 28 Mar 2015 06:14:06 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Ybnkg-0004m9-Rt
	for bug-diffutils@gnu.org; Sat, 28 Mar 2015 06:14:05 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:48791)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Ybnkg-0004lv-Oz
	for bug-diffutils@gnu.org; Sat, 28 Mar 2015 06:14:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Ybnkf-0002ip-S3
	for bug-diffutils@gnu.org; Sat, 28 Mar 2015 06:14:01 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivan@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Sat, 28 Mar 2015 10:14:01 +0000
Resent-Message-ID: <handler.20062.B20062.142753762310427@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: 20062@debbugs.gnu.org
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.142753762310427
	(code B ref 20062); Sat, 28 Mar 2015 10:14:01 +0000
Received: (at 20062) by debbugs.gnu.org; 28 Mar 2015 10:13:43 +0000
Received: from localhost ([127.0.0.1]:38567 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1YbnkN-0002i7-3J
	for submit@debbugs.gnu.org; Sat, 28 Mar 2015 06:13:43 -0400
Received: from mx1.redhat.com ([209.132.183.28]:56446)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivan@redhat.com>) id 1YbnkK-0002hy-TD
	for 20062@debbugs.gnu.org; Sat, 28 Mar 2015 06:13:41 -0400
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (Postfix) with ESMTPS id D5F36AC7D7;
	Sat, 28 Mar 2015 10:13:39 +0000 (UTC)
Received: from foobarbaz (vpn1-6-107.ams2.redhat.com [10.36.6.107])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t2SADaqq025364
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=NO); Sat, 28 Mar 2015 06:13:38 -0400
From: Giuseppe Scrivano <gscrivan@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<87fv9dj28c.fsf@redhat.com> <874mptgo2c.fsf@redhat.com>
	<54FF1A4C.6080104@cs.ucla.edu> <87k2yoebrl.fsf@redhat.com>
	<54FF7742.6050500@cs.ucla.edu> <87egowctaa.fsf@redhat.com>
	<54FF870C.5000902@cs.ucla.edu> <878uf3b92g.fsf@redhat.com>
	<5500CD49.1060505@cs.ucla.edu> <87twxqa884.fsf@redhat.com>
	<5501A668.5050104@cs.ucla.edu> <87pp8d9ap1.fsf@redhat.com>
	<55020934.8080505@cs.ucla.edu> <87h9tp91uy.fsf@redhat.com>
	<55023863.6000407@cs.ucla.edu> <87wq2l6u7s.fsf@redhat.com>
	<87oanw7otj.fsf@redhat.com>
	<CAHpGcMJ3em9Ld0cjXfNYWX0uF+2V_nyJxY+oo4KSUgrJ7LAWvg@mail.gmail.com>
	<87wq2i3tf9.fsf@redhat.com> <87wq2duba0.fsf_-_@redhat.com>
Date: Sat, 28 Mar 2015 11:13:35 +0100
In-Reply-To: <87wq2duba0.fsf_-_@redhat.com> (Giuseppe Scrivano's message of
	"Thu, 19 Mar 2015 00:38:15 +0100")
Message-ID: <87d23t1lbk.fsf@redhat.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Subject: [bug-diffutils] bug#20062: bug#20062: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 28 Mar 2015 10:14:07 -0000

Giuseppe Scrivano <gscrivan@redhat.com> writes:

> I've attached the last version of the patch.  Is there anything left
> that should be done?

Is there anything holding this version of the patch?

Thanks,
Giuseppe




From MAILER-DAEMON Sat Mar 28 21:38:14 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Yc2B4-0003ai-Kh
	for mharc-bug-diffutils@gnu.org; Sat, 28 Mar 2015 21:38:14 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:40358)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Yc2B2-0003Zv-1Y
	for bug-diffutils@gnu.org; Sat, 28 Mar 2015 21:38:13 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Yc2At-0003ip-8q
	for bug-diffutils@gnu.org; Sat, 28 Mar 2015 21:38:11 -0400
Received: from debbugs.gnu.org ([140.186.70.43]:49456)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Yc2At-0003ik-5M
	for bug-diffutils@gnu.org; Sat, 28 Mar 2015 21:38:03 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Yc2As-0001Zv-PN
	for bug-diffutils@gnu.org; Sat, 28 Mar 2015 21:38:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Paul Eggert <eggert@cs.ucla.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Sun, 29 Mar 2015 01:38:02 +0000
Resent-Message-ID: <handler.20062.B20062.14275930456014@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 20062
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: patch
To: Giuseppe Scrivano <gscrivan@redhat.com>, 20062@debbugs.gnu.org
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.14275930456014
	(code B ref 20062); Sun, 29 Mar 2015 01:38:02 +0000
Received: (at 20062) by debbugs.gnu.org; 29 Mar 2015 01:37:25 +0000
Received: from localhost ([127.0.0.1]:39232 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1Yc2AH-0001Yw-BF
	for submit@debbugs.gnu.org; Sat, 28 Mar 2015 21:37:25 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:38585)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1Yc2AE-0001Yd-AQ
	for 20062@debbugs.gnu.org; Sat, 28 Mar 2015 21:37:23 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
	by smtp.cs.ucla.edu (Postfix) with ESMTP id 51AB8A60005;
	Sat, 28 Mar 2015 18:37:15 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
	by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id abH0Nv3aJRnt; Sat, 28 Mar 2015 18:37:15 -0700 (PDT)
Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net
	[100.32.155.148])
	by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 10E6B39E8014;
	Sat, 28 Mar 2015 18:37:15 -0700 (PDT)
Message-ID: <5517574A.2020508@cs.ucla.edu>
Date: Sat, 28 Mar 2015 18:37:14 -0700
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>	<87fv9dj28c.fsf@redhat.com>
	<874mptgo2c.fsf@redhat.com>	<54FF1A4C.6080104@cs.ucla.edu>
	<87k2yoebrl.fsf@redhat.com>	<54FF7742.6050500@cs.ucla.edu>
	<87egowctaa.fsf@redhat.com>	<54FF870C.5000902@cs.ucla.edu>
	<878uf3b92g.fsf@redhat.com>	<5500CD49.1060505@cs.ucla.edu>
	<87twxqa884.fsf@redhat.com>	<5501A668.5050104@cs.ucla.edu>
	<87pp8d9ap1.fsf@redhat.com>	<55020934.8080505@cs.ucla.edu>
	<87h9tp91uy.fsf@redhat.com>	<55023863.6000407@cs.ucla.edu>
	<87wq2l6u7s.fsf@redhat.com>	<87oanw7otj.fsf@redhat.com>	<CAHpGcMJ3em9Ld0cjXfNYWX0uF+2V_nyJxY+oo4KSUgrJ7LAWvg@mail.gmail.com>	<87wq2i3tf9.fsf@redhat.com>
	<87wq2duba0.fsf_-_@redhat.com> <87d23t1lbk.fsf@redhat.com>
In-Reply-To: <87d23t1lbk.fsf@redhat.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 140.186.70.43
Subject: [bug-diffutils] bug#20062: bug#20062: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 29 Mar 2015 01:38:13 -0000

Giuseppe Scrivano wrote:
> Is there anything holding this version of the patch?

Sorry, I haven't had time to review it carefully yet.  It's definitely on my 
list of things to do.




