From MAILER-DAEMON Thu Oct 08 03:39:48 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Zk5no-0003EE-K6
	for mharc-bug-diffutils@gnu.org; Thu, 08 Oct 2015 03:39:48 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:59791)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZhpQE-0001V2-EO
	for bug-diffutils@gnu.org; Thu, 01 Oct 2015 21:46:07 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZhpQB-0002is-6O
	for bug-diffutils@gnu.org; Thu, 01 Oct 2015 21:46:06 -0400
Received: from debbugs.gnu.org ([208.118.235.43]:33904)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZhpQB-0002iV-3K
	for bug-diffutils@gnu.org; Thu, 01 Oct 2015 21:46:03 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZhpQA-0005JC-HH
	for bug-diffutils@gnu.org; Thu, 01 Oct 2015 21:46:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Song Li <lisong@stanford.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Fri, 02 Oct 2015 01:46:02 +0000
Resent-Message-ID: <handler.21579.B21579.144375030220311@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 21579
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: Jim Meyering <jim@meyering.net>
Received: via spool by 21579-submit@debbugs.gnu.org id=B21579.144375030220311
	(code B ref 21579); Fri, 02 Oct 2015 01:46:02 +0000
Received: (at 21579) by debbugs.gnu.org; 2 Oct 2015 01:45:02 +0000
Received: from localhost ([127.0.0.1]:51108 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZhpPB-0005HM-2q
	for submit@debbugs.gnu.org; Thu, 01 Oct 2015 21:45:01 -0400
Received: from mail-pa0-f49.google.com ([209.85.220.49]:33831)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <lisong.pine@gmail.com>) id 1ZhpP7-0005HD-LO
	for 21579@debbugs.gnu.org; Thu, 01 Oct 2015 21:44:58 -0400
Received: by padhy16 with SMTP id hy16so91511891pad.1
	for <21579@debbugs.gnu.org>; Thu, 01 Oct 2015 18:44:56 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=sender:date:from:reply-to:to:cc:subject:in-reply-to:message-id
	:references:user-agent:mime-version:content-type;
	bh=sEovB7He4JIwtf7/t7y2iFgfGagDaeKzhDI1lhpSr+s=;
	b=OV+I4edLgE6GTBitwwCCLtT2EZm+lGMk2QVLXUeot3sFV/EHEBAfQJOtTjDTS+y3E6
	pwX8yQ7BD2N0JPh8sQ0k8nAC/e0L/1fOHdkmVc5W6upQmVoz/HYCFqEdHTmpm9/FYEQC
	jiZvUOtPw9rRVFyOU0Kgblo1oWBpHgQCtqbkyUevScJoMAaziBcaCxbVEMaGxOdbJdsJ
	ORGEt3GR6bGNqYYCOD1yUfrMI2AVzO6k6kV4ktfu/4EPYuyA85HjQoqbyvl17NOjehkN
	un5IycqmKvAabYaXSjcJYB0rxoR8yXwZtU4xyo/8ya+yAHT/rOgrW8T7OLSRzDqSnm1R
	7hXA==
X-Received: by 10.68.190.5 with SMTP id gm5mr16343815pbc.25.1443750296599;
	Thu, 01 Oct 2015 18:44:56 -0700 (PDT)
Received: from [2601:647:4203:20dc:7db9:3343:7e48:2d3c]
	([2601:647:4203:20dc:7db9:3343:7e48:2d3c])
	by smtp.gmail.com with ESMTPSA id
	hq8sm9170498pad.35.2015.10.01.18.44.54
	(version=TLSv1 cipher=RC4-SHA bits=128/128);
	Thu, 01 Oct 2015 18:44:55 -0700 (PDT)
Date: Thu, 1 Oct 2015 18:44:50 -0700 (PDT)
From: Song Li <lisong@stanford.edu>
X-X-Sender: songli@leucine.local
In-Reply-To: <CA+8g5KGKPjrjXm6mnWN8GMSVcWJUVfQE2HcDR2GTe59X5QFHEQ@mail.gmail.com>
Message-ID: <alpine.OSX.2.01.1510011844360.2244@leucine.local>
References: <CAEUGwxaoj61PoZ2bBERUOSoXh_-WbxYDJLYzxkCdyhQ15Crm0A@mail.gmail.com>
	<CA+8g5KGKPjrjXm6mnWN8GMSVcWJUVfQE2HcDR2GTe59X5QFHEQ@mail.gmail.com>
User-Agent: Alpine 2.01 (OSX 1266 2009-07-14)
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
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: 208.118.235.43
Cc: 21579@debbugs.gnu.org
Subject: [bug-diffutils] bug#21579: bug#21579: diffutils 3.3 man page may
	need update
X-BeenThere: bug-diffutils@gnu.org
Reply-To: Song Li <lisong@stanford.edu>
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, 02 Oct 2015 01:46:07 -0000

Hi Jim,

Thanks for fixing it and keeping me updated.

Song


On Wed, 30 Sep 2015, Jim Meyering wrote:

> forcemerge 20123 21579
> thanks
>
> On Mon, Sep 28, 2015 at 9:05 AM, Song Li <lisong@stanford.edu> wrote:
>> Hi: the man page of diffutils 3.3 (after installing through brew) does
>> not seem to include the description for the nice option
>> '--no-dereference', which is valid, and also appears in `diff --help`
>> from that package (diffutils 3.3). I assume the OS version does not
>> matter, but in case needed, I use mac os x el capitan.
>
> Thank you for the report.
> That was indeed a bug. It was fixed by this change:
> http://git.savannah.gnu.org/cgit/diffutils.git/commit/?id=2cd4ff3a5ff52d89b6b992d158f389b757f4faf4
>




From MAILER-DAEMON Thu Oct 08 05:30:08 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Zk7Wa-0002vx-Gc
	for mharc-bug-diffutils@gnu.org; Thu, 08 Oct 2015 05:30:08 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:55984)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZhVEv-0006Yr-V3
	for bug-diffutils@gnu.org; Thu, 01 Oct 2015 00:13:06 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZhVEs-00053u-PO
	for bug-diffutils@gnu.org; Thu, 01 Oct 2015 00:13:05 -0400
Received: from debbugs.gnu.org ([208.118.235.43]:60784)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZhVEs-00053i-M1
	for bug-diffutils@gnu.org; Thu, 01 Oct 2015 00:13:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZhVEs-00005U-85
	for bug-diffutils@gnu.org; Thu, 01 Oct 2015 00:13:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Jim Meyering <jim@meyering.net>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Thu, 01 Oct 2015 04:13:02 +0000
Resent-Message-ID: <handler.21579.B21579.1443672765313@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 21579
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: Song Li <lisong@stanford.edu>
Received: via spool by 21579-submit@debbugs.gnu.org id=B21579.1443672765313
	(code B ref 21579); Thu, 01 Oct 2015 04:13:02 +0000
Received: (at 21579) by debbugs.gnu.org; 1 Oct 2015 04:12:45 +0000
Received: from localhost ([127.0.0.1]:49755 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZhVEa-00004z-PA
	for submit@debbugs.gnu.org; Thu, 01 Oct 2015 00:12:44 -0400
Received: from mail-ig0-f174.google.com ([209.85.213.174]:37379)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>) id 1ZhVEZ-00004r-3q
	for 21579@debbugs.gnu.org; Thu, 01 Oct 2015 00:12:43 -0400
Received: by igbni9 with SMTP id ni9so6330984igb.0
	for <21579@debbugs.gnu.org>; Wed, 30 Sep 2015 21:12:42 -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:from:date:message-id
	:subject:to:cc:content-type;
	bh=s8O3QI//WszTLhdAZOmtWWSdsAcSuNawCjduj6FpPdU=;
	b=YMrnlLm3iv2p8KlOxuUjEmeTgQI/9Q7HugroGG4bVH26EGNxefN6gToXOz34/xMqDi
	3+zYhW4TqPbod+2TLFtwreIQW/A3ougR7WzsloAZc3nQLQAdX8tl4DLvBlS2aQcIW7lB
	vDRYwumh/7ARly8/rnAImg4jrnID9BBoopQEeDQp2iJL6paCM6HCtSDODAfpnbxrHvy7
	/pSKVJiGweLUv6/ZkNqt/Eas3HhcqGaAzagwqLQwR5mmkobgGZU5BVuG9ty0UBn8U/Q4
	7mJtCTm+a+xouvQ8y9c+bM0tZPdJs+0dOkgzKA8TE+l4jQuQHb/Y3CdFFKEj3pGXkbYs
	Z0Dw==
X-Received: by 10.50.110.37 with SMTP id hx5mr955005igb.50.1443672762665; Wed,
	30 Sep 2015 21:12:42 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.36.137.136 with HTTP; Wed, 30 Sep 2015 21:12:23 -0700 (PDT)
In-Reply-To: <CAEUGwxaoj61PoZ2bBERUOSoXh_-WbxYDJLYzxkCdyhQ15Crm0A@mail.gmail.com>
References: <CAEUGwxaoj61PoZ2bBERUOSoXh_-WbxYDJLYzxkCdyhQ15Crm0A@mail.gmail.com>
From: Jim Meyering <jim@meyering.net>
Date: Wed, 30 Sep 2015 21:12:23 -0700
X-Google-Sender-Auth: 3Fdtx9IDrFXmfJe4G5i_-uCJd9s
Message-ID: <CA+8g5KGKPjrjXm6mnWN8GMSVcWJUVfQE2HcDR2GTe59X5QFHEQ@mail.gmail.com>
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: 208.118.235.43
Cc: 21579@debbugs.gnu.org
Subject: [bug-diffutils] bug#21579: bug#21579: diffutils 3.3 man page may
	need update
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, 01 Oct 2015 04:13:07 -0000

forcemerge 20123 21579
thanks

On Mon, Sep 28, 2015 at 9:05 AM, Song Li <lisong@stanford.edu> wrote:
> Hi: the man page of diffutils 3.3 (after installing through brew) does
> not seem to include the description for the nice option
> '--no-dereference', which is valid, and also appears in `diff --help`
> from that package (diffutils 3.3). I assume the OS version does not
> matter, but in case needed, I use mac os x el capitan.

Thank you for the report.
That was indeed a bug. It was fixed by this change:
http://git.savannah.gnu.org/cgit/diffutils.git/commit/?id=2cd4ff3a5ff52d89b6b992d158f389b757f4faf4




From MAILER-DAEMON Sun Oct 11 17:16:29 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZlNyn-0000iL-KJ
	for mharc-bug-diffutils@gnu.org; Sun, 11 Oct 2015 17:16:29 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:59896)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZlNyR-0000fp-5s
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 17:16:07 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZlNyN-0001wg-3g
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 17:16:07 -0400
Received: from debbugs.gnu.org ([208.118.235.43]:47491)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZlNyM-0001wc-Vl
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 17:16:03 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZlNyM-0002OK-GN
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 17:16: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, 11 Oct 2015 21:16:02 +0000
Resent-Message-ID: <handler.21665.B.14445981049089@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 21665
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: 21665@debbugs.gnu.org
X-Debbugs-Original-To: bug-diffutils@gnu.org
Received: via spool by submit@debbugs.gnu.org id=B.14445981049089
	(code B ref -1); Sun, 11 Oct 2015 21:16:02 +0000
Received: (at submit) by debbugs.gnu.org; 11 Oct 2015 21:15:04 +0000
Received: from localhost ([127.0.0.1]:36459 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZlNxP-0002MV-Or
	for submit@debbugs.gnu.org; Sun, 11 Oct 2015 17:15:04 -0400
Received: from eggs.gnu.org ([208.118.235.92]:49740)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1ZlNxN-0002Lo-2y
	for submit@debbugs.gnu.org; Sun, 11 Oct 2015 17:15:01 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <eggert@cs.ucla.edu>) id 1ZlNxL-0001nJ-Va
	for submit@debbugs.gnu.org; Sun, 11 Oct 2015 17:15:00 -0400
Received: from lists.gnu.org ([2001:4830:134:3::11]:36313)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <eggert@cs.ucla.edu>) id 1ZlNxL-0001nF-Su
	for submit@debbugs.gnu.org; Sun, 11 Oct 2015 17:14:59 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:59740)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <eggert@cs.ucla.edu>) id 1ZlNxL-0000ab-4V
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 17:14:59 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <eggert@cs.ucla.edu>) id 1ZlNxH-0001mN-4c
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 17:14:59 -0400
Received: from zimbra.cs.ucla.edu ([131.179.128.68]:41265)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <eggert@cs.ucla.edu>) id 1ZlNxG-0001mG-W4
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 17:14:55 -0400
Received: from localhost (localhost [127.0.0.1])
	by zimbra.cs.ucla.edu (Postfix) with ESMTP id 1E9D3160195
	for <bug-diffutils@gnu.org>; Sun, 11 Oct 2015 14:14:54 -0700 (PDT)
Received: from zimbra.cs.ucla.edu ([127.0.0.1])
	by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032)
	with ESMTP id dHdnGhGBdWPb for <bug-diffutils@gnu.org>;
	Sun, 11 Oct 2015 14:14:53 -0700 (PDT)
Received: from localhost (localhost [127.0.0.1])
	by zimbra.cs.ucla.edu (Postfix) with ESMTP id 5A70E160E14
	for <bug-diffutils@gnu.org>; Sun, 11 Oct 2015 14:14:53 -0700 (PDT)
X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu
Received: from zimbra.cs.ucla.edu ([127.0.0.1])
	by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026)
	with ESMTP id pMXTd57pctEU for <bug-diffutils@gnu.org>;
	Sun, 11 Oct 2015 14:14:53 -0700 (PDT)
Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net
	[100.32.155.148])
	by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 37DFA160195
	for <bug-diffutils@gnu.org>; Sun, 11 Oct 2015 14:14:53 -0700 (PDT)
References: <20151011134203.GA1315@kfk4ever.com>
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
Message-ID: <561AD14D.5080009@cs.ucla.edu>
Date: Sun, 11 Oct 2015 14:14:53 -0700
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
	Thunderbird/38.3.0
MIME-Version: 1.0
In-Reply-To: <20151011134203.GA1315@kfk4ever.com>
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-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: 208.118.235.43
Subject: [bug-diffutils] bug#21665: bug#21665: Use of mmap for large files
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, 11 Oct 2015 21:16:10 -0000

Maurice van der Pot wrote:
> Would you be open to patches that enable diffing large files by using
> mmap?

I doubt whether that would help that much, as it still needs to construct 
information about each line, and that information consumes memory too.  Doing 
this in secondary storage would be a bear.  In practice when I've run into this 
problem, I've either gotten a bigger machine or made my input lines shorter. 
Preferably the former.




From MAILER-DAEMON Mon Oct 12 16:05:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZljLJ-00057F-BA
	for mharc-bug-diffutils@gnu.org; Mon, 12 Oct 2015 16:05:09 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:54570)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZljLG-00050z-8c
	for bug-diffutils@gnu.org; Mon, 12 Oct 2015 16:05:07 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZljLD-0002G5-HC
	for bug-diffutils@gnu.org; Mon, 12 Oct 2015 16:05:06 -0400
Received: from debbugs.gnu.org ([208.118.235.43]:48548)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZljLD-0002Fx-EK
	for bug-diffutils@gnu.org; Mon, 12 Oct 2015 16:05:03 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZljLC-0003uC-WB
	for bug-diffutils@gnu.org; Mon, 12 Oct 2015 16:05: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: Mon, 12 Oct 2015 20:05:02 +0000
Resent-Message-ID: <handler.21674.B.144468026014953@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: report 21674
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: 21674@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.144468026014953
	(code B ref -1); Mon, 12 Oct 2015 20:05:02 +0000
Received: (at submit) by debbugs.gnu.org; 12 Oct 2015 20:04:20 +0000
Received: from localhost ([127.0.0.1]:37519 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZljKV-0003t7-TE
	for submit@debbugs.gnu.org; Mon, 12 Oct 2015 16:04:20 -0400
Received: from eggs.gnu.org ([208.118.235.92]:44185)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gvanem@yahoo.no>) id 1ZljKT-0003sz-HU
	for submit@debbugs.gnu.org; Mon, 12 Oct 2015 16:04:17 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <gvanem@yahoo.no>) id 1ZljKS-00022i-EW
	for submit@debbugs.gnu.org; Mon, 12 Oct 2015 16:04:17 -0400
Received: from lists.gnu.org ([2001:4830:134:3::11]:41180)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <gvanem@yahoo.no>) id 1ZljKS-00022e-CV
	for submit@debbugs.gnu.org; Mon, 12 Oct 2015 16:04:16 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:54180)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <gvanem@yahoo.no>) id 1ZljKR-0003X4-DJ
	for bug-diffutils@gnu.org; Mon, 12 Oct 2015 16:04:16 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <gvanem@yahoo.no>) id 1ZljKO-00021c-MM
	for bug-diffutils@gnu.org; Mon, 12 Oct 2015 16:04:15 -0400
Received: from nm1-vm8.bullet.mail.ir2.yahoo.com ([212.82.96.79]:45263)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <gvanem@yahoo.no>) id 1ZljKO-00020f-Bw
	for bug-diffutils@gnu.org; Mon, 12 Oct 2015 16:04:12 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.no; s=s2048;
	t=1444680250; bh=RQWd5TKL13PoVAWHggkYI8EyjaGwJgS79J1MKLy+UK4=;
	h=From:Subject:To:Date:From:Subject;
	b=K7GSS53sKao4U8KjYvpYAVSawjklWxYbSSC7kX5DsGLGX9CMn1/R0KH5Z3VgJQIeeiDOtBtJH8kCXd2GRJjZAK1PC5UIGk4n/8bgdA3e/0NAWCk07qm2+IENLFkCJUUPELTbOKH3cySzzn/QiECIkJeRQQ+EI9+U+4ZOrYj+XAubUisCoEivih74UAGX6JySNETMvcsKK3K548tToLkRjkB3BymZlGsaPpa1ESgR06lfq+iHUZ2uSyt8eAVMni+EZ0LrZ5AnrA5O7sZiWGTmyuUfkk0KbTYiCjGhXHRCPbLJA9bBMbYJIJrsXBTV/XHd0ri8yGxI6Of0CWoYeVmxMg==
Received: from [212.82.98.125] by nm1.bullet.mail.ir2.yahoo.com with NNFMP;
	12 Oct 2015 20:04:10 -0000
Received: from [46.228.39.110] by tm18.bullet.mail.ir2.yahoo.com with NNFMP;
	12 Oct 2015 20:04:10 -0000
Received: from [127.0.0.1] by smtp147.mail.ir2.yahoo.com with NNFMP;
	12 Oct 2015 20:04:10 -0000
X-Yahoo-Newman-Id: 388534.32485.bm@smtp147.mail.ir2.yahoo.com
X-Yahoo-Newman-Property: ymail-3
X-YMail-OSG: VwhTGvcVM1mTjiynoBxjpeV7nq1LAttUODjqCV8wYJEn0z.
	y0Kj293NGfU7ZrUtJsp96pw0tNMeCMS8tSrFS7bhtiQDnxhJUvDQ6Qswym6a
	AU49Ric4FbIpD1FfUu8C.RWCx5oxn2NTk9um2V_UbtelgVBJbKVVjGYY6gHH
	g6oVMyqvwvdaYQ.ItBki2fUVDBEijWMSOeSWk0f6_twgpmTRdp6ZcpqgTrA6
	BHkcFC3lLe8rf9f8NqQ593A6XHZNlpS.mHSkLXyxLR0evXEaKMCkB.GpIx1T
	jpGFtWx1z1ik0s3TFi.W1vAOdK1NcqTDH3Yi2WGmVwkg0ItDraIT_kU.1FwW
	7sflLfCKyVwynC.U2QDtxSfC3zguHCkDBvTwU9FpMo.zrzHxGbyu6zIsaYyx
	Hzlj5tdqrCu32auM7yBJ533tR3kJcOkqfndizE8jBiFU60C87ifW.8kdE3sB
	aszxfc89_tur9x5C0PUQ6T4D4JLjI3rl0M6AMrzkLWXcSTnhOxGEXAxOqnDA
	YVFsyGQmQndg2PU7CIDGUiuzwVk4aWdzR9BIrU8Kk2ZECXSKB0n9Et6dTlDm
	_uigWSDaYyoVR0QOiFK2s
X-Yahoo-SMTP: 8zhYLGyswBB3AGU8c4pvFIFOfA--
From: Gisle Vanem <gvanem@yahoo.no>
Message-ID: <561C123B.3070504@yahoo.no>
Date: Mon, 12 Oct 2015 22:04:11 +0200
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:44.0) Gecko/20100101
	Firefox/44.0 SeaMonkey/2.41a1
MIME-Version: 1.0
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-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: 208.118.235.43
Subject: [bug-diffutils] bug#21674: Fix for context-header
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, 12 Oct 2015 20:05:07 -0000

I've made a small fix for the context-header. Which IMHO
makes it more apparent which of the 2 files are newest.

Header in Git-repo is now (example from libcurl):
   --- ./lib/curl_addrinfo.c 2015-03-25 23:44:19
   +++ Git-latest/lib/curl_addrinfo.c 2015-03-25 23:39:26

Header after my .diff:
   --- ./lib/curl_addrinfo.c          2015-03-25 23:44:19
   +++ Git-latest/lib/curl_addrinfo.c 2015-03-25 23:39:26

I've put the .diff and some description here:
   https://gist.github.com/gvanem/b28fe02889e05005bba5

(so I don't loose the reference to it).

-- 
--gv




From MAILER-DAEMON Wed Oct 14 05:35:52 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZmITQ-0004Y8-4H
	for mharc-bug-diffutils@gnu.org; Wed, 14 Oct 2015 05:35:52 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49449)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZmIRh-0003SL-TM
	for bug-diffutils@gnu.org; Wed, 14 Oct 2015 05:34:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZmIRe-00050a-Id
	for bug-diffutils@gnu.org; Wed, 14 Oct 2015 05:34:05 -0400
Received: from debbugs.gnu.org ([208.118.235.43]:50508)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZmIRe-00050W-EB
	for bug-diffutils@gnu.org; Wed, 14 Oct 2015 05:34:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZmIRe-0000n8-6C
	for bug-diffutils@gnu.org; Wed, 14 Oct 2015 05:34:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivano@gnu.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Wed, 14 Oct 2015 09:34:02 +0000
Resent-Message-ID: <handler.20062.B20062.14448152353029@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.14448152353029
	(code B ref 20062); Wed, 14 Oct 2015 09:34:02 +0000
Received: (at 20062) by debbugs.gnu.org; 14 Oct 2015 09:33:55 +0000
Received: from localhost ([127.0.0.1]:39479 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZmIRV-0000ml-OD
	for submit@debbugs.gnu.org; Wed, 14 Oct 2015 05:33:55 -0400
Received: from mx1.redhat.com ([209.132.183.28]:47403)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivano@gnu.org>) id 1ZmIRQ-0000mZ-VE
	for 20062@debbugs.gnu.org; Wed, 14 Oct 2015 05:33:51 -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 (Postfix) with ESMTPS id CE74F19F228;
	Wed, 14 Oct 2015 09:33:47 +0000 (UTC)
Received: from foo.bar.baz (vpn1-4-156.ams2.redhat.com [10.36.4.156])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t9E9Xhf2028902
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=NO); Wed, 14 Oct 2015 05:33:44 -0400
From: Giuseppe Scrivano <gscrivano@gnu.org>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<87d23t1lbk.fsf@redhat.com> <5517574A.2020508@cs.ucla.edu>
	<87fv7uleyp.fsf@redhat.com> <55358394.5040809@cs.ucla.edu>
	<87r3rbg9qc.fsf@redhat.com> <55382807.3020408@cs.ucla.edu>
	<87y4jf24w8.fsf@foo.bar.baz> <5584B2CB.7040104@cs.ucla.edu>
	<87bnd9sak5.fsf@foo.bar.baz> <55F283AC.9030704@cs.ucla.edu>
	<55F29E35.50808@yahoo.no> <55F2F304.2070808@cs.ucla.edu>
	<87vbbgr5kt.fsf@foo.bar.baz> <55F35117.5080005@redhat.com>
	<55F3525D.7050006@cs.ucla.edu> <87lhccqapr.fsf@foo.bar.baz>
	<55F3F26A.4050400@cs.ucla.edu> <87bnd7n9wn.fsf@foo.bar.baz>
	<55F44A2E.2050506@cs.ucla.edu> <8737y5h281.fsf@foo.bar.baz>
Date: Wed, 14 Oct 2015 11:33:42 +0200
In-Reply-To: <8737y5h281.fsf@foo.bar.baz> (Giuseppe Scrivano's message of
	"Wed, 23 Sep 2015 12:14:22 +0200")
Message-ID: <87oag1aj61.fsf@foo.bar.baz>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (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: 208.118.235.43
Cc: 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: Wed, 14 Oct 2015 09:34:08 -0000

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

Giuseppe Scrivano <gscrivano@gnu.org> writes:

> Hi Paul,
>
> Paul Eggert <eggert@cs.ucla.edu> writes:
>
>>> Either we block signals or we catch them and process as ls does (calling
>>> 'process_signals' periodically) that problem will still be present.
>>
>> True.  However, blocking signals means we'll need to periodically
>> fflush-unblock-block, which will slow us down; the whole point of
>> stdio is efficiency via buffering, after all.  Doing it the 'ls' way
>> avoids this overhead, as we'll need to fflush only when a signal has
>> actually arrived, plus we avoid the syscall overhead of periodic
>> unblock-block.
>
> I have attached a new version of the patch where I've copied the signals
> handling code from coreutils and ensure that output_1_line won't block
> for too long without checking `process_signals'.

Any comments?

Thanks,
Giuseppe


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

>From 1c74f569083f2dcc7456f6c6fde93f5436dc0c90 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
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.
(output_1_line): Periodically call `process_signals'.
(caught_signals): New sigset_t.
(colors_enabled): New boolean variable.
(interrupt_signal): New sig_atomic_t.
(stop_signal_count): New sig_atomic_t.
(check_color_output): New function.
(install_signal_handlers): Likewise. Copied from coreutils ls.
(process_signals): Likewise.  Copied from coreutils ls.
(reset_color_context): Likewise.
(set_add_color_context): Likewise.
(set_delete_color_context): Likewise.
(set_header_color_context): Likewise.
(set_line_numbers_color_context): Likewise.
(sighandler): Likewise.  Copied from coreutils ls.
(stophandler): Likewise.  Copied from coreutils ls.
---
 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         | 309 +++++++++++++++++++++++++++++++++++++++++++++++------
 7 files changed, 418 insertions(+), 44 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 091257f..0944b44 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3742,6 +3742,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..8e9a74f 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 ();
 }
 
 /* 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 ();
 	}
     }
 
@@ -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 ();
 	}
     }
 }
@@ -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 ();
 
   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 ();
 	  next = next->link;
 	}
     }
diff --git a/src/diff.c b/src/diff.c
index efd7e47..4e0f602 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..472fa93 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 (void);
+extern void set_line_numbers_color_context (void);
diff --git a/src/normal.c b/src/normal.c
index 721fd1a..227af10 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 ();
 
   /* 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 ();
+    }
 
   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 ();
+    }
 }
diff --git a/src/side.c b/src/side.c
index 155512c..b762d31 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 ();
 }
 
 /* Print lines common to both files in side-by-side format.  */
diff --git a/src/util.c b/src/util.c
index 2d6d3fc..b5b39a2 100644
--- a/src/util.c
+++ b/src/util.c
@@ -24,6 +24,22 @@
 #include <system-quote.h>
 #include <xalloc.h>
 #include "xvasprintf.h"
+#include <signal.h>
+
+/* Use SA_NOCLDSTOP as a proxy for whether the sigaction machinery is
+   present.  */
+#ifndef SA_NOCLDSTOP
+# define SA_NOCLDSTOP 0
+# define sigprocmask(How, Set, Oset) /* empty */
+# define sigset_t int
+# if ! HAVE_SIGINTERRUPT
+#  define siginterrupt(sig, flag) /* empty */
+# endif
+#endif
+
+#ifndef SA_RESTART
+# define SA_RESTART 0
+#endif
 
 char const pr_program[] = PR_PROGRAM;
 
@@ -143,6 +159,152 @@ print_message_queue (void)
     }
 }
 
+/* The set of signals that are caught.  */
+
+static sigset_t caught_signals;
+
+/* If nonzero, the value of the pending fatal signal.  */
+
+static sig_atomic_t volatile interrupt_signal;
+
+/* A count of the number of pending stop signals that have been received.  */
+
+static sig_atomic_t volatile stop_signal_count;
+
+/* An ordinary signal was received; arrange for the program to exit.  */
+
+static void
+sighandler (int sig)
+{
+  if (! SA_NOCLDSTOP)
+    signal (sig, SIG_IGN);
+  if (! interrupt_signal)
+    interrupt_signal = sig;
+}
+
+/* A SIGTSTP was received; arrange for the program to suspend itself.  */
+
+static void
+stophandler (int sig)
+{
+  if (! SA_NOCLDSTOP)
+    signal (sig, stophandler);
+  if (! interrupt_signal)
+    stop_signal_count++;
+}
+/* Process any pending signals.  If signals are caught, this function
+   should be called periodically.  Ideally there should never be an
+   unbounded amount of time when signals are not being processed.
+   Signal handling can restore the default colors, so callers must
+   immediately change colors after invoking this function.  */
+
+static void
+process_signals (void)
+{
+  while (interrupt_signal || stop_signal_count)
+    {
+      int sig;
+      int stops;
+      sigset_t oldset;
+
+      reset_color_context ();
+      fflush (stdout);
+
+      sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
+
+      /* Reload interrupt_signal and stop_signal_count, in case a new
+         signal was handled before sigprocmask took effect.  */
+      sig = interrupt_signal;
+      stops = stop_signal_count;
+
+      /* SIGTSTP is special, since the application can receive that signal
+         more than once.  In this case, don't set the signal handler to the
+         default.  Instead, just raise the uncatchable SIGSTOP.  */
+      if (stops)
+        {
+          stop_signal_count = stops - 1;
+          sig = SIGSTOP;
+        }
+      else
+        signal (sig, SIG_DFL);
+
+      /* Exit or suspend the program.  */
+      raise (sig);
+      sigprocmask (SIG_SETMASK, &oldset, NULL);
+
+      /* If execution reaches here, then the program has been
+         continued (after being suspended).  */
+    }
+}
+
+static void
+install_signal_handlers (void)
+{
+  /* The signals that are trapped, and the number of such signals.  */
+  static int const sig[] =
+    {
+      /* This one is handled specially.  */
+      SIGTSTP,
+
+      /* The usual suspects.  */
+      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
+    };
+  enum { nsigs = sizeof (sig) / sizeof *(sig) };
+
+#if ! SA_NOCLDSTOP
+  bool caught_sig[nsigs];
+#endif
+  {
+    int j;
+#if SA_NOCLDSTOP
+    struct sigaction act;
+
+    sigemptyset (&caught_signals);
+    for (j = 0; j < nsigs; j++)
+      {
+        sigaction (sig[j], NULL, &act);
+        if (act.sa_handler != SIG_IGN)
+          sigaddset (&caught_signals, sig[j]);
+      }
+
+    act.sa_mask = caught_signals;
+    act.sa_flags = SA_RESTART;
+
+    for (j = 0; j < nsigs; j++)
+      if (sigismember (&caught_signals, sig[j]))
+        {
+          act.sa_handler = sig[j] == SIGTSTP ? stophandler : sighandler;
+          sigaction (sig[j], &act, NULL);
+        }
+#else
+    for (j = 0; j < nsigs; j++)
+      {
+        caught_sig[j] = (signal (sig[j], SIG_IGN) != SIG_IGN);
+        if (caught_sig[j])
+          {
+            signal (sig[j], sig[j] == SIGTSTP ? stophandler : sighandler);
+            siginterrupt (sig[j], 0);
+          }
+      }
+#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 +315,24 @@ 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 (bool is_pipe)
+{
+  bool output_is_tty;
+
+  if (! outfile || colors_style == NEVER)
+    return;
+
+  output_is_tty = !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 +493,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 +501,7 @@ begin_output (void)
 	outfile = popen (command, "w");
 	if (!outfile)
 	  pfatal_with_name (command);
+	check_color_output (true);
 	free (command);
 #endif
       }
@@ -330,6 +512,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 +855,21 @@ void
 output_1_line (char const *base, char const *limit, char const *flag_format,
 	       char const *line_flag)
 {
+  const size_t MAX_CHUNK = 1024;
   if (!expand_tabs)
-    fwrite (base, sizeof (char), limit - base, outfile);
+    {
+      size_t left = limit - base;
+      while (left)
+        {
+          size_t to_write = MIN (left, MAX_CHUNK);
+          size_t written = fwrite (base, sizeof (char), to_write, outfile);
+          if (written < to_write)
+            return;
+          base += written;
+          left -= written;
+          process_signals ();
+        }
+    }
   else
     {
       register FILE *out = outfile;
@@ -681,40 +877,93 @@ 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 counter_proc_signals = 0;
 
       while (t < limit)
-	switch ((c = *t++))
-	  {
-	  case '\t':
-	    {
-	      size_t spaces = tab_size - column % tab_size;
-	      column += spaces;
-	      do
-		putc (' ', out);
-	      while (--spaces);
-	    }
-	    break;
+        {
+          counter_proc_signals++;
+          if (counter_proc_signals == MAX_CHUNK)
+            {
+              process_signals ();
+              counter_proc_signals = 0;
+            }
+
+          switch ((c = *t++))
+            {
+            case '\t':
+              {
+                size_t spaces = tab_size - column % tab_size;
+                column += spaces;
+                do
+                  putc (' ', out);
+                while (--spaces);
+              }
+              break;
+
+            case '\r':
+              putc (c, out);
+              if (flag_format && t < limit && *t != '\n')
+                fprintf (out, flag_format, line_flag);
+              column = 0;
+              break;
+
+            case '\b':
+              if (column == 0)
+                continue;
+              column--;
+              putc (c, out);
+              break;
+
+            default:
+              column += isprint (c) != 0;
+              putc (c, out);
+              break;
+            }
+        }
+    }
+}
 
-	  case '\r':
-	    putc (c, out);
-	    if (flag_format && t < limit && *t != '\n')
-	      fprintf (out, flag_format, line_flag);
-	    column = 0;
-	    break;
+void
+set_header_color_context (void)
+{
+  process_signals ();
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[1;39m");
+}
 
-	  case '\b':
-	    if (column == 0)
-	      continue;
-	    column--;
-	    putc (c, out);
-	    break;
+void
+set_line_numbers_color_context (void)
+{
+  process_signals ();
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[36m");
+}
 
-	  default:
-	    column += isprint (c) != 0;
-	    putc (c, out);
-	    break;
-	  }
-    }
+void
+set_add_color_context (void)
+{
+  process_signals ();
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[32m");
+  fflush (outfile);
+}
+
+void
+set_delete_color_context (void)
+{
+  process_signals ();
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[31m");
+}
+
+void
+reset_color_context (void)
+{
+  static char const reset_sequence[] = "\x1b[0m";
+  if (! colors_enabled)
+    return;
+
+  fputs (reset_sequence, outfile);
 }
 
 char const change_letter[] = { 0, 'd', 'a', 'c' };
-- 
2.4.3


--=-=-=--




From MAILER-DAEMON Thu Oct 15 17:56:39 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZmqVr-0002y2-IM
	for mharc-bug-diffutils@gnu.org; Thu, 15 Oct 2015 17:56:39 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:57231)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZlK7N-0002cl-NC
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 13: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 1ZlK7K-0007e0-HC
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 13:09:05 -0400
Received: from debbugs.gnu.org ([208.118.235.43]:47392)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZlK7K-0007dw-Dp
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 13:09:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZlK7J-0004IQ-Vc
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 13:09:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Maurice van der Pot <griffon26@kfk4ever.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Sun, 11 Oct 2015 17:09:01 +0000
Resent-Message-ID: <handler.21665.B.144458329416432@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: report 21665
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: 21665@debbugs.gnu.org
X-Debbugs-Original-To: bug-diffutils@gnu.org
Received: via spool by submit@debbugs.gnu.org id=B.144458329416432
	(code B ref -1); Sun, 11 Oct 2015 17:09:01 +0000
Received: (at submit) by debbugs.gnu.org; 11 Oct 2015 17:08:14 +0000
Received: from localhost ([127.0.0.1]:36361 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZlK6Y-0004Gy-5F
	for submit@debbugs.gnu.org; Sun, 11 Oct 2015 13:08:14 -0400
Received: from eggs.gnu.org ([208.118.235.92]:58721)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <griffon26@kfk4ever.com>) id 1ZlGtA-0007MT-2U
	for submit@debbugs.gnu.org; Sun, 11 Oct 2015 09:42:12 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <griffon26@kfk4ever.com>) id 1ZlGt8-0001ct-ST
	for submit@debbugs.gnu.org; Sun, 11 Oct 2015 09:42:11 -0400
Received: from lists.gnu.org ([2001:4830:134:3::11]:44896)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <griffon26@kfk4ever.com>) id 1ZlGt8-0001cp-QT
	for submit@debbugs.gnu.org; Sun, 11 Oct 2015 09:42:10 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:40480)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <griffon26@kfk4ever.com>) id 1ZlGt7-0007ak-SH
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 09:42:10 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <griffon26@kfk4ever.com>) id 1ZlGt3-0001Zz-Ob
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 09:42:09 -0400
Received: from griffon26.demon.nl ([83.163.44.87]:37298
	helo=griffon26.kfk4ever.com) by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <griffon26@kfk4ever.com>) id 1ZlGt3-0001ZW-HS
	for bug-diffutils@gnu.org; Sun, 11 Oct 2015 09:42:05 -0400
Received: by griffon26.kfk4ever.com (Postfix, from userid 1000)
	id 99CB6127E2F; Sun, 11 Oct 2015 15:42:03 +0200 (CEST)
Date: Sun, 11 Oct 2015 15:42:03 +0200
From: Maurice van der Pot <griffon26@kfk4ever.com>
Message-ID: <20151011134203.GA1315@kfk4ever.com>
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="jRHKVT23PllUwdXP"
Content-Disposition: inline
X-URL: http://www.kfk4ever.com/
X-PGP-Key: http://www.kfk4ever.com/~griffon26/pubkey.asc
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
	(bad octet value).
X-Mailman-Approved-At: Sun, 11 Oct 2015 13:08:13 -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: 208.118.235.43
X-Mailman-Approved-At: Sun, 11 Oct 2015 16:35:47 -0400
Subject: [bug-diffutils] bug#21665: Use of mmap for large files
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, 11 Oct 2015 17:09:06 -0000


--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

I am working on an application suitable for visually merging large files.
This application delegates determination of differences to GNU diff.

Unfortunately I have found that diff reads the entire input files into
memory, leading to "/usr/bin/diff: memory exhausted" messages on the
types of files I'd like to support.

Would you be open to patches that enable diffing large files by using
mmap?

Kind regards,
Maurice.

--=20
Maurice van der Pot

Kdiff3 developer   griffon26@kfk4ever.com   http://kdiff3.sourceforge.net
Tdiff3 developer                            https://github.com/Griffon26/td=
iff3

--jRHKVT23PllUwdXP
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlYaZysACgkQMGnpIbeahxxSIQCgmUl58w1BR6+oOUQK7TUZkhYl
6EcAnjRMByA1+xXDEtfjFHXa/oCCAwxw
=Zs9+
-----END PGP SIGNATURE-----

--jRHKVT23PllUwdXP--




From MAILER-DAEMON Sun Oct 18 13:27:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Znrjh-00017U-HZ
	for mharc-bug-diffutils@gnu.org; Sun, 18 Oct 2015 13:27:09 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49846)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Znrje-000179-Lc
	for bug-diffutils@gnu.org; Sun, 18 Oct 2015 13:27:07 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Znrja-0007Re-LV
	for bug-diffutils@gnu.org; Sun, 18 Oct 2015 13:27:06 -0400
Received: from debbugs.gnu.org ([208.118.235.43]:36375)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Znrja-0007RU-IA
	for bug-diffutils@gnu.org; Sun, 18 Oct 2015 13:27:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Znrja-0001WS-Dc
	for bug-diffutils@gnu.org; Sun, 18 Oct 2015 13:27:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Jim Meyering <jim@meyering.net>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Sun, 18 Oct 2015 17:27:02 +0000
Resent-Message-ID: <handler.20062.B20062.14451891825807@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 <gscrivano@gnu.org>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.14451891825807
	(code B ref 20062); Sun, 18 Oct 2015 17:27:02 +0000
Received: (at 20062) by debbugs.gnu.org; 18 Oct 2015 17:26:22 +0000
Received: from localhost ([127.0.0.1]:55316 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1Znriw-0001Vb-1T
	for submit@debbugs.gnu.org; Sun, 18 Oct 2015 13:26:22 -0400
Received: from mail-io0-f174.google.com ([209.85.223.174]:35516)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>) id 1Znriu-0001VT-E8
	for 20062@debbugs.gnu.org; Sun, 18 Oct 2015 13:26:20 -0400
Received: by iofz202 with SMTP id z202so25008674iof.2
	for <20062@debbugs.gnu.org>; Sun, 18 Oct 2015 10:26:20 -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:from:date:message-id
	:subject:to:cc:content-type;
	bh=6yaJJexNOauGZeYMuxE1axJkDjif0ZamND1Cx+BvDC0=;
	b=LdhbW7ZwkXyWOquJ8jFhCm4ZyVlwquPNlTx3/6Wa5a3ABQWLR9VMWzuOgdNiW18Ziv
	A9aShUBINdTM1GL5KLZiPXFFqvCmv8spFy0fRfftn2SJg121BZPib7MSOZ2Lfp3BgNnN
	5XOg3FVBCDPRZ1gqhZK1G+KgoA8mHccEDFSWLm/t3DkMGUVTT5kOzF5E8vEq87+khfqS
	cYXpej1Hl+CI76x64Gz8HOzhdjPu+SM8XeHBLmONqGdJdFW22yEUsjSeiiq+LkYf4Is0
	zV96bnhtpRnAbHUXVsb4EnYU4namFYuO+aIq8UdQWfEKmK/jXBjsJOPwH2++errCA0hm
	Bc1w==
X-Received: by 10.107.166.79 with SMTP id p76mr27417664ioe.163.1445189179956; 
	Sun, 18 Oct 2015 10:26:19 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.36.10.66 with HTTP; Sun, 18 Oct 2015 10:26:00 -0700 (PDT)
In-Reply-To: <87oag1aj61.fsf@foo.bar.baz>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<87d23t1lbk.fsf@redhat.com> <5517574A.2020508@cs.ucla.edu>
	<87fv7uleyp.fsf@redhat.com> <55358394.5040809@cs.ucla.edu>
	<87r3rbg9qc.fsf@redhat.com> <55382807.3020408@cs.ucla.edu>
	<87y4jf24w8.fsf@foo.bar.baz> <5584B2CB.7040104@cs.ucla.edu>
	<87bnd9sak5.fsf@foo.bar.baz> <55F283AC.9030704@cs.ucla.edu>
	<55F29E35.50808@yahoo.no> <55F2F304.2070808@cs.ucla.edu>
	<87vbbgr5kt.fsf@foo.bar.baz>
	<55F35117.5080005@redhat.com> <55F3525D.7050006@cs.ucla.edu>
	<87lhccqapr.fsf@foo.bar.baz> <55F3F26A.4050400@cs.ucla.edu>
	<87bnd7n9wn.fsf@foo.bar.baz> <55F44A2E.2050506@cs.ucla.edu>
	<8737y5h281.fsf@foo.bar.baz> <87oag1aj61.fsf@foo.bar.baz>
From: Jim Meyering <jim@meyering.net>
Date: Sun, 18 Oct 2015 10:26:00 -0700
X-Google-Sender-Auth: 3QNs97FnroFKaOeicyKn8pzsku8
Message-ID: <CA+8g5KEuUCv-rWgDjZu0fEd7VAekq_V0XFJZtKhBmtdMqxfeLg@mail.gmail.com>
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: 208.118.235.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: 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, 18 Oct 2015 17:27:07 -0000

Thank you for that patch and for your patience.
I've skimmed through and so far have only a question and a request:

Regarding this section:

+void
+set_header_color_context (void)
+{
+  process_signals ();
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[1;39m");
+}
+
+void
+set_line_numbers_color_context (void)
+{
+  process_signals ();
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[36m");
+}
+
+void
+set_add_color_context (void)
+{
+  process_signals ();
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[32m");
+  fflush (outfile);
+}
+
+void
+set_delete_color_context (void)
+{
+  process_signals ();
+  if (colors_enabled)
+    fprintf (outfile, "\x1B[31m");
+}
+
+void
+reset_color_context (void)
+{
+  static char const reset_sequence[] = "\x1b[0m";
+  if (! colors_enabled)
+    return;
+
+  fputs (reset_sequence, outfile);
+}

Why does set_add_color_context call fflush, yet the others do not?
Please use fputs rather than fprintf for those literal strings.
The former is often far more efficient.

Finally, should there be some way to specify different colors,
e.g., for those who use different-background-colored terminals,
or for the color blind?




From MAILER-DAEMON Tue Oct 20 08:13:35 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZoRLA-0003nU-Vc
	for mharc-bug-diffutils@gnu.org; Tue, 20 Oct 2015 03:28:12 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:39423)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoMek-00065R-7i
	for bug-diffutils@gnu.org; Mon, 19 Oct 2015 22:28:07 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoMeg-0003yr-Vp
	for bug-diffutils@gnu.org; Mon, 19 Oct 2015 22:28:06 -0400
Received: from debbugs.gnu.org ([208.118.235.43]:38252)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoMeg-0003yl-Si
	for bug-diffutils@gnu.org; Mon, 19 Oct 2015 22:28:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoMeg-00069J-B4
	for bug-diffutils@gnu.org; Mon, 19 Oct 2015 22:28:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Aaron Davies <aaron.davies@gmail.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 20 Oct 2015 02:28:02 +0000
Resent-Message-ID: <handler.21715.B.144530806223610@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: report 21715
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: 21715@debbugs.gnu.org
X-Debbugs-Original-To: bug-diffutils@gnu.org
Received: via spool by submit@debbugs.gnu.org id=B.144530806223610
	(code B ref -1); Tue, 20 Oct 2015 02:28:02 +0000
Received: (at submit) by debbugs.gnu.org; 20 Oct 2015 02:27:42 +0000
Received: from localhost ([127.0.0.1]:57193 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZoMeL-00068k-OM
	for submit@debbugs.gnu.org; Mon, 19 Oct 2015 22:27:42 -0400
Received: from eggs.gnu.org ([208.118.235.92]:57557)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <aaron.davies@gmail.com>) id 1ZoMeI-00068a-AB
	for submit@debbugs.gnu.org; Mon, 19 Oct 2015 22:27:38 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <aaron.davies@gmail.com>) id 1ZoMeH-0003vh-2C
	for submit@debbugs.gnu.org; Mon, 19 Oct 2015 22:27:37 -0400
Received: from lists.gnu.org ([2001:4830:134:3::11]:40654)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <aaron.davies@gmail.com>) id 1ZoMeG-0003vd-Vy
	for submit@debbugs.gnu.org; Mon, 19 Oct 2015 22:27:36 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:39330)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <aaron.davies@gmail.com>) id 1ZoMeF-00064X-Vv
	for bug-diffutils@gnu.org; Mon, 19 Oct 2015 22:27:36 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <aaron.davies@gmail.com>) id 1ZoMeC-0003u2-NQ
	for bug-diffutils@gnu.org; Mon, 19 Oct 2015 22:27:35 -0400
Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]:34357)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <aaron.davies@gmail.com>) id 1ZoMeC-0003tZ-HN
	for bug-diffutils@gnu.org; Mon, 19 Oct 2015 22:27:32 -0400
Received: by wikq8 with SMTP id q8so24898147wik.1
	for <bug-diffutils@gnu.org>; Mon, 19 Oct 2015 19:27:32 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=from:content-type:content-transfer-encoding:subject:message-id:date
	:to:mime-version;
	bh=xocypU0paAtn5otJA93kSUuz1qDfuVuCsduhY83r3WE=;
	b=cE2iNv/ofbzEWNtkkvP7gt7bKHBDpWJOrUlWazjqYR2nSAPD3VApNaRHXpONrLaSkk
	j7F/IMMX1hmftNrrtGiKC5Hy9rMaS6giGKTcNsO9NlH7Ts91iIAClT5EReNGX0s89zcl
	Rbc75OBz/ePKn2UVR4+wWI/4F14LA0+TVqdPPNFcO4sIeIPxxtMP6+loYBYj5WW9xTK9
	UxgXQb4wUogrbAsEfWCDJksxsWScstyaz+7SI1uZOlUTp0g2tI7n7JbmQYQbGE1SV/UA
	HDmjFs6bDrC8zYEbJqlakjRnR9ykxHxny6bXa3DnTw7ARdNEzrYbFT52B9NCiiSxCixt
	jIIQ==
X-Received: by 10.180.76.177 with SMTP id l17mr1230838wiw.16.1445308052087;
	Mon, 19 Oct 2015 19:27:32 -0700 (PDT)
Received: from [10.8.0.8] (nl4x.mullvad.net. [95.211.148.154])
	by smtp.gmail.com with ESMTPSA id r9sm722455wjz.35.2015.10.19.19.27.30
	for <bug-diffutils@gnu.org>
	(version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
	Mon, 19 Oct 2015 19:27:31 -0700 (PDT)
From: Aaron Davies <aaron.davies@gmail.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Message-Id: <18A193A3-1591-4696-B8D1-5B86ED291450@gmail.com>
Date: Mon, 19 Oct 2015 22:27:28 -0400
Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\))
X-Mailer: Apple Mail (2.2104)
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: 208.118.235.43
X-Mailman-Approved-At: Tue, 20 Oct 2015 03:28:11 -0400
Subject: [bug-diffutils] bug#21715: feat req: an option to skip directory
	inode comparison
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, 20 Oct 2015 02:28:07 -0000

i have a situation where diff -r of two directories fails to report =
differences that diff of two files in those directories shows

i haven't dug into the code yet, but the directories involved are on an =
NFS mount of a netapp filer, one is the copy-on-write snapshot =
counterpart of the other, they show up as the same filesystem, and are =
the same inode

so my guess is that there's something in the recursive traversal that =
says that any two directories that are on the same fs and are the same =
inode must have identical descendent contents and can be skipped =
completely

this fs probably violates POSIX by doing this, but there's no easy way =
around it[1], so it would be very useful if diff had a command-line =
option to turn that optimization off

i've heard anecdotal reports of other filesystems that cause the same =
problem

here's a sample session:

$ mkdir foo
$ echo baz >foo/bar
$ # wait until the next snapshot is created
$ echo quux >foo/bar
$ diff -r .snapshot/nightly.0/foo foo
$ diff .snapshot/nightly.0/foo/bar foo/bar
1c1
< baz
---
> quux
$ stat -c %i .snapshot/nightly.0/foo foo
69403847
69403847
$=20
--=20
Aaron Davies
aaron.davies@gmail.com

[1] when i ran into this, i ended up using something like diff <(find =
.snapshot/nightly.0/foo -type f|sort|xargs cat) <(find foo -type =
f|sort|xargs cat) to do the comparison -- sufficient for my needs at the =
time, but cleaning it up for general purpose use would essentially be =
rewriting the -r part of diff from scratch=




From MAILER-DAEMON Tue Oct 20 12:24:20 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZoZi0-0001aF-17
	for mharc-bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:24:20 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:33212)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoZhp-0001Q9-K6
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:24:17 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoZhi-0001qc-RG
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:24:09 -0400
Received: from debbugs.gnu.org ([208.118.235.43]:39338)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoZhi-0001qU-Hz
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:24:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoZhi-0003zz-7Y
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:24:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivano@gnu.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 20 Oct 2015 16:24:02 +0000
Resent-Message-ID: <handler.20062.B20062.144535820115317@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: Jim Meyering <jim@meyering.net>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.144535820115317
	(code B ref 20062); Tue, 20 Oct 2015 16:24:02 +0000
Received: (at 20062) by debbugs.gnu.org; 20 Oct 2015 16:23:21 +0000
Received: from localhost ([127.0.0.1]:58279 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZoZh1-0003yw-4I
	for submit@debbugs.gnu.org; Tue, 20 Oct 2015 12:23:21 -0400
Received: from mx1.redhat.com ([209.132.183.28]:60640)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivano@gnu.org>) id 1ZoZgv-0003yj-ED
	for 20062@debbugs.gnu.org; Tue, 20 Oct 2015 12:23:17 -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 (Postfix) with ESMTPS id 6C02AC0C18A6;
	Tue, 20 Oct 2015 16:23:12 +0000 (UTC)
Received: from foo.bar.baz (vpn1-7-40.ams2.redhat.com [10.36.7.40])
	by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t9KGN7oL009859
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=NO); Tue, 20 Oct 2015 12:23:09 -0400
From: Giuseppe Scrivano <gscrivano@gnu.org>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<87fv7uleyp.fsf@redhat.com> <55358394.5040809@cs.ucla.edu>
	<87r3rbg9qc.fsf@redhat.com> <55382807.3020408@cs.ucla.edu>
	<87y4jf24w8.fsf@foo.bar.baz> <5584B2CB.7040104@cs.ucla.edu>
	<87bnd9sak5.fsf@foo.bar.baz> <55F283AC.9030704@cs.ucla.edu>
	<55F29E35.50808@yahoo.no> <55F2F304.2070808@cs.ucla.edu>
	<87vbbgr5kt.fsf@foo.bar.baz> <55F35117.5080005@redhat.com>
	<55F3525D.7050006@cs.ucla.edu> <87lhccqapr.fsf@foo.bar.baz>
	<55F3F26A.4050400@cs.ucla.edu> <87bnd7n9wn.fsf@foo.bar.baz>
	<55F44A2E.2050506@cs.ucla.edu> <8737y5h281.fsf@foo.bar.baz>
	<87oag1aj61.fsf@foo.bar.baz>
	<CA+8g5KEuUCv-rWgDjZu0fEd7VAekq_V0XFJZtKhBmtdMqxfeLg@mail.gmail.com>
Date: Tue, 20 Oct 2015 18:23:06 +0200
In-Reply-To: <CA+8g5KEuUCv-rWgDjZu0fEd7VAekq_V0XFJZtKhBmtdMqxfeLg@mail.gmail.com>
	(Jim Meyering's message of "Sun, 18 Oct 2015 10:26:00 -0700")
Message-ID: <87wpuh1pcl.fsf@foo.bar.baz>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (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: 208.118.235.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: 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: Tue, 20 Oct 2015 16:24:18 -0000

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

Hi Jim,

Jim Meyering <jim@meyering.net> writes:

> Thank you for that patch and for your patience.

thank you very much for the review!

> I've skimmed through and so far have only a question and a request:
>
> Regarding this section:
>
> +void
> +set_header_color_context (void)
> +{
> +  process_signals ();
> +  if (colors_enabled)
> +    fprintf (outfile, "\x1B[1;39m");
> +}
> +
> +void
> +set_line_numbers_color_context (void)
> +{
> +  process_signals ();
> +  if (colors_enabled)
> +    fprintf (outfile, "\x1B[36m");
> +}
> +
> +void
> +set_add_color_context (void)
> +{
> +  process_signals ();
> +  if (colors_enabled)
> +    fprintf (outfile, "\x1B[32m");
> +  fflush (outfile);
> +}
> +
> +void
> +set_delete_color_context (void)
> +{
> +  process_signals ();
> +  if (colors_enabled)
> +    fprintf (outfile, "\x1B[31m");
> +}
> +
> +void
> +reset_color_context (void)
> +{
> +  static char const reset_sequence[] = "\x1b[0m";
> +  if (! colors_enabled)
> +    return;
> +
> +  fputs (reset_sequence, outfile);
> +}
>
> Why does set_add_color_context call fflush, yet the others do not?
> Please use fputs rather than fprintf for those literal strings.
> The former is often far more efficient.

Yes, it shouldn't as well.  I have changed it.


> Finally, should there be some way to specify different colors,
> e.g., for those who use different-background-colored terminals,
> or for the color blind?

I have took more code from coreutils ls and diff honors DIFF_COLORS
now.  I added it in a separate patch to facilitate the review.  Probably
all the shared code should end up in a gnulib module, but it probably
needs a better API before it can happen.

Changes in the first patch:

1) dropped fflush from set_add_color_context
2) use fputs instead of fprintf (the second patch replaces it)
3) change the code color of the header to the default color to match
the "git diff" output.

Regards,
Giuseppe


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

>From 581c602ef651f99418a086025ad6a035959a7ad7 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Sun, 8 Mar 2015 22:45:11 +0100
Subject: [PATCH 1/2] 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.
(output_1_line): Periodically call `process_signals'.
(caught_signals): New sigset_t.
(colors_enabled): New boolean variable.
(interrupt_signal): New sig_atomic_t.
(stop_signal_count): New sig_atomic_t.
(check_color_output): New function.
(install_signal_handlers): Likewise. Copied from coreutils ls.
(process_signals): Likewise.  Copied from coreutils ls.
(reset_color_context): Likewise.
(set_add_color_context): Likewise.
(set_delete_color_context): Likewise.
(set_header_color_context): Likewise.
(set_line_numbers_color_context): Likewise.
(sighandler): Likewise.  Copied from coreutils ls.
(stophandler): Likewise.  Copied from coreutils ls.
---
 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         | 316 +++++++++++++++++++++++++++++++++++++++++++++++------
 7 files changed, 421 insertions(+), 48 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 091257f..0944b44 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3742,6 +3742,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..8e9a74f 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 ();
 }
 
 /* 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 ();
 	}
     }
 
@@ -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 ();
 	}
     }
 }
@@ -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 ();
 
   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 ();
 	  next = next->link;
 	}
     }
diff --git a/src/diff.c b/src/diff.c
index efd7e47..4e0f602 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..472fa93 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 (void);
+extern void set_line_numbers_color_context (void);
diff --git a/src/normal.c b/src/normal.c
index 721fd1a..227af10 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 ();
 
   /* 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 ();
+    }
 
   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 ();
+    }
 }
diff --git a/src/side.c b/src/side.c
index 155512c..b762d31 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 ();
 }
 
 /* Print lines common to both files in side-by-side format.  */
diff --git a/src/util.c b/src/util.c
index 2d6d3fc..6cc1411 100644
--- a/src/util.c
+++ b/src/util.c
@@ -24,6 +24,22 @@
 #include <system-quote.h>
 #include <xalloc.h>
 #include "xvasprintf.h"
+#include <signal.h>
+
+/* Use SA_NOCLDSTOP as a proxy for whether the sigaction machinery is
+   present.  */
+#ifndef SA_NOCLDSTOP
+# define SA_NOCLDSTOP 0
+# define sigprocmask(How, Set, Oset) /* empty */
+# define sigset_t int
+# if ! HAVE_SIGINTERRUPT
+#  define siginterrupt(sig, flag) /* empty */
+# endif
+#endif
+
+#ifndef SA_RESTART
+# define SA_RESTART 0
+#endif
 
 char const pr_program[] = PR_PROGRAM;
 
@@ -143,6 +159,174 @@ print_message_queue (void)
     }
 }
 
+/* The set of signals that are caught.  */
+
+static sigset_t caught_signals;
+
+/* If nonzero, the value of the pending fatal signal.  */
+
+static sig_atomic_t volatile interrupt_signal;
+
+/* A count of the number of pending stop signals that have been received.  */
+
+static sig_atomic_t volatile stop_signal_count;
+
+/* An ordinary signal was received; arrange for the program to exit.  */
+
+static void
+sighandler (int sig)
+{
+  if (! SA_NOCLDSTOP)
+    signal (sig, SIG_IGN);
+  if (! interrupt_signal)
+    interrupt_signal = sig;
+}
+
+/* A SIGTSTP was received; arrange for the program to suspend itself.  */
+
+static void
+stophandler (int sig)
+{
+  if (! SA_NOCLDSTOP)
+    signal (sig, stophandler);
+  if (! interrupt_signal)
+    stop_signal_count++;
+}
+/* Process any pending signals.  If signals are caught, this function
+   should be called periodically.  Ideally there should never be an
+   unbounded amount of time when signals are not being processed.
+   Signal handling can restore the default colors, so callers must
+   immediately change colors after invoking this function.  */
+
+static void
+process_signals (void)
+{
+  while (interrupt_signal || stop_signal_count)
+    {
+      int sig;
+      int stops;
+      sigset_t oldset;
+
+      reset_color_context ();
+      fflush (stdout);
+
+      sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
+
+      /* Reload interrupt_signal and stop_signal_count, in case a new
+         signal was handled before sigprocmask took effect.  */
+      sig = interrupt_signal;
+      stops = stop_signal_count;
+
+      /* SIGTSTP is special, since the application can receive that signal
+         more than once.  In this case, don't set the signal handler to the
+         default.  Instead, just raise the uncatchable SIGSTOP.  */
+      if (stops)
+        {
+          stop_signal_count = stops - 1;
+          sig = SIGSTOP;
+        }
+      else
+        signal (sig, SIG_DFL);
+
+      /* Exit or suspend the program.  */
+      raise (sig);
+      sigprocmask (SIG_SETMASK, &oldset, NULL);
+
+      /* If execution reaches here, then the program has been
+         continued (after being suspended).  */
+    }
+}
+
+static void
+install_signal_handlers (void)
+{
+  /* The signals that are trapped, and the number of such signals.  */
+  static int const sig[] =
+    {
+      /* This one is handled specially.  */
+      SIGTSTP,
+
+      /* The usual suspects.  */
+      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
+    };
+  enum { nsigs = sizeof (sig) / sizeof *(sig) };
+
+#if ! SA_NOCLDSTOP
+  bool caught_sig[nsigs];
+#endif
+  {
+    int j;
+#if SA_NOCLDSTOP
+    struct sigaction act;
+
+    sigemptyset (&caught_signals);
+    for (j = 0; j < nsigs; j++)
+      {
+        sigaction (sig[j], NULL, &act);
+        if (act.sa_handler != SIG_IGN)
+          sigaddset (&caught_signals, sig[j]);
+      }
+
+    act.sa_mask = caught_signals;
+    act.sa_flags = SA_RESTART;
+
+    for (j = 0; j < nsigs; j++)
+      if (sigismember (&caught_signals, sig[j]))
+        {
+          act.sa_handler = sig[j] == SIGTSTP ? stophandler : sighandler;
+          sigaction (sig[j], &act, NULL);
+        }
+#else
+    for (j = 0; j < nsigs; j++)
+      {
+        caught_sig[j] = (signal (sig[j], SIG_IGN) != SIG_IGN);
+        if (caught_sig[j])
+          {
+            signal (sig[j], sig[j] == SIGTSTP ? stophandler : sighandler);
+            siginterrupt (sig[j], 0);
+          }
+      }
+#endif
+    }
+}
+
+static char const *current_name0;
+static char const *current_name1;
+static bool currently_recursive;
+static bool colors_enabled;
+
+static void
+check_color_output (bool is_pipe)
+{
+  bool output_is_tty;
+
+  if (! outfile || colors_style == NEVER)
+    return;
+
+  output_is_tty = !is_pipe && isatty (fileno (outfile));
+
+  colors_enabled = (colors_style == ALWAYS
+                    || (colors_style == AUTO && output_is_tty));
+
+  if (output_is_tty)
+    install_signal_handlers ();
+}
+
 /* Call before outputting the results of comparing files NAME0 and NAME1
    to set up OUTFILE, the stdio stream for the output to go to.
 
@@ -150,10 +334,6 @@ print_message_queue (void)
    we fork off a 'pr' and make OUTFILE a pipe to it.
    'pr' then outputs to our stdout.  */
 
-static char const *current_name0;
-static char const *current_name1;
-static bool currently_recursive;
-
 void
 setup_output (char const *name0, char const *name1, bool recursive)
 {
@@ -313,6 +493,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 +501,7 @@ begin_output (void)
 	outfile = popen (command, "w");
 	if (!outfile)
 	  pfatal_with_name (command);
+	check_color_output (true);
 	free (command);
 #endif
       }
@@ -330,6 +512,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 +855,21 @@ void
 output_1_line (char const *base, char const *limit, char const *flag_format,
 	       char const *line_flag)
 {
+  const size_t MAX_CHUNK = 1024;
   if (!expand_tabs)
-    fwrite (base, sizeof (char), limit - base, outfile);
+    {
+      size_t left = limit - base;
+      while (left)
+        {
+          size_t to_write = MIN (left, MAX_CHUNK);
+          size_t written = fwrite (base, sizeof (char), to_write, outfile);
+          if (written < to_write)
+            return;
+          base += written;
+          left -= written;
+          process_signals ();
+        }
+    }
   else
     {
       register FILE *out = outfile;
@@ -681,40 +877,92 @@ 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 counter_proc_signals = 0;
 
       while (t < limit)
-	switch ((c = *t++))
-	  {
-	  case '\t':
-	    {
-	      size_t spaces = tab_size - column % tab_size;
-	      column += spaces;
-	      do
-		putc (' ', out);
-	      while (--spaces);
-	    }
-	    break;
+        {
+          counter_proc_signals++;
+          if (counter_proc_signals == MAX_CHUNK)
+            {
+              process_signals ();
+              counter_proc_signals = 0;
+            }
+
+          switch ((c = *t++))
+            {
+            case '\t':
+              {
+                size_t spaces = tab_size - column % tab_size;
+                column += spaces;
+                do
+                  putc (' ', out);
+                while (--spaces);
+              }
+              break;
+
+            case '\r':
+              putc (c, out);
+              if (flag_format && t < limit && *t != '\n')
+                fprintf (out, flag_format, line_flag);
+              column = 0;
+              break;
+
+            case '\b':
+              if (column == 0)
+                continue;
+              column--;
+              putc (c, out);
+              break;
+
+            default:
+              column += isprint (c) != 0;
+              putc (c, out);
+              break;
+            }
+        }
+    }
+}
 
-	  case '\r':
-	    putc (c, out);
-	    if (flag_format && t < limit && *t != '\n')
-	      fprintf (out, flag_format, line_flag);
-	    column = 0;
-	    break;
+void
+set_header_color_context (void)
+{
+  process_signals ();
+  if (colors_enabled)
+    fputs ("\x1B[1m", outfile);
+}
 
-	  case '\b':
-	    if (column == 0)
-	      continue;
-	    column--;
-	    putc (c, out);
-	    break;
+void
+set_line_numbers_color_context (void)
+{
+  process_signals ();
+  if (colors_enabled)
+    fputs ("\x1B[36m", outfile);
+}
 
-	  default:
-	    column += isprint (c) != 0;
-	    putc (c, out);
-	    break;
-	  }
-    }
+void
+set_add_color_context (void)
+{
+  process_signals ();
+  if (colors_enabled)
+    fputs ("\x1B[32m", outfile);
+}
+
+void
+set_delete_color_context (void)
+{
+  process_signals ();
+  if (colors_enabled)
+    fputs ("\x1B[31m", outfile);
+}
+
+void
+reset_color_context (void)
+{
+  static char const reset_sequence[] = "\x1b[0m";
+  if (! colors_enabled)
+    return;
+
+  fputs (reset_sequence, outfile);
 }
 
 char const change_letter[] = { 0, 'd', 'a', 'c' };
-- 
2.4.3


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0002-diff-honor-env-variable-DIFF_COLORS.patch

>From 2e2e078878d04311791c2facd9cac79ec969f24d Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Mon, 19 Oct 2015 10:29:41 +0200
Subject: [PATCH 2/2] diff: honor env variable DIFF_COLORS

doc/diffutils.texi: Add documentation for DIFF_COLORS
src/utils.c (struct bin_str): New struct.
(struct color_ext_type): New struct.
(color_indicator): New array.
(indicator_name): New array.
(indicator_no): New enum.
(parse_state): New enum.
(put_indicator): New function.
(get_funky_string): New function. Copied from coreutils ls.
(parse_diff_color):  New function. Copied from coreutils ls
"parse_ls_color" function.
(set_header_color_context): Use put_indicator instead of directly
outputting the sequence.
(set_line_numbers_colors_context): Likewise.
(set_add_color_context): Likewise.
(set_delete_color_context): Likewise.
(reset_color_context): Likewise.
---
 doc/diffutils.texi |   5 +
 src/util.c         | 431 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 427 insertions(+), 9 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 0944b44..75ad0d7 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3763,6 +3763,11 @@ Always use color.
 Specifying @option{--color} and no @var{when} is equivalent to
 @option{--color=auto}.
 
+The colors are defined by the environment variable @env{DIFF_COLORS}
+and default to @samp{rs=0:hd=1:ad=32:de=31:ln=36}
+for red added lines, green deleted lines, cyan line numbers, bold header.
+
+
 @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/util.c b/src/util.c
index 6cc1411..8d27bc7 100644
--- a/src/util.c
+++ b/src/util.c
@@ -310,6 +310,388 @@ static char const *current_name1;
 static bool currently_recursive;
 static bool colors_enabled;
 
+static struct color_ext_type *color_ext_list = NULL;
+
+struct bin_str
+  {
+    size_t len;			/* Number of bytes */
+    const char *string;		/* Pointer to the same */
+  };
+
+struct color_ext_type
+  {
+    struct bin_str ext;		/* The extension we're looking for */
+    struct bin_str seq;		/* The sequence to output when we do */
+    struct color_ext_type *next;	/* Next in list */
+  };
+
+/* Parse a string as part of the DIFF_COLORS variable; this may involve
+   decoding all kinds of escape characters.  If equals_end is set an
+   unescaped equal sign ends the string, otherwise only a : or \0
+   does.  Set *OUTPUT_COUNT to the number of bytes output.  Return
+   true if successful.
+
+   The resulting string is *not* null-terminated, but may contain
+   embedded nulls.
+
+   Note that both dest and src are char **; on return they point to
+   the first free byte after the array and the character that ended
+   the input string, respectively.  */
+
+static bool
+get_funky_string (char **dest, const char **src, bool equals_end,
+                  size_t *output_count)
+{
+  char num;			/* For numerical codes */
+  size_t count;			/* Something to count with */
+  enum {
+    ST_GND, ST_BACKSLASH, ST_OCTAL, ST_HEX, ST_CARET, ST_END, ST_ERROR
+  } state;
+  const char *p;
+  char *q;
+
+  p = *src;			/* We don't want to double-indirect */
+  q = *dest;			/* the whole darn time.  */
+
+  count = 0;			/* No characters counted in yet.  */
+  num = 0;
+
+  state = ST_GND;		/* Start in ground state.  */
+  while (state < ST_END)
+    {
+      switch (state)
+        {
+        case ST_GND:		/* Ground state (no escapes) */
+          switch (*p)
+            {
+            case ':':
+            case '\0':
+              state = ST_END;	/* End of string */
+              break;
+            case '\\':
+              state = ST_BACKSLASH; /* Backslash scape sequence */
+              ++p;
+              break;
+            case '^':
+              state = ST_CARET; /* Caret escape */
+              ++p;
+              break;
+            case '=':
+              if (equals_end)
+                {
+                  state = ST_END; /* End */
+                  break;
+                }
+              /* else fall through */
+            default:
+              *(q++) = *(p++);
+              ++count;
+              break;
+            }
+          break;
+
+        case ST_BACKSLASH:	/* Backslash escaped character */
+          switch (*p)
+            {
+            case '0':
+            case '1':
+            case '2':
+            case '3':
+            case '4':
+            case '5':
+            case '6':
+            case '7':
+              state = ST_OCTAL;	/* Octal sequence */
+              num = *p - '0';
+              break;
+            case 'x':
+            case 'X':
+              state = ST_HEX;	/* Hex sequence */
+              num = 0;
+              break;
+            case 'a':		/* Bell */
+              num = '\a';
+              break;
+            case 'b':		/* Backspace */
+              num = '\b';
+              break;
+            case 'e':		/* Escape */
+              num = 27;
+              break;
+            case 'f':		/* Form feed */
+              num = '\f';
+              break;
+            case 'n':		/* Newline */
+              num = '\n';
+              break;
+            case 'r':		/* Carriage return */
+              num = '\r';
+              break;
+            case 't':		/* Tab */
+              num = '\t';
+              break;
+            case 'v':		/* Vtab */
+              num = '\v';
+              break;
+            case '?':		/* Delete */
+              num = 127;
+              break;
+            case '_':		/* Space */
+              num = ' ';
+              break;
+            case '\0':		/* End of string */
+              state = ST_ERROR;	/* Error! */
+              break;
+            default:		/* Escaped character like \ ^ : = */
+              num = *p;
+              break;
+            }
+          if (state == ST_BACKSLASH)
+            {
+              *(q++) = num;
+              ++count;
+              state = ST_GND;
+            }
+          ++p;
+          break;
+
+        case ST_OCTAL:		/* Octal sequence */
+          if (*p < '0' || *p > '7')
+            {
+              *(q++) = num;
+              ++count;
+              state = ST_GND;
+            }
+          else
+            num = (num << 3) + (*(p++) - '0');
+          break;
+
+        case ST_HEX:		/* Hex sequence */
+          switch (*p)
+            {
+            case '0':
+            case '1':
+            case '2':
+            case '3':
+            case '4':
+            case '5':
+            case '6':
+            case '7':
+            case '8':
+            case '9':
+              num = (num << 4) + (*(p++) - '0');
+              break;
+            case 'a':
+            case 'b':
+            case 'c':
+            case 'd':
+            case 'e':
+            case 'f':
+              num = (num << 4) + (*(p++) - 'a') + 10;
+              break;
+            case 'A':
+            case 'B':
+            case 'C':
+            case 'D':
+            case 'E':
+            case 'F':
+              num = (num << 4) + (*(p++) - 'A') + 10;
+              break;
+            default:
+              *(q++) = num;
+              ++count;
+              state = ST_GND;
+              break;
+            }
+          break;
+
+        case ST_CARET:		/* Caret escape */
+          state = ST_GND;	/* Should be the next state... */
+          if (*p >= '@' && *p <= '~')
+            {
+              *(q++) = *(p++) & 037;
+              ++count;
+            }
+          else if (*p == '?')
+            {
+              *(q++) = 127;
+              ++count;
+            }
+          else
+            state = ST_ERROR;
+          break;
+
+        default:
+          abort ();
+        }
+    }
+
+  *dest = q;
+  *src = p;
+  *output_count = count;
+
+  return state != ST_ERROR;
+}
+
+enum parse_state
+  {
+    PS_START = 1,
+    PS_2,
+    PS_3,
+    PS_4,
+    PS_DONE,
+    PS_FAIL
+  };
+
+#define LEN_STR_PAIR(s) sizeof (s) - 1, s
+
+static struct bin_str color_indicator[] =
+  {
+    { LEN_STR_PAIR ("\033[") },		/* lc: Left of color sequence */
+    { LEN_STR_PAIR ("m") },		/* rc: Right of color sequence */
+    { 0, NULL },			/* ec: End color (replaces lc+rs+rc) */
+    { LEN_STR_PAIR ("0") },		/* rs: Reset to ordinary colors */
+    { LEN_STR_PAIR ("1") },		/* hd: Header */
+    { LEN_STR_PAIR ("32") },		/* ad: Add line */
+    { LEN_STR_PAIR ("31") },		/* de: Delete line */
+    { LEN_STR_PAIR ("36") },		/* ln: Line number */
+  };
+
+static const char *const indicator_name[]=
+  {
+    "lc", "rc", "ec", "rs", "hd", "ad", "de", "ln", NULL
+  };
+
+static void
+parse_diff_color (void)
+{
+  char *color_buf;
+  const char *p;		/* Pointer to character being parsed */
+  char *buf;			/* color_buf buffer pointer */
+  int ind_no;			/* Indicator number */
+  char label[3];		/* Indicator label */
+  struct color_ext_type *ext;	/* Extension we are working on */
+
+  if ((p = getenv ("DIFF_COLORS")) == NULL || *p == '\0')
+    return;
+
+  ext = NULL;
+  strcpy (label, "??");
+
+  /* This is an overly conservative estimate, but any possible
+     DIFF_COLORS string will *not* generate a color_buf longer than
+     itself, so it is a safe way of allocating a buffer in
+     advance.  */
+  buf = color_buf = xstrdup (p);
+
+  enum parse_state state = PS_START;
+  while (true)
+    {
+      switch (state)
+        {
+        case PS_START:		/* First label character */
+          switch (*p)
+            {
+            case ':':
+              ++p;
+              break;
+
+            case '*':
+              /* Allocate new extension block and add to head of
+                 linked list (this way a later definition will
+                 override an earlier one, which can be useful for
+                 having terminal-specific defs override global).  */
+
+              ext = xmalloc (sizeof *ext);
+              ext->next = color_ext_list;
+              color_ext_list = ext;
+
+              ++p;
+              ext->ext.string = buf;
+
+              state = (get_funky_string (&buf, &p, true, &ext->ext.len)
+                       ? PS_4 : PS_FAIL);
+              break;
+
+            case '\0':
+              state = PS_DONE;	/* Done! */
+              goto done;
+
+            default:	/* Assume it is file type label */
+              label[0] = *(p++);
+              state = PS_2;
+              break;
+            }
+          break;
+
+        case PS_2:		/* Second label character */
+          if (*p)
+            {
+              label[1] = *(p++);
+              state = PS_3;
+            }
+          else
+            state = PS_FAIL;	/* Error */
+          break;
+
+        case PS_3:		/* Equal sign after indicator label */
+          state = PS_FAIL;	/* Assume failure...  */
+          if (*(p++) == '=')/* It *should* be...  */
+            {
+              for (ind_no = 0; indicator_name[ind_no] != NULL; ++ind_no)
+                {
+                  if (STREQ (label, indicator_name[ind_no]))
+                    {
+                      color_indicator[ind_no].string = buf;
+                      state = (get_funky_string (&buf, &p, false,
+                                                 &color_indicator[ind_no].len)
+                               ? PS_START : PS_FAIL);
+                      break;
+                    }
+                }
+              if (state == PS_FAIL)
+                error (0, 0, _("unrecognized prefix: %s"), label);
+            }
+          break;
+
+        case PS_4:		/* Equal sign after *.ext */
+          if (*(p++) == '=')
+            {
+              ext->seq.string = buf;
+              state = (get_funky_string (&buf, &p, false, &ext->seq.len)
+                       ? PS_START : PS_FAIL);
+            }
+          else
+            state = PS_FAIL;
+          break;
+
+        case PS_FAIL:
+          goto done;
+
+        default:
+          abort ();
+        }
+    }
+ done:
+
+  if (state == PS_FAIL)
+    {
+      struct color_ext_type *e;
+      struct color_ext_type *e2;
+
+      error (0, 0,
+             _("unparsable value for DIFF_COLORS environment variable"));
+      free (color_buf);
+      for (e = color_ext_list; e != NULL; /* empty */)
+        {
+          e2 = e;
+          e = e->next;
+          free (e2);
+        }
+      colors_enabled = false;
+    }
+}
+
 static void
 check_color_output (bool is_pipe)
 {
@@ -323,6 +705,9 @@ check_color_output (bool is_pipe)
   colors_enabled = (colors_style == ALWAYS
                     || (colors_style == AUTO && output_is_tty));
 
+  if (colors_enabled)
+    parse_diff_color ();
+
   if (output_is_tty)
     install_signal_handlers ();
 }
@@ -923,12 +1308,27 @@ output_1_line (char const *base, char const *limit, char const *flag_format,
     }
 }
 
+enum indicator_no
+  {
+    C_LEFT, C_RIGHT, C_END, C_RESET, C_HEADER, C_ADD, C_DELETE, C_LINE
+  };
+
+static void
+put_indicator (const struct bin_str *ind)
+{
+  fwrite (ind->string, ind->len, 1, outfile);
+}
+
 void
 set_header_color_context (void)
 {
   process_signals ();
   if (colors_enabled)
-    fputs ("\x1B[1m", outfile);
+    {
+      put_indicator (&color_indicator[C_LEFT]);
+      put_indicator (&color_indicator[C_HEADER]);
+      put_indicator (&color_indicator[C_RIGHT]);
+    }
 }
 
 void
@@ -936,7 +1336,11 @@ set_line_numbers_color_context (void)
 {
   process_signals ();
   if (colors_enabled)
-    fputs ("\x1B[36m", outfile);
+    {
+      put_indicator (&color_indicator[C_LEFT]);
+      put_indicator (&color_indicator[C_LINE]);
+      put_indicator (&color_indicator[C_RIGHT]);
+    }
 }
 
 void
@@ -944,7 +1348,11 @@ set_add_color_context (void)
 {
   process_signals ();
   if (colors_enabled)
-    fputs ("\x1B[32m", outfile);
+    {
+      put_indicator (&color_indicator[C_LEFT]);
+      put_indicator (&color_indicator[C_ADD]);
+      put_indicator (&color_indicator[C_RIGHT]);
+    }
 }
 
 void
@@ -952,17 +1360,22 @@ set_delete_color_context (void)
 {
   process_signals ();
   if (colors_enabled)
-    fputs ("\x1B[31m", outfile);
+    {
+      put_indicator (&color_indicator[C_LEFT]);
+      put_indicator (&color_indicator[C_DELETE]);
+      put_indicator (&color_indicator[C_RIGHT]);
+    }
 }
 
 void
 reset_color_context (void)
 {
-  static char const reset_sequence[] = "\x1b[0m";
-  if (! colors_enabled)
-    return;
-
-  fputs (reset_sequence, outfile);
+  if (colors_enabled)
+    {
+      put_indicator (&color_indicator[C_LEFT]);
+      put_indicator (&color_indicator[C_RESET]);
+      put_indicator (&color_indicator[C_RIGHT]);
+    }
 }
 
 char const change_letter[] = { 0, 'd', 'a', 'c' };
-- 
2.4.3


--=-=-=--




From MAILER-DAEMON Tue Oct 20 12:27:13 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZoZkn-0003FZ-MR
	for mharc-bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:27:13 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:34100)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoZkh-0003Dx-70
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:27:11 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoZkc-0002SU-4d
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:27:07 -0400
Received: from debbugs.gnu.org ([208.118.235.43]:39342)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoZkc-0002SP-1e
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:27:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoZkb-00044R-QL
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:27: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: Tue, 20 Oct 2015 16:27:01 +0000
Resent-Message-ID: <handler.20062.B20062.144535837815589@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 <gscrivano@gnu.org>, Jim Meyering <jim@meyering.net>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.144535837815589
	(code B ref 20062); Tue, 20 Oct 2015 16:27:01 +0000
Received: (at 20062) by debbugs.gnu.org; 20 Oct 2015 16:26:18 +0000
Received: from localhost ([127.0.0.1]:58283 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZoZju-00043N-3V
	for submit@debbugs.gnu.org; Tue, 20 Oct 2015 12:26:18 -0400
Received: from zimbra.cs.ucla.edu ([131.179.128.68]:33091)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1ZoZjZ-00042g-83
	for 20062@debbugs.gnu.org; Tue, 20 Oct 2015 12:26:16 -0400
Received: from localhost (localhost [127.0.0.1])
	by zimbra.cs.ucla.edu (Postfix) with ESMTP id 71317160D74;
	Tue, 20 Oct 2015 09:25:56 -0700 (PDT)
Received: from zimbra.cs.ucla.edu ([127.0.0.1])
	by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032)
	with ESMTP id 0IP0dTlU8P_G; Tue, 20 Oct 2015 09:25:55 -0700 (PDT)
Received: from localhost (localhost [127.0.0.1])
	by zimbra.cs.ucla.edu (Postfix) with ESMTP id CC198160DFD;
	Tue, 20 Oct 2015 09:25:55 -0700 (PDT)
X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu
Received: from zimbra.cs.ucla.edu ([127.0.0.1])
	by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026)
	with ESMTP id 04qFM6XmBnsp; Tue, 20 Oct 2015 09:25:55 -0700 (PDT)
Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net
	[100.32.155.148])
	by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id A76F2160D74;
	Tue, 20 Oct 2015 09:25:55 -0700 (PDT)
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<87fv7uleyp.fsf@redhat.com> <55358394.5040809@cs.ucla.edu>
	<87r3rbg9qc.fsf@redhat.com> <55382807.3020408@cs.ucla.edu>
	<87y4jf24w8.fsf@foo.bar.baz> <5584B2CB.7040104@cs.ucla.edu>
	<87bnd9sak5.fsf@foo.bar.baz> <55F283AC.9030704@cs.ucla.edu>
	<55F29E35.50808@yahoo.no> <55F2F304.2070808@cs.ucla.edu>
	<87vbbgr5kt.fsf@foo.bar.baz> <55F35117.5080005@redhat.com>
	<55F3525D.7050006@cs.ucla.edu> <87lhccqapr.fsf@foo.bar.baz>
	<55F3F26A.4050400@cs.ucla.edu> <87bnd7n9wn.fsf@foo.bar.baz>
	<55F44A2E.2050506@cs.ucla.edu> <8737y5h281.fsf@foo.bar.baz>
	<87oag1aj61.fsf@foo.bar.baz>
	<CA+8g5KEuUCv-rWgDjZu0fEd7VAekq_V0XFJZtKhBmtdMqxfeLg@mail.gmail.com>
	<87wpuh1pcl.fsf@foo.bar.baz>
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
Message-ID: <56266B13.2020503@cs.ucla.edu>
Date: Tue, 20 Oct 2015 09:25:55 -0700
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
	Thunderbird/38.3.0
MIME-Version: 1.0
In-Reply-To: <87wpuh1pcl.fsf@foo.bar.baz>
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: 208.118.235.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: 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: Tue, 20 Oct 2015 16:27:11 -0000

Giuseppe Scrivano wrote:
> diff honors DIFF_COLORS
> now.

Aren't we trying to move away from environment variables' affecting program 
behavior, given all the maintenance and security hassles that entails?




From MAILER-DAEMON Tue Oct 20 12:43:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Zoa0C-0004VT-Vc
	for mharc-bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:43:08 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:39304)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Zoa0A-0004Uz-6R
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:43:07 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Zoa06-000894-0V
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:43:06 -0400
Received: from debbugs.gnu.org ([208.118.235.43]:39363)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Zoa05-00088v-UJ
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:43:01 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Zoa05-000647-Lr
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 12:43:01 -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: Tue, 20 Oct 2015 16:43:01 +0000
Resent-Message-ID: <handler.20062.B20062.144535936323292@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>, Giuseppe Scrivano <gscrivano@gnu.org>,
	Jim Meyering <jim@meyering.net>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.144535936323292
	(code B ref 20062); Tue, 20 Oct 2015 16:43:01 +0000
Received: (at 20062) by debbugs.gnu.org; 20 Oct 2015 16:42:43 +0000
Received: from localhost ([127.0.0.1]:58304 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZoZzm-00063b-Cq
	for submit@debbugs.gnu.org; Tue, 20 Oct 2015 12:42:42 -0400
Received: from mx1.redhat.com ([209.132.183.28]:52665)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eblake@redhat.com>) id 1ZoZzk-00063T-6D
	for 20062@debbugs.gnu.org; Tue, 20 Oct 2015 12:42:41 -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 (Postfix) with ESMTPS id CAA702FE847;
	Tue, 20 Oct 2015 16:42:38 +0000 (UTC)
Received: from [10.3.113.176] (ovpn-113-176.phx2.redhat.com [10.3.113.176])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t9KGgbjg004452; Tue, 20 Oct 2015 12:42:38 -0400
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<87fv7uleyp.fsf@redhat.com> <55358394.5040809@cs.ucla.edu>
	<87r3rbg9qc.fsf@redhat.com> <55382807.3020408@cs.ucla.edu>
	<87y4jf24w8.fsf@foo.bar.baz> <5584B2CB.7040104@cs.ucla.edu>
	<87bnd9sak5.fsf@foo.bar.baz> <55F283AC.9030704@cs.ucla.edu>
	<55F29E35.50808@yahoo.no> <55F2F304.2070808@cs.ucla.edu>
	<87vbbgr5kt.fsf@foo.bar.baz> <55F35117.5080005@redhat.com>
	<55F3525D.7050006@cs.ucla.edu> <87lhccqapr.fsf@foo.bar.baz>
	<55F3F26A.4050400@cs.ucla.edu> <87bnd7n9wn.fsf@foo.bar.baz>
	<55F44A2E.2050506@cs.ucla.edu> <8737y5h281.fsf@foo.bar.baz>
	<87oag1aj61.fsf@foo.bar.baz>
	<CA+8g5KEuUCv-rWgDjZu0fEd7VAekq_V0XFJZtKhBmtdMqxfeLg@mail.gmail.com>
	<87wpuh1pcl.fsf@foo.bar.baz> <56266B13.2020503@cs.ucla.edu>
From: Eric Blake <eblake@redhat.com>
Openpgp: url=http://people.redhat.com/eblake/eblake.gpg
X-Enigmail-Draft-Status: N1110
Organization: Red Hat, Inc.
Message-ID: <56266EF8.7090908@redhat.com>
Date: Tue, 20 Oct 2015 10:42:32 -0600
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
	Thunderbird/38.3.0
MIME-Version: 1.0
In-Reply-To: <56266B13.2020503@cs.ucla.edu>
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature";
	boundary="8LUvQ0oEw4hwmL8K32NKV9kLockmXtFpH"
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: 208.118.235.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: 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: Tue, 20 Oct 2015 16:43:07 -0000

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

On 10/20/2015 10:25 AM, Paul Eggert wrote:
> Giuseppe Scrivano wrote:
>> diff honors DIFF_COLORS
>> now.
>=20
> Aren't we trying to move away from environment variables' affecting
> program behavior, given all the maintenance and security hassles that
> entails?

I think there's a difference between an environment variable which only
affects optional behavior (LS_COLORS, DIFF_COLORS - only affect things
for 'ls --color' or 'diff --color') vs. those that affect ALL behavior
(GREP_OPTIONS - cruelly affects all executions of grep, no matter what
options were in use).

You do have a point that allowing the choice to come through a command
line option, and wrapping diff behind an alias or shell function, will
let the interactive user set up their terminal to get the same effect
(typing 'diff' gets the colored version, whether the details were hidden
behind an env-var or a shell alias).

Other arguments:
In favor of an env-var:
LS_COLORS is now understood by more than just 'ls' - at least tcsh
honors the contents of LS_COLORS (sometimes good, but also annoying when
we extend 'ls' to understand new options and then tcsh spews out error
messages about unknown directives in LS_COLORS).
Likewise, other programs could be taught to honor DIFF_COLORS (git,
perhaps?) - but do we then need a common location to specify how it
works so that all future programs buy in to the same interpretation?

Against env-var:
LS_COLORS is already quite large, and we may be adding yet another large
env-var in DIFF_COLORS. On some platforms, the environment space is
already limited; on mingw, every byte added in the environment is one
less byte towards the command line maximum limit (argv and env share the
same 64k block of memory - not quite POSIX-y, but not all the world is
POSIX).
In an interactive environment, the user is already likely to be creating
a shell alias/function to turn 'diff' into 'diff --color' - it is not
that much harder to have the alias be 'diff --color
--option-to-set-colors' compared to 'DIFF_COLORS=3D... diff --color', but=

conceptually having it all through the command line rather than split
among two sources makes it easier to trace where the change is made.

I don't have a strong opinion on whether an env-var is right or wrong,
so long as we have at least SOME way to override default colors.  But I
_do_ think that this is at least a safe env-var if we want to go that
route (since it only affects the behavior of opt-in --color usage,
rather than all situations).

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


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

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

iQEcBAEBCAAGBQJWJm74AAoJEKeha0olJ0NqaEUH/0VBeuO54411hZG/O/K5bitt
RVCmGbRh0WBW3NQ5TvNvgcJch6wceAZFoJCvt4Xmxo7/cyLs28Hvm9jBJgkZKR2/
T4fTE1GHHhJnDqiUXOYLs7q5+hl/Uc4cShsAafVwhe1WCHXivU66NVRZvKcNqsT3
4O0PoNs2E0s3kDrwm306vPMTvOJMyMgQDdVFJ9T5mUnDtf7+kIaoXJsPKFsKU6WX
Pa/J/pQab53UMNhUomgZW2ApNEyKgAY88BKNRby9A2BmURr3eHdHdolpkEX1ljSe
/EFl84fNc02BE5jwha2fcAXSDudf5uLy1hNK3LTqAU6FLjotCN31LvfXsyN0Z14=
=zBhn
-----END PGP SIGNATURE-----

--8LUvQ0oEw4hwmL8K32NKV9kLockmXtFpH--




From MAILER-DAEMON Tue Oct 20 13:33:12 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Zoame-0000ns-If
	for mharc-bug-diffutils@gnu.org; Tue, 20 Oct 2015 13:33:12 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:54601)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoamY-0000i9-AG
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 13:33:10 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoamU-0007CW-V4
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 13:33:06 -0400
Received: from debbugs.gnu.org ([208.118.235.43]:39411)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoamU-0007CP-SD
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 13:33:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZoamU-0000Ox-M4
	for bug-diffutils@gnu.org; Tue, 20 Oct 2015 13:33:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Aaron Davies <aaron.davies@gmail.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 20 Oct 2015 17:33:02 +0000
Resent-Message-ID: <handler.20062.B20062.14453623731513@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.14453623731513
	(code B ref 20062); Tue, 20 Oct 2015 17:33:02 +0000
Received: (at 20062) by debbugs.gnu.org; 20 Oct 2015 17:32:53 +0000
Received: from localhost ([127.0.0.1]:58350 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZoamK-0000OJ-Nn
	for submit@debbugs.gnu.org; Tue, 20 Oct 2015 13:32:53 -0400
Received: from mail-qk0-f177.google.com ([209.85.220.177]:35998)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <aaron.davies@gmail.com>) id 1Zoalz-0000Ni-Hl
	for 20062@debbugs.gnu.org; Tue, 20 Oct 2015 13:32:50 -0400
Received: by qkca6 with SMTP id a6so10888181qkc.3
	for <20062@debbugs.gnu.org>; Tue, 20 Oct 2015 10:32:31 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=content-type:mime-version:subject:from:in-reply-to:date:cc
	:content-transfer-encoding:message-id:references:to;
	bh=UjS0fkVqVm03PEAxr+GCBK6XRgYKydALlgIKqcIUUXI=;
	b=I9oV386pi4YxcesosddpMG5jTqIwpVHM3E9aqfZcXE0tY9oUcYBj2+Cu3Zx5zoPQaN
	EP18nSVlLByf69Sj/cB3vPKv2zC+Vc2QQmejLlE9utYa4BFAVf3sKAl/HuCS1j2DFjGu
	7pKNjsGWI9LkEi2oHt8GePSg6FmSD8mbPvW70THwSjfQO4lRFNpAZiCMYou9WsCri34b
	PcLO/8tkl7CWPIRWc3W0mcblPUknzsGBjG/wmLTUGzYv+glymGxngZ50hdNDS7BMTSDe
	Ksh6F3a8fbDKEUxpzDm2sq/nWtFB/UOcuFRwgUu7M6lxd2UwS0uZaYudXTH2+ixDNGyC
	vprA==
X-Received: by 10.55.55.82 with SMTP id e79mr5223457qka.59.1445362351128;
	Tue, 20 Oct 2015 10:32:31 -0700 (PDT)
Received: from [10.180.255.86] (mobile-107-107-57-41.mycingular.net.
	[107.107.57.41]) by smtp.gmail.com with ESMTPSA id
	m26sm1638557qki.28.2015.10.20.10.32.30
	(version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
	Tue, 20 Oct 2015 10:32:30 -0700 (PDT)
Content-Type: text/plain;
	charset=us-ascii
Mime-Version: 1.0 (1.0)
From: Aaron Davies <aaron.davies@gmail.com>
X-Mailer: iPhone Mail (12F70)
In-Reply-To: <56266EF8.7090908@redhat.com>
Date: Tue, 20 Oct 2015 13:32:29 -0400
Content-Transfer-Encoding: quoted-printable
Message-Id: <C6A8D992-E07C-4A0C-BA6E-3F4CA9C14015@gmail.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<87fv7uleyp.fsf@redhat.com> <55358394.5040809@cs.ucla.edu>
	<87r3rbg9qc.fsf@redhat.com> <55382807.3020408@cs.ucla.edu>
	<87y4jf24w8.fsf@foo.bar.baz> <5584B2CB.7040104@cs.ucla.edu>
	<87bnd9sak5.fsf@foo.bar.baz> <55F283AC.9030704@cs.ucla.edu>
	<55F29E35.50808@yahoo.no> <55F2F304.2070808@cs.ucla.edu>
	<87vbbgr5kt.fsf@foo.bar.baz> <55F35117.5080005@redhat.com>
	<55F3525D.7050006@cs.ucla.edu> <87lhccqapr.fsf@foo.bar.baz>
	<55F3F26A.4050400@cs.ucla.edu> <87bnd7n9wn.fsf@foo.bar.baz>
	<55F44A2E.2050506@cs.ucla.edu> <8737y5h281.fsf@foo.bar.baz>
	<87oag1aj61.fsf@foo.bar.baz>
	<CA+8g5KEuUCv-rWgDjZu0fEd7VAekq_V0XFJZtKhBmtdMqxfeLg@mail.gmail.com>
	<87wpuh1pcl.fsf@foo.bar.baz> <56266B13.2020503@cs.ucla.edu>
	<56266EF8.7090908@redhat.com>
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: 208.118.235.43
Cc: Giuseppe Scrivano <gscrivano@gnu.org>,
	"20062@debbugs.gnu.org" <20062@debbugs.gnu.org>
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: 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: Tue, 20 Oct 2015 17:33:10 -0000

On Oct 20, 2015, at 12:42 PM, Eric Blake <eblake@redhat.com> wrote:

>> On 10/20/2015 10:25 AM, Paul Eggert wrote:
>> Giuseppe Scrivano wrote:
>>> diff honors DIFF_COLORS
>>> now.
>>=20
>> Aren't we trying to move away from environment variables' affecting
>> program behavior, given all the maintenance and security hassles that
>> entails?
>=20
> I think there's a difference between an environment variable which only
> affects optional behavior (LS_COLORS, DIFF_COLORS - only affect things
> for 'ls --color' or 'diff --color') vs. those that affect ALL behavior
> (GREP_OPTIONS - cruelly affects all executions of grep, no matter what
> options were in use).
>=20
> You do have a point that allowing the choice to come through a command
> line option, and wrapping diff behind an alias or shell function, will
> let the interactive user set up their terminal to get the same effect
> (typing 'diff' gets the colored version, whether the details were hidden
> behind an env-var or a shell alias).
>=20
> Other arguments:
> In favor of an env-var:
> LS_COLORS is now understood by more than just 'ls' - at least tcsh
> honors the contents of LS_COLORS (sometimes good, but also annoying when
> we extend 'ls' to understand new options and then tcsh spews out error
> messages about unknown directives in LS_COLORS).
> Likewise, other programs could be taught to honor DIFF_COLORS (git,
> perhaps?) - but do we then need a common location to specify how it
> works so that all future programs buy in to the same interpretation?
>=20
> Against env-var:
> LS_COLORS is already quite large, and we may be adding yet another large
> env-var in DIFF_COLORS. On some platforms, the environment space is
> already limited; on mingw, every byte added in the environment is one
> less byte towards the command line maximum limit (argv and env share the
> same 64k block of memory - not quite POSIX-y, but not all the world is
> POSIX).
> In an interactive environment, the user is already likely to be creating
> a shell alias/function to turn 'diff' into 'diff --color' - it is not
> that much harder to have the alias be 'diff --color
> --option-to-set-colors' compared to 'DIFF_COLORS=3D... diff --color', but
> conceptually having it all through the command line rather than split
> among two sources makes it easier to trace where the change is made.
>=20
> I don't have a strong opinion on whether an env-var is right or wrong,
> so long as we have at least SOME way to override default colors.  But I
> _do_ think that this is at least a safe env-var if we want to go that
> route (since it only affects the behavior of opt-in --color usage,
> rather than all situations).

I'm very new here, so feel free to take my opinions with a grain of salt, bu=
t one thing I've been noticing in my scripting work is that environment vari=
ables' biggest drawback is often also their big advantage: you don't have to=
 propagate them manually.

Suppose you want to encapsulate some common diff operation in a small shell s=
cript. Then anything you want that diff to do that you specified in an alias=
 or function in your interactive shell has to be written out again.

Alternatively, you could have a diff wrapper in your ~/bin setting the optio=
n, but it's hard to actually write those correctly to handle things like std=
in vs. file args.

None of this comes with env vars.

Still, I understand your other concerns.

Maybe a ~/.diffrc is the solution?=




From MAILER-DAEMON Wed Oct 28 11:30:16 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZrSg3-00063h-VG
	for mharc-bug-diffutils@gnu.org; Wed, 28 Oct 2015 11:30:15 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:45616)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZrSfy-00061E-QN
	for bug-diffutils@gnu.org; Wed, 28 Oct 2015 11:30:15 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZrSft-0002xs-5l
	for bug-diffutils@gnu.org; Wed, 28 Oct 2015 11:30:10 -0400
Received: from debbugs.gnu.org ([208.118.235.43]:51963)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZrSft-0002xm-3Z
	for bug-diffutils@gnu.org; Wed, 28 Oct 2015 11:30:05 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZrSfs-00056Z-4r
	for bug-diffutils@gnu.org; Wed, 28 Oct 2015 11:30:04 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Giuseppe Scrivano <gscrivano@gnu.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Wed, 28 Oct 2015 15:30:03 +0000
Resent-Message-ID: <handler.20062.B20062.144604617219560@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: Aaron Davies <aaron.davies@gmail.com>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.144604617219560
	(code B ref 20062); Wed, 28 Oct 2015 15:30:03 +0000
Received: (at 20062) by debbugs.gnu.org; 28 Oct 2015 15:29:32 +0000
Received: from localhost ([127.0.0.1]:42671 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZrSfM-00055P-E0
	for submit@debbugs.gnu.org; Wed, 28 Oct 2015 11:29:32 -0400
Received: from mx1.redhat.com ([209.132.183.28]:49908)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivano@gnu.org>) id 1ZrSf2-00054x-DJ
	for 20062@debbugs.gnu.org; Wed, 28 Oct 2015 11:29:31 -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 (Postfix) with ESMTPS id 3961F8E235;
	Wed, 28 Oct 2015 15:29:11 +0000 (UTC)
Received: from foo.bar.baz (vpn1-7-84.ams2.redhat.com [10.36.7.84])
	by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id t9SFT7nL016197
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=NO); Wed, 28 Oct 2015 11:29:08 -0400
From: Giuseppe Scrivano <gscrivano@gnu.org>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<87y4jf24w8.fsf@foo.bar.baz> <5584B2CB.7040104@cs.ucla.edu>
	<87bnd9sak5.fsf@foo.bar.baz> <55F283AC.9030704@cs.ucla.edu>
	<55F29E35.50808@yahoo.no> <55F2F304.2070808@cs.ucla.edu>
	<87vbbgr5kt.fsf@foo.bar.baz> <55F35117.5080005@redhat.com>
	<55F3525D.7050006@cs.ucla.edu> <87lhccqapr.fsf@foo.bar.baz>
	<55F3F26A.4050400@cs.ucla.edu> <87bnd7n9wn.fsf@foo.bar.baz>
	<55F44A2E.2050506@cs.ucla.edu> <8737y5h281.fsf@foo.bar.baz>
	<87oag1aj61.fsf@foo.bar.baz>
	<CA+8g5KEuUCv-rWgDjZu0fEd7VAekq_V0XFJZtKhBmtdMqxfeLg@mail.gmail.com>
	<87wpuh1pcl.fsf@foo.bar.baz> <56266B13.2020503@cs.ucla.edu>
	<56266EF8.7090908@redhat.com>
	<C6A8D992-E07C-4A0C-BA6E-3F4CA9C14015@gmail.com>
Date: Wed, 28 Oct 2015 16:29:06 +0100
In-Reply-To: <C6A8D992-E07C-4A0C-BA6E-3F4CA9C14015@gmail.com> (Aaron Davies's
	message of "Tue, 20 Oct 2015 13:32:29 -0400")
Message-ID: <87y4enj9kt.fsf@foo.bar.baz>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
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: 208.118.235.43
Cc: "20062@debbugs.gnu.org" <20062@debbugs.gnu.org>
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: 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: Wed, 28 Oct 2015 15:30:15 -0000

Aaron Davies <aaron.davies@gmail.com> writes:

> I'm very new here, so feel free to take my opinions with a grain of salt, but one thing I've been noticing in my scripting work is that environment variables' biggest drawback is often also their big advantage: you don't have to propagate them manually.
>
> Suppose you want to encapsulate some common diff operation in a small shell script. Then anything you want that diff to do that you specified in an alias or function in your interactive shell has to be written out again.
>
> Alternatively, you could have a diff wrapper in your ~/bin setting the option, but it's hard to actually write those correctly to handle things like stdin vs. file args.
>
> None of this comes with env vars.
>
> Still, I understand your other concerns.
>
> Maybe a ~/.diffrc is the solution?

that could be a good solution, and probably other kind of options can be
moved but IMHO it seems a bit over-engineered to read just the colors
settings.

If the choice is between an env variable or adding a new command line
argument, the former makes more sense as it works similarly to other
tools that people already know.

If there is any strong argument against not using an environment
variable as this patch is doing, I will rework the patch to use a
command line argument instead.

Regards,
Giuseppe




