From MAILER-DAEMON Mon Nov 02 00:08:08 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Zt7Lk-0007Yj-Am
	for mharc-bug-diffutils@gnu.org; Mon, 02 Nov 2015 00:08:08 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41230)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Zt7Li-0007YY-Kn
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 00:08:07 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Zt7Le-0001NF-6k
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 00:08:06 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:57645)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Zt7Le-0001NB-35
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 00:08:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Zt7Ld-0005xM-LZ
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 00:08:01 -0500
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: Mon, 02 Nov 2015 05:08:01 +0000
Resent-Message-ID: <handler.20062.B20062.144644084422847@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.144644084422847
	(code B ref 20062); Mon, 02 Nov 2015 05:08:01 +0000
Received: (at 20062) by debbugs.gnu.org; 2 Nov 2015 05:07:24 +0000
Received: from localhost ([127.0.0.1]:48353 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1Zt7L1-0005wR-Db
	for submit@debbugs.gnu.org; Mon, 02 Nov 2015 00:07:23 -0500
Received: from mail-vk0-f52.google.com ([209.85.213.52]:34018)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>) id 1Zt7Kh-0005vw-67
	for 20062@debbugs.gnu.org; Mon, 02 Nov 2015 00:07:21 -0500
Received: by vkgs66 with SMTP id s66so78877822vkg.1
	for <20062@debbugs.gnu.org>; Sun, 01 Nov 2015 21:07:03 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:from:date:message-id
	:subject:to:cc:content-type;
	bh=HYpZy5mUz4UekO8Tk29O+RelpMAAweJFQ9XnpPTYXZ8=;
	b=yBYgapgTaybIFhl3erWtQpLy7wcDK0pTjRZ7xzUwAU50ThgFRib18L3aWNQJDzowJY
	fB5dyy1KUqVjtxWTvCU/0ECYY6qtlbxOc/1qgCgJ9XhR0vEX7EzqiGPpeopp26legrJo
	DXTQSEr0NS1mGXHBQ/PDFWRXm42G1ifCy+SbBIwHBxf7qIkOmXo2qNzPLZjw5sqgWECQ
	K67aNlRyfq8kbf9Gaujkw0BNODHMYZS8noE7XMNA6hH/YaUNBMMdrHa+RSVAHCOMhyRx
	Txer8v/csZCRVDaR7i/VMPVF6+SGLi71ER2VmVmXXAQtsdnTDSnAZpZkdThfj0w79aNx
	pFjg==
X-Received: by 10.31.155.138 with SMTP id d132mr13687605vke.55.1446440822912; 
	Sun, 01 Nov 2015 21:07:02 -0800 (PST)
MIME-Version: 1.0
Received: by 10.31.65.11 with HTTP; Sun, 1 Nov 2015 21:06:43 -0800 (PST)
In-Reply-To: <87wpuh1pcl.fsf@foo.bar.baz>
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: Jim Meyering <jim@meyering.net>
Date: Sun, 1 Nov 2015 21:06:43 -0800
X-Google-Sender-Auth: KIdvUHWApCKROiM1J0x2Vc1oGNY
Message-ID: <CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@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: Mon, 02 Nov 2015 05:08:07 -0000

On Tue, Oct 20, 2015 at 9:23 AM, Giuseppe Scrivano <gscrivano@gnu.org> wrote:
> 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:
...
>> 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.

Thanks for the quick work.
I'll try to be quicker, this time.

>> 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.

Those revisions to your first patch look fine, and I will look over that
one once more in the morning, then expect to push.

Regarding the support for configurable colors, as already mentioned
here, we really do want to avoid adding support for any more
environment variables.  Would you please adjust the second
patch to take the settings from a command line argument instead?
With that, it will be trivial to add an envvar-honoring wrapper script,
function or alias, for those who desire that convenience.

The most important reason not to provide this functionality via
an envvar is that it would then allow that envvar setting to alter
the behavior of any program that invokes diff, and that sort of
interaction is often surprising and undesirable.

Thanks again for contributing!




From MAILER-DAEMON Mon Nov 02 10:07:10 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZtGhS-0002OH-Pe
	for mharc-bug-diffutils@gnu.org; Mon, 02 Nov 2015 10:07:10 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:52739)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtGhP-0002NJ-Hf
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 10:07:08 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtGhL-00005K-5C
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 10:07:07 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:59117)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtGhL-00005F-2O
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 10:07:03 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtGhK-0005xC-En
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 10:07:02 -0500
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: Mon, 02 Nov 2015 15:07:02 +0000
Resent-Message-ID: <handler.20062.B20062.144647680122848@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.144647680122848
	(code B ref 20062); Mon, 02 Nov 2015 15:07:02 +0000
Received: (at 20062) by debbugs.gnu.org; 2 Nov 2015 15:06:41 +0000
Received: from localhost ([127.0.0.1]:49825 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZtGgz-0005wR-05
	for submit@debbugs.gnu.org; Mon, 02 Nov 2015 10:06:41 -0500
Received: from mx1.redhat.com ([209.132.183.28]:38178)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivano@gnu.org>) id 1ZtGgv-0005wG-VW
	for 20062@debbugs.gnu.org; Mon, 02 Nov 2015 10:06:39 -0500
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 26D9B19CB9D;
	Mon,  2 Nov 2015 15:06:36 +0000 (UTC)
Received: from foo.bar.baz (vpn1-6-75.ams2.redhat.com [10.36.6.75])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id tA2F6WR3011235
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=NO); Mon, 2 Nov 2015 10:06:34 -0500
From: Giuseppe Scrivano <gscrivano@gnu.org>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
Date: Mon, 02 Nov 2015 16:06:31 +0100
In-Reply-To: <CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	(Jim Meyering's message of "Sun, 1 Nov 2015 21:06:43 -0800")
Message-ID: <87h9l4tp8o.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: bug#20062: [PATCH] diff: add support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 02 Nov 2015 15:07:08 -0000

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

Hi Jim,

Jim Meyering <jim@meyering.net> writes:

> Regarding the support for configurable colors, as already mentioned
> here, we really do want to avoid adding support for any more
> environment variables.  Would you please adjust the second
> patch to take the settings from a command line argument instead?
> With that, it will be trivial to add an envvar-honoring wrapper script,
> function or alias, for those who desire that convenience.
>
> The most important reason not to provide this functionality via
> an envvar is that it would then allow that envvar setting to alter
> the behavior of any program that invokes diff, and that sort of
> interaction is often surprising and undesirable.
>
> Thanks again for contributing!

Thanks for your review.

Would something like this patch work?

I have attached the difference from the previous version to make the
review easier as few lines are changed.

I have included the full ChangeLog entries in the commit message so it
will be easier to squash the patch on top of the previous one.

Regards,
Giuseppe


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

>From 0ed880f2e6f76809563597cc698da4c15b19ba1d Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Mon, 2 Nov 2015 15:43:23 +0100
Subject: [PATCH] squash! diff: honor env variable DIFF_COLORS

diff: add --color-scheme

doc/diffutils.texi: Add documentation for --color-scheme
src/diff.h (set_color_scheme): New prototype.
src/diff.c (set_color_scheme): New function.
(color_scheme): New variable.
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 |  7 ++++---
 src/diff.c         |  6 ++++++
 src/diff.h         |  1 +
 src/util.c         | 10 +++++++++-
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 75ad0d7..9f2cdbb 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3763,9 +3763,10 @@ 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 --color-scheme=@var{scheme}
+It allows to specify what colors are used to colorize the output.  It
+defaults 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}
diff --git a/src/diff.c b/src/diff.c
index 4e0f602..55ed69d 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -140,6 +140,7 @@ enum
   CHANGED_GROUP_FORMAT_OPTION,
 
   COLOR_OPTION,
+  COLOR_SCHEME_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -163,6 +164,7 @@ static struct option const longopts[] =
   {"brief", 0, 0, 'q'},
   {"changed-group-format", 1, 0, CHANGED_GROUP_FORMAT_OPTION},
   {"color", 2, 0, COLOR_OPTION},
+  {"color-scheme", 1, 0, COLOR_SCHEME_OPTION},
   {"context", 2, 0, 'C'},
   {"ed", 0, 0, 'e'},
   {"exclude", 1, 0, 'x'},
@@ -635,6 +637,10 @@ main (int argc, char **argv)
 	  specify_colors_style (optarg);
 	  break;
 
+	case COLOR_SCHEME_OPTION:
+	  set_color_scheme (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
diff --git a/src/diff.h b/src/diff.h
index 472fa93..883119e 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -411,3 +411,4 @@ 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);
+extern void set_color_scheme (const char *scheme);
diff --git a/src/util.c b/src/util.c
index 8d27bc7..108b8e0 100644
--- a/src/util.c
+++ b/src/util.c
@@ -562,6 +562,14 @@ static const char *const indicator_name[]=
     "lc", "rc", "ec", "rs", "hd", "ad", "de", "ln", NULL
   };
 
+static const char *color_scheme;
+
+void
+set_color_scheme (const char *scheme)
+{
+  color_scheme = scheme;
+}
+
 static void
 parse_diff_color (void)
 {
@@ -572,7 +580,7 @@ parse_diff_color (void)
   char label[3];		/* Indicator label */
   struct color_ext_type *ext;	/* Extension we are working on */
 
-  if ((p = getenv ("DIFF_COLORS")) == NULL || *p == '\0')
+  if ((p = color_scheme) == NULL || *p == '\0')
     return;
 
   ext = NULL;
-- 
2.5.0


--=-=-=--




From MAILER-DAEMON Mon Nov 02 12:17:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZtIjF-00057l-QD
	for mharc-bug-diffutils@gnu.org; Mon, 02 Nov 2015 12:17:09 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:33434)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtIjC-00057R-Ty
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 12:17:07 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtIj8-0006Si-Js
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 12:17:06 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:59211)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtIj8-0006Sd-GB
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 12:17:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtIj7-0002Mq-SV
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 12:17:01 -0500
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: Mon, 02 Nov 2015 17:17:01 +0000
Resent-Message-ID: <handler.20062.B20062.14464845789050@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.14464845789050
	(code B ref 20062); Mon, 02 Nov 2015 17:17:01 +0000
Received: (at 20062) by debbugs.gnu.org; 2 Nov 2015 17:16:18 +0000
Received: from localhost ([127.0.0.1]:49919 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZtIiQ-0002Lt-8E
	for submit@debbugs.gnu.org; Mon, 02 Nov 2015 12:16:18 -0500
Received: from mail-vk0-f50.google.com ([209.85.213.50]:36262)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>) id 1ZtIi5-0002Kx-UJ
	for 20062@debbugs.gnu.org; Mon, 02 Nov 2015 12:16:16 -0500
Received: by vkex70 with SMTP id x70so88872188vke.3
	for <20062@debbugs.gnu.org>; Mon, 02 Nov 2015 09:15:57 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:from:date:message-id
	:subject:to:cc:content-type;
	bh=ZZNL58WAKdmjd7HW/DoLbBngnT4+MRpTPQKTY4I5aUs=;
	b=D24aJtBM+f9M+Ms2vCNOzxWppT0/vA+PgzF4aSxc6XQKUhqa4pE2utfkaff36PCAqw
	SaQCUQlVLPwSrsjRt5w+6dc41pVS4+5eRzuBgv69rj1vucYpa/GQSLi4FjUReRbCPRpE
	uwosc1L8T/RNjun6ZpQel9mMDjyYkJav8OmA2NKAH8/142WPhBERB2NZ7NJyFzFzOB8D
	Was5kCbdE4anusnKAmHiX4FV3Tx3i6rqoDXbzejtozEFfHo/8ypLL15CZuh2N9RFbNec
	gfe1n9s6Qoy6j1Zp8hJqaRJDEMyiMYzvcOGKx5trsAdGitzNVAVVtKW9zVBYb3CzTwxM
	1w9A==
X-Received: by 10.31.8.4 with SMTP id 4mr15358418vki.77.1446484557299; Mon, 02
	Nov 2015 09:15:57 -0800 (PST)
MIME-Version: 1.0
Received: by 10.31.65.11 with HTTP; Mon, 2 Nov 2015 09:15:37 -0800 (PST)
In-Reply-To: <CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
From: Jim Meyering <jim@meyering.net>
Date: Mon, 2 Nov 2015 09:15:37 -0800
X-Google-Sender-Auth: qw36WXKyQclpnwBSP99hlZ5pjgE
Message-ID: <CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@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: bug#20062: [PATCH] diff: add support
	for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 02 Nov 2015 17:17:08 -0000

On Sun, Nov 1, 2015 at 9:06 PM, Jim Meyering <jim@meyering.net> wrote:
> On Tue, Oct 20, 2015 at 9:23 AM, Giuseppe Scrivano <gscrivano@gnu.org> wrote:
>> 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:
> ...
>>> 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.
>
> Thanks for the quick work.
> I'll try to be quicker, this time.
>
>>> 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.
>
> Those revisions to your first patch look fine, and I will look over that
> one once more in the morning, then expect to push.

Your first patch adds a useful new feature, but includes
neither a NEWS addition nor any test. Would you please add those?




From MAILER-DAEMON Mon Nov 02 14:18:08 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZtKcK-0004oy-HL
	for mharc-bug-diffutils@gnu.org; Mon, 02 Nov 2015 14:18:08 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:59318)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtKcI-0004on-N1
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 14:18:07 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtKcE-0005Kp-8g
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 14:18:06 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:59256)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtKcE-0005Kl-5l
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 14:18:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtKcD-0005QI-Pq
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 14:18:01 -0500
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: Mon, 02 Nov 2015 19:18:01 +0000
Resent-Message-ID: <handler.20062.B20062.144649183520777@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.144649183520777
	(code B ref 20062); Mon, 02 Nov 2015 19:18:01 +0000
Received: (at 20062) by debbugs.gnu.org; 2 Nov 2015 19:17:15 +0000
Received: from localhost ([127.0.0.1]:49964 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZtKbS-0005P2-LJ
	for submit@debbugs.gnu.org; Mon, 02 Nov 2015 14:17:15 -0500
Received: from mx1.redhat.com ([209.132.183.28]:39868)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivano@gnu.org>) id 1ZtKbP-0005Ot-UC
	for 20062@debbugs.gnu.org; Mon, 02 Nov 2015 14:17:13 -0500
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (Postfix) with ESMTPS id 17469C1C74E2;
	Mon,  2 Nov 2015 19:17:11 +0000 (UTC)
Received: from foo.bar.baz (vpn1-6-75.ams2.redhat.com [10.36.6.75])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id tA2JH8NC031509
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=NO); Mon, 2 Nov 2015 14:17:09 -0500
From: Giuseppe Scrivano <gscrivano@gnu.org>
References: <1425851791-29188-1-git-send-email-gscrivan@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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
Date: Mon, 02 Nov 2015 20:17:07 +0100
In-Reply-To: <CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	(Jim Meyering's message of "Mon, 2 Nov 2015 09:15:37 -0800")
Message-ID: <87bnbcrz2k.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.23
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 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: Mon, 02 Nov 2015 19:18:07 -0000

Jim Meyering <jim@meyering.net> writes:

> On Sun, Nov 1, 2015 at 9:06 PM, Jim Meyering <jim@meyering.net> wrote:
>> On Tue, Oct 20, 2015 at 9:23 AM, Giuseppe Scrivano <gscrivano@gnu.org> wrote:
>>> 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:
>> ...
>>>> 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.
>>
>> Thanks for the quick work.
>> I'll try to be quicker, this time.
>>
>>>> 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.
>>
>> Those revisions to your first patch look fine, and I will look over that
>> one once more in the morning, then expect to push.
>
> Your first patch adds a useful new feature, but includes
> neither a NEWS addition nor any test. Would you please add those?

sure, I will do.

I forgot to update "option_help_msgid" in my previous patch which adds
--color-scheme to define the colors used by diff.

Anyway, I would like an opinion about the new name before I send te full
series again.  I avoided --colors as it is very similar to --color, but
I am not sure how --color-scheme sounds for a native speaker.

Regards,
Giuseppe




From MAILER-DAEMON Mon Nov 02 14:35:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZtKsn-0008Ej-EM
	for mharc-bug-diffutils@gnu.org; Mon, 02 Nov 2015 14:35:09 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:34021)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtKsk-0008DK-Qu
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 14:35:07 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtKsg-0000Le-QU
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 14:35:06 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:59271)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtKsg-0000LS-No
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 14:35:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtKsg-0007Tz-D2
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 14:35:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Eric Blake <eblake@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Mon, 02 Nov 2015 19:35:02 +0000
Resent-Message-ID: <handler.20062.B20062.144649287628729@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.144649287628729
	(code B ref 20062); Mon, 02 Nov 2015 19:35:02 +0000
Received: (at 20062) by debbugs.gnu.org; 2 Nov 2015 19:34:36 +0000
Received: from localhost ([127.0.0.1]:49979 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZtKsF-0007TH-Dq
	for submit@debbugs.gnu.org; Mon, 02 Nov 2015 14:34:35 -0500
Received: from mx1.redhat.com ([209.132.183.28]:43482)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eblake@redhat.com>) id 1ZtKrv-0007Sn-8O
	for 20062@debbugs.gnu.org; Mon, 02 Nov 2015 14:34:34 -0500
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 121C88CF6E;
	Mon,  2 Nov 2015 19:34:13 +0000 (UTC)
Received: from [10.3.113.189] (ovpn-113-189.phx2.redhat.com [10.3.113.189])
	by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id tA2JYCKf021740; Mon, 2 Nov 2015 14:34:13 -0500
References: <1425851791-29188-1-git-send-email-gscrivan@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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz>
From: Eric Blake <eblake@redhat.com>
Openpgp: url=http://people.redhat.com/eblake/eblake.gpg
Organization: Red Hat, Inc.
Message-ID: <5637BAAC.8020301@redhat.com>
Date: Mon, 2 Nov 2015 12:34:04 -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: <87bnbcrz2k.fsf@foo.bar.baz>
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature";
	boundary="nKL9lNoDeG4DSb04q0NmtBtwqE74MSR7p"
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: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 02 Nov 2015 19:35:07 -0000

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

On 11/02/2015 12:17 PM, Giuseppe Scrivano wrote:

> Anyway, I would like an opinion about the new name before I send te ful=
l
> series again.  I avoided --colors as it is very similar to --color, but=

> I am not sure how --color-scheme sounds for a native speaker.

--color-scheme sounds okay to a native, but has the issue that it cannot
be abbreviated (--col would be short for --color, not --color-scheme).
Can you come up with a name that does not share a common prefix?  Maybe
--palette?

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


--nKL9lNoDeG4DSb04q0NmtBtwqE74MSR7p
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/

iQEcBAEBCAAGBQJWN7qsAAoJEKeha0olJ0NqE5gH/AvfePAaAsejaWJbJckDvCda
CNVYWrDzMRjqejdCL61v2XA+oNBU5pU/DdfolTPVd5aZw4Wn3qWxWgS80y29HQK4
TnHO/HasYoWWcDxQ8/Qx1hhdfXOvFjTvvJqgbatBewKzJzomdua7iOuxnkfmXVcP
aAgi5ltHg4UPuw33CRVVh/H1zPH9vyHGAhV8u0LHXjN8qHmAe8lfKXlCwd7Rx9PV
BcqaXXWgITIESrr5lF+N58zKbVkVJE6e+7dGAszgpgdrvn9RGiXn0f30nplPa1iU
XHqmm+SSo5pxmKdyL1mWw/rh9i5pGs3/Xtzffs9QIkx5eG8AXoK/uuaUVE8QTek=
=t0mH
-----END PGP SIGNATURE-----

--nKL9lNoDeG4DSb04q0NmtBtwqE74MSR7p--




From MAILER-DAEMON Mon Nov 02 16:22:08 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZtMYK-00026P-BE
	for mharc-bug-diffutils@gnu.org; Mon, 02 Nov 2015 16:22:08 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:56005)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtMYH-00021U-IE
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 16:22:06 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtMYE-0004gd-8r
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 16:22:05 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:59320)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtMYE-0004gZ-5w
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 16:22:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtMYD-0001oE-RS
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 16:22:01 -0500
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: Mon, 02 Nov 2015 21:22:01 +0000
Resent-Message-ID: <handler.20062.B20062.14464992916909@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.14464992916909
	(code B ref 20062); Mon, 02 Nov 2015 21:22:01 +0000
Received: (at 20062) by debbugs.gnu.org; 2 Nov 2015 21:21:31 +0000
Received: from localhost ([127.0.0.1]:50028 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZtMXi-0001nN-NY
	for submit@debbugs.gnu.org; Mon, 02 Nov 2015 16:21:30 -0500
Received: from mail-vk0-f50.google.com ([209.85.213.50]:35765)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>) id 1ZtMXg-0001nE-1Y
	for 20062@debbugs.gnu.org; Mon, 02 Nov 2015 16:21:28 -0500
Received: by vkfw189 with SMTP id w189so93492397vkf.2
	for <20062@debbugs.gnu.org>; Mon, 02 Nov 2015 13:21:27 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:from:date:message-id
	:subject:to:cc:content-type;
	bh=TUf9lMrr05wuoo/kHYRcr78aLv3LrkJtqueOpBXF4jU=;
	b=w3xw2MD/20GAdZEYKupAZ0aXmoI9N+Fy57goLfMJU0yinONUjiEgIok52kxajqGVjt
	VMA13hAMBO2/P3b+HjgeaMk4/J153ijWp7DzxIzvZMhBNXajduXbTZcEuqXBdAyssVvG
	HSrAadaesjpbyXe4ZXs17h+c+HYYidMI5BFpE6iA/mumaNrzmpm3noL+8PDJpy8GdvTo
	WGV+gRfFqXZhryJyLPxSDf5fvUAijdmNTSALswDs6fbblxOfTtnsRd9S2rcR8Y0tu3Vv
	7izsbUmMvn04GajRHJdcN1F1VHOfeiRe7U2bivfO2sztUz006uxl3V+ie2rJW9WWs2sS
	Ctng==
X-Received: by 10.31.155.138 with SMTP id d132mr16322221vke.55.1446499287532; 
	Mon, 02 Nov 2015 13:21:27 -0800 (PST)
MIME-Version: 1.0
Received: by 10.31.65.11 with HTTP; Mon, 2 Nov 2015 13:21:08 -0800 (PST)
In-Reply-To: <5637BAAC.8020301@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
From: Jim Meyering <jim@meyering.net>
Date: Mon, 2 Nov 2015 13:21:08 -0800
X-Google-Sender-Auth: HVDnyzs1Gdz-B5_DlUX45v5zdto
Message-ID: <CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@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: Giuseppe Scrivano <gscrivano@gnu.org>, 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 02 Nov 2015 21:22:06 -0000

On Mon, Nov 2, 2015 at 11:34 AM, Eric Blake <eblake@redhat.com> wrote:
> On 11/02/2015 12:17 PM, Giuseppe Scrivano wrote:
>
>> Anyway, I would like an opinion about the new name before I send te full
>> series again.  I avoided --colors as it is very similar to --color, but
>> I am not sure how --color-scheme sounds for a native speaker.
>
> --color-scheme sounds okay to a native, but has the issue that it cannot
> be abbreviated (--col would be short for --color, not --color-scheme).
> Can you come up with a name that does not share a common prefix?  Maybe
> --palette?

Good point.
I too prefer --palette='...'
That does have the tiny downside that diff's rarely used
--paginate option will no longer be able to be abbreviated
as "--pa", but that is barely worth mentioning.




From MAILER-DAEMON Mon Nov 02 16:27:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZtMdB-0003ue-4F
	for mharc-bug-diffutils@gnu.org; Mon, 02 Nov 2015 16:27:09 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:57066)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtMd8-0003u6-Ff
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 16:27:07 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtMd4-0005kg-Jm
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 16:27:06 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:59328)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtMd4-0005ka-GJ
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 16:27:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtMd4-0001xi-C5
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 16:27:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Eric Blake <eblake@redhat.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Mon, 02 Nov 2015 21:27:02 +0000
Resent-Message-ID: <handler.20062.B20062.14464995737475@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.14464995737475
	(code B ref 20062); Mon, 02 Nov 2015 21:27:02 +0000
Received: (at 20062) by debbugs.gnu.org; 2 Nov 2015 21:26:13 +0000
Received: from localhost ([127.0.0.1]:50036 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZtMcH-0001wU-6v
	for submit@debbugs.gnu.org; Mon, 02 Nov 2015 16:26:13 -0500
Received: from mx1.redhat.com ([209.132.183.28]:41034)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eblake@redhat.com>) id 1ZtMcE-0001wH-07
	for 20062@debbugs.gnu.org; Mon, 02 Nov 2015 16:26:10 -0500
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 421EC42E5B2;
	Mon,  2 Nov 2015 21:26:09 +0000 (UTC)
Received: from [10.3.113.189] (ovpn-113-189.phx2.redhat.com [10.3.113.189])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id tA2LQ7Zt016583; Mon, 2 Nov 2015 16:26:08 -0500
References: <1425851791-29188-1-git-send-email-gscrivan@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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
From: Eric Blake <eblake@redhat.com>
Openpgp: url=http://people.redhat.com/eblake/eblake.gpg
Organization: Red Hat, Inc.
Message-ID: <5637D4EF.8000604@redhat.com>
Date: Mon, 2 Nov 2015 14:26:07 -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: <CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature";
	boundary="vRtUe9oeq3VJt2SQ3C3VBwm8CIerwn1EN"
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: Giuseppe Scrivano <gscrivano@gnu.org>, 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 02 Nov 2015 21:27:07 -0000

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

On 11/02/2015 02:21 PM, Jim Meyering wrote:
> I too prefer --palette=3D'...'
> That does have the tiny downside that diff's rarely used
> --paginate option will no longer be able to be abbreviated
> as "--pa", but that is barely worth mentioning.

Why do we even have -l/--paginate instead of telling people to run 'diff
| pr'?  Is it worth deprecating that option?

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


--vRtUe9oeq3VJt2SQ3C3VBwm8CIerwn1EN
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/

iQEcBAEBCAAGBQJWN9TvAAoJEKeha0olJ0NqRP8H/35N7P90S/Ms2PPmfbsvUXKE
qhPHboErT6E3n8EfDaU+Y5ocDIVLaIwa14oIyVe7zlrb6HHmez4BGMMAkHRTYMmk
GrggvQQBe/sJFvqJHRCz3zzwSFop8NxbrTf46RaQ8hXPxgxnky3qUZrpmvy+j4WI
/+QF1R7wo9rFWKFb/vo8zwtxxnLwZrY7CZYtFKA821utly/csL4putE/ZyQLyqWR
PjD7/FSq9UkTG6/OTmETcUxxjR7ymr+ftmjr2WgwtXZdQrAvye5/Xcfn8tNi+jVm
zfs8pWKTEXIJrSt5t0mUHWb0TvU1CdYc4v8nMQxtyzuWVnShj2ywIymT7HNu3K4=
=wSgf
-----END PGP SIGNATURE-----

--vRtUe9oeq3VJt2SQ3C3VBwm8CIerwn1EN--




From MAILER-DAEMON Mon Nov 02 21:22:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZtREf-0002JD-Rs
	for mharc-bug-diffutils@gnu.org; Mon, 02 Nov 2015 21:22:09 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:51089)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtREd-0002IU-LS
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 21:22:08 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtREY-0003J7-QG
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 21:22:07 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:59516)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtREY-0003J3-NF
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 21:22:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtREY-0003uZ-6U
	for bug-diffutils@gnu.org; Mon, 02 Nov 2015 21:22:02 -0500
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, 03 Nov 2015 02:22:02 +0000
Resent-Message-ID: <handler.20062.B20062.144651730015008@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>, Jim Meyering <jim@meyering.net>
Received: via spool by 20062-submit@debbugs.gnu.org id=B20062.144651730015008
	(code B ref 20062); Tue, 03 Nov 2015 02:22:02 +0000
Received: (at 20062) by debbugs.gnu.org; 3 Nov 2015 02:21:40 +0000
Received: from localhost ([127.0.0.1]:50224 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZtREC-0003tz-9s
	for submit@debbugs.gnu.org; Mon, 02 Nov 2015 21:21:40 -0500
Received: from zimbra.cs.ucla.edu ([131.179.128.68]:53057)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1ZtREA-0003tr-M9
	for 20062@debbugs.gnu.org; Mon, 02 Nov 2015 21:21:39 -0500
Received: from localhost (localhost [127.0.0.1])
	by zimbra.cs.ucla.edu (Postfix) with ESMTP id 2CFE516063E;
	Mon,  2 Nov 2015 18:21:37 -0800 (PST)
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 KyTyRyyfksop; Mon,  2 Nov 2015 18:21:36 -0800 (PST)
Received: from localhost (localhost [127.0.0.1])
	by zimbra.cs.ucla.edu (Postfix) with ESMTP id 6F46B160D6A;
	Mon,  2 Nov 2015 18:21:36 -0800 (PST)
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 nf35Z31Ei0Qw; Mon,  2 Nov 2015 18:21:36 -0800 (PST)
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 45AD116063E;
	Mon,  2 Nov 2015 18:21:36 -0800 (PST)
References: <1425851791-29188-1-git-send-email-gscrivan@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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
	<5637D4EF.8000604@redhat.com>
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
Message-ID: <56381A2D.10401@cs.ucla.edu>
Date: Mon, 2 Nov 2015 18:21:33 -0800
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: <5637D4EF.8000604@redhat.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 208.118.235.43
Cc: Giuseppe Scrivano <gscrivano@gnu.org>, 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Nov 2015 02:22:08 -0000

Eric Blake wrote:
> Why do we even have -l/--paginate

4.3BSD had it.  As you mention, -l was a bad idea, but we wanted to be 
compatible with BSD.  I suppose we could deprecate it at some point....




From MAILER-DAEMON Tue Nov 03 12:06:12 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Ztf2C-0000rr-Ho
	for mharc-bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:06:12 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:38463)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Ztf28-0000pa-FF
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:06:10 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Ztf22-000244-Qd
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:06:08 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:60980)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Ztf22-00023r-Nh
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:06:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1Ztf22-0004RI-7O
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:06:02 -0500
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, 03 Nov 2015 17:06:02 +0000
Resent-Message-ID: <handler.20062.B20062.144657036017050@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.144657036017050
	(code B ref 20062); Tue, 03 Nov 2015 17:06:02 +0000
Received: (at 20062) by debbugs.gnu.org; 3 Nov 2015 17:06:00 +0000
Received: from localhost ([127.0.0.1]:51686 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1Ztf1g-0004QS-HF
	for submit@debbugs.gnu.org; Tue, 03 Nov 2015 12:06:00 -0500
Received: from mx1.redhat.com ([209.132.183.28]:57147)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivano@gnu.org>) id 1Ztf1a-0004QF-RB
	for 20062@debbugs.gnu.org; Tue, 03 Nov 2015 12:05:36 -0500
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (Postfix) with ESMTPS id CC8FA19F27D;
	Tue,  3 Nov 2015 17:05:33 +0000 (UTC)
Received: from foo.bar.baz (vpn1-5-245.ams2.redhat.com [10.36.5.245])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id tA3H5TAl015634
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=NO); Tue, 3 Nov 2015 12:05:31 -0500
From: Giuseppe Scrivano <gscrivano@gnu.org>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
Date: Tue, 03 Nov 2015 18:05:29 +0100
In-Reply-To: <CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
	(Jim Meyering's message of "Mon, 2 Nov 2015 13:21:08 -0800")
Message-ID: <87fv0nko86.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.23
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 208.118.235.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Nov 2015 17:06:10 -0000

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

Jim Meyering <jim@meyering.net> writes:

> On Mon, Nov 2, 2015 at 11:34 AM, Eric Blake <eblake@redhat.com> wrote:
>> On 11/02/2015 12:17 PM, Giuseppe Scrivano wrote:
>>
>>> Anyway, I would like an opinion about the new name before I send te full
>>> series again.  I avoided --colors as it is very similar to --color, but
>>> I am not sure how --color-scheme sounds for a native speaker.
>>
>> --color-scheme sounds okay to a native, but has the issue that it cannot
>> be abbreviated (--col would be short for --color, not --color-scheme).
>> Can you come up with a name that does not share a common prefix?  Maybe
>> --palette?
>
> Good point.
> I too prefer --palette='...'
> That does have the tiny downside that diff's rarely used
> --paginate option will no longer be able to be abbreviated
> as "--pa", but that is barely worth mentioning.

I have attached the patches that implement --palette, the missing tests
and update the NEWS file.

Regards,
Giuseppe


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

>From f7bf589e9a0c4b893837cfbbdaae5543d72c2b85 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Mon, 19 Oct 2015 10:29:41 +0200
Subject: [PATCH 1/3] diff: add --palette

* doc/diffutils.texi: Add documentation for --palette
* src/diff.h (set_color_palette): New prototype.
* src/diff.c (set_color_palette): New function.
(color_palette): New variable.
* 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 |   6 +
 src/diff.c         |   7 +
 src/diff.h         |   1 +
 src/util.c         | 439 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 444 insertions(+), 9 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 0944b44..b689673 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3763,6 +3763,7 @@ Always use color.
 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
@@ -3890,6 +3891,11 @@ if-then-else format.  @xref{Line Formats}.
 @itemx --show-c-function
 Show which C function each change is in.  @xref{C Function Headings}.
 
+@item --palette=@var{scheme}
+It allows to specify what colors are used to colorize the output.  It
+defaults 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 -q
 @itemx --brief
 Report only whether the files differ, not the details of the
diff --git a/src/diff.c b/src/diff.c
index 4e0f602..f5298e1 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -140,6 +140,7 @@ enum
   CHANGED_GROUP_FORMAT_OPTION,
 
   COLOR_OPTION,
+  COLOR_PALETTE_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -196,6 +197,7 @@ static struct option const longopts[] =
   {"old-group-format", 1, 0, OLD_GROUP_FORMAT_OPTION},
   {"old-line-format", 1, 0, OLD_LINE_FORMAT_OPTION},
   {"paginate", 0, 0, 'l'},
+  {"palette", 1, 0, COLOR_PALETTE_OPTION},
   {"rcs", 0, 0, 'n'},
   {"recursive", 0, 0, 'r'},
   {"report-identical-files", 0, 0, 's'},
@@ -635,6 +637,10 @@ main (int argc, char **argv)
 	  specify_colors_style (optarg);
 	  break;
 
+	case COLOR_PALETTE_OPTION:
+	  set_color_palette (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
@@ -950,6 +956,7 @@ static char const * const option_help_msgid[] = {
   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_("    --palette=SCHEME    specify the colors to use when --color is active"),
   "",
   N_("    --help               display this help and exit"),
   N_("-v, --version            output version information and exit"),
diff --git a/src/diff.h b/src/diff.h
index 472fa93..5930cd1 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -411,3 +411,4 @@ 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);
+extern void set_color_palette (const char *palette);
diff --git a/src/util.c b/src/util.c
index 6cc1411..50dce82 100644
--- a/src/util.c
+++ b/src/util.c
@@ -310,6 +310,396 @@ 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 const char *color_palette;
+
+void
+set_color_palette (const char *palette)
+{
+  color_palette = palette;
+}
+
+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 = color_palette) == 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 +713,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 +1316,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 +1344,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 +1356,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 +1368,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.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0002-doc-mention-color-and-palette-in-NEWS.patch

>From 1e9f443fcd587bd6e137d7c627d3a250d09ca5c2 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Mon, 2 Nov 2015 19:03:32 +0000
Subject: [PATCH 2/3] doc: mention --color and --palette in NEWS

---
 NEWS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/NEWS b/NEWS
index 7cdfedd..685dc9d 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,13 @@ GNU diffutils NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** New features
+
+   diff accepts two new options --color and --palette to set a colored
+   output.  --color takes an optional argument specifying when to
+   colorize a line: --color=always, --color=auto, --color=never.
+   --palette is used to change the used colors.
+
 ** Bug fixes
 
   When binary files differ, diff now exits with status 1 as POSIX requires.
-- 
2.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0003-tests-Add-tests-for-color-and-palette.patch

>From 091ffa10f77e0e006d7173b2e7efb21966075824 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Mon, 2 Nov 2015 19:05:10 +0000
Subject: [PATCH 3/3] tests: Add tests for --color and --palette

* tests/colors: New file.
* tests/Makefile.am (TESTS): Add colors.
---
 tests/Makefile.am |  3 ++-
 tests/colors      | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100755 tests/colors

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 438fbdf..805ccc2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,7 +15,8 @@ TESTS = \
   no-newline-at-eof \
   stdin \
   strcoll-0-names \
-  filename-quoting
+  filename-quoting \
+  colors
 
 EXTRA_DIST = \
   $(TESTS) init.sh t-local.sh
diff --git a/tests/colors b/tests/colors
new file mode 100755
index 0000000..9e1ef40
--- /dev/null
+++ b/tests/colors
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+TZ=UTC0
+export TZ
+
+fail=0
+
+echo a > a
+echo b > b
+
+touch --date='1970-01-01 00:00:00' a b
+
+# Compare with some known outputs
+
+diff --color=always a b | sha1sum \
+     | grep dbed959c9975cf761ff4950d93d342d7c271c11f || fail=1
+
+diff --color=auto a b | sha1sum \
+     | grep 90742ce0d628cc2f2067b232404578e000b80cce || fail=1
+
+diff --color=never a b | sha1sum \
+     | grep 90742ce0d628cc2f2067b232404578e000b80cce || fail=1
+
+diff --color a b | sha1sum \
+     | grep 90742ce0d628cc2f2067b232404578e000b80cce || fail=1
+
+diff -u --color=always a b | sha1sum \
+     | grep 5712fbffc94c501eaeec5cb02468ce2bbed6d7c9 || fail=1
+
+diff -c --color=always a b | sha1sum \
+     | grep 904a91f82474e3532459b759fdacbdb339070e14 || fail=1
+
+diff -N --color=always --palette="rs=0:hd=33:ad=34:de=35:ln=36" a b \
+     | sha1sum | grep 7796a82c2e7bd1f4ee04cb44352d83e1db87c092 || fail=1
+
+Exit $fail
-- 
2.5.0


--=-=-=--




From MAILER-DAEMON Tue Nov 03 12:28:08 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZtfNP-00008S-RP
	for mharc-bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:28:08 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:43879)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtfNN-00005N-GA
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:28:06 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtfNK-0007OL-5K
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:28:05 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:60995)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtfNK-0007OH-1v
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:28:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtfNJ-0006aB-Tt
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:28:01 -0500
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, 03 Nov 2015 17:28:01 +0000
Resent-Message-ID: <handler.20062.B20062.144657164025243@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.144657164025243
	(code B ref 20062); Tue, 03 Nov 2015 17:28:01 +0000
Received: (at 20062) by debbugs.gnu.org; 3 Nov 2015 17:27:20 +0000
Received: from localhost ([127.0.0.1]:51703 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZtfMd-0006Z5-If
	for submit@debbugs.gnu.org; Tue, 03 Nov 2015 12:27:20 -0500
Received: from mx1.redhat.com ([209.132.183.28]:47854)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eblake@redhat.com>) id 1ZtfMa-0006Yw-T6
	for 20062@debbugs.gnu.org; Tue, 03 Nov 2015 12:27:17 -0500
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 DD35EA4507;
	Tue,  3 Nov 2015 17:27:15 +0000 (UTC)
Received: from [10.3.113.189] (ovpn-113-189.phx2.redhat.com [10.3.113.189])
	by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id tA3HRFqf001795; Tue, 3 Nov 2015 12:27:15 -0500
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
	<87fv0nko86.fsf@foo.bar.baz>
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: <5638EE6E.3050901@redhat.com>
Date: Tue, 3 Nov 2015 10:27:10 -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: <87fv0nko86.fsf@foo.bar.baz>
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature";
	boundary="iGKRV9wqRvHfDfEgSg7GAsJ6Kj0p6iTmg"
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: [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, 03 Nov 2015 17:28:07 -0000

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

On 11/03/2015 10:05 AM, Giuseppe Scrivano wrote:

> I have attached the patches that implement --palette, the missing tests=

> and update the NEWS file.
>=20

> +++ b/doc/diffutils.texi
> @@ -3763,6 +3763,7 @@ Always use color.
>  Specifying @option{--color} and no @var{when} is equivalent to
>  @option{--color=3Dauto}.
> =20
> +
>  @item -C @var{lines}

Spurious change?

>  @itemx --context@r{[}=3D@var{lines}@r{]}
>  Use the context output format, showing @var{lines} (an integer) lines =
of
> @@ -3890,6 +3891,11 @@ if-then-else format.  @xref{Line Formats}.
>  @itemx --show-c-function
>  Show which C function each change is in.  @xref{C Function Headings}.
> =20
> +@item --palette=3D@var{scheme}
> +It allows to specify what colors are used to colorize the output.  It

Passive voice.  Would sound better as:

Specify what color palette to use when colored output to use.

> +defaults to @samp{rs=3D0:hd=3D1:ad=3D32:de=3D31:ln=3D36} for red added=
 lines,
> +green deleted lines, cyan line numbers, bold header.

That says the default, but doesn't say what conventions to apply to get
something other than the default.  What are 'rs', 'hd', 'ad', 'de', and
'ln'?  Can we link to the fact that the values of these variables are
generally applied inside a terminal '\e[Xm' sequence, for a given X?
Can we link to dircolors output for comparison?  Do we need parameters
for the '\e[' and 'm' prefix/suffix, in case the terminal understands
something different than ANSI escapes for colors?

> @@ -950,6 +956,7 @@ static char const * const option_help_msgid[] =3D {=

>    N_("    --speed-large-files  assume large files and many scattered s=
mall changes"),
>    N_("    --color[=3DWHEN]         colorize the output; WHEN can be 'n=
ever', 'always',"),
>    N_("                             or 'auto' (the default)"),
> +  N_("    --palette=3DSCHEME    specify the colors to use when --color=
 is active"),
>    "",
>    N_("    --help               display this help and exit"),
>    N_("-v, --version            output version information and exit"),

Where is SCHEME documented in --help?  Should it be?


> +
> +/* Parse a string as part of the DIFF_COLORS variable; this may involv=
e

Stale reference to envvar instead of --palette.

> +
> +static struct bin_str color_indicator[] =3D
> +  {
> +    { 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 */
> +  };

This needs to be documented in more than just code comments.


> +  ext =3D 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 =3D color_buf =3D xstrdup (p);

Another stale ref to DIFF_COLORS.

> 0002-doc-mention-color-and-palette-in-NEWS.patch
>=20

Looked okay to me.

> 0003-tests-Add-tests-for-color-and-palette.patch
>=20

> +
> +# Compare with some known outputs
> +

> +diff -c --color=3Dalways a b | sha1sum \
> +     | grep 904a91f82474e3532459b759fdacbdb339070e14 || fail=3D1
> +
> +diff -N --color=3Dalways --palette=3D"rs=3D0:hd=3D33:ad=3D34:de=3D35:l=
n=3D36" a b \
> +     | sha1sum | grep 7796a82c2e7bd1f4ee04cb44352d83e1db87c092 || fail=
=3D1

Nice; a test of a non-default palette.

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


--iGKRV9wqRvHfDfEgSg7GAsJ6Kj0p6iTmg
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/

iQEcBAEBCAAGBQJWOO5uAAoJEKeha0olJ0NqVcAH/j2U6DM/8le1FeRK5kjam8VA
o69eVCjxathMl5uMdi4Rnod2/xoYIcMAkxwO02uObvZyJPe1uYhMRI8nXKa7nrxM
zdI5cQLOdOuwOIK4Q5yoNHoJ83SQ3kko7bh+Rblh2LrtQAEgjIV1aewilI016J0k
Jk+9up/u1XyzyZMB4zd9j6vdTlclLfUuogkeFaC6i8yluUVzvr0gLutsOOoCjcdw
+ODOvcELo7FCE8VS7zEPSu4BbOGLSN4sMccE9S+J8kyc6BQqsbVNKFsGbVsmhWBo
n+Hq9LhCH2pJGVLFfQ8nB1Snu97VjSMDXT7Z0db05vq7KIURsaV/P3iYo5ABpvM=
=K8+y
-----END PGP SIGNATURE-----

--iGKRV9wqRvHfDfEgSg7GAsJ6Kj0p6iTmg--




From MAILER-DAEMON Tue Nov 03 12:32:08 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZtfRI-0003S2-8N
	for mharc-bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:32:08 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:45372)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtfRF-0003PG-S7
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:32:06 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtfRC-0000GT-Hw
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:32:05 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:60999)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtfRC-0000GM-E5
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:32:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtfRC-0006hX-5w
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:32:02 -0500
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: Tue, 03 Nov 2015 17:32:02 +0000
Resent-Message-ID: <handler.20062.B20062.144657188225695@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.144657188225695
	(code B ref 20062); Tue, 03 Nov 2015 17:32:02 +0000
Received: (at 20062) by debbugs.gnu.org; 3 Nov 2015 17:31:22 +0000
Received: from localhost ([127.0.0.1]:51707 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZtfQG-0006g5-CH
	for submit@debbugs.gnu.org; Tue, 03 Nov 2015 12:31:22 -0500
Received: from mail-yk0-f170.google.com ([209.85.160.170]:35595)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>) id 1ZtfQE-0006fp-CU
	for 20062@debbugs.gnu.org; Tue, 03 Nov 2015 12:31:02 -0500
Received: by ykek133 with SMTP id k133so27881248yke.2
	for <20062@debbugs.gnu.org>; Tue, 03 Nov 2015 09:31:01 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:from:date:message-id
	:subject:to:cc:content-type;
	bh=sebaZ+IHRL7H8273CapE3GmeD+l6dR58aooqytXR6FY=;
	b=NHkThpxL9CTcaLw3DDUZxV+Y6luSSH9oTKaI45d6IGD1uCWnrdHOMbiP/juyhYfa/H
	wvbVlDqTRnUj65VNc+1uevbxobgu2VaacT2pPtVRy4vhf79m7rmnkTKMHbdSVPsAJcEh
	1EitRgBGX8F/7wakDv7W7JDbn/11dwaeyulRYq6ej/T8Gsah+3tPnRXXRRUfnQMjRuZP
	pYgJa8fFD0lgKI7dVPR3FTF/mJdbemenrRH2nXdoAHei4uJ56vfO3hVHApmcNB1ltB/R
	2xAwI0tEdhzh9AfDjWmmOAHDfl4358mDez1TH5HQpApuvBDheWzN0T5p2D39O3DrXTBe
	K+LA==
X-Received: by 10.31.54.86 with SMTP id d83mr17757357vka.139.1446571861823;
	Tue, 03 Nov 2015 09:31:01 -0800 (PST)
MIME-Version: 1.0
Received: by 10.31.65.11 with HTTP; Tue, 3 Nov 2015 09:30:42 -0800 (PST)
In-Reply-To: <5638EE6E.3050901@redhat.com>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
	<87fv0nko86.fsf@foo.bar.baz> <5638EE6E.3050901@redhat.com>
From: Jim Meyering <jim@meyering.net>
Date: Tue, 3 Nov 2015 09:30:42 -0800
X-Google-Sender-Auth: -5BeHr3cCRp5ro64wfxdL2srM4Q
Message-ID: <CA+8g5KHcMiMiGnQJ3ibhe2W=4crcy9g6jSyMnWo-T9E4uzm=Og@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: Giuseppe Scrivano <gscrivano@gnu.org>, 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Nov 2015 17:32:06 -0000

On Tue, Nov 3, 2015 at 9:27 AM, Eric Blake <eblake@redhat.com> wrote:
> On 11/03/2015 10:05 AM, Giuseppe Scrivano wrote:
>
>> I have attached the patches that implement --palette, the missing tests
>> and update the NEWS file.
>>
>
>> +++ b/doc/diffutils.texi
>> @@ -3763,6 +3763,7 @@ Always use color.
>>  Specifying @option{--color} and no @var{when} is equivalent to
>>  @option{--color=auto}.
>>
>> +
>>  @item -C @var{lines}
>
> Spurious change?
>
>>  @itemx --context@r{[}=@var{lines}@r{]}
>>  Use the context output format, showing @var{lines} (an integer) lines of
>> @@ -3890,6 +3891,11 @@ if-then-else format.  @xref{Line Formats}.
>>  @itemx --show-c-function
>>  Show which C function each change is in.  @xref{C Function Headings}.
>>
>> +@item --palette=@var{scheme}
>> +It allows to specify what colors are used to colorize the output.  It
>
> Passive voice.  Would sound better as:
>
> Specify what color palette to use when colored output to use.

Thanks for the quick review, Eric.
I'll wait for the next iteration.




From MAILER-DAEMON Tue Nov 03 12:39:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZtfY4-0000Ya-N7
	for mharc-bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:39:08 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:48006)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtfY1-0000WN-A6
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:39:06 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtfXy-0002WL-Ko
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:39:05 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:32774)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtfXy-0002W5-Ht
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:39:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZtfXy-0006u0-6L
	for bug-diffutils@gnu.org; Tue, 03 Nov 2015 12:39:02 -0500
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, 03 Nov 2015 17:39:02 +0000
Resent-Message-ID: <handler.20062.B20062.144657232426479@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.144657232426479
	(code B ref 20062); Tue, 03 Nov 2015 17:39:02 +0000
Received: (at 20062) by debbugs.gnu.org; 3 Nov 2015 17:38:44 +0000
Received: from localhost ([127.0.0.1]:51715 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZtfXg-0006t0-CG
	for submit@debbugs.gnu.org; Tue, 03 Nov 2015 12:38:44 -0500
Received: from mx1.redhat.com ([209.132.183.28]:38005)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eblake@redhat.com>) id 1ZtfXe-0006sh-04
	for 20062@debbugs.gnu.org; Tue, 03 Nov 2015 12:38:42 -0500
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (Postfix) with ESMTPS id 049F7ABC;
	Tue,  3 Nov 2015 17:38:40 +0000 (UTC)
Received: from [10.3.113.189] (ovpn-113-189.phx2.redhat.com [10.3.113.189])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id tA3HcdbD003696; Tue, 3 Nov 2015 12:38:40 -0500
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
	<87fv0nko86.fsf@foo.bar.baz> <5638EE6E.3050901@redhat.com>
From: Eric Blake <eblake@redhat.com>
Openpgp: url=http://people.redhat.com/eblake/eblake.gpg
Organization: Red Hat, Inc.
Message-ID: <5638F11E.4020004@redhat.com>
Date: Tue, 3 Nov 2015 10:38:38 -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: <5638EE6E.3050901@redhat.com>
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature";
	boundary="1LqF9DMXRXbUiBhnndFXVvLd1BvifOFD9"
X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 208.118.235.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: [PATCH] diff: add
	support for --color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Nov 2015 17:39:06 -0000

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

On 11/03/2015 10:27 AM, Eric Blake wrote:

>> +@item --palette=3D@var{scheme}
>> +It allows to specify what colors are used to colorize the output.  It=

>=20
> Passive voice.  Would sound better as:
>=20
> Specify what color palette to use when colored output to use.

Bad editing on my part.

Specify what color palette to use when colored output is enabled.

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


--1LqF9DMXRXbUiBhnndFXVvLd1BvifOFD9
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/

iQEcBAEBCAAGBQJWOPEeAAoJEKeha0olJ0NqnM4H/3LzqGKd6S/IBB5zo0gPk4De
bmSzu10kHo+CZJrZn6itrbRzMJOwBbcHqbDcSAiERBTO1/q5i9pO83nFibOFBVpZ
ZBsj/5ov4GLAHKAY6vuJVaYj1go3ZrjTzceSHi1H+DVnygMov27RbfA5eam+AKgR
AA/FCTcLqXTDiPJ1tnoRhrLyTsKCEWACPpHQK2q83qMYBvDVjDnKb1za7VW4xcY3
iA1dGg2nxqc/ru7tNwxBBr5Qo+Rk8uzvc++xrYNNFMtM83wqVyzXI4IoETMQUsjf
wcqNyoNbMvNkDSY984FLJ8aeU+0XlucEc36Xe2a7wsP0mQmmvYL6Y0uKobaWqV0=
=YGgR
-----END PGP SIGNATURE-----

--1LqF9DMXRXbUiBhnndFXVvLd1BvifOFD9--




From MAILER-DAEMON Mon Nov 16 19:47:25 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZyUQf-0005qR-I3
	for mharc-bug-diffutils@gnu.org; Mon, 16 Nov 2015 19:47:25 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:59615)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZyU0F-0001D2-5r
	for bug-diffutils@gnu.org; Mon, 16 Nov 2015 19:20:09 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZyU0B-0003VO-S6
	for bug-diffutils@gnu.org; Mon, 16 Nov 2015 19:20:07 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:50922)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZyU0B-0003VK-OS
	for bug-diffutils@gnu.org; Mon, 16 Nov 2015 19:20:03 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZyU0A-0007wX-Rb
	for bug-diffutils@gnu.org; Mon, 16 Nov 2015 19:20:03 -0500
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, 17 Nov 2015 00:20:02 +0000
Resent-Message-ID: <handler.20062.B20062.144771959030509@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.144771959030509
	(code B ref 20062); Tue, 17 Nov 2015 00:20:02 +0000
Received: (at 20062) by debbugs.gnu.org; 17 Nov 2015 00:19:50 +0000
Received: from localhost ([127.0.0.1]:40630 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZyTzx-0007vy-6A
	for submit@debbugs.gnu.org; Mon, 16 Nov 2015 19:19:50 -0500
Received: from mx1.redhat.com ([209.132.183.28]:52475)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivano@gnu.org>) id 1ZyTzb-0007vI-A0
	for 20062@debbugs.gnu.org; Mon, 16 Nov 2015 19:19:47 -0500
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 7883B3B757;
	Tue, 17 Nov 2015 00:19:25 +0000 (UTC)
Received: from foo.bar.baz (vpn1-7-57.ams2.redhat.com [10.36.7.57])
	by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id tAH0JJtD002712
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=NO); Mon, 16 Nov 2015 19:19:22 -0500
From: Giuseppe Scrivano <gscrivano@gnu.org>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
	<87fv0nko86.fsf@foo.bar.baz> <5638EE6E.3050901@redhat.com>
	<CA+8g5KHcMiMiGnQJ3ibhe2W=4crcy9g6jSyMnWo-T9E4uzm=Og@mail.gmail.com>
Date: Tue, 17 Nov 2015 01:19:19 +0100
In-Reply-To: <CA+8g5KHcMiMiGnQJ3ibhe2W=4crcy9g6jSyMnWo-T9E4uzm=Og@mail.gmail.com>
	(Jim Meyering's message of "Tue, 3 Nov 2015 09:30:42 -0800")
Message-ID: <87twol1nqw.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: [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, 17 Nov 2015 00:20:09 -0000

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

Jim Meyering <jim@meyering.net> writes:

> On Tue, Nov 3, 2015 at 9:27 AM, Eric Blake <eblake@redhat.com> wrote:
>> On 11/03/2015 10:05 AM, Giuseppe Scrivano wrote:
>>
>>> I have attached the patches that implement --palette, the missing tests
>>> and update the NEWS file.
>>>
>>
>>> +++ b/doc/diffutils.texi
>>> @@ -3763,6 +3763,7 @@ Always use color.
>>>  Specifying @option{--color} and no @var{when} is equivalent to
>>>  @option{--color=auto}.
>>>
>>> +
>>>  @item -C @var{lines}
>>
>> Spurious change?
>>
>>>  @itemx --context@r{[}=@var{lines}@r{]}
>>>  Use the context output format, showing @var{lines} (an integer) lines of
>>> @@ -3890,6 +3891,11 @@ if-then-else format.  @xref{Line Formats}.
>>>  @itemx --show-c-function
>>>  Show which C function each change is in.  @xref{C Function Headings}.
>>>
>>> +@item --palette=@var{scheme}
>>> +It allows to specify what colors are used to colorize the output.  It
>>
>> Passive voice.  Would sound better as:
>>
>> Specify what color palette to use when colored output to use.
>
> Thanks for the quick review, Eric.
> I'll wait for the next iteration.

sorry for taking so long, I hope the attached version is fine.

Regards,
Giuseppe



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

>From 0861846757aa711d1ee5a0176205320e807c306b Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Mon, 19 Oct 2015 10:29:41 +0200
Subject: [PATCH 1/3] diff: add --palette

* doc/diffutils.texi: Add documentation for --palette
* src/diff.h (set_color_palette): New prototype.
* src/diff.c (set_color_palette): New function.
(color_palette): New variable.
* 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 |  34 +++++
 src/diff.c         |   8 +
 src/diff.h         |   1 +
 src/util.c         | 439 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 473 insertions(+), 9 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 0944b44..39ba35d 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3890,6 +3890,40 @@ if-then-else format.  @xref{Line Formats}.
 @itemx --show-c-function
 Show which C function each change is in.  @xref{C Function Headings}.
 
+@item --palette=@var{palette}
+Specify what color palette to use when colored output is enabled.  It
+defaults to @samp{rs=0:hd=1:ad=32:de=31:ln=36} for red deleted lines,
+green added lines, cyan line numbers, bold header.
+
+Supported capabilities are as follows.
+
+@table @code
+@item ad=32
+@vindex ad @r{capability}
+
+SGR substring for added lines.
+The default is green foreground.
+
+@item de=31
+@vindex de @r{capability}
+
+SGR substring for deleted lines.
+The default is red foreground.
+
+@item hd=1
+@vindex hd @r{capability}
+
+SGR substring for chunk header.
+The default is bold foreground.
+
+@item ln=36
+@vindex ln @r{capability}
+
+SGR substring for line numbers.
+The default is cyan foreground.
+@end table
+
+
 @item -q
 @itemx --brief
 Report only whether the files differ, not the details of the
diff --git a/src/diff.c b/src/diff.c
index 4e0f602..4c3d29a 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -140,6 +140,7 @@ enum
   CHANGED_GROUP_FORMAT_OPTION,
 
   COLOR_OPTION,
+  COLOR_PALETTE_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -196,6 +197,7 @@ static struct option const longopts[] =
   {"old-group-format", 1, 0, OLD_GROUP_FORMAT_OPTION},
   {"old-line-format", 1, 0, OLD_LINE_FORMAT_OPTION},
   {"paginate", 0, 0, 'l'},
+  {"palette", 1, 0, COLOR_PALETTE_OPTION},
   {"rcs", 0, 0, 'n'},
   {"recursive", 0, 0, 'r'},
   {"report-identical-files", 0, 0, 's'},
@@ -635,6 +637,10 @@ main (int argc, char **argv)
 	  specify_colors_style (optarg);
 	  break;
 
+	case COLOR_PALETTE_OPTION:
+	  set_color_palette (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
@@ -950,6 +956,8 @@ static char const * const option_help_msgid[] = {
   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_("    --palette=PALETTE    specify the colors to use when --color is active"),
+  N_("                         PALETTE is a colon-separated list terminfo capabilities"),
   "",
   N_("    --help               display this help and exit"),
   N_("-v, --version            output version information and exit"),
diff --git a/src/diff.h b/src/diff.h
index 472fa93..5930cd1 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -411,3 +411,4 @@ 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);
+extern void set_color_palette (const char *palette);
diff --git a/src/util.c b/src/util.c
index 6cc1411..dedf3b3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -310,6 +310,396 @@ 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 --palette argument; 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 const char *color_palette;
+
+void
+set_color_palette (const char *palette)
+{
+  color_palette = palette;
+}
+
+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 = color_palette) == NULL || *p == '\0')
+    return;
+
+  ext = NULL;
+  strcpy (label, "??");
+
+  /* This is an overly conservative estimate, but any possible
+     --palette 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 --palette"));
+      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 +713,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 +1316,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 +1344,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 +1356,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 +1368,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.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0002-doc-mention-color-and-palette-in-NEWS.patch

>From 24a52233fd92f2f34b5050aa7f575b15ed51e0ff Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Mon, 2 Nov 2015 19:03:32 +0000
Subject: [PATCH 2/3] doc: mention --color and --palette in NEWS

---
 NEWS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/NEWS b/NEWS
index 7cdfedd..685dc9d 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,13 @@ GNU diffutils NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** New features
+
+   diff accepts two new options --color and --palette to set a colored
+   output.  --color takes an optional argument specifying when to
+   colorize a line: --color=always, --color=auto, --color=never.
+   --palette is used to change the used colors.
+
 ** Bug fixes
 
   When binary files differ, diff now exits with status 1 as POSIX requires.
-- 
2.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0003-tests-Add-tests-for-color-and-palette.patch

>From 6537a0d21f3bbb17690effcc33db2c5a7fdea795 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Mon, 2 Nov 2015 19:05:10 +0000
Subject: [PATCH 3/3] tests: Add tests for --color and --palette

* tests/colors: New file.
* tests/Makefile.am (TESTS): Add colors.
---
 tests/Makefile.am |  3 ++-
 tests/colors      | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100755 tests/colors

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 438fbdf..805ccc2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,7 +15,8 @@ TESTS = \
   no-newline-at-eof \
   stdin \
   strcoll-0-names \
-  filename-quoting
+  filename-quoting \
+  colors
 
 EXTRA_DIST = \
   $(TESTS) init.sh t-local.sh
diff --git a/tests/colors b/tests/colors
new file mode 100755
index 0000000..02da181
--- /dev/null
+++ b/tests/colors
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+TZ=UTC0
+export TZ
+
+fail=0
+
+echo a > a
+echo b > b
+
+touch --date='1970-01-01 00:00:00' a b
+
+# Compare with some known outputs
+
+diff --color=always a b | sha1sum \
+     | grep dbed959c9975cf761ff4950d93d342d7c271c11f || fail=1
+
+diff --color=auto a b | sha1sum \
+     | grep 90742ce0d628cc2f2067b232404578e000b80cce || fail=1
+
+diff --color=never a b | sha1sum \
+     | grep 90742ce0d628cc2f2067b232404578e000b80cce || fail=1
+
+diff --color a b | sha1sum \
+     | grep 90742ce0d628cc2f2067b232404578e000b80cce || fail=1
+
+diff -u --color=always a b | sha1sum \
+     | grep 5712fbffc94c501eaeec5cb02468ce2bbed6d7c9 || fail=1
+
+diff -c --color=always a b | sha1sum \
+     | grep a9bfa18ea6425db547ac69bc13fb78cf9416ad55 || fail=1
+
+diff -N --color=always --palette="rs=0:hd=33:ad=34:de=35:ln=36" a b \
+     | sha1sum | grep 7796a82c2e7bd1f4ee04cb44352d83e1db87c092 || fail=1
+
+Exit $fail
-- 
2.5.0


--=-=-=--




From MAILER-DAEMON Tue Nov 17 18:57:26 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Zyq7q-0003bl-9a
	for mharc-bug-diffutils@gnu.org; Tue, 17 Nov 2015 18:57:26 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:50236)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZykIc-0006y2-GG
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 12:44:11 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZykIX-0006jk-Fg
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 12:44:10 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:52282)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZykIX-0006jg-Ce
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 12:44:05 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZykIX-0005kx-7j
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 12:44:05 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Stephan =?UTF-8?Q?M=C3=BCller?= <muellste@math.hu-berlin.de>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 17 Nov 2015 17:44:05 +0000
Resent-Message-ID: <handler.21945.B.144778222522000@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: report 21945
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: 21945@debbugs.gnu.org
X-Debbugs-Original-To: bug-diffutils@gnu.org
Received: via spool by submit@debbugs.gnu.org id=B.144778222522000
	(code B ref -1); Tue, 17 Nov 2015 17:44:05 +0000
Received: (at submit) by debbugs.gnu.org; 17 Nov 2015 17:43:45 +0000
Received: from localhost ([127.0.0.1]:41984 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZykIC-0005ij-Nl
	for submit@debbugs.gnu.org; Tue, 17 Nov 2015 12:43:45 -0500
Received: from eggs.gnu.org ([208.118.235.92]:35280)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <muellste@math.hu-berlin.de>) id 1ZycxV-0006ys-Qz
	for submit@debbugs.gnu.org; Tue, 17 Nov 2015 04:53:54 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <muellste@math.hu-berlin.de>) id 1ZycxV-0007x5-0i
	for submit@debbugs.gnu.org; Tue, 17 Nov 2015 04:53:53 -0500
Received: from lists.gnu.org ([2001:4830:134:3::11]:53372)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <muellste@math.hu-berlin.de>) id 1ZycxU-0007x1-Tt
	for submit@debbugs.gnu.org; Tue, 17 Nov 2015 04:53:52 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:45286)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <muellste@math.hu-berlin.de>) id 1ZycxU-0004VI-5a
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 04:53:52 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <muellste@math.hu-berlin.de>) id 1ZycxQ-0007sH-Vo
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 04:53:52 -0500
Received: from hermes.mathematik.hu-berlin.de ([141.20.53.110]:51523)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <muellste@math.hu-berlin.de>) id 1ZycxQ-0007pC-PK
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 04:53:48 -0500
Received: from localhost (nil [127.0.0.1])
	by hermes.mathematik.hu-berlin.de (Postfix) with ESMTP id DC7462D8932
	for <bug-diffutils@gnu.org>; Tue, 17 Nov 2015 10:53:46 +0100 (CET)
X-Virus-Scanned: amavisd-new at mathematik.hu-berlin.de
Received: from hermes.mathematik.hu-berlin.de ([127.0.0.1])
	by localhost (hermes.mathematik.hu-berlin.de [127.0.0.1]) (amavisd-new, 
	port 10024) with ESMTP id ivIYxwqVElUA for <bug-diffutils@gnu.org>;
	Tue, 17 Nov 2015 10:53:46 +0100 (CET)
Received: from fuckup.fritz.box (adsl-89-217-233-109.adslplus.ch
	[89.217.233.109]) (using TLSv1 with cipher AES128-SHA (128/128 bits))
	(Client did not present a certificate)
	by hermes.mathematik.hu-berlin.de (Postfix) with ESMTPSA id 87E082D8931
	for <bug-diffutils@gnu.org>; Tue, 17 Nov 2015 10:53:46 +0100 (CET)
Date: Tue, 17 Nov 2015 10:53:44 +0100
From: Stephan =?UTF-8?Q?M=C3=BCller?= <muellste@math.hu-berlin.de>
Message-ID: <20151117105344.77aa242e@fuckup.fritz.box>
X-Mailer: Claws Mail 3.12.0 (GTK+ 2.24.28; i686-redhat-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
	(bad octet value).
X-Mailman-Approved-At: Tue, 17 Nov 2015 12:43:43 -0500
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 208.118.235.43
X-Mailman-Approved-At: Tue, 17 Nov 2015 18:57:24 -0500
Subject: [bug-diffutils] bug#21945: Bug: Build dependency gperf
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, 17 Nov 2015 17:44:11 -0000

Hello,

building difftools (from Oct 2015) fails without gperf. A check for
gperf should be added to the configure script.

I am not really into it, but autoconf should be able to recognize this
dependency itself? Any Ideas?

 ~stephan




From MAILER-DAEMON Tue Nov 17 18:57:27 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Zyq7r-0003da-Cc
	for mharc-bug-diffutils@gnu.org; Tue, 17 Nov 2015 18:57:27 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:50209)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZykIa-0006vo-UD
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 12:44:14 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZykIV-0006he-7J
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 12:44:08 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:52277)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZykIV-0006ha-3Z
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 12:44:03 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZykIU-0005k8-Gl
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 12:44:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Stephan =?UTF-8?Q?M=C3=BCller?= <fruktopus@gmail.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Tue, 17 Nov 2015 17:44:02 +0000
Resent-Message-ID: <handler.21942.B.144778219421882@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: report 21942
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: 21942@debbugs.gnu.org
X-Debbugs-Original-To: bug-diffutils@gnu.org
Received: via spool by submit@debbugs.gnu.org id=B.144778219421882
	(code B ref -1); Tue, 17 Nov 2015 17:44:02 +0000
Received: (at submit) by debbugs.gnu.org; 17 Nov 2015 17:43:14 +0000
Received: from localhost ([127.0.0.1]:41978 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZykHi-0005gq-58
	for submit@debbugs.gnu.org; Tue, 17 Nov 2015 12:43:14 -0500
Received: from eggs.gnu.org ([208.118.235.92]:59989)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <fruktopus@gmail.com>) id 1ZyegL-0001Ht-JE
	for submit@debbugs.gnu.org; Tue, 17 Nov 2015 06:44:18 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <fruktopus@gmail.com>) id 1ZyegK-0001eN-N7
	for submit@debbugs.gnu.org; Tue, 17 Nov 2015 06:44:17 -0500
Received: from lists.gnu.org ([2001:4830:134:3::11]:48288)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <fruktopus@gmail.com>) id 1ZyegK-0001eJ-K7
	for submit@debbugs.gnu.org; Tue, 17 Nov 2015 06:44:16 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41758)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <fruktopus@gmail.com>) id 1ZyegJ-0005ZC-OZ
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 06:44:16 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <fruktopus@gmail.com>) id 1ZyegG-0001do-FL
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 06:44:15 -0500
Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:38482)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <fruktopus@gmail.com>) id 1ZyegG-0001dh-A4
	for bug-diffutils@gnu.org; Tue, 17 Nov 2015 06:44:12 -0500
Received: by wmec201 with SMTP id c201so21793933wme.1
	for <bug-diffutils@gnu.org>; Tue, 17 Nov 2015 03:44:11 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=date:from:to:subject:message-id:mime-version:content-type
	:content-transfer-encoding;
	bh=Yy9YiLytiqvZgKpLv3iuxZdPquknRrK2supzDkVAn6o=;
	b=YOnPgVbX4735BQbFPinlAPXSuXxSVAQifAMAaPCF18+3Q4c7lWuOYZYTcbq2fKM8Za
	M43asQI1k3V8z/n6cu4xOSwWzEgiK83rWlPERq1H4j5s1K9fvzuxWNDQTRrmrEt6bg7R
	iFQyejzFalHMpAK610rdF0Ltr7XCHXw7xRfEms618OXhx8wtuePxZ/6piu/noLL94ayl
	tupiQ18WI/sIFBzh7UlaupMetL+U0g5oBVhbfY4FMvn0py7p6s3NYk9dckN1LDc6T/ny
	IQGZSOiB+UN9gOnkg0MJ0fnXkV2Y0CBjp5vvgZN8OQiShcEN9QaiBbomP0mMOMEhUEIl
	Xa7Q==
X-Received: by 10.194.249.97 with SMTP id yt1mr41712741wjc.89.1447760651800;
	Tue, 17 Nov 2015 03:44:11 -0800 (PST)
Received: from fuckup.fritz.box (adsl-89-217-233-109.adslplus.ch.
	[89.217.233.109]) by smtp.gmail.com with ESMTPSA id
	cv3sm38154574wjc.20.2015.11.17.03.44.11 for <bug-diffutils@gnu.org>
	(version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
	Tue, 17 Nov 2015 03:44:11 -0800 (PST)
Date: Tue, 17 Nov 2015 12:44:08 +0100
From: Stephan =?UTF-8?Q?M=C3=BCller?= <fruktopus@gmail.com>
Message-ID: <20151117124408.27185c58@fuckup.fritz.box>
X-Mailer: Claws Mail 3.12.0 (GTK+ 2.24.28; i686-redhat-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
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-Mailman-Approved-At: Tue, 17 Nov 2015 12:43:12 -0500
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 208.118.235.43
X-Mailman-Approved-At: Tue, 17 Nov 2015 18:57:26 -0500
Subject: [bug-diffutils] bug#21942: Files with incorrect file sizes
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, 17 Nov 2015 17:44:14 -0000

Hi there,

recently I had to debug weird problem. Finally I figured it out.

Virtual file systems like /sys or /proc usually don't care about file
sizes. All files have a size of 0. This leads to difficulties as diff
sometimes looks for file sizes.

Say you do:

> $ cp /proc/cmdline my_cmdline
> $ diff /proc/cmdline my_cmdline ; echo $?
> 0      // ok, files don't differ
> $ diff --brief /proc/cmdline my_cmdline
> Files /proc/cmdline and mycmdline differ  

The --brief option triggers a binary compare, as we aren't interested
in the actual differences this makes sense. As a first step, file sizes
are compared (0 vs ~150) and the files are reported as different.

I am not sure how to fix this. I.e. are the files different or not? What
is the correct behavior. In any case --brief should have no influence on
the overall result! I see the following options (I prefer the 2nd):

1: Don't use file sizes in comparing. This is rather expensive but
would certainly fix it.

2: add a --use-file-sizes flag which enables decisions
based on file sizes. Without this flag, always look into the files.
And --brief should report, if the files differ because of their data or
size. That is 

> $ diff /proc/cmdline my_cmdline ; echo $?
> 0      // ok, files don't differ  

> $ diff --brief /proc/cmdline my_cmdline ; echo $0
> 0  

> $ diff --brief --use-file-sizes /proc/cmdline my_cmdline
> Files /proc/cmdline and mycmdline differ in file size  

3: Leave it at it is and add a warning in the man page. However that
would be very inconvenient.


   best, stephan




From MAILER-DAEMON Fri Nov 20 12:30:13 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZzpVk-0004yu-Nu
	for mharc-bug-diffutils@gnu.org; Fri, 20 Nov 2015 12:30:12 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:46871)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzpVh-0004r6-8v
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 12:30:10 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzpVc-0000GK-9W
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 12:30:09 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:56672)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzpVc-0000Fh-23
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 12:30:04 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzpVb-00079h-AL
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 12:30:03 -0500
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: Fri, 20 Nov 2015 17:30:02 +0000
Resent-Message-ID: <handler.21942.B21942.144804055727414@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 21942
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: Stephan =?UTF-8?Q?M=C3=BCller?= <fruktopus@gmail.com>
Received: via spool by 21942-submit@debbugs.gnu.org id=B21942.144804055727414
	(code B ref 21942); Fri, 20 Nov 2015 17:30:02 +0000
Received: (at 21942) by debbugs.gnu.org; 20 Nov 2015 17:29:17 +0000
Received: from localhost ([127.0.0.1]:46380 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZzpUr-000786-0x
	for submit@debbugs.gnu.org; Fri, 20 Nov 2015 12:29:17 -0500
Received: from mail-vk0-f54.google.com ([209.85.213.54]:33413)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>) id 1ZzpUX-00077B-Ip
	for 21942@debbugs.gnu.org; Fri, 20 Nov 2015 12:29:16 -0500
Received: by vkfr145 with SMTP id r145so2042244vkf.0
	for <21942@debbugs.gnu.org>; Fri, 20 Nov 2015 09:28:56 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:from:date:message-id
	:subject:to:cc:content-type:content-transfer-encoding;
	bh=IFpDuph2UhOGGSIBiLpRvHIhbXT43vGJ++v9AbFdJmU=;
	b=wFL7j6hfa31HfWwIVffAHE9pTpyCU1jaMedY4RjSglNZVGAFL5ZqSQ4ntIk4dWNkF6
	aaxpqJuUEpCKIFgwe23tKM3lpbkS301MIZvxMOHtHseRWiUHOJIuHfRHbLLBt8+jrkTD
	lNXqlbYwVxe6JPmLskjScWJoT+jqxmA3GiAxfzNWR+N4BtxnUWxyEDP6aTX2pCJYxIwc
	AyhMdFWbbEXU++UGvxyX3KLZxBxQOdc5hBqikJvBtdVEZExYSfeQHo882XdBb+Wv6fmQ
	cmVu18NDUs7qchnUnzmf2bhqvLg3Eb6gU19Y4ts2Y3ICiUGDQrQjQY1G8GAbgetYfA93
	C/ZQ==
X-Received: by 10.31.41.131 with SMTP id p125mr510374vkp.133.1448040536801;
	Fri, 20 Nov 2015 09:28:56 -0800 (PST)
MIME-Version: 1.0
Received: by 10.31.84.198 with HTTP; Fri, 20 Nov 2015 09:28:37 -0800 (PST)
In-Reply-To: <20151117124408.27185c58@fuckup.fritz.box>
References: <20151117124408.27185c58@fuckup.fritz.box>
From: Jim Meyering <jim@meyering.net>
Date: Fri, 20 Nov 2015 18:28:37 +0100
X-Google-Sender-Auth: X8A8qxUY-LIK52wClPblla2I1LI
Message-ID: <CA+8g5KF0+wT2bR6rBxSbvAxXrw2Ah8DT3_Gzx++LNnkepJX5Bw@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
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: 21942@debbugs.gnu.org
Subject: [bug-diffutils] bug#21942: bug#21942: Files with incorrect file
	sizes
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 20 Nov 2015 17:30:10 -0000

On Tue, Nov 17, 2015 at 12:44 PM, Stephan M=C3=BCller <fruktopus@gmail.com>=
 wrote:
> recently I had to debug weird problem. Finally I figured it out.
>
> Virtual file systems like /sys or /proc usually don't care about file
> sizes. All files have a size of 0. This leads to difficulties as diff
> sometimes looks for file sizes.
>
> Say you do:
>
>> $ cp /proc/cmdline my_cmdline
>> $ diff /proc/cmdline my_cmdline ; echo $?
>> 0      // ok, files don't differ
>> $ diff --brief /proc/cmdline my_cmdline
>> Files /proc/cmdline and mycmdline differ
>
> The --brief option triggers a binary compare, as we aren't interested
> in the actual differences this makes sense. As a first step, file sizes
> are compared (0 vs ~150) and the files are reported as different.

thanks for the report.
What version of diffutils are you using?
I think this has been fixed for some time.
I was unable to reproduce with 2.8.1 nor with the latest built from git.
I.e., I created an empty file and used diff-2.8.1 to compare it with
the nominally-
zero-length /proc/cmdline file, and diff did the right thing.
Also, I ran stat to show st_size of each file is indeed 0:

  $ : > /tmp/k; /p/p/diffutils-2.8.1/bin/diff /proc/cmdline /tmp/k; \
     stat --format %s /proc/cmdline /tmp/k
  1d0
  < ro root=3DLABEL=3D...
  0
  0

In fact, I went ahead and built all available versions and tested them
like this:

  $ for i in /p/p/*/bin/diff; do p=3Ddiffutils-$i; echo $i; $i
/proc/cmdline /tmp/k > /dev/null && echo bad; done
  /p/p/diffutils-2.7/bin/diff
  /p/p/diffutils-2.8.1/bin/diff
  /p/p/diffutils-2.8/bin/diff
  /p/p/diffutils-2.9/bin/diff
  /p/p/diffutils-3.0/bin/diff
  /p/p/diffutils-3.1/bin/diff
  /p/p/diffutils-3.2/bin/diff
  /p/p/diffutils-3.3/bin/diff




From MAILER-DAEMON Fri Nov 20 15:08:07 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZzryZ-0001JX-Ko
	for mharc-bug-diffutils@gnu.org; Fri, 20 Nov 2015 15:08:07 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:59494)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzryX-0001J5-P6
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 15:08:06 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzryU-0000ri-IY
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 15:08:05 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:56725)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzryU-0000rd-Ea
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 15:08:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzryT-00035k-Mo
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 15:08:01 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Stephan =?UTF-8?Q?M=C3=BCller?= <fruktopus@gmail.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Fri, 20 Nov 2015 20:08:01 +0000
Resent-Message-ID: <handler.21942.B21942.144805002511812@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 21942
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: Jim Meyering <jim@meyering.net>
Received: via spool by 21942-submit@debbugs.gnu.org id=B21942.144805002511812
	(code B ref 21942); Fri, 20 Nov 2015 20:08:01 +0000
Received: (at 21942) by debbugs.gnu.org; 20 Nov 2015 20:07:05 +0000
Received: from localhost ([127.0.0.1]:46433 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZzrxY-00034R-I5
	for submit@debbugs.gnu.org; Fri, 20 Nov 2015 15:07:04 -0500
Received: from mail-wm0-f48.google.com ([74.125.82.48]:37479)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <fruktopus@gmail.com>) id 1ZzrxV-000343-O3
	for 21942@debbugs.gnu.org; Fri, 20 Nov 2015 15:07:02 -0500
Received: by wmww144 with SMTP id w144so34887103wmw.0
	for <21942@debbugs.gnu.org>; Fri, 20 Nov 2015 12:07:01 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=date:from:to:cc:subject:message-id:in-reply-to:references
	:mime-version:content-type:content-transfer-encoding;
	bh=UKvHnkjjJYLc2WNAvECQ9+uus4XndK9TWTmZC436uZU=;
	b=HSCBKThIfcD9pHn/nejevPDn2VnH3lls6HgGPt3JrgEfV2rrsQboIur8AUENqwyYiN
	aJHG35NveIURw57ikN1LZuGeftbaRuCc4myRXcl4c/OEXVIW4si2M31jVor5oNgy7JXb
	xoc8J4JXqH9pDf4OnskUA2xfus1XfY/khm7AKMr94lfBYl0aYJ+hLgkF/KcWsMdVgK9P
	Lclt+rPIWaGXL6bQuQ+qQdlZ+YQx8fDlbqZgsCaxJ5WGI5i8Nx3QfK55LRTWqpmYcYEn
	xdLGWr0+AhFISIIjz9Ct7RR2RNFZDtIUYiwjLD7OfvAO3EEnIZ0GOxzDgQj+gix+v93R
	jFQA==
X-Received: by 10.194.117.68 with SMTP id kc4mr4259941wjb.77.1448050020511;
	Fri, 20 Nov 2015 12:07:00 -0800 (PST)
Received: from fuckup.fritz.box (adsl-89-217-233-109.adslplus.ch.
	[89.217.233.109]) by smtp.gmail.com with ESMTPSA id
	t133sm930053wmf.24.2015.11.20.12.07.00
	(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
	Fri, 20 Nov 2015 12:07:00 -0800 (PST)
Date: Fri, 20 Nov 2015 21:06:54 +0100
From: Stephan =?UTF-8?Q?M=C3=BCller?= <fruktopus@gmail.com>
Message-ID: <20151120210654.779970ad@fuckup.fritz.box>
In-Reply-To: <CA+8g5KF0+wT2bR6rBxSbvAxXrw2Ah8DT3_Gzx++LNnkepJX5Bw@mail.gmail.com>
References: <20151117124408.27185c58@fuckup.fritz.box>
	<CA+8g5KF0+wT2bR6rBxSbvAxXrw2Ah8DT3_Gzx++LNnkepJX5Bw@mail.gmail.com>
X-Mailer: Claws Mail 3.12.0 (GTK+ 2.24.28; i686-redhat-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
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: 21942@debbugs.gnu.org
Subject: [bug-diffutils] bug#21942: bug#21942: Files with incorrect file
	sizes
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 20 Nov 2015 20:08:06 -0000

Am Fri, 20 Nov 2015 18:28:37 +0100
schrieb Jim Meyering <jim@meyering.net>:

> On Tue, Nov 17, 2015 at 12:44 PM, Stephan M=C3=BCller
> <fruktopus@gmail.com> wrote:
> > recently I had to debug weird problem. Finally I figured it out.
> >
> > Virtual file systems like /sys or /proc usually don't care about
> > file sizes. All files have a size of 0. This leads to difficulties
> > as diff sometimes looks for file sizes.
> >
> > Say you do:
> >
> >> $ cp /proc/cmdline my_cmdline
> >> $ diff /proc/cmdline my_cmdline ; echo $?
> >> 0      // ok, files don't differ
> >> $ diff --brief /proc/cmdline my_cmdline
> >> Files /proc/cmdline and mycmdline differ
> >
> > The --brief option triggers a binary compare, as we aren't
> > interested in the actual differences this makes sense. As a first
> > step, file sizes are compared (0 vs ~150) and the files are
> > reported as different.
>=20
> thanks for the report.
> What version of diffutils are you using?
> I think this has been fixed for some time.
> I was unable to reproduce with 2.8.1 nor with the latest built from
> git. I.e., I created an empty file and used diff-2.8.1 to compare it
> with the nominally-
> zero-length /proc/cmdline file, and diff did the right thing.
> Also, I ran stat to show st_size of each file is indeed 0:
>=20
>   $ : > /tmp/k; /p/p/diffutils-2.8.1/bin/diff /proc/cmdline /tmp/k; \
>      stat --format %s /proc/cmdline /tmp/k
>   1d0
>   < ro root=3DLABEL=3D...
>   0
>   0
>=20
> In fact, I went ahead and built all available versions and tested them
> like this:
>=20
>   $ for i in /p/p/*/bin/diff; do p=3Ddiffutils-$i; echo $i; $i
> /proc/cmdline /tmp/k > /dev/null && echo bad; done
>   /p/p/diffutils-2.7/bin/diff
>   /p/p/diffutils-2.8.1/bin/diff
>   /p/p/diffutils-2.8/bin/diff
>   /p/p/diffutils-2.9/bin/diff
>   /p/p/diffutils-3.0/bin/diff
>   /p/p/diffutils-3.1/bin/diff
>   /p/p/diffutils-3.2/bin/diff
>   /p/p/diffutils-3.3/bin/diff

Hi,

I am using v.3.3 of diffutils

$ diff -v=20
diff (GNU diffutils) 3.3

but I think you misunderstood the problem. Sorry for being ambiguous. I
am not diffing against an empty file. That works well. The point is
procfs doesn't care about size, but 'normal' file systems do. So for
example on my system I have (after cp /proc/cmdline mycmdline)

$ stat --format %s /proc/cmdline mycmdline
0
140

The result of diffing /proc/cmdline against mycmdline depends on the
--brief flag.

STEPS TO REPRODUCE:

cp /proc/cmdline mycmdline
diff --brief /proc/cmdline mycmdline > /dev/null ; echo ?$
1
diff /proc/cmdline mycmdline ; echo $?
0

EXPECTED RESULT:

cp /proc/cmdline mycmdline
diff --brief /proc/cmdline mycmdline > /dev/null ; echo ?$
0
diff /proc/cmdline mycmdline ; echo $?
0

 ~stephan




From MAILER-DAEMON Fri Nov 20 17:14:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZztwX-0001Im-E8
	for mharc-bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:14:09 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:59322)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZztwU-0001Hz-DF
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:14:07 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZztwR-0007F3-3Q
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:14:06 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:56775)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZztwQ-0007Ep-Lp
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:14:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZztwQ-0006F7-7K
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:14:02 -0500
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: Fri, 20 Nov 2015 22:14:02 +0000
Resent-Message-ID: <handler.21942.B21942.144805758423917@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 21942
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: Stephan =?UTF-8?Q?M=C3=BCller?= <fruktopus@gmail.com>
Received: via spool by 21942-submit@debbugs.gnu.org id=B21942.144805758423917
	(code B ref 21942); Fri, 20 Nov 2015 22:14:02 +0000
Received: (at 21942) by debbugs.gnu.org; 20 Nov 2015 22:13:04 +0000
Received: from localhost ([127.0.0.1]:46483 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZztvT-0006Dg-9f
	for submit@debbugs.gnu.org; Fri, 20 Nov 2015 17:13:03 -0500
Received: from mail-vk0-f50.google.com ([209.85.213.50]:35526)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>) id 1ZztvQ-0006DF-SX
	for 21942@debbugs.gnu.org; Fri, 20 Nov 2015 17:13:01 -0500
Received: by vkha189 with SMTP id a189so6923960vkh.2
	for <21942@debbugs.gnu.org>; Fri, 20 Nov 2015 14:13:00 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:from:date:message-id
	:subject:to:cc:content-type;
	bh=IiXYBX2ZVNLIOVkP5pq9QYKiG/XIoS6DBIesTyw04mI=;
	b=IZ30tv0Thqeq1hSvT6oXKOqX2VPrZ+cMo8lPygjvnKHW/QYFJ4gIFH4HhYxTMgyO4J
	ASkpJq7ANL3TheNCe6A2E1zAeBDtKWT1SEu4FIn0ZQzOWIn+VB+c3NvC6XM9oPiMzpVW
	irM/BWj1AnE31LwqcPKaiX2XcqZvfSoySxRs/NpPx1RYHN8oT6Dhu6hP8rAKej1Dy7W6
	/BhrnuOzd1aH2HfXvM46lGwpuYYCqR8dHZij9h1ScDWbBljySMQuZ0+dOJs8Vun87Rp7
	3MIOZkUBMH+9ls1PClK5YGNjolqZ6h+6OAEu++9aqGm1kP653nNHDqG75J/gMZ4dIxHD
	q00w==
X-Received: by 10.31.41.131 with SMTP id p125mr1881566vkp.133.1448057580398;
	Fri, 20 Nov 2015 14:13:00 -0800 (PST)
MIME-Version: 1.0
Received: by 10.31.84.198 with HTTP; Fri, 20 Nov 2015 14:12:40 -0800 (PST)
In-Reply-To: <20151120210654.779970ad@fuckup.fritz.box>
References: <20151117124408.27185c58@fuckup.fritz.box>
	<CA+8g5KF0+wT2bR6rBxSbvAxXrw2Ah8DT3_Gzx++LNnkepJX5Bw@mail.gmail.com>
	<20151120210654.779970ad@fuckup.fritz.box>
From: Jim Meyering <jim@meyering.net>
Date: Fri, 20 Nov 2015 23:12:40 +0100
X-Google-Sender-Auth: 2ZMGQ3vV9iP63--qEgnB5K55kQM
Message-ID: <CA+8g5KH46mq54tgyzAATRh10vacNJKetCyWPq681ttmKuGxq_A@mail.gmail.com>
Content-Type: multipart/mixed; boundary=001a113f0e46b1c1300525002d33
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: 21942@debbugs.gnu.org
Subject: [bug-diffutils] bug#21942: bug#21942: Files with incorrect file
	sizes
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 20 Nov 2015 22:14:07 -0000

--001a113f0e46b1c1300525002d33
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Fri, Nov 20, 2015 at 9:06 PM, Stephan M=C3=BCller <fruktopus@gmail.com> =
wrote:
> Am Fri, 20 Nov 2015 18:28:37 +0100
> schrieb Jim Meyering <jim@meyering.net>:
>
>> On Tue, Nov 17, 2015 at 12:44 PM, Stephan M=C3=BCller
>> <fruktopus@gmail.com> wrote:
>> > recently I had to debug weird problem. Finally I figured it out.
>> >
>> > Virtual file systems like /sys or /proc usually don't care about
>> > file sizes. All files have a size of 0. This leads to difficulties
>> > as diff sometimes looks for file sizes.
>> >
>> > Say you do:
>> >
>> >> $ cp /proc/cmdline my_cmdline
>> >> $ diff /proc/cmdline my_cmdline ; echo $?
>> >> 0      // ok, files don't differ
>> >> $ diff --brief /proc/cmdline my_cmdline
>> >> Files /proc/cmdline and mycmdline differ
>> >
>> > The --brief option triggers a binary compare, as we aren't
>> > interested in the actual differences this makes sense. As a first
>> > step, file sizes are compared (0 vs ~150) and the files are
>> > reported as different.
>>
>> thanks for the report.
>> What version of diffutils are you using?
>> I think this has been fixed for some time.
>> I was unable to reproduce with 2.8.1 nor with the latest built from
>> git. I.e., I created an empty file and used diff-2.8.1 to compare it
>> with the nominally-
>> zero-length /proc/cmdline file, and diff did the right thing.
>> Also, I ran stat to show st_size of each file is indeed 0:
>>
>>   $ : > /tmp/k; /p/p/diffutils-2.8.1/bin/diff /proc/cmdline /tmp/k; \
>>      stat --format %s /proc/cmdline /tmp/k
>>   1d0
>>   < ro root=3DLABEL=3D...
>>   0
>>   0
>>
>> In fact, I went ahead and built all available versions and tested them
>> like this:
>>
>>   $ for i in /p/p/*/bin/diff; do p=3Ddiffutils-$i; echo $i; $i
>> /proc/cmdline /tmp/k > /dev/null && echo bad; done
>>   /p/p/diffutils-2.7/bin/diff
>>   /p/p/diffutils-2.8.1/bin/diff
>>   /p/p/diffutils-2.8/bin/diff
>>   /p/p/diffutils-2.9/bin/diff
>>   /p/p/diffutils-3.0/bin/diff
>>   /p/p/diffutils-3.1/bin/diff
>>   /p/p/diffutils-3.2/bin/diff
>>   /p/p/diffutils-3.3/bin/diff
>
> Hi,
>
> I am using v.3.3 of diffutils
>
> $ diff -v
> diff (GNU diffutils) 3.3
>
> but I think you misunderstood the problem. Sorry for being ambiguous. I
> am not diffing against an empty file. That works well. The point is
> procfs doesn't care about size, but 'normal' file systems do. So for
> example on my system I have (after cp /proc/cmdline mycmdline)
>
> $ stat --format %s /proc/cmdline mycmdline
> 0
> 140
>
> The result of diffing /proc/cmdline against mycmdline depends on the
> --brief flag.
>
> STEPS TO REPRODUCE:
>
> cp /proc/cmdline mycmdline
> diff --brief /proc/cmdline mycmdline > /dev/null ; echo ?$
> 1
> diff /proc/cmdline mycmdline ; echo $?
> 0
>
> EXPECTED RESULT:
>
> cp /proc/cmdline mycmdline
> diff --brief /proc/cmdline mycmdline > /dev/null ; echo ?$
> 0
> diff /proc/cmdline mycmdline ; echo $?
> 0

Oh, indeed. Thank you for clarifying. That feels like a bug.
Here's a knee-jerk patch that refrains from using the st_size-comparing
heuristic when either of the sizes is zero. This may well be wrong.
I have only barely tested the diff.c code path.

--001a113f0e46b1c1300525002d33
Content-Type: text/x-patch; charset=US-ASCII; name="st_size-is-zero.patch"
Content-Disposition: attachment; filename="st_size-is-zero.patch"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_ih881vmf0

ZGlmZiAtLWdpdCBhL3NyYy9hbmFseXplLmMgYi9zcmMvYW5hbHl6ZS5jCmluZGV4IDg5M2QwN2Mu
LjI2MjI4MTAgMTAwNjQ0Ci0tLSBhL3NyYy9hbmFseXplLmMKKysrIGIvc3JjL2FuYWx5emUuYwpA
QCAtNDc3LDYgKzQ3Nyw4IEBAIGRpZmZfMl9maWxlcyAoc3RydWN0IGNvbXBhcmlzb24gKmNtcCkK
ICAgICB7CiAgICAgICAvKiBGaWxlcyB3aXRoIGRpZmZlcmVudCBsZW5ndGhzIG11c3QgYmUgZGlm
ZmVyZW50LiAgKi8KICAgICAgIGlmIChjbXAtPmZpbGVbMF0uc3RhdC5zdF9zaXplICE9IGNtcC0+
ZmlsZVsxXS5zdGF0LnN0X3NpemUKKwkgICYmIDAgPCBjbXAtPmZpbGVbMF0uc3RhdC5zdF9zaXpl
CisJICAmJiAwIDwgY21wLT5maWxlWzFdLnN0YXQuc3Rfc2l6ZQogCSAgJiYgKGNtcC0+ZmlsZVsw
XS5kZXNjIDwgMCB8fCBTX0lTUkVHIChjbXAtPmZpbGVbMF0uc3RhdC5zdF9tb2RlKSkKIAkgICYm
IChjbXAtPmZpbGVbMV0uZGVzYyA8IDAgfHwgU19JU1JFRyAoY21wLT5maWxlWzFdLnN0YXQuc3Rf
bW9kZSkpKQogCWNoYW5nZXMgPSAxOwpkaWZmIC0tZ2l0IGEvc3JjL2RpZmYuYyBiL3NyYy9kaWZm
LmMKaW5kZXggZWZkN2U0Ny4uYjJhOTBhYSAxMDA2NDQKLS0tIGEvc3JjL2RpZmYuYworKysgYi9z
cmMvZGlmZi5jCkBAIC0xMzQ0LDcgKzEzNDQsOSBAQCBjb21wYXJlX2ZpbGVzIChzdHJ1Y3QgY29t
cGFyaXNvbiBjb25zdCAqcGFyZW50LAogICBlbHNlIGlmIChmaWxlc19jYW5fYmVfdHJlYXRlZF9h
c19iaW5hcnkKIAkgICAmJiBTX0lTUkVHIChjbXAuZmlsZVswXS5zdGF0LnN0X21vZGUpCiAJICAg
JiYgU19JU1JFRyAoY21wLmZpbGVbMV0uc3RhdC5zdF9tb2RlKQotCSAgICYmIGNtcC5maWxlWzBd
LnN0YXQuc3Rfc2l6ZSAhPSBjbXAuZmlsZVsxXS5zdGF0LnN0X3NpemUpCisJICAgJiYgY21wLmZp
bGVbMF0uc3RhdC5zdF9zaXplICE9IGNtcC5maWxlWzFdLnN0YXQuc3Rfc2l6ZQorCSAgICYmIDAg
PCBjbXAuZmlsZVswXS5zdGF0LnN0X3NpemUKKwkgICAmJiAwIDwgY21wLmZpbGVbMV0uc3RhdC5z
dF9zaXplKQogICAgIHsKICAgICAgIG1lc3NhZ2UgKCJGaWxlcyAlcyBhbmQgJXMgZGlmZmVyXG4i
LAogCSAgICAgICBmaWxlX2xhYmVsWzBdID8gZmlsZV9sYWJlbFswXSA6IGNtcC5maWxlWzBdLm5h
bWUsCg==
--001a113f0e46b1c1300525002d33--




From MAILER-DAEMON Fri Nov 20 17:34:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZzuFt-0005vC-LE
	for mharc-bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:34:09 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:34109)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzuFq-0005tg-Vw
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:34:08 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzuFm-0003GQ-Or
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:34:06 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:56794)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzuFm-0003GM-KN
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:34:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzuFm-0006ly-6F
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:34:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Stephan =?UTF-8?Q?M=C3=BCller?= <fruktopus@gmail.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Fri, 20 Nov 2015 22:34:02 +0000
Resent-Message-ID: <handler.21942.B21942.144805883926021@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 21942
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: Jim Meyering <jim@meyering.net>
Received: via spool by 21942-submit@debbugs.gnu.org id=B21942.144805883926021
	(code B ref 21942); Fri, 20 Nov 2015 22:34:02 +0000
Received: (at 21942) by debbugs.gnu.org; 20 Nov 2015 22:33:59 +0000
Received: from localhost ([127.0.0.1]:46502 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZzuFi-0006ld-Jv
	for submit@debbugs.gnu.org; Fri, 20 Nov 2015 17:33:59 -0500
Received: from mail-wm0-f48.google.com ([74.125.82.48]:35382)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <fruktopus@gmail.com>) id 1ZzuFO-0006kv-MR
	for 21942@debbugs.gnu.org; Fri, 20 Nov 2015 17:33:57 -0500
Received: by wmdw130 with SMTP id w130so36183095wmd.0
	for <21942@debbugs.gnu.org>; Fri, 20 Nov 2015 14:33:38 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=date:from:to:cc:subject:message-id:in-reply-to:references
	:mime-version:content-type:content-transfer-encoding;
	bh=LDP4p3xE8CjoJsSo/SPWTzaEgcqSHDAxe0WCgESJznM=;
	b=P/sj35TLCHSNFHd2mAyKj1sqtSBbWWY0duIBr/2vL6olFCN62E2tFn+uxC2XVf0eKb
	Z/lCNtX223xU14wiTLD7YYFH1w9mpkoS0wsA6ezesqZXd2BQm1+vVhREGudKZwzoSJU6
	WbSk6LUKSRhlYd9XGXm691CeQxzPDbbWTtJTwIip+dgfUZ2Pqj4UDDzNSiqeA7m2V9yE
	dg7sYxGi8ASQOKWHzQdRK/iY5f1/p487j44dEpiNranqtQpcWZpJIeZLp9aOf557y0SL
	sxxG5Y78AlkqmWUG/FG8q+L5FxvojwDLL/vMkyKsdSoKgV+zzrpWvrGq/5rTDFXGR9d6
	IpVw==
X-Received: by 10.194.116.100 with SMTP id jv4mr16195570wjb.67.1448058818116; 
	Fri, 20 Nov 2015 14:33:38 -0800 (PST)
Received: from fuckup.fritz.box (adsl-89-217-233-109.adslplus.ch.
	[89.217.233.109]) by smtp.gmail.com with ESMTPSA id
	gl10sm1423134wjb.30.2015.11.20.14.33.37
	(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
	Fri, 20 Nov 2015 14:33:37 -0800 (PST)
Date: Fri, 20 Nov 2015 23:33:34 +0100
From: Stephan =?UTF-8?Q?M=C3=BCller?= <fruktopus@gmail.com>
Message-ID: <20151120233334.7e93f488@fuckup.fritz.box>
In-Reply-To: <CA+8g5KH46mq54tgyzAATRh10vacNJKetCyWPq681ttmKuGxq_A@mail.gmail.com>
References: <20151117124408.27185c58@fuckup.fritz.box>
	<CA+8g5KF0+wT2bR6rBxSbvAxXrw2Ah8DT3_Gzx++LNnkepJX5Bw@mail.gmail.com>
	<20151120210654.779970ad@fuckup.fritz.box>
	<CA+8g5KH46mq54tgyzAATRh10vacNJKetCyWPq681ttmKuGxq_A@mail.gmail.com>
X-Mailer: Claws Mail 3.12.0 (GTK+ 2.24.28; i686-redhat-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
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: 21942@debbugs.gnu.org
Subject: [bug-diffutils] bug#21942: bug#21942: Files with incorrect file
	sizes
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 20 Nov 2015 22:34:08 -0000

Am Fri, 20 Nov 2015 23:12:40 +0100
schrieb Jim Meyering <jim@meyering.net>:

> On Fri, Nov 20, 2015 at 9:06 PM, Stephan M=C3=BCller <fruktopus@gmail.com>
> wrote:
> > Am Fri, 20 Nov 2015 18:28:37 +0100
> > schrieb Jim Meyering <jim@meyering.net>:
> >
> >> On Tue, Nov 17, 2015 at 12:44 PM, Stephan M=C3=BCller
> >> <fruktopus@gmail.com> wrote:
> >> > recently I had to debug weird problem. Finally I figured it out.
> >> >
> >> > Virtual file systems like /sys or /proc usually don't care about
> >> > file sizes. All files have a size of 0. This leads to
> >> > difficulties as diff sometimes looks for file sizes.
> >> >
> >> > Say you do:
> >> >
> >> >> $ cp /proc/cmdline my_cmdline
> >> >> $ diff /proc/cmdline my_cmdline ; echo $?
> >> >> 0      // ok, files don't differ
> >> >> $ diff --brief /proc/cmdline my_cmdline
> >> >> Files /proc/cmdline and mycmdline differ
> >> >
> >> > The --brief option triggers a binary compare, as we aren't
> >> > interested in the actual differences this makes sense. As a first
> >> > step, file sizes are compared (0 vs ~150) and the files are
> >> > reported as different.
> >>
> >> thanks for the report.
> >> What version of diffutils are you using?
> >> I think this has been fixed for some time.
> >> I was unable to reproduce with 2.8.1 nor with the latest built from
> >> git. I.e., I created an empty file and used diff-2.8.1 to compare
> >> it with the nominally-
> >> zero-length /proc/cmdline file, and diff did the right thing.
> >> Also, I ran stat to show st_size of each file is indeed 0:
> >>
> >>   $ :
> >> > /tmp/k; /p/p/diffutils-2.8.1/bin/diff /proc/cmdline /tmp/k; \
> >> > stat --format %s /proc/cmdline /tmp/k
> >>   1d0
> >>   < ro root=3DLABEL=3D...
> >>   0
> >>   0
> >>
> >> In fact, I went ahead and built all available versions and tested
> >> them like this:
> >>
> >>   $ for i in /p/p/*/bin/diff; do p=3Ddiffutils-$i; echo $i; $i
> >> /proc/cmdline /tmp/k > /dev/null && echo bad; done
> >>   /p/p/diffutils-2.7/bin/diff
> >>   /p/p/diffutils-2.8.1/bin/diff
> >>   /p/p/diffutils-2.8/bin/diff
> >>   /p/p/diffutils-2.9/bin/diff
> >>   /p/p/diffutils-3.0/bin/diff
> >>   /p/p/diffutils-3.1/bin/diff
> >>   /p/p/diffutils-3.2/bin/diff
> >>   /p/p/diffutils-3.3/bin/diff
> >
> > Hi,
> >
> > I am using v.3.3 of diffutils
> >
> > $ diff -v
> > diff (GNU diffutils) 3.3
> >
> > but I think you misunderstood the problem. Sorry for being
> > ambiguous. I am not diffing against an empty file. That works well.
> > The point is procfs doesn't care about size, but 'normal' file
> > systems do. So for example on my system I have (after
> > cp /proc/cmdline mycmdline)
> >
> > $ stat --format %s /proc/cmdline mycmdline
> > 0
> > 140
> >
> > The result of diffing /proc/cmdline against mycmdline depends on the
> > --brief flag.
> >
> > STEPS TO REPRODUCE:
> >
> > cp /proc/cmdline mycmdline
> > diff --brief /proc/cmdline mycmdline > /dev/null ; echo ?$
> > 1
> > diff /proc/cmdline mycmdline ; echo $?
> > 0
> >
> > EXPECTED RESULT:
> >
> > cp /proc/cmdline mycmdline
> > diff --brief /proc/cmdline mycmdline > /dev/null ; echo ?$
> > 0
> > diff /proc/cmdline mycmdline ; echo $?
> > 0
>=20
> Oh, indeed. Thank you for clarifying. That feels like a bug.
> Here's a knee-jerk patch that refrains from using the
> st_size-comparing heuristic when either of the sizes is zero. This
> may well be wrong. I have only barely tested the diff.c code path.

Thanks, that makes the problem at least (even) less unlikely. But if we
cant trust file sizes we're doomed. What do you think about a flag
controlling comparison by size and a notice if files differ by size.

I can craft a patch for this.

  ~s




From MAILER-DAEMON Fri Nov 20 17:41:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1ZzuMf-0008To-AH
	for mharc-bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:41:09 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:35639)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzuMd-0008Td-7n
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:41:08 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzuMZ-0005lh-3a
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:41:07 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:56799)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzuMZ-0005ld-0Y
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:41:03 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1ZzuMY-0006wQ-Ho
	for bug-diffutils@gnu.org; Fri, 20 Nov 2015 17:41:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Paul Eggert <eggert@cs.ucla.edu>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Fri, 20 Nov 2015 22:41:02 +0000
Resent-Message-ID: <handler.21942.B21942.144805920326604@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 21942
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: Stephan =?UTF-8?Q?M=C3=BCller?= <fruktopus@gmail.com>,
	Jim Meyering <jim@meyering.net>
Received: via spool by 21942-submit@debbugs.gnu.org id=B21942.144805920326604
	(code B ref 21942); Fri, 20 Nov 2015 22:41:02 +0000
Received: (at 21942) by debbugs.gnu.org; 20 Nov 2015 22:40:03 +0000
Received: from localhost ([127.0.0.1]:46507 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1ZzuLa-0006v0-LM
	for submit@debbugs.gnu.org; Fri, 20 Nov 2015 17:40:03 -0500
Received: from zimbra.cs.ucla.edu ([131.179.128.68]:59742)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <eggert@cs.ucla.edu>) id 1ZzuLY-0006uS-Bu
	for 21942@debbugs.gnu.org; Fri, 20 Nov 2015 17:40:00 -0500
Received: from localhost (localhost [127.0.0.1])
	by zimbra.cs.ucla.edu (Postfix) with ESMTP id 1128E160D72;
	Fri, 20 Nov 2015 14:39:58 -0800 (PST)
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 AOY9-Ev6YB9q; Fri, 20 Nov 2015 14:39:57 -0800 (PST)
Received: from localhost (localhost [127.0.0.1])
	by zimbra.cs.ucla.edu (Postfix) with ESMTP id 69AF1160DFD;
	Fri, 20 Nov 2015 14:39:57 -0800 (PST)
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 RmvhN21ora9Y; Fri, 20 Nov 2015 14:39:57 -0800 (PST)
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 4A666160D72;
	Fri, 20 Nov 2015 14:39:57 -0800 (PST)
References: <20151117124408.27185c58@fuckup.fritz.box>
	<CA+8g5KF0+wT2bR6rBxSbvAxXrw2Ah8DT3_Gzx++LNnkepJX5Bw@mail.gmail.com>
	<20151120210654.779970ad@fuckup.fritz.box>
	<CA+8g5KH46mq54tgyzAATRh10vacNJKetCyWPq681ttmKuGxq_A@mail.gmail.com>
	<20151120233334.7e93f488@fuckup.fritz.box>
From: Paul Eggert <eggert@cs.ucla.edu>
Organization: UCLA Computer Science Department
Message-ID: <564FA13D.9030401@cs.ucla.edu>
Date: Fri, 20 Nov 2015 14:39:57 -0800
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: <20151120233334.7e93f488@fuckup.fritz.box>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
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: 21942@debbugs.gnu.org
Subject: [bug-diffutils] bug#21942: bug#21942: bug#21942: Files with
	incorrect file sizes
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 20 Nov 2015 22:41:08 -0000

Stephan M=C3=BCller wrote:
> What do you think about a flag

I'd rather avoid a flag. User-visible complexity has a cost, and we're be=
tter=20
off keeping things simple.

Is there some easy way to tell whether we're on a file system like procfs=
 that=20
has the bug?  Perhaps we can have a list of known good file systems.  But=
 this=20
is lower priority than getting the bug fixed.




From MAILER-DAEMON Sat Nov 21 06:34:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1a06Qj-000331-CE
	for mharc-bug-diffutils@gnu.org; Sat, 21 Nov 2015 06:34:09 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49421)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a06Qg-00032v-Ga
	for bug-diffutils@gnu.org; Sat, 21 Nov 2015 06:34:07 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a06Qc-0004Cq-Fd
	for bug-diffutils@gnu.org; Sat, 21 Nov 2015 06:34:06 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:56943)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a06Qc-0004C5-C1
	for bug-diffutils@gnu.org; Sat, 21 Nov 2015 06:34:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a06Qb-0001lB-W6
	for bug-diffutils@gnu.org; Sat, 21 Nov 2015 06:34:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Stephan =?UTF-8?Q?M=C3=BCller?= <fruktopus@gmail.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-diffutils@gnu.org
Resent-Date: Sat, 21 Nov 2015 11:34:01 +0000
Resent-Message-ID: <handler.21942.B21942.14481056176730@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 21942
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: Paul Eggert <eggert@cs.ucla.edu>
Received: via spool by 21942-submit@debbugs.gnu.org id=B21942.14481056176730
	(code B ref 21942); Sat, 21 Nov 2015 11:34:01 +0000
Received: (at 21942) by debbugs.gnu.org; 21 Nov 2015 11:33:37 +0000
Received: from localhost ([127.0.0.1]:46650 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1a06QD-0001kU-A0
	for submit@debbugs.gnu.org; Sat, 21 Nov 2015 06:33:37 -0500
Received: from mail-wm0-f51.google.com ([74.125.82.51]:33028)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <fruktopus@gmail.com>) id 1a06Ps-0001k3-Sb
	for 21942@debbugs.gnu.org; Sat, 21 Nov 2015 06:33:35 -0500
Received: by wmec201 with SMTP id c201so103849140wme.0
	for <21942@debbugs.gnu.org>; Sat, 21 Nov 2015 03:33:16 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=date:from:to:cc:subject:message-id:in-reply-to:references
	:mime-version:content-type:content-transfer-encoding;
	bh=pKqcohp5Tg9lvGoOVn52623eK0/V3r8hvzB1yOfheco=;
	b=TzKToOKvpr0MaxJU9wLGHgakcs2DrR7kA41soa9LEKID2PD6u2ZYXMOq/CiVJIfGJ+
	npfB/mkZz0hfilVX6Ipm+2BMFdWSBAjZEpkN/JSFPC+7+n2LgqG+vnseeSsAgkumLdVv
	Iml6EoVOIaWGISZ41XrTAdBn+73kkxje2bCkpSTCPfMAwEYViwge+h8ykfHVvkbD+lFB
	pw8v3hnDcUKFdc0EbSklVcd5JD2akRxTuNADhsT69Fjsp0e2u6jFfd9Y/iaSOoBRpE7l
	8qU1rkpr4w97WHkRTt1AahroeRZ7JZKoTdwNvQtZo7+ucgoLxMn9uqY6NM9CTeFxDGXN
	pxkQ==
X-Received: by 10.28.130.7 with SMTP id e7mr5242326wmd.68.1448105596176;
	Sat, 21 Nov 2015 03:33:16 -0800 (PST)
Received: from fuckup.fritz.box (adsl-89-217-233-109.adslplus.ch.
	[89.217.233.109])
	by smtp.gmail.com with ESMTPSA id m11sm3734968wma.5.2015.11.21.03.33.15
	(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
	Sat, 21 Nov 2015 03:33:16 -0800 (PST)
Date: Sat, 21 Nov 2015 12:33:12 +0100
From: Stephan =?UTF-8?Q?M=C3=BCller?= <fruktopus@gmail.com>
Message-ID: <20151121123312.7af8070f@fuckup.fritz.box>
In-Reply-To: <564FA13D.9030401@cs.ucla.edu>
References: <20151117124408.27185c58@fuckup.fritz.box>
	<CA+8g5KF0+wT2bR6rBxSbvAxXrw2Ah8DT3_Gzx++LNnkepJX5Bw@mail.gmail.com>
	<20151120210654.779970ad@fuckup.fritz.box>
	<CA+8g5KH46mq54tgyzAATRh10vacNJKetCyWPq681ttmKuGxq_A@mail.gmail.com>
	<20151120233334.7e93f488@fuckup.fritz.box>
	<564FA13D.9030401@cs.ucla.edu>
X-Mailer: Claws Mail 3.12.0 (GTK+ 2.24.28; i686-redhat-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
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: 21942@debbugs.gnu.org
Subject: [bug-diffutils] bug#21942: bug#21942: bug#21942: Files with
	incorrect file sizes
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 21 Nov 2015 11:34:07 -0000

Am Fri, 20 Nov 2015 14:39:57 -0800
schrieb Paul Eggert <eggert@cs.ucla.edu>:
> I'd rather avoid a flag. User-visible complexity has a cost, and
> we're better off keeping things simple.
> 
> Is there some easy way to tell whether we're on a file system like
> procfs that has the bug?  Perhaps we can have a list of known good
> file systems.  But this is lower priority than getting the bug fixed.

Ok, I agree. A flag is not optimal.

I did some reading but I think you cant tell if a file system has that
issue. I slightly more elaborate approach than just checking for file
size 0 (as Jim did) would be to actually try to read such a file and
see if you can get anything from it. If yes, than diff by looking into
the content.

However, still procfs or worse debugfs could report anything as size.
The only proper fix would be to ignore file sizes entirely.

 ~stephan




From MAILER-DAEMON Thu Nov 26 12:18:11 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1a20BP-0002bl-G8
	for mharc-bug-diffutils@gnu.org; Thu, 26 Nov 2015 12:18:11 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:33543)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a20BM-0002ba-Os
	for bug-diffutils@gnu.org; Thu, 26 Nov 2015 12:18:09 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a20BG-0008AS-Lb
	for bug-diffutils@gnu.org; Thu, 26 Nov 2015 12:18:08 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:36622)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a20BG-0008AO-Hn
	for bug-diffutils@gnu.org; Thu, 26 Nov 2015 12:18:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a20BG-0000bi-0r
	for bug-diffutils@gnu.org; Thu, 26 Nov 2015 12:18:02 -0500
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, 26 Nov 2015 17:18:01 +0000
Resent-Message-ID: <handler.20062.B20062.14485582672309@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.14485582672309
	(code B ref 20062); Thu, 26 Nov 2015 17:18:01 +0000
Received: (at 20062) by debbugs.gnu.org; 26 Nov 2015 17:17:47 +0000
Received: from localhost ([127.0.0.1]:54563 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1a20B0-0000bB-K9
	for submit@debbugs.gnu.org; Thu, 26 Nov 2015 12:17:47 -0500
Received: from mail-vk0-f50.google.com ([209.85.213.50]:35184)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>) id 1a20Ay-0000b3-En
	for 20062@debbugs.gnu.org; Thu, 26 Nov 2015 12:17:45 -0500
Received: by vkha189 with SMTP id a189so56500873vkh.2
	for <20062@debbugs.gnu.org>; Thu, 26 Nov 2015 09:17:44 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:from:date:message-id
	:subject:to:cc:content-type;
	bh=Pdo1GH/gT5Yfel2Aip1aqZkjV4E+AM0dKJWuMs+itj4=;
	b=ZP5HkgM6naLAqUP0WFFhXduYy58MGG55SXw2h4D3L0dcEbwy4tmqieZCWfK4+thrWO
	Vo0rTofTWxUHLb1f2DXMcKr5NtxSAWs5PX18/JPXO5aw9wM6gtZdWtS7zSSYfzohtjHf
	IgMDJYKGjN67U0UX7Hu4+WpuMPHHjoN/PS8A1BNEkWH4kAtpo7rqjRchfG+grr1C8/1+
	6m/AECf8/LnnM83tTIwTCGG0n3QvV8VDp88Vi+yN7ZdjgEUfx4OM1TPKlMk4cWTuHff5
	qOTrxcB89IJ5oGMV129y8s3TtEFLbvUxOa8wEeDV8SO8G42lrJog7x2hSlF4sdP5I27I
	vI6g==
X-Received: by 10.31.183.200 with SMTP id h191mr39482604vkf.147.1448558264017; 
	Thu, 26 Nov 2015 09:17:44 -0800 (PST)
MIME-Version: 1.0
Received: by 10.31.84.198 with HTTP; Thu, 26 Nov 2015 09:17:24 -0800 (PST)
In-Reply-To: <87twol1nqw.fsf@foo.bar.baz>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
	<87fv0nko86.fsf@foo.bar.baz> <5638EE6E.3050901@redhat.com>
	<CA+8g5KHcMiMiGnQJ3ibhe2W=4crcy9g6jSyMnWo-T9E4uzm=Og@mail.gmail.com>
	<87twol1nqw.fsf@foo.bar.baz>
From: Jim Meyering <jim@meyering.net>
Date: Thu, 26 Nov 2015 09:17:24 -0800
X-Google-Sender-Auth: aoUHj1iKURNsqWjYjBMhKcqFHRU
Message-ID: <CA+8g5KFs5CKoAzUw8T45-f8f+0t93XzZnfWKfkfrYrc4DXYQHQ@mail.gmail.com>
Content-Type: multipart/mixed; boundary=001a11439778c38359052574c093
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: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 26 Nov 2015 17:18:10 -0000

--001a11439778c38359052574c093
Content-Type: text/plain; charset=UTF-8

On Mon, Nov 16, 2015 at 4:19 PM, Giuseppe Scrivano <gscrivano@gnu.org> wrote:
> Jim Meyering <jim@meyering.net> writes:
>
>> On Tue, Nov 3, 2015 at 9:27 AM, Eric Blake <eblake@redhat.com> wrote:
>>> On 11/03/2015 10:05 AM, Giuseppe Scrivano wrote:
>>>
>>>> I have attached the patches that implement --palette, the missing tests
>>>> and update the NEWS file.
>>>>
>>>
>>>> +++ b/doc/diffutils.texi
>>>> @@ -3763,6 +3763,7 @@ Always use color.
>>>>  Specifying @option{--color} and no @var{when} is equivalent to
>>>>  @option{--color=auto}.
>>>>
>>>> +
>>>>  @item -C @var{lines}
>>>
>>> Spurious change?
>>>
>>>>  @itemx --context@r{[}=@var{lines}@r{]}
>>>>  Use the context output format, showing @var{lines} (an integer) lines of
>>>> @@ -3890,6 +3891,11 @@ if-then-else format.  @xref{Line Formats}.
>>>>  @itemx --show-c-function
>>>>  Show which C function each change is in.  @xref{C Function Headings}.
>>>>
>>>> +@item --palette=@var{scheme}
>>>> +It allows to specify what colors are used to colorize the output.  It
>>>
>>> Passive voice.  Would sound better as:
>>>
>>> Specify what color palette to use when colored output to use.
>>
>> Thanks for the quick review, Eric.
>> I'll wait for the next iteration.
>
> sorry for taking so long, I hope the attached version is fine.

I have begun reviewing carefully.
I adjusted NEWS.  Here is the modified paragraph:

** New features

   diff accepts two new options --color and --palette to generate
   and configure colored output.  --color takes an optional argument
   specifying when to colorize a line: --color=always, --color=auto,
   --color=never.  --palette is used to configure which colors are used.

I looked at the tests/colors script: we cannot/should not use sha1sum
for two reasons. 1) it is a short cut; better to include the precise expected
output in each case. Using this approach, if/when a test fails, there is
no record of what the expected output was. 2) the "sha1sum" command
is not universally available by that name. On BSD-based systems it is
called "sha1". Thus, I began the conversion, and in so doing, I found
some room for improvement: with the current patches I have, diff -u
emits a pair of identical color-changing escape sequences before each
"+"-prefixed line:

  $ diff -u --color=always a b|cat -A
  ^[[1;39m--- a^I1969-12-31 16:00:00.000000000 -0800$
  +++ b^I1969-12-31 16:00:00.000000000 -0800$
  ^[[0m^[[36m@@ -1 +1 @@^[[0m$
  ^[[31m-a$
  ^[[32m^[[32m+b$
  ^[[0m

Notice also how the final \e[0m is on the final line by itself,
with no following newline. Please adjust so that it appears at the
end of the final line instead. I confirmed that git-diff appears
to do the same thing, but noted that git uses \e[m instead (no
"0" part). Do you know of any pros/cons for one or the other?

I've attached the beginnings of the adjusted tests/colors
script that I used to discover these things. Can you finish the job
of converting it to use "compare" rather than sha1sum?

--001a11439778c38359052574c093
Content-Type: application/x-sh; name="colors.sh"
Content-Disposition: attachment; filename="colors.sh"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_ihgi5f3w3

IyEvYmluL3NoCgouICIke3NyY2Rpcj0ufS9pbml0LnNoIjsgcGF0aF9wcmVwZW5kXyAuLi9zcmMK
ClRaPVVUQzAKZXhwb3J0IFRaCgpmYWlsPTAKCmVjaG8gYSA+IGEKZWNobyBiID4gYgoKZXBvY2g9
JzE5NzAtMDEtMDEgMDA6MDA6MDAnCnRvdWNoIC0tZGF0ZT0iJGVwb2NoIiBhIGIKCmdlbl9leHBf
dSgpCnsKICAgIGxvY2FsIHRhYj0kKHByaW50ZiAnXHQnKQogICAgbG9jYWwgZXBvY2hfcGx1cz0i
JGVwb2NoLjAwMDAwMDAwMCArMDAwMCIKICAgIGxvY2FsIHJzPSQocHJpbnRmICJcZVske3JzfW0i
KQogICAgbG9jYWwgaGQ9JChwcmludGYgIlxlWyR7aGR9bSIpCiAgICBsb2NhbCBhZD0kKHByaW50
ZiAiXGVbJHthZH1tIikKICAgIGxvY2FsIGRlPSQocHJpbnRmICJcZVske2RlfW0iKQogICAgbG9j
YWwgbG49JChwcmludGYgIlxlWyR7bG59bSIpCiAgICBwcmludGYgJyVzJyBcCiIkaGQtLS0gYSR0
YWIkZXBvY2hfcGx1cworKysgYiR0YWIkZXBvY2hfcGx1cwokcnMbWzM2bUBAIC0xICsxIEBAG1sw
bQokZGUtYQokYWQkYWQrYgokcnMiCiAgICB9CgojIENvbXBhcmUgd2l0aCBzb21lIGtub3duIG91
dHB1dHMKCmRpZmYgLS1jb2xvcj1hbHdheXMgYSBiIHwgc2hhMXN1bSBcCiAgICAgfCBncmVwIGRi
ZWQ5NTljOTk3NWNmNzYxZmY0OTUwZDkzZDM0MmQ3YzI3MWMxMWYgfHwgZmFpbD0xCgpkaWZmIC0t
Y29sb3I9YXV0byBhIGIgfCBzaGExc3VtIFwKICAgICB8IGdyZXAgOTA3NDJjZTBkNjI4Y2MyZjIw
NjdiMjMyNDA0NTc4ZTAwMGI4MGNjZSB8fCBmYWlsPTEKCmRpZmYgLS1jb2xvcj1uZXZlciBhIGIg
fCBzaGExc3VtIFwKICAgICB8IGdyZXAgOTA3NDJjZTBkNjI4Y2MyZjIwNjdiMjMyNDA0NTc4ZTAw
MGI4MGNjZSB8fCBmYWlsPTEKCmRpZmYgLS1jb2xvciBhIGIgfCBzaGExc3VtIFwKICAgICB8IGdy
ZXAgOTA3NDJjZTBkNjI4Y2MyZjIwNjdiMjMyNDA0NTc4ZTAwMGI4MGNjZSB8fCBmYWlsPTEKCmRp
ZmYgLXUgLS1jb2xvcj1hbHdheXMgYSBiIHwgc2hhMXN1bSBcCiAgICAgfCBncmVwIDU3MTJmYmZm
Yzk0YzUwMWVhZWVjNWNiMDI0NjhjZTJiYmVkNmQ3YzkgfHwgZmFpbD0xCgpkaWZmIC1jIC0tY29s
b3I9YWx3YXlzIGEgYiB8IHNoYTFzdW0gXAogICAgIHwgZ3JlcCBhOWJmYTE4ZWE2NDI1ZGI1NDdh
YzY5YmMxM2ZiNzhjZjk0MTZhZDU1IHx8IGZhaWw9MQoKcnM9MCBoZD0zMyBhZD0zNCBkZT0zNSBs
bj0zNgpkaWZmIC11IC0tY29sb3I9YWx3YXlzIC0tcGFsZXR0ZT0icnM9MDpoZD0zMzphZD0zNDpk
ZT0zNTpsbj0zNiIgYSBiID4gawp0ZXN0ICQ/ID0gMSB8fCBmYWlsPTEKZ2VuX2V4cF91ID4gZXhw
IHx8IGZyYW1ld29ya19mYWlsdXJlXwpjb21wYXJlIGsgZXhwIHx8IGZhaWw9MQoKRXhpdCAkZmFp
bAo=
--001a11439778c38359052574c093--




From MAILER-DAEMON Fri Nov 27 10:04:18 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1a2KZO-0008CO-EF
	for mharc-bug-diffutils@gnu.org; Fri, 27 Nov 2015 10:04:18 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:35265)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2KZG-0007xe-NX
	for bug-diffutils@gnu.org; Fri, 27 Nov 2015 10:04:16 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2KZ8-0002vd-6f
	for bug-diffutils@gnu.org; Fri, 27 Nov 2015 10:04:10 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:38401)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2KZ8-0002vX-3Y
	for bug-diffutils@gnu.org; Fri, 27 Nov 2015 10:04:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2KZ7-0002QP-Q8
	for bug-diffutils@gnu.org; Fri, 27 Nov 2015 10:04:01 -0500
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: Fri, 27 Nov 2015 15:04:01 +0000
Resent-Message-ID: <handler.20062.B20062.14486365979252@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.14486365979252
	(code B ref 20062); Fri, 27 Nov 2015 15:04:01 +0000
Received: (at 20062) by debbugs.gnu.org; 27 Nov 2015 15:03:17 +0000
Received: from localhost ([127.0.0.1]:56339 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1a2KYL-0002P7-GC
	for submit@debbugs.gnu.org; Fri, 27 Nov 2015 10:03:17 -0500
Received: from mx1.redhat.com ([209.132.183.28]:56174)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivano@gnu.org>) id 1a2KYF-0002Ov-MK
	for 20062@debbugs.gnu.org; Fri, 27 Nov 2015 10:03:11 -0500
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (Postfix) with ESMTPS id CE60A8F4EF;
	Fri, 27 Nov 2015 15:03:06 +0000 (UTC)
Received: from foo.bar.baz (vpn1-7-113.ams2.redhat.com [10.36.7.113])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id tARF30Vi018751
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=NO); Fri, 27 Nov 2015 10:03:02 -0500
From: Giuseppe Scrivano <gscrivano@gnu.org>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
	<87fv0nko86.fsf@foo.bar.baz> <5638EE6E.3050901@redhat.com>
	<CA+8g5KHcMiMiGnQJ3ibhe2W=4crcy9g6jSyMnWo-T9E4uzm=Og@mail.gmail.com>
	<87twol1nqw.fsf@foo.bar.baz>
	<CA+8g5KFs5CKoAzUw8T45-f8f+0t93XzZnfWKfkfrYrc4DXYQHQ@mail.gmail.com>
Date: Fri, 27 Nov 2015 16:01:56 +0100
In-Reply-To: <CA+8g5KFs5CKoAzUw8T45-f8f+0t93XzZnfWKfkfrYrc4DXYQHQ@mail.gmail.com>
	(Jim Meyering's message of "Thu, 26 Nov 2015 09:17:24 -0800")
Message-ID: <87a8pz4haz.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.23
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 208.118.235.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 27 Nov 2015 15:04:16 -0000

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

Hi Jim,

thanks for the great advices.

Jim Meyering <jim@meyering.net> writes:

> I looked at the tests/colors script: we cannot/should not use sha1sum
> for two reasons. 1) it is a short cut; better to include the precise expected
> output in each case. Using this approach, if/when a test fails, there is
> no record of what the expected output was. 2) the "sha1sum" command
> is not universally available by that name. On BSD-based systems it is
> called "sha1". Thus, I began the conversion, and in so doing, I found
> some room for improvement: with the current patches I have, diff -u
> emits a pair of identical color-changing escape sequences before each
> "+"-prefixed line:
>
>   $ diff -u --color=always a b|cat -A
>   ^[[1;39m--- a^I1969-12-31 16:00:00.000000000 -0800$
>   +++ b^I1969-12-31 16:00:00.000000000 -0800$
>   ^[[0m^[[36m@@ -1 +1 @@^[[0m$
>   ^[[31m-a$
>   ^[[32m^[[32m+b$
>   ^[[0m
>
> Notice also how the final \e[0m is on the final line by itself,
> with no following newline. Please adjust so that it appears at the
> end of the final line instead. I confirmed that git-diff appears
> to do the same thing, but noted that git uses \e[m instead (no
> "0" part). Do you know of any pros/cons for one or the other?

I don't know if there is any difference in practice between \e[m and
\e0[m. I took the implementation in ls as reference which uses \e0[m.


> I've attached the beginnings of the adjusted tests/colors
> script that I used to discover these things. Can you finish the job
> of converting it to use "compare" rather than sha1sum?

Sure.  The new tests helped me to spot two issues in the "diff: add
support for --color" patch.  I also added some extra check to avoid to
enter the same colors context twice.  These fixes are in
0004-fixup-diff-add-support-for-color.patch.

To generate sequences on the same line they belong, I have created a new
patch to facilitate the review.  Probably the patch should get squashed
into 0001-diff-add-support-for-color.patch and 0005-tests-Add-tests-for-color-and-palette.patch
once reviewed.

I have not changed the first two patches of the series, I am including
them just for completeness.

Regards,
Giuseppe


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

>From 50def324f48ff09501e6f07cecae2a6cd5a16e3c 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/6] 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.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=0002-diff-add-palette.patch

>From 0bbbbc9ce6a2b68e2ff20a1a8b4ed69a7e43619b 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/6] diff: add --palette

* doc/diffutils.texi: Add documentation for --palette
* src/diff.h (set_color_palette): New prototype.
* src/diff.c (set_color_palette): New function.
(color_palette): New variable.
* 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 |  34 +++++
 src/diff.c         |   8 +
 src/diff.h         |   1 +
 src/util.c         | 439 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 473 insertions(+), 9 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 0944b44..39ba35d 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3890,6 +3890,40 @@ if-then-else format.  @xref{Line Formats}.
 @itemx --show-c-function
 Show which C function each change is in.  @xref{C Function Headings}.
 
+@item --palette=@var{palette}
+Specify what color palette to use when colored output is enabled.  It
+defaults to @samp{rs=0:hd=1:ad=32:de=31:ln=36} for red deleted lines,
+green added lines, cyan line numbers, bold header.
+
+Supported capabilities are as follows.
+
+@table @code
+@item ad=32
+@vindex ad @r{capability}
+
+SGR substring for added lines.
+The default is green foreground.
+
+@item de=31
+@vindex de @r{capability}
+
+SGR substring for deleted lines.
+The default is red foreground.
+
+@item hd=1
+@vindex hd @r{capability}
+
+SGR substring for chunk header.
+The default is bold foreground.
+
+@item ln=36
+@vindex ln @r{capability}
+
+SGR substring for line numbers.
+The default is cyan foreground.
+@end table
+
+
 @item -q
 @itemx --brief
 Report only whether the files differ, not the details of the
diff --git a/src/diff.c b/src/diff.c
index 4e0f602..4c3d29a 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -140,6 +140,7 @@ enum
   CHANGED_GROUP_FORMAT_OPTION,
 
   COLOR_OPTION,
+  COLOR_PALETTE_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -196,6 +197,7 @@ static struct option const longopts[] =
   {"old-group-format", 1, 0, OLD_GROUP_FORMAT_OPTION},
   {"old-line-format", 1, 0, OLD_LINE_FORMAT_OPTION},
   {"paginate", 0, 0, 'l'},
+  {"palette", 1, 0, COLOR_PALETTE_OPTION},
   {"rcs", 0, 0, 'n'},
   {"recursive", 0, 0, 'r'},
   {"report-identical-files", 0, 0, 's'},
@@ -635,6 +637,10 @@ main (int argc, char **argv)
 	  specify_colors_style (optarg);
 	  break;
 
+	case COLOR_PALETTE_OPTION:
+	  set_color_palette (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
@@ -950,6 +956,8 @@ static char const * const option_help_msgid[] = {
   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_("    --palette=PALETTE    specify the colors to use when --color is active"),
+  N_("                         PALETTE is a colon-separated list terminfo capabilities"),
   "",
   N_("    --help               display this help and exit"),
   N_("-v, --version            output version information and exit"),
diff --git a/src/diff.h b/src/diff.h
index 472fa93..5930cd1 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -411,3 +411,4 @@ 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);
+extern void set_color_palette (const char *palette);
diff --git a/src/util.c b/src/util.c
index 6cc1411..dedf3b3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -310,6 +310,396 @@ 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 --palette argument; 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 const char *color_palette;
+
+void
+set_color_palette (const char *palette)
+{
+  color_palette = palette;
+}
+
+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 = color_palette) == NULL || *p == '\0')
+    return;
+
+  ext = NULL;
+  strcpy (label, "??");
+
+  /* This is an overly conservative estimate, but any possible
+     --palette 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 --palette"));
+      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 +713,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 +1316,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 +1344,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 +1356,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 +1368,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.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0003-doc-mention-color-and-palette-in-NEWS.patch

>From 88b6384539d6d6e5c74e07efa55dbc6f4b12de6d Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Mon, 2 Nov 2015 19:03:32 +0000
Subject: [PATCH 3/6] doc: mention --color and --palette in NEWS

---
 NEWS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/NEWS b/NEWS
index 7cdfedd..088f13b 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,13 @@ GNU diffutils NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** New features
+
+   diff accepts two new options --color and --palette to generate
+   and configure colored output.  --color takes an optional argument
+   specifying when to colorize a line: --color=always, --color=auto,
+   --color=never.  --palette is used to configure which colors are used.
+
 ** Bug fixes
 
   When binary files differ, diff now exits with status 1 as POSIX requires.
-- 
2.5.0


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

>From 49d2d3887f3358874a9e548209b0bd83ec347234 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Fri, 27 Nov 2015 11:43:58 +0000
Subject: [PATCH 4/6] fixup! diff: add support for --color

---
 src/context.c |  5 ++++-
 src/util.c    | 17 ++++++++++++-----
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/context.c b/src/context.c
index 8e9a74f..216f547 100644
--- a/src/context.c
+++ b/src/context.c
@@ -207,9 +207,11 @@ pr_context_hunk (struct change *hunk)
   if (function)
     print_context_function (out, function);
 
+  set_line_numbers_color_context ();
   fputs ("\n*** ", out);
   print_context_number_range (&files[0], first0, last0);
   fputs (" ****\n", out);
+  reset_color_context ();
 
   if (changes & OLD)
     {
@@ -243,9 +245,11 @@ pr_context_hunk (struct change *hunk)
 	}
     }
 
+  set_line_numbers_color_context ();
   fputs ("--- ", out);
   print_context_number_range (&files[1], first1, last1);
   fputs (" ----\n", out);
+  reset_color_context ();
 
   if (changes & NEW)
     {
@@ -408,7 +412,6 @@ pr_unidiff_hunk (struct change *hunk)
 	  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);
diff --git a/src/util.c b/src/util.c
index dedf3b3..b0e277b 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1327,15 +1327,18 @@ put_indicator (const struct bin_str *ind)
   fwrite (ind->string, ind->len, 1, outfile);
 }
 
+static enum indicator_no last_context = C_RESET;
+
 void
 set_header_color_context (void)
 {
   process_signals ();
-  if (colors_enabled)
+  if (colors_enabled && last_context != C_HEADER)
     {
       put_indicator (&color_indicator[C_LEFT]);
       put_indicator (&color_indicator[C_HEADER]);
       put_indicator (&color_indicator[C_RIGHT]);
+      last_context = C_HEADER;
     }
 }
 
@@ -1343,11 +1346,12 @@ void
 set_line_numbers_color_context (void)
 {
   process_signals ();
-  if (colors_enabled)
+  if (colors_enabled && last_context != C_LINE)
     {
       put_indicator (&color_indicator[C_LEFT]);
       put_indicator (&color_indicator[C_LINE]);
       put_indicator (&color_indicator[C_RIGHT]);
+      last_context = C_LINE;
     }
 }
 
@@ -1355,11 +1359,12 @@ void
 set_add_color_context (void)
 {
   process_signals ();
-  if (colors_enabled)
+  if (colors_enabled && last_context != C_ADD)
     {
       put_indicator (&color_indicator[C_LEFT]);
       put_indicator (&color_indicator[C_ADD]);
       put_indicator (&color_indicator[C_RIGHT]);
+      last_context = C_ADD;
     }
 }
 
@@ -1367,22 +1372,24 @@ void
 set_delete_color_context (void)
 {
   process_signals ();
-  if (colors_enabled)
+  if (colors_enabled && last_context != C_DELETE)
     {
       put_indicator (&color_indicator[C_LEFT]);
       put_indicator (&color_indicator[C_DELETE]);
       put_indicator (&color_indicator[C_RIGHT]);
+      last_context = C_DELETE;
     }
 }
 
 void
 reset_color_context (void)
 {
-  if (colors_enabled)
+  if (colors_enabled && last_context != C_RESET)
     {
       put_indicator (&color_indicator[C_LEFT]);
       put_indicator (&color_indicator[C_RESET]);
       put_indicator (&color_indicator[C_RIGHT]);
+      last_context = C_RESET;
     }
 }
 
-- 
2.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0005-tests-Add-tests-for-color-and-palette.patch

>From a2b6721675cb4d90fc0322a5b2fc9d5c1d4c35df Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Mon, 2 Nov 2015 19:05:10 +0000
Subject: [PATCH 5/6] tests: Add tests for --color and --palette

* tests/colors: New file.
* tests/Makefile.am (TESTS): Add colors.
---
 tests/Makefile.am |   3 +-
 tests/colors      | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 1 deletion(-)
 create mode 100755 tests/colors

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 438fbdf..805ccc2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,7 +15,8 @@ TESTS = \
   no-newline-at-eof \
   stdin \
   strcoll-0-names \
-  filename-quoting
+  filename-quoting \
+  colors
 
 EXTRA_DIST = \
   $(TESTS) init.sh t-local.sh
diff --git a/tests/colors b/tests/colors
new file mode 100755
index 0000000..5a62232
--- /dev/null
+++ b/tests/colors
@@ -0,0 +1,119 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+TZ=UTC0
+export TZ
+
+fail=0
+
+echo a > a
+echo b > b
+
+epoch='1970-01-01 00:00:00'
+touch --date="$epoch" a b
+
+gen_exp_u()
+{
+    local tab=$(printf '\t')
+    local epoch_plus="$epoch.000000000 +0000"
+    local rs=$(printf "\e[${rs}m")
+    local hd=$(printf "\e[${hd}m")
+    local ad=$(printf "\e[${ad}m")
+    local de=$(printf "\e[${de}m")
+    local ln=$(printf "\e[${ln}m")
+    printf '%s' \
+"$hd--- a$tab$epoch_plus
++++ b$tab$epoch_plus
+$rs${ln}@@ -1 +1 @@$rs
+$de-a
+$ad+b
+$rs"
+}
+
+gen_exp_c()
+{
+    local tab=$(printf '\t')
+    local epoch_posix_1003_1_2001="Thu Jan  1 00:00:00 1970"
+    local rs=$(printf "\e[${rs}m")
+    local hd=$(printf "\e[${hd}m")
+    local ad=$(printf "\e[${ad}m")
+    local de=$(printf "\e[${de}m")
+    local ln=$(printf "\e[${ln}m")
+    printf '%s' \
+"$hd*** a$tab$epoch_posix_1003_1_2001
+--- b$tab$epoch_posix_1003_1_2001
+$rs***************$ln
+*** 1 ****
+$rs$de! a
+$rs$ln--- 1 ----
+$rs$ad! b
+$rs"
+}
+
+gen_exp_default()
+{
+    printf '%s' \
+"1c1
+< a
+---
+> b
+"
+}
+
+gen_exp_default_colors()
+{
+    local rs=$(printf "\e[${rs}m")
+    local hd=$(printf "\e[${hd}m")
+    local ad=$(printf "\e[${ad}m")
+    local de=$(printf "\e[${de}m")
+    local ln=$(printf "\e[${ln}m")
+    printf '%s' \
+"${ln}1c1
+$rs$de< a
+$rs---
+$ad> b
+$rs"
+}
+
+# Compare with some known outputs
+
+rs=0 hd=1 ad=32 de=31 ln=36
+
+diff --color=auto a b > k
+test $? = 1 || fail=1
+gen_exp_default > exp || framework_failure_
+compare exp k || fail=1
+
+diff --color=never a b > k
+test $? = 1 || fail=1
+gen_exp_default > exp || framework_failure_
+compare exp k || fail=1
+
+diff a b > k
+test $? = 1 || fail=1
+gen_exp_default > exp || framework_failure_
+compare exp k || fail=1
+
+diff --color=always a b > k
+test $? = 1 || fail=1
+gen_exp_default_colors > exp || framework_failure_
+compare exp k || fail=1
+
+diff -u --color=always a b > k
+test $? = 1 || fail=1
+gen_exp_u > exp || framework_failure_
+compare exp k || fail=1
+
+diff -c --color=always a b > k
+test $? = 1 || fail=1
+gen_exp_c > exp || framework_failure_
+compare exp k || fail=1
+
+rs=0 hd=33 ad=34 de=35 ln=36
+diff -u --color=always --palette="rs=0:hd=33:ad=34:de=35:ln=36" a b > k
+test $? = 1 || fail=1
+gen_exp_u > exp || framework_failure_
+compare exp k || fail=1
+
+Exit $fail
-- 
2.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0006-Generate-terminal-sequences-on-the-line-they-belong.patch

>From 031a5778004cc492fbf33f647838116780a73938 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Fri, 27 Nov 2015 13:56:05 +0100
Subject: [PATCH 6/6] Generate terminal sequences on the line they belong

* src/diff.h: New function 'print_1_line_nl'.
* src/context.c (pr_context_hunk): Use 'print_1_line_nl'.
Generate terminal sequences on the line they belong.
(pr_unidiff_hunk): Likewise.
* src/normal.c (print_normal_hunk): Likewise.
* src/util.c (print_1_line_nl): New function.
(print_1_line): Become a wrapper of 'print_1_line_nl'.
* tests/colors: Adjust tests.
---
 src/context.c | 64 ++++++++++++++++++++++++++++++++++-------------------------
 src/diff.h    |  1 +
 src/normal.c  | 26 +++++++++++++++++-------
 src/util.c    | 19 ++++++++++++++++--
 tests/colors  | 28 +++++++++++++-------------
 5 files changed, 88 insertions(+), 50 deletions(-)

diff --git a/src/context.c b/src/context.c
index 216f547..0834079 100644
--- a/src/context.c
+++ b/src/context.c
@@ -207,19 +207,23 @@ pr_context_hunk (struct change *hunk)
   if (function)
     print_context_function (out, function);
 
+  putc ('\n', out);
   set_line_numbers_color_context ();
-  fputs ("\n*** ", out);
+  fputs ("*** ", out);
   print_context_number_range (&files[0], first0, last0);
-  fputs (" ****\n", out);
+  fputs (" ****", out);
   reset_color_context ();
+  putc ('\n', out);
 
   if (changes & OLD)
     {
       struct change *next = hunk;
 
+      if (first0 <= last0)
+        set_delete_color_context ();
+
       for (i = first0; i <= last0; i++)
 	{
-          bool reset_context = false;
 	  /* Skip past changes that apply (in file 0)
 	     only to lines before line I.  */
 
@@ -231,33 +235,36 @@ pr_context_hunk (struct change *hunk)
 	  prefix = " ";
 	  if (next && next->line0 <= i)
             {
-              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)
+	  print_1_line_nl (prefix, &files[0].linbuf[i], true);
+          if (i == last0)
             reset_color_context ();
+          if (files[0].linbuf[i + 1][-1] == '\n')
+            putc ('\n', out);
 	}
     }
 
   set_line_numbers_color_context ();
   fputs ("--- ", out);
   print_context_number_range (&files[1], first1, last1);
-  fputs (" ----\n", out);
+  fputs (" ----", out);
   reset_color_context ();
+  putc ('\n', out);
 
   if (changes & NEW)
     {
       struct change *next = hunk;
 
+      if (first1 <= last1)
+        set_add_color_context ();
+
       for (i = first1; i <= last1; i++)
 	{
-          bool reset_context = false;
 	  /* Skip past changes that apply (in file 1)
 	     only to lines before line I.  */
 
@@ -269,16 +276,16 @@ pr_context_hunk (struct change *hunk)
 	  prefix = " ";
 	  if (next && next->line1 <= i)
             {
-              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)
+	  print_1_line_nl (prefix, &files[1].linbuf[i], true);
+          if (i == last1)
             reset_color_context ();
+          if (files[1].linbuf[i + 1][-1] == '\n')
+            putc ('\n', out);
 	}
     }
 }
@@ -381,16 +388,11 @@ 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 ();
-            }
+            set_delete_color_context ();
 
 	  while (k--)
 	    {
@@ -398,30 +400,38 @@ pr_unidiff_hunk (struct change *hunk)
 	      putc ('-', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
-	      print_1_line (NULL, line);
+	      print_1_line_nl (NULL, line, true);
+
+              if (!k)
+                reset_color_context ();
+
+              if (line[1][-1] == '\n')
+                putc ('\n', out);
 	    }
 
 	  /* Then output the inserted part. */
 
 	  k = next->inserted;
           if (k)
-            {
-              reset_context = true;
-              set_add_color_context ();
-            }
+            set_add_color_context ();
+
 	  while (k--)
 	    {
 	      char const * const *line = &files[1].linbuf[j++];
 	      putc ('+', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
-	      print_1_line (NULL, line);
+	      print_1_line_nl (NULL, line, true);
+
+              if (!k)
+                reset_color_context ();
+
+              if (line[1][-1] == '\n')
+                putc ('\n', out);
 	    }
 
 	  /* 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.h b/src/diff.h
index 5930cd1..791c29e 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -399,6 +399,7 @@ extern void output_1_line (char const *, char const *, char const *,
 extern void perror_with_name (char const *);
 extern void pfatal_with_name (char const *) __attribute__((noreturn));
 extern void print_1_line (char const *, char const * const *);
+extern void print_1_line_nl (char const *, char const * const *, bool);
 extern void print_message_queue (void);
 extern void print_number_range (char, struct file_data *, lin, lin);
 extern void print_script (struct change *, struct change * (*) (struct change *),
diff --git a/src/normal.c b/src/normal.c
index 227af10..5a1e687 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -53,16 +53,22 @@ print_normal_hunk (struct change *hunk)
   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 ();
+  fputc ('\n', outfile);
 
   /* Print the lines that the first file has.  */
   if (changes & OLD)
     {
-      set_delete_color_context ();
+      if (first0 <= last0)
+        set_delete_color_context ();
       for (i = first0; i <= last0; i++)
-        print_1_line ("<", &files[0].linbuf[i]);
-      reset_color_context ();
+        {
+          print_1_line_nl ("<", &files[0].linbuf[i], true);
+          if (i == last0)
+            reset_color_context ();
+          if (files[0].linbuf[i + 1][-1] == '\n')
+            putc ('\n', outfile);
+        }
     }
 
   if (changes == CHANGED)
@@ -71,9 +77,15 @@ print_normal_hunk (struct change *hunk)
   /* Print the lines that the second file has.  */
   if (changes & NEW)
     {
-      set_add_color_context ();
+      if (first1 <= last1)
+        set_add_color_context ();
       for (i = first1; i <= last1; i++)
-        print_1_line (">", &files[1].linbuf[i]);
-      reset_color_context ();
+        {
+          print_1_line_nl (">", &files[1].linbuf[i], true);
+          if (i == last1)
+            reset_color_context ();
+          if (files[1].linbuf[i + 1][-1] == '\n')
+            putc ('\n', outfile);
+        }
     }
 }
diff --git a/src/util.c b/src/util.c
index b0e277b..65b06e9 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1206,6 +1206,18 @@ print_script (struct change *script,
 void
 print_1_line (char const *line_flag, char const *const *line)
 {
+  print_1_line_nl (line_flag, line, false);
+}
+
+/* Print the text of a single line LINE,
+   flagging it with the characters in LINE_FLAG (which say whether
+   the line is inserted, deleted, changed, etc.).  LINE_FLAG must not
+   end in a blank, unless it is a single blank.  If SKIP_NL is set, then
+   the final '\n' is not printed.  */
+
+void
+print_1_line_nl (char const *line_flag, char const *const *line, bool skip_nl)
+{
   char const *base = line[0], *limit = line[1]; /* Help the compiler.  */
   FILE *out = outfile; /* Help the compiler some more.  */
   char const *flag_format = 0;
@@ -1233,10 +1245,13 @@ print_1_line (char const *line_flag, char const *const *line)
       fprintf (out, flag_format_1, line_flag_1);
     }
 
-  output_1_line (base, limit, flag_format, line_flag);
+  output_1_line (base, limit - (skip_nl && limit[-1] == '\n'), flag_format, line_flag);
 
   if ((!line_flag || line_flag[0]) && limit[-1] != '\n')
-    fprintf (out, "\n\\ %s\n", _("No newline at end of file"));
+    {
+      reset_color_context ();
+      fprintf (out, "\n\\ %s\n", _("No newline at end of file"));
+    }
 }
 
 /* Output a line from BASE up to LIMIT.
diff --git a/tests/colors b/tests/colors
index 5a62232..7593ca9 100755
--- a/tests/colors
+++ b/tests/colors
@@ -26,9 +26,9 @@ gen_exp_u()
 "$hd--- a$tab$epoch_plus
 +++ b$tab$epoch_plus
 $rs${ln}@@ -1 +1 @@$rs
-$de-a
-$ad+b
-$rs"
+$de-a$rs
+$ad+b$rs
+"
 }
 
 gen_exp_c()
@@ -43,12 +43,12 @@ gen_exp_c()
     printf '%s' \
 "$hd*** a$tab$epoch_posix_1003_1_2001
 --- b$tab$epoch_posix_1003_1_2001
-$rs***************$ln
-*** 1 ****
-$rs$de! a
-$rs$ln--- 1 ----
-$rs$ad! b
-$rs"
+$rs***************
+$ln*** 1 ****$rs
+$de! a$rs
+$ln--- 1 ----$rs
+$ad! b$rs
+"
 }
 
 gen_exp_default()
@@ -69,11 +69,11 @@ gen_exp_default_colors()
     local de=$(printf "\e[${de}m")
     local ln=$(printf "\e[${ln}m")
     printf '%s' \
-"${ln}1c1
-$rs$de< a
-$rs---
-$ad> b
-$rs"
+"${ln}1c1$rs
+$de< a$rs
+---
+$ad> b$rs
+"
 }
 
 # Compare with some known outputs
-- 
2.5.0


--=-=-=--




From MAILER-DAEMON Fri Nov 27 14:46:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1a2Oy9-0001pO-Og
	for mharc-bug-diffutils@gnu.org; Fri, 27 Nov 2015 14:46:09 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:48561)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2Oy6-0001oQ-Du
	for bug-diffutils@gnu.org; Fri, 27 Nov 2015 14:46:07 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2Oy2-0003fG-9w
	for bug-diffutils@gnu.org; Fri, 27 Nov 2015 14:46:06 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:38528)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2Oy2-0003fB-6O
	for bug-diffutils@gnu.org; Fri, 27 Nov 2015 14:46:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2Oy1-0002Uu-Ud
	for bug-diffutils@gnu.org; Fri, 27 Nov 2015 14:46:02 -0500
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: Fri, 27 Nov 2015 19:46:01 +0000
Resent-Message-ID: <handler.20062.B20062.14486535459570@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.14486535459570
	(code B ref 20062); Fri, 27 Nov 2015 19:46:01 +0000
Received: (at 20062) by debbugs.gnu.org; 27 Nov 2015 19:45:45 +0000
Received: from localhost ([127.0.0.1]:56469 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1a2Oxk-0002UH-NX
	for submit@debbugs.gnu.org; Fri, 27 Nov 2015 14:45:45 -0500
Received: from mail-vk0-f51.google.com ([209.85.213.51]:33556)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>) id 1a2Oxh-0002U4-G2
	for 20062@debbugs.gnu.org; Fri, 27 Nov 2015 14:45:42 -0500
Received: by vkca188 with SMTP id a188so17632537vkc.0
	for <20062@debbugs.gnu.org>; Fri, 27 Nov 2015 11:45:41 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:from:date:message-id
	:subject:to:cc:content-type;
	bh=EL4GteLfwO5JOrw5ddQ6Y+NKuSqBENvflH3E0Pcu1w8=;
	b=A40iwneP+oUlPX6p0hBJHnoLW+rHMSqU6EbcVq/IXeQ5efoSd9kUua5iEit7f5A5Bl
	6+YEBx6pSTx6b7eqDpvkKMtm4hQ7CjJuomNgi5uX5/pA6z/wkP5tKQTaAl/r5Mdw2N1e
	18mNitRiGkqR1WNtbLFI61ebKhce2cZ/2rP0KL1URyBoR+54+V57ZsAWxS0ykbFcO9Cr
	x7MnDLRqTPOxNuCLhxe20l1L2p6XScmWPXjhelEyo51ppAju7q4jH5YfMyksqjxKOIEq
	GEPCNPA04h2ifXsxZdl72+NCC2Ucc+5spOuQJ4fS93FktuJhGJksXk2UDaxdantQtijT
	0ycg==
X-Received: by 10.31.183.200 with SMTP id h191mr44547393vkf.147.1448653540950; 
	Fri, 27 Nov 2015 11:45:40 -0800 (PST)
MIME-Version: 1.0
Received: by 10.31.84.198 with HTTP; Fri, 27 Nov 2015 11:45:21 -0800 (PST)
In-Reply-To: <87a8pz4haz.fsf@foo.bar.baz>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
	<87fv0nko86.fsf@foo.bar.baz> <5638EE6E.3050901@redhat.com>
	<CA+8g5KHcMiMiGnQJ3ibhe2W=4crcy9g6jSyMnWo-T9E4uzm=Og@mail.gmail.com>
	<87twol1nqw.fsf@foo.bar.baz>
	<CA+8g5KFs5CKoAzUw8T45-f8f+0t93XzZnfWKfkfrYrc4DXYQHQ@mail.gmail.com>
	<87a8pz4haz.fsf@foo.bar.baz>
From: Jim Meyering <jim@meyering.net>
Date: Fri, 27 Nov 2015 11:45:21 -0800
X-Google-Sender-Auth: 3iC-SfYLtPocKJSm-lcKeIF0lUs
Message-ID: <CA+8g5KF25c5oNrE4zGRjS3SQGt+VfitfWRrnOvPJEUnvzEspOw@mail.gmail.com>
Content-Type: multipart/mixed; boundary=001a11439778b61cd805258aefdb
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: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 27 Nov 2015 19:46:08 -0000

--001a11439778b61cd805258aefdb
Content-Type: text/plain; charset=UTF-8

On Fri, Nov 27, 2015 at 7:01 AM, Giuseppe Scrivano <gscrivano@gnu.org> wrote:
> Hi Jim,
>
> thanks for the great advices.
>
> Jim Meyering <jim@meyering.net> writes:
>
>> I looked at the tests/colors script: we cannot/should not use sha1sum
>> for two reasons. 1) it is a short cut; better to include the precise expected
>> output in each case. Using this approach, if/when a test fails, there is
>> no record of what the expected output was. 2) the "sha1sum" command
>> is not universally available by that name. On BSD-based systems it is
>> called "sha1". Thus, I began the conversion, and in so doing, I found
>> some room for improvement: with the current patches I have, diff -u
>> emits a pair of identical color-changing escape sequences before each
>> "+"-prefixed line:
>>
>>   $ diff -u --color=always a b|cat -A
>>   ^[[1;39m--- a^I1969-12-31 16:00:00.000000000 -0800$
>>   +++ b^I1969-12-31 16:00:00.000000000 -0800$
>>   ^[[0m^[[36m@@ -1 +1 @@^[[0m$
>>   ^[[31m-a$
>>   ^[[32m^[[32m+b$
>>   ^[[0m
>>
>> Notice also how the final \e[0m is on the final line by itself,
>> with no following newline. Please adjust so that it appears at the
>> end of the final line instead. I confirmed that git-diff appears
>> to do the same thing, but noted that git uses \e[m instead (no
>> "0" part). Do you know of any pros/cons for one or the other?
>
> I don't know if there is any difference in practice between \e[m and
> \e0[m. I took the implementation in ls as reference which uses \e0[m.
>
>
>> I've attached the beginnings of the adjusted tests/colors
>> script that I used to discover these things. Can you finish the job
>> of converting it to use "compare" rather than sha1sum?
>
> Sure.  The new tests helped me to spot two issues in the "diff: add
> support for --color" patch.  I also added some extra check to avoid to
> enter the same colors context twice.  These fixes are in
> 0004-fixup-diff-add-support-for-color.patch.
>
> To generate sequences on the same line they belong, I have created a new
> patch to facilitate the review.  Probably the patch should get squashed
> into 0001-diff-add-support-for-color.patch and 0005-tests-Add-tests-for-color-and-palette.patch
> once reviewed.
>
> I have not changed the first two patches of the series, I am including
> them just for completeness.

Thank you for the quick and nice work.
Please adjust the test to use "out" rather than (my fault) "k" as the
output file name.

Your fixup diff highlights the fact that there is too much
duplication in the definitions of the reset_color_context and
the four set_*_color_context functions. Any reason not to use
a single function named e.g., set_color_context, and pass it
the C_* enum constant?

This comment was clearly intended for a different enum:

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

Two nits in the .texi:

  +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.

s/present/specified/
s/Only use color/Use color only/

In the --help output addition, the spacing is slightly off:

     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"),

The "c" in the added description, "colorize the ..." is indented
two spaces too much. Same for the continuation line.

In your palette option description, the continuation line must be
indented by two spaces, so that help2man knows to format it
as such:

  +  N_("    --palette=PALETTE    specify the colors to use when
--color is active"),
  +  N_("                         PALETTE is a colon-separated list
terminfo capabilities"),

Nit: s/const char/char const/, e.g., here:

  +extern void set_color_palette (const char *palette);

For any pair of arrays whose lengths must be aligned, e.g.,

  +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
  +  };

Please add the following to ensure that no one adds
an element to one without also adding the matching
element in the other:

  ARGMATCH_VERIFY (indicator_name, color_indicator);

But that would be the first use of argmatch.h and the
argmatch module, so you'll actually have to make two
more changes (include the .h and add the argmatch
module to bootstrap.conf). I've attached a tiny patch.

With that, I think we'll be ready to go.
Thank you for your patience.

--001a11439778b61cd805258aefdb
Content-Type: text/x-patch; charset=US-ASCII; name="argmatch.patch"
Content-Disposition: attachment; filename="argmatch.patch"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_ihi2jtbu6

ZGlmZiAtLWdpdCBhL2Jvb3RzdHJhcC5jb25mIGIvYm9vdHN0cmFwLmNvbmYKaW5kZXggOWIyZGUy
Mi4uM2FiMmM4YiAxMDA2NDQKLS0tIGEvYm9vdHN0cmFwLmNvbmYKKysrIGIvYm9vdHN0cmFwLmNv
bmYKQEAgLTE5LDYgKzE5LDcgQEAKICMgZ251bGliIG1vZHVsZXMgdXNlZCBieSB0aGlzIHBhY2th
Z2UuCiBnbnVsaWJfbW9kdWxlcz0nCiBhbm5vdW5jZS1nZW4KK2FyZ21hdGNoCiBiaW5hcnktaW8K
IGMtc3RhY2sKIGNvbmZpZy1oCmRpZmYgLS1naXQgYS9zcmMvdXRpbC5jIGIvc3JjL3V0aWwuYwpp
bmRleCA2NWIwNmU5Li5kMjdkMjAyIDEwMDY0NAotLS0gYS9zcmMvdXRpbC5jCisrKyBiL3NyYy91
dGlsLmMKQEAgLTE5LDYgKzE5LDcgQEAKICAgIGFsb25nIHdpdGggdGhpcyBwcm9ncmFtLiAgSWYg
bm90LCBzZWUgPGh0dHA6Ly93d3cuZ251Lm9yZy9saWNlbnNlcy8+LiAgKi8KCiAjaW5jbHVkZSAi
ZGlmZi5oIgorI2luY2x1ZGUgImFyZ21hdGNoLmgiCiAjaW5jbHVkZSA8ZGlybmFtZS5oPgogI2lu
Y2x1ZGUgPGVycm9yLmg+CiAjaW5jbHVkZSA8c3lzdGVtLXF1b3RlLmg+CkBAIC01NjEsNiArNTYy
LDcgQEAgc3RhdGljIGNvbnN0IGNoYXIgKmNvbnN0IGluZGljYXRvcl9uYW1lW109CiAgIHsKICAg
ICAibGMiLCAicmMiLCAiZWMiLCAicnMiLCAiaGQiLCAiYWQiLCAiZGUiLCAibG4iLCBOVUxMCiAg
IH07CitBUkdNQVRDSF9WRVJJRlkgKGluZGljYXRvcl9uYW1lLCBjb2xvcl9pbmRpY2F0b3IpOwoK
IHN0YXRpYyBjb25zdCBjaGFyICpjb2xvcl9wYWxldHRlOwoK
--001a11439778b61cd805258aefdb--




From MAILER-DAEMON Sat Nov 28 15:38:16 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1a2mG7-0005jy-W0
	for mharc-bug-diffutils@gnu.org; Sat, 28 Nov 2015 15:38:16 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:37336)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2mG0-0005g3-6R
	for bug-diffutils@gnu.org; Sat, 28 Nov 2015 15:38:14 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2mFu-0003ct-EL
	for bug-diffutils@gnu.org; Sat, 28 Nov 2015 15:38:08 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:40518)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2mFu-0003cp-8t
	for bug-diffutils@gnu.org; Sat, 28 Nov 2015 15:38:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2mFu-00088h-2S
	for bug-diffutils@gnu.org; Sat, 28 Nov 2015 15:38:02 -0500
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: Sat, 28 Nov 2015 20:38:01 +0000
Resent-Message-ID: <handler.20062.B20062.144874302131198@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.144874302131198
	(code B ref 20062); Sat, 28 Nov 2015 20:38:01 +0000
Received: (at 20062) by debbugs.gnu.org; 28 Nov 2015 20:37:01 +0000
Received: from localhost ([127.0.0.1]:58459 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1a2mEr-000870-VK
	for submit@debbugs.gnu.org; Sat, 28 Nov 2015 15:37:01 -0500
Received: from mx1.redhat.com ([209.132.183.28]:43161)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivano@gnu.org>) id 1a2mEm-00086o-DT
	for 20062@debbugs.gnu.org; Sat, 28 Nov 2015 15:36:56 -0500
Received: from int-mx10.intmail.prod.int.phx2.redhat.com
	(int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23])
	by mx1.redhat.com (Postfix) with ESMTPS id 26ED7C0B7ACA;
	Sat, 28 Nov 2015 20:36:51 +0000 (UTC)
Received: from foo.bar.baz (vpn1-7-167.ams2.redhat.com [10.36.7.167])
	by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id tASKajlj031414
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=NO); Sat, 28 Nov 2015 15:36:46 -0500
From: Giuseppe Scrivano <gscrivano@gnu.org>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
	<87fv0nko86.fsf@foo.bar.baz> <5638EE6E.3050901@redhat.com>
	<CA+8g5KHcMiMiGnQJ3ibhe2W=4crcy9g6jSyMnWo-T9E4uzm=Og@mail.gmail.com>
	<87twol1nqw.fsf@foo.bar.baz>
	<CA+8g5KFs5CKoAzUw8T45-f8f+0t93XzZnfWKfkfrYrc4DXYQHQ@mail.gmail.com>
	<87a8pz4haz.fsf@foo.bar.baz>
	<CA+8g5KF25c5oNrE4zGRjS3SQGt+VfitfWRrnOvPJEUnvzEspOw@mail.gmail.com>
Date: Sat, 28 Nov 2015 21:36:44 +0100
In-Reply-To: <CA+8g5KF25c5oNrE4zGRjS3SQGt+VfitfWRrnOvPJEUnvzEspOw@mail.gmail.com>
	(Jim Meyering's message of "Fri, 27 Nov 2015 11:45:21 -0800")
Message-ID: <87610l509v.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.23
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 208.118.235.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 28 Nov 2015 20:38:14 -0000

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

Jim Meyering <jim@meyering.net> writes:

> diff --git a/bootstrap.conf b/bootstrap.conf
> index 9b2de22..3ab2c8b 100644
> --- a/bootstrap.conf
> +++ b/bootstrap.conf
> @@ -19,6 +19,7 @@
>  # gnulib modules used by this package.
>  gnulib_modules='
>  announce-gen
> +argmatch
>  binary-io
>  c-stack
>  config-h
> diff --git a/src/util.c b/src/util.c
> index 65b06e9..d27d202 100644
> --- a/src/util.c
> +++ b/src/util.c
> @@ -19,6 +19,7 @@
>     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
>
>  #include "diff.h"
> +#include "argmatch.h"
>  #include <dirname.h>
>  #include <error.h>
>  #include <system-quote.h>
> @@ -561,6 +562,7 @@ static const char *const indicator_name[]=
>    {
>      "lc", "rc", "ec", "rs", "hd", "ad", "de", "ln", NULL
>    };
> +ARGMATCH_VERIFY (indicator_name, color_indicator);
>
>  static const char *color_palette;

thanks for the review and the patch.  I had to add this chunk as
reported by "make syntax-check":

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 74fb756..af39427 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -15,6 +15,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+lib/argmatch.c
 lib/c-stack.c
 lib/error.c
 lib/file-type.c


As it is hopefully getting closer to be accepted, I am attaching the
full series with the amended changes.  I've verified that each patch
passes "make check" and "make syntax-check".

Regards,
Giuseppe


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

>From 900ab32b3cd9d06a9c002c53eb5c9738047f203f 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/5] 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_color_context): Add function definition.
* src/diff.c: : Define COLOR_OPTION.
(specify_colors_style): New function.
(longopts): Add --color.
(main): Handle --color argument.
(option_help_msgid): Add usage string for --color.
* src/normal.c (print_normal_hunk): 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.
(set_color_context): New function.
(sighandler): Likewise.  Copied from coreutils ls.
(stophandler): Likewise.  Copied from coreutils ls.
---
 doc/diffutils.texi |  21 ++++
 src/context.c      |  54 ++++++++--
 src/diff.c         |  27 ++++-
 src/diff.h         |  27 +++++
 src/normal.c       |  18 +++-
 src/side.c         |  15 +++
 src/util.c         | 308 +++++++++++++++++++++++++++++++++++++++++++++++------
 7 files changed, 423 insertions(+), 47 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 091257f..b2c39da 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 specified.
+@item auto
+@vindex auto @r{color option}
+@cindex terminal, using color iff
+Use color only 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..104c90b 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_color_context (HEADER_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]);
     }
+  set_color_context (RESET_CONTEXT);
 }
 
 /* Print an edit script in context format.  */
@@ -205,9 +207,11 @@ pr_context_hunk (struct change *hunk)
   if (function)
     print_context_function (out, function);
 
+  set_color_context (LINE_NUMBER_CONTEXT);
   fputs ("\n*** ", out);
   print_context_number_range (&files[0], first0, last0);
   fputs (" ****\n", out);
+  set_color_context (RESET_CONTEXT);
 
   if (changes & OLD)
     {
@@ -215,6 +219,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,18 +230,26 @@ 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_color_context (DELETE_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)
+            set_color_context (RESET_CONTEXT);
 	}
     }
 
+  set_color_context (LINE_NUMBER_CONTEXT);
   fputs ("--- ", out);
   print_context_number_range (&files[1], first1, last1);
   fputs (" ----\n", out);
+  set_color_context (RESET_CONTEXT);
 
   if (changes & NEW)
     {
@@ -244,6 +257,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 +268,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_color_context (ADD_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)
+            set_color_context (RESET_CONTEXT);
 	}
     }
 }
@@ -330,11 +349,13 @@ pr_unidiff_hunk (struct change *hunk)
   begin_output ();
   out = outfile;
 
+  set_color_context (LINE_NUMBER_CONTEXT);
   fputs ("@@ -", out);
   print_unidiff_number_range (&files[0], first0, last0);
   fputs (" +", out);
   print_unidiff_number_range (&files[1], first1, last1);
   fputs (" @@", out);
+  set_color_context (RESET_CONTEXT);
 
   if (function)
     print_context_function (out, function);
@@ -360,9 +381,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_color_context (DELETE_CONTEXT);
+            }
+
 	  while (k--)
 	    {
 	      char const * const *line = &files[0].linbuf[i++];
@@ -375,6 +404,11 @@ pr_unidiff_hunk (struct change *hunk)
 	  /* Then output the inserted part. */
 
 	  k = next->inserted;
+          if (k)
+            {
+              reset_context = true;
+              set_color_context (ADD_CONTEXT);
+            }
 	  while (k--)
 	    {
 	      char const * const *line = &files[1].linbuf[j++];
@@ -386,6 +420,8 @@ pr_unidiff_hunk (struct change *hunk)
 
 	  /* We're done with this hunk, so on to the next! */
 
+          if (reset_context)
+            set_color_context (RESET_CONTEXT);
 	  next = next->link;
 	}
     }
diff --git a/src/diff.c b/src/diff.c
index efd7e47..536f545 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..3c46042 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
 };
+
+/* When colors should be used in the output.  */
+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,14 @@ 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 *);
+
+enum color_context
+{
+  HEADER_CONTEXT,
+  ADD_CONTEXT,
+  DELETE_CONTEXT,
+  RESET_CONTEXT,
+  LINE_NUMBER_CONTEXT,
+};
+
+extern void set_color_context (enum color_context color_context);
diff --git a/src/normal.c b/src/normal.c
index 721fd1a..82aee77 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_color_context (LINE_NUMBER_CONTEXT);
   print_number_range (',', &files[0], first0, last0);
   fputc (change_letter[changes], outfile);
   print_number_range (',', &files[1], first1, last1);
   fputc ('\n', outfile);
+  set_color_context (RESET_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_color_context (DELETE_CONTEXT);
+      for (i = first0; i <= last0; i++)
+        print_1_line ("<", &files[0].linbuf[i]);
+      set_color_context (RESET_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_color_context (ADD_CONTEXT);
+      for (i = first1; i <= last1; i++)
+        print_1_line (">", &files[1].linbuf[i]);
+      set_color_context (RESET_CONTEXT);
+    }
 }
diff --git a/src/side.c b/src/side.c
index 155512c..a0213c4 100644
--- a/src/side.c
+++ b/src/side.c
@@ -206,6 +206,18 @@ print_1sdiff_line (char const *const *left, char sep,
   size_t c2o = sdiff_column2_offset;
   size_t col = 0;
   bool put_newline = false;
+  bool color_to_reset = false;
+
+  if (sep == '<')
+    {
+      set_color_context (DELETE_CONTEXT);
+      color_to_reset = true;
+    }
+  else if (sep == '>')
+    {
+      set_color_context (ADD_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)
+    set_color_context (RESET_CONTEXT);
 }
 
 /* Print lines common to both files in side-by-side format.  */
diff --git a/src/util.c b/src/util.c
index 2d6d3fc..694f4d9 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;
+
+      set_color_context (RESET_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,39 +877,85 @@ 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;
 
-	  case '\b':
-	    if (column == 0)
-	      continue;
-	    column--;
-	    putc (c, out);
-	    break;
+void
+set_color_context (enum color_context color_context)
+{
+  process_signals ();
+  if (colors_enabled)
+    {
+      switch (color_context)
+        {
+        case HEADER_CONTEXT:
+          fputs ("\x1B[1m", outfile);
+          break;
 
-	  default:
-	    column += isprint (c) != 0;
-	    putc (c, out);
-	    break;
-	  }
+        case LINE_NUMBER_CONTEXT:
+          fputs ("\x1B[36m", outfile);
+
+          break;
+
+        case ADD_CONTEXT:
+          fputs ("\x1B[32m", outfile);
+          break;
+
+        case DELETE_CONTEXT:
+          fputs ("\x1B[31m", outfile);
+          break;
+
+        case RESET_CONTEXT:
+          fputs ("\x1b[0m", outfile);
+          break;
+
+        default:
+          abort ();
+        }
     }
 }
 
-- 
2.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=0002-diff-add-palette.patch

>From f860a90da16f6d21939611718696347c3506b075 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/5] diff: add --palette

* bootstrap (gnulib_modules): Add 'argmatch'.
* doc/diffutils.texi: Add documentation for --palette
* src/diff.h (set_color_palette): New prototype.
* src/diff.c (set_color_palette): New function.
(color_palette): New variable.
* src/utils.c: Include "argmatch.h".
(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_color_context): Use put_indicator instead of directly
outputting the sequence.
* po/POTFILES.in: Add 'lib/argmatch.c'
---
 bootstrap.conf     |   1 +
 doc/diffutils.texi |  34 +++++
 po/POTFILES.in     |   1 +
 src/diff.c         |   8 +
 src/diff.h         |   1 +
 src/util.c         | 424 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 6 files changed, 462 insertions(+), 7 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 9b2de22..3ab2c8b 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -19,6 +19,7 @@
 # gnulib modules used by this package.
 gnulib_modules='
 announce-gen
+argmatch
 binary-io
 c-stack
 config-h
diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index b2c39da..4ec9a0b 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3890,6 +3890,40 @@ if-then-else format.  @xref{Line Formats}.
 @itemx --show-c-function
 Show which C function each change is in.  @xref{C Function Headings}.
 
+@item --palette=@var{palette}
+Specify what color palette to use when colored output is enabled.  It
+defaults to @samp{rs=0:hd=1:ad=32:de=31:ln=36} for red deleted lines,
+green added lines, cyan line numbers, bold header.
+
+Supported capabilities are as follows.
+
+@table @code
+@item ad=32
+@vindex ad @r{capability}
+
+SGR substring for added lines.
+The default is green foreground.
+
+@item de=31
+@vindex de @r{capability}
+
+SGR substring for deleted lines.
+The default is red foreground.
+
+@item hd=1
+@vindex hd @r{capability}
+
+SGR substring for chunk header.
+The default is bold foreground.
+
+@item ln=36
+@vindex ln @r{capability}
+
+SGR substring for line numbers.
+The default is cyan foreground.
+@end table
+
+
 @item -q
 @itemx --brief
 Report only whether the files differ, not the details of the
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 74fb756..af39427 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -15,6 +15,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+lib/argmatch.c
 lib/c-stack.c
 lib/error.c
 lib/file-type.c
diff --git a/src/diff.c b/src/diff.c
index 536f545..46ac99d 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -140,6 +140,7 @@ enum
   CHANGED_GROUP_FORMAT_OPTION,
 
   COLOR_OPTION,
+  COLOR_PALETTE_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -196,6 +197,7 @@ static struct option const longopts[] =
   {"old-group-format", 1, 0, OLD_GROUP_FORMAT_OPTION},
   {"old-line-format", 1, 0, OLD_LINE_FORMAT_OPTION},
   {"paginate", 0, 0, 'l'},
+  {"palette", 1, 0, COLOR_PALETTE_OPTION},
   {"rcs", 0, 0, 'n'},
   {"recursive", 0, 0, 'r'},
   {"report-identical-files", 0, 0, 's'},
@@ -635,6 +637,10 @@ main (int argc, char **argv)
 	  specify_colors_style (optarg);
 	  break;
 
+	case COLOR_PALETTE_OPTION:
+	  set_color_palette (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
@@ -950,6 +956,8 @@ static char const * const option_help_msgid[] = {
   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_("    --palette=PALETTE    specify the colors to use when --color is active"),
+  N_("                           PALETTE is a colon-separated list terminfo capabilities"),
   "",
   N_("    --help               display this help and exit"),
   N_("-v, --version            output version information and exit"),
diff --git a/src/diff.h b/src/diff.h
index 3c46042..c5fe4f9 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -417,3 +417,4 @@ enum color_context
 };
 
 extern void set_color_context (enum color_context color_context);
+extern void set_color_palette (char const *palette);
diff --git a/src/util.c b/src/util.c
index 694f4d9..3bd828f 100644
--- a/src/util.c
+++ b/src/util.c
@@ -19,6 +19,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "diff.h"
+#include "argmatch.h"
 #include <dirname.h>
 #include <error.h>
 #include <system-quote.h>
@@ -310,6 +311,397 @@ 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 --palette argument; 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
+  };
+ARGMATCH_VERIFY (indicator_name, color_indicator);
+
+static char const *color_palette;
+
+void
+set_color_palette (char const *palette)
+{
+  color_palette = palette;
+}
+
+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 = color_palette) == NULL || *p == '\0')
+    return;
+
+  ext = NULL;
+  strcpy (label, "??");
+
+  /* This is an overly conservative estimate, but any possible
+     --palette 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 --palette"));
+      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 +715,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,42 +1318,57 @@ 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);
+}
+
+static enum color_context last_context = RESET_CONTEXT;
 
 void
 set_color_context (enum color_context color_context)
 {
   process_signals ();
-  if (colors_enabled)
+  if (colors_enabled && last_context != color_context)
     {
+      put_indicator (&color_indicator[C_LEFT]);
       switch (color_context)
         {
         case HEADER_CONTEXT:
-          fputs ("\x1B[1m", outfile);
+          put_indicator (&color_indicator[C_HEADER]);
           break;
 
         case LINE_NUMBER_CONTEXT:
-          fputs ("\x1B[36m", outfile);
-
+          put_indicator (&color_indicator[C_LINE]);
           break;
 
         case ADD_CONTEXT:
-          fputs ("\x1B[32m", outfile);
+          put_indicator (&color_indicator[C_ADD]);
           break;
 
         case DELETE_CONTEXT:
-          fputs ("\x1B[31m", outfile);
+          put_indicator (&color_indicator[C_DELETE]);
           break;
 
         case RESET_CONTEXT:
-          fputs ("\x1b[0m", outfile);
+          put_indicator (&color_indicator[C_RESET]);
           break;
 
         default:
           abort ();
         }
+      put_indicator (&color_indicator[C_RIGHT]);
+      last_context = color_context;
     }
 }
 
+
 char const change_letter[] = { 0, 'd', 'a', 'c' };
 
 /* Translate an internal line number (an index into diff's table of lines)
-- 
2.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0003-doc-mention-color-and-palette-in-NEWS.patch

>From bebef1281fdb6d53f725b0eb1d18703e8845d768 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Mon, 2 Nov 2015 19:03:32 +0000
Subject: [PATCH 3/5] doc: mention --color and --palette in NEWS

---
 NEWS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/NEWS b/NEWS
index 7cdfedd..088f13b 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,13 @@ GNU diffutils NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** New features
+
+   diff accepts two new options --color and --palette to generate
+   and configure colored output.  --color takes an optional argument
+   specifying when to colorize a line: --color=always, --color=auto,
+   --color=never.  --palette is used to configure which colors are used.
+
 ** Bug fixes
 
   When binary files differ, diff now exits with status 1 as POSIX requires.
-- 
2.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0004-tests-Add-tests-for-color-and-palette.patch

>From e58c36a9062168bf56a8447d1c4287879ef54e9f Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Mon, 2 Nov 2015 19:05:10 +0000
Subject: [PATCH 4/5] tests: Add tests for --color and --palette

* tests/colors: New file.
* tests/Makefile.am (TESTS): Add colors.
---
 tests/Makefile.am |   3 +-
 tests/colors      | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 1 deletion(-)
 create mode 100755 tests/colors

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 438fbdf..805ccc2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,7 +15,8 @@ TESTS = \
   no-newline-at-eof \
   stdin \
   strcoll-0-names \
-  filename-quoting
+  filename-quoting \
+  colors
 
 EXTRA_DIST = \
   $(TESTS) init.sh t-local.sh
diff --git a/tests/colors b/tests/colors
new file mode 100755
index 0000000..92c0452
--- /dev/null
+++ b/tests/colors
@@ -0,0 +1,119 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+TZ=UTC0
+export TZ
+
+fail=0
+
+echo a > a
+echo b > b
+
+epoch='1970-01-01 00:00:00'
+touch --date="$epoch" a b
+
+gen_exp_u()
+{
+    local tab=$(printf '\t')
+    local epoch_plus="$epoch.000000000 +0000"
+    local rs=$(printf "\e[${rs}m")
+    local hd=$(printf "\e[${hd}m")
+    local ad=$(printf "\e[${ad}m")
+    local de=$(printf "\e[${de}m")
+    local ln=$(printf "\e[${ln}m")
+    printf '%s' \
+"$hd--- a$tab$epoch_plus
++++ b$tab$epoch_plus
+$rs${ln}@@ -1 +1 @@$rs
+$de-a
+$ad+b
+$rs"
+}
+
+gen_exp_c()
+{
+    local tab=$(printf '\t')
+    local epoch_posix_1003_1_2001="Thu Jan  1 00:00:00 1970"
+    local rs=$(printf "\e[${rs}m")
+    local hd=$(printf "\e[${hd}m")
+    local ad=$(printf "\e[${ad}m")
+    local de=$(printf "\e[${de}m")
+    local ln=$(printf "\e[${ln}m")
+    printf '%s' \
+"$hd*** a$tab$epoch_posix_1003_1_2001
+--- b$tab$epoch_posix_1003_1_2001
+$rs***************$ln
+*** 1 ****
+$rs$de! a
+$rs$ln--- 1 ----
+$rs$ad! b
+$rs"
+}
+
+gen_exp_default()
+{
+    printf '%s' \
+"1c1
+< a
+---
+> b
+"
+}
+
+gen_exp_default_colors()
+{
+    local rs=$(printf "\e[${rs}m")
+    local hd=$(printf "\e[${hd}m")
+    local ad=$(printf "\e[${ad}m")
+    local de=$(printf "\e[${de}m")
+    local ln=$(printf "\e[${ln}m")
+    printf '%s' \
+"${ln}1c1
+$rs$de< a
+$rs---
+$ad> b
+$rs"
+}
+
+# Compare with some known outputs
+
+rs=0 hd=1 ad=32 de=31 ln=36
+
+diff --color=auto a b > out
+test $? = 1 || fail=1
+gen_exp_default > exp || framework_failure_
+compare exp out || fail=1
+
+diff --color=never a b > out
+test $? = 1 || fail=1
+gen_exp_default > exp || framework_failure_
+compare exp out || fail=1
+
+diff a b > out
+test $? = 1 || fail=1
+gen_exp_default > exp || framework_failure_
+compare exp out || fail=1
+
+diff --color=always a b > out
+test $? = 1 || fail=1
+gen_exp_default_colors > exp || framework_failure_
+compare exp out || fail=1
+
+diff -u --color=always a b > out
+test $? = 1 || fail=1
+gen_exp_u > exp || framework_failure_
+compare exp out || fail=1
+
+diff -c --color=always a b > out
+test $? = 1 || fail=1
+gen_exp_c > exp || framework_failure_
+compare exp out || fail=1
+
+rs=0 hd=33 ad=34 de=35 ln=36
+diff -u --color=always --palette="rs=0:hd=33:ad=34:de=35:ln=36" a b > out
+test $? = 1 || fail=1
+gen_exp_u > exp || framework_failure_
+compare exp out || fail=1
+
+Exit $fail
-- 
2.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0005-Generate-terminal-sequences-on-the-line-they-belong.patch

>From a61b7dc46b43459656cde44824d23948cc28d5f9 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Fri, 27 Nov 2015 13:56:05 +0100
Subject: [PATCH 5/5] Generate terminal sequences on the line they belong

* src/diff.h: New function 'print_1_line_nl'.
* src/context.c (pr_context_hunk): Use 'print_1_line_nl'.
Generate terminal sequences on the line they belong.
(pr_unidiff_hunk): Likewise.
* src/normal.c (print_normal_hunk): Likewise.
* src/util.c (print_1_line_nl): New function.
(print_1_line): Become a wrapper of 'print_1_line_nl'.
* tests/colors: Adjust tests.
---
 src/context.c | 67 +++++++++++++++++++++++++++++++++--------------------------
 src/diff.h    |  1 +
 src/normal.c  | 26 ++++++++++++++++-------
 src/util.c    | 19 +++++++++++++++--
 tests/colors  | 28 ++++++++++++-------------
 5 files changed, 89 insertions(+), 52 deletions(-)

diff --git a/src/context.c b/src/context.c
index 104c90b..46b5b1f 100644
--- a/src/context.c
+++ b/src/context.c
@@ -207,19 +207,23 @@ pr_context_hunk (struct change *hunk)
   if (function)
     print_context_function (out, function);
 
+  putc ('\n', out);
   set_color_context (LINE_NUMBER_CONTEXT);
-  fputs ("\n*** ", out);
+  fputs ("*** ", out);
   print_context_number_range (&files[0], first0, last0);
-  fputs (" ****\n", out);
+  fputs (" ****", out);
   set_color_context (RESET_CONTEXT);
+  putc ('\n', out);
 
   if (changes & OLD)
     {
       struct change *next = hunk;
 
+      if (first0 <= last0)
+        set_color_context (DELETE_CONTEXT);
+
       for (i = first0; i <= last0; i++)
 	{
-          bool reset_context = false;
 	  /* Skip past changes that apply (in file 0)
 	     only to lines before line I.  */
 
@@ -231,33 +235,35 @@ pr_context_hunk (struct change *hunk)
 	  prefix = " ";
 	  if (next && next->line0 <= i)
             {
-              reset_context = true;
-              set_color_context (DELETE_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)
+	  print_1_line_nl (prefix, &files[0].linbuf[i], true);
+          if (i == last0)
             set_color_context (RESET_CONTEXT);
+          if (files[0].linbuf[i + 1][-1] == '\n')
+            putc ('\n', out);
 	}
     }
 
   set_color_context (LINE_NUMBER_CONTEXT);
   fputs ("--- ", out);
   print_context_number_range (&files[1], first1, last1);
-  fputs (" ----\n", out);
+  fputs (" ----", out);
   set_color_context (RESET_CONTEXT);
+  putc ('\n', out);
 
   if (changes & NEW)
     {
       struct change *next = hunk;
 
+      if (first1 <= last1)
+        set_color_context (ADD_CONTEXT);
+
       for (i = first1; i <= last1; i++)
 	{
-          bool reset_context = false;
 	  /* Skip past changes that apply (in file 1)
 	     only to lines before line I.  */
 
@@ -269,16 +275,16 @@ pr_context_hunk (struct change *hunk)
 	  prefix = " ";
 	  if (next && next->line1 <= i)
             {
-              reset_context = true;
-              set_color_context (ADD_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)
+	  print_1_line_nl (prefix, &files[1].linbuf[i], true);
+          if (i == last1)
             set_color_context (RESET_CONTEXT);
+          if (files[1].linbuf[i + 1][-1] == '\n')
+            putc ('\n', out);
 	}
     }
 }
@@ -381,16 +387,11 @@ 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_color_context (DELETE_CONTEXT);
-            }
+            set_color_context (DELETE_CONTEXT);
 
 	  while (k--)
 	    {
@@ -398,30 +399,38 @@ pr_unidiff_hunk (struct change *hunk)
 	      putc ('-', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
-	      print_1_line (NULL, line);
+	      print_1_line_nl (NULL, line, true);
+
+              if (!k)
+                set_color_context (RESET_CONTEXT);
+
+              if (line[1][-1] == '\n')
+                putc ('\n', out);
 	    }
 
 	  /* Then output the inserted part. */
 
 	  k = next->inserted;
           if (k)
-            {
-              reset_context = true;
-              set_color_context (ADD_CONTEXT);
-            }
-	  while (k--)
+            set_color_context (ADD_CONTEXT);
+
+          while (k--)
 	    {
 	      char const * const *line = &files[1].linbuf[j++];
 	      putc ('+', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
-	      print_1_line (NULL, line);
+	      print_1_line_nl (NULL, line, true);
+
+              if (!k)
+                set_color_context (RESET_CONTEXT);
+
+              if (line[1][-1] == '\n')
+                putc ('\n', out);
 	    }
 
 	  /* We're done with this hunk, so on to the next! */
 
-          if (reset_context)
-            set_color_context (RESET_CONTEXT);
 	  next = next->link;
 	}
     }
diff --git a/src/diff.h b/src/diff.h
index c5fe4f9..6f1bb34 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -399,6 +399,7 @@ extern void output_1_line (char const *, char const *, char const *,
 extern void perror_with_name (char const *);
 extern void pfatal_with_name (char const *) __attribute__((noreturn));
 extern void print_1_line (char const *, char const * const *);
+extern void print_1_line_nl (char const *, char const * const *, bool);
 extern void print_message_queue (void);
 extern void print_number_range (char, struct file_data *, lin, lin);
 extern void print_script (struct change *, struct change * (*) (struct change *),
diff --git a/src/normal.c b/src/normal.c
index 82aee77..e78e8ba 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -53,16 +53,22 @@ print_normal_hunk (struct change *hunk)
   print_number_range (',', &files[0], first0, last0);
   fputc (change_letter[changes], outfile);
   print_number_range (',', &files[1], first1, last1);
-  fputc ('\n', outfile);
   set_color_context (RESET_CONTEXT);
+  fputc ('\n', outfile);
 
   /* Print the lines that the first file has.  */
   if (changes & OLD)
     {
-      set_color_context (DELETE_CONTEXT);
+      if (first0 <= last0)
+        set_color_context (DELETE_CONTEXT);
       for (i = first0; i <= last0; i++)
-        print_1_line ("<", &files[0].linbuf[i]);
-      set_color_context (RESET_CONTEXT);
+        {
+          print_1_line_nl ("<", &files[0].linbuf[i], true);
+          if (i == last0)
+            set_color_context (RESET_CONTEXT);
+          if (files[0].linbuf[i + 1][-1] == '\n')
+            putc ('\n', outfile);
+        }
     }
 
   if (changes == CHANGED)
@@ -71,9 +77,15 @@ print_normal_hunk (struct change *hunk)
   /* Print the lines that the second file has.  */
   if (changes & NEW)
     {
-      set_color_context (ADD_CONTEXT);
+      if (first1 <= last1)
+        set_color_context (ADD_CONTEXT);
       for (i = first1; i <= last1; i++)
-        print_1_line (">", &files[1].linbuf[i]);
-      set_color_context (RESET_CONTEXT);
+        {
+          print_1_line_nl (">", &files[1].linbuf[i], true);
+          if (i == last1)
+            set_color_context (RESET_CONTEXT);
+          if (files[1].linbuf[i + 1][-1] == '\n')
+            putc ('\n', outfile);
+        }
     }
 }
diff --git a/src/util.c b/src/util.c
index 3bd828f..1fa61fa 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1208,6 +1208,18 @@ print_script (struct change *script,
 void
 print_1_line (char const *line_flag, char const *const *line)
 {
+  print_1_line_nl (line_flag, line, false);
+}
+
+/* Print the text of a single line LINE,
+   flagging it with the characters in LINE_FLAG (which say whether
+   the line is inserted, deleted, changed, etc.).  LINE_FLAG must not
+   end in a blank, unless it is a single blank.  If SKIP_NL is set, then
+   the final '\n' is not printed.  */
+
+void
+print_1_line_nl (char const *line_flag, char const *const *line, bool skip_nl)
+{
   char const *base = line[0], *limit = line[1]; /* Help the compiler.  */
   FILE *out = outfile; /* Help the compiler some more.  */
   char const *flag_format = 0;
@@ -1235,10 +1247,13 @@ print_1_line (char const *line_flag, char const *const *line)
       fprintf (out, flag_format_1, line_flag_1);
     }
 
-  output_1_line (base, limit, flag_format, line_flag);
+  output_1_line (base, limit - (skip_nl && limit[-1] == '\n'), flag_format, line_flag);
 
   if ((!line_flag || line_flag[0]) && limit[-1] != '\n')
-    fprintf (out, "\n\\ %s\n", _("No newline at end of file"));
+    {
+      set_color_context (RESET_CONTEXT);
+      fprintf (out, "\n\\ %s\n", _("No newline at end of file"));
+    }
 }
 
 /* Output a line from BASE up to LIMIT.
diff --git a/tests/colors b/tests/colors
index 92c0452..facfd8d 100755
--- a/tests/colors
+++ b/tests/colors
@@ -26,9 +26,9 @@ gen_exp_u()
 "$hd--- a$tab$epoch_plus
 +++ b$tab$epoch_plus
 $rs${ln}@@ -1 +1 @@$rs
-$de-a
-$ad+b
-$rs"
+$de-a$rs
+$ad+b$rs
+"
 }
 
 gen_exp_c()
@@ -43,12 +43,12 @@ gen_exp_c()
     printf '%s' \
 "$hd*** a$tab$epoch_posix_1003_1_2001
 --- b$tab$epoch_posix_1003_1_2001
-$rs***************$ln
-*** 1 ****
-$rs$de! a
-$rs$ln--- 1 ----
-$rs$ad! b
-$rs"
+$rs***************
+$ln*** 1 ****$rs
+$de! a$rs
+$ln--- 1 ----$rs
+$ad! b$rs
+"
 }
 
 gen_exp_default()
@@ -69,11 +69,11 @@ gen_exp_default_colors()
     local de=$(printf "\e[${de}m")
     local ln=$(printf "\e[${ln}m")
     printf '%s' \
-"${ln}1c1
-$rs$de< a
-$rs---
-$ad> b
-$rs"
+"${ln}1c1$rs
+$de< a$rs
+---
+$ad> b$rs
+"
 }
 
 # Compare with some known outputs
-- 
2.5.0


--=-=-=--




From MAILER-DAEMON Sat Nov 28 23:31:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1a2tdl-0003o5-3S
	for mharc-bug-diffutils@gnu.org; Sat, 28 Nov 2015 23:31:09 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:51244)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2tdi-0003mZ-QP
	for bug-diffutils@gnu.org; Sat, 28 Nov 2015 23:31:07 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2tde-0000o0-Ms
	for bug-diffutils@gnu.org; Sat, 28 Nov 2015 23:31:06 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:40696)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2tde-0000nu-IO
	for bug-diffutils@gnu.org; Sat, 28 Nov 2015 23:31:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2tde-0003NR-Fh
	for bug-diffutils@gnu.org; Sat, 28 Nov 2015 23:31:02 -0500
Resent-From: Jim Meyering <jim@meyering.net>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-To: bug-diffutils@gnu.org
Resent-Date: Sun, 29 Nov 2015 04:31:02 +0000
Resent-Message-ID: <handler.21945.D21945.144877145812966.done@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: cc-closed 21945
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: Stephan =?UTF-8?Q?M=C3=BCller?= <muellste@math.hu-berlin.de>
Mail-Followup-To: 21945@debbugs.gnu.org, jim@meyering.net,
	muellste@math.hu-berlin.de
Received: via spool by 21945-done@debbugs.gnu.org id=D21945.144877145812966
	(code D ref 21945); Sun, 29 Nov 2015 04:31:02 +0000
Received: (at 21945-done) by debbugs.gnu.org; 29 Nov 2015 04:30:58 +0000
Received: from localhost ([127.0.0.1]:58637 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1a2tdZ-0003N3-7F
	for submit@debbugs.gnu.org; Sat, 28 Nov 2015 23:30:57 -0500
Received: from mail-vk0-f51.google.com ([209.85.213.51]:33374)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>) id 1a2tdE-0003Md-1Y
	for 21945-done@debbugs.gnu.org; Sat, 28 Nov 2015 23:30:55 -0500
Received: by vkca188 with SMTP id a188so30168671vkc.0
	for <21945-done@debbugs.gnu.org>; Sat, 28 Nov 2015 20:30:35 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:from:date:message-id
	:subject:to:cc:content-type;
	bh=W3TUMpMjEmg0oSi/IstgVcDXLhfKL68yDfnT8YxVobc=;
	b=Rogywog+5oMba82s27FkeocLZWB6VMDS2gMAYPbiBcGH7NqLOpAEI3S1F3GkD0b/bt
	oKqIZoE5zae5R2NmCCRmwxvirAOeLMGNxYUZtDA82CCHTYpo0YRmTRWsNwj3D4bk2e7t
	VEsgK2QOB9kq5LJj0ZHY9vwJ1ajOWoGrdyaG9RU7PjDf/tuj0CMWXs4gzN61NrJQxvYL
	zWqBq6qqwFtl1nfJtFOITFJ5dunn83uWM8Nq2jIHUZjqYuxvrSEbYUGY9anL0s+UVie8
	ukbouJYSmHKD3IqXDB9NLPGN+U46bbG+hhGz4KUJD+w6/OjeQS5ONM9WEMuKtD2v4Tjx
	UIRQ==
X-Received: by 10.31.5.132 with SMTP id 126mr49238876vkf.107.1448771435267;
	Sat, 28 Nov 2015 20:30:35 -0800 (PST)
MIME-Version: 1.0
Received: by 10.31.84.198 with HTTP; Sat, 28 Nov 2015 20:30:15 -0800 (PST)
In-Reply-To: <20151117105344.77aa242e@fuckup.fritz.box>
References: <20151117105344.77aa242e@fuckup.fritz.box>
From: Jim Meyering <jim@meyering.net>
Date: Sat, 28 Nov 2015 20:30:15 -0800
X-Google-Sender-Auth: SP-I8HF5HZFsygSrB7i9gizUMPw
Message-ID: <CA+8g5KEbEE6RS9rbSr+=yRDuN=KFwECxS73VFWCfuq5=tj7jgg@mail.gmail.com>
Content-Type: multipart/mixed; boundary=001a11440f82c294fa0525a6627e
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: 21945-done@debbugs.gnu.org
Subject: [bug-diffutils] bug#21945: bug#21945: Bug: Build dependency gperf
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 29 Nov 2015 04:31:07 -0000

--001a11440f82c294fa0525a6627e
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Tue, Nov 17, 2015 at 1:53 AM, Stephan M=C3=BCller
<muellste@math.hu-berlin.de> wrote:
> Hello,
>
> building difftools (from Oct 2015) fails without gperf. A check for
> gperf should be added to the configure script.
>
> I am not really into it, but autoconf should be able to recognize this
> dependency itself? Any Ideas?

Thank you for the report. That was a bug, indeed.
The attached patch records the requirement in bootstrap.conf,
so that those building from DVCS notice it. Others should not
require gperf, because the gperf-generated files are always
generated and up-to-date in a distribution tarball.

--001a11440f82c294fa0525a6627e
Content-Type: text/x-patch; charset=UTF-8; 
	name="0001-build-add-gperf-to-the-list-of-required-programs.patch"
Content-Disposition: attachment; 
	filename="0001-build-add-gperf-to-the-list-of-required-programs.patch"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_ihk12pcj0

RnJvbSBkYmE2MTNhMGRlNTEyMTcxNDliMDE1YzJmZjRhY2IxYjg1MTlhNDJjIE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBKaW0gTWV5ZXJpbmcgPG1leWVyaW5nQGZiLmNvbT4KRGF0ZTog
U2F0LCAyOCBOb3YgMjAxNSAxOToyOTozNyAtMDgwMApTdWJqZWN0OiBbUEFUQ0hdIGJ1aWxkOiBh
ZGQgZ3BlcmYgdG8gdGhlIGxpc3Qgb2YgcmVxdWlyZWQgcHJvZ3JhbXMKTUlNRS1WZXJzaW9uOiAx
LjAKQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluOyBjaGFyc2V0PVVURi04CkNvbnRlbnQtVHJhbnNm
ZXItRW5jb2Rpbmc6IDhiaXQKCiogYm9vdHN0cmFwLmNvbmYgKGJ1aWxkcmVxKTogQWRkIGdwZXJm
IHRvIHRoZSBsaXN0LgpSZXBvcnRlZCBieSBTdGVwaGFuIE3DvGxsZXIgaW4gaHR0cDovL2RlYmJ1
Z3MuZ251Lm9yZy8yMTk0NQotLS0KIGJvb3RzdHJhcC5jb25mIHwgMSArCiAxIGZpbGUgY2hhbmdl
ZCwgMSBpbnNlcnRpb24oKykKCmRpZmYgLS1naXQgYS9ib290c3RyYXAuY29uZiBiL2Jvb3RzdHJh
cC5jb25mCmluZGV4IDNhYjJjOGIuLmFmNGYzNWEgMTAwNjQ0Ci0tLSBhL2Jvb3RzdHJhcC5jb25m
CisrKyBiL2Jvb3RzdHJhcC5jb25mCkBAIC0xNTUsNiArMTU1LDcgQEAgYXV0b21ha2UgICAxLjEy
LjIKIGF1dG9wb2ludCAgLQogZ2V0dGV4dCAgICAtCiBnaXQgICAgICAgIDEuNC40CitncGVyZiAg
ICAgIC0KIGd6aXAgICAgICAgLQogaGVscDJtYW4gICAtCiBtYWtlaW5mbyAgIC0KLS0gCjIuNi4y
Cgo=
--001a11440f82c294fa0525a6627e--




From MAILER-DAEMON Sat Nov 28 23:35:09 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1a2thd-00040i-O8
	for mharc-bug-diffutils@gnu.org; Sat, 28 Nov 2015 23:35:09 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:51683)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2thb-0003z6-8T
	for bug-diffutils@gnu.org; Sat, 28 Nov 2015 23:35:08 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2thW-0001U1-E4
	for bug-diffutils@gnu.org; Sat, 28 Nov 2015 23:35:07 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:40703)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2thW-0001Tr-9u
	for bug-diffutils@gnu.org; Sat, 28 Nov 2015 23:35:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a2thV-0003Tr-TM
	for bug-diffutils@gnu.org; Sat, 28 Nov 2015 23:35:01 -0500
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, 29 Nov 2015 04:35:01 +0000
Resent-Message-ID: <handler.20062.B20062.144877166113329@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.144877166113329
	(code B ref 20062); Sun, 29 Nov 2015 04:35:01 +0000
Received: (at 20062) by debbugs.gnu.org; 29 Nov 2015 04:34:21 +0000
Received: from localhost ([127.0.0.1]:58644 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1a2tgr-0003Su-5x
	for submit@debbugs.gnu.org; Sat, 28 Nov 2015 23:34:21 -0500
Received: from mail-vk0-f47.google.com ([209.85.213.47]:34081)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>) id 1a2tgo-0003Sm-Vg
	for 20062@debbugs.gnu.org; Sat, 28 Nov 2015 23:34:19 -0500
Received: by vkbs1 with SMTP id s1so85940144vkb.1
	for <20062@debbugs.gnu.org>; Sat, 28 Nov 2015 20:34:18 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:from:date:message-id
	:subject:to:cc:content-type;
	bh=PZ/K8pxc2DaZl637ZwDgcU+kNQpbqdSmFKNZWXi2lCM=;
	b=b+LF68bfoUNef/EIk50nDjAUMbSfdAv+0Lfvk78kDh5KESk2qURJH5Hpj+JM21ZcOq
	QHVNaaWHK9JfPkMivEf8FZZQuWEX/OXU4H7AtMfX/sh+sWWoMbNdrVIaalkFz5kjGBSM
	YCiZztQIiwwT8+PJb5rJu9Dp31au9qNcrTaiz+93fNs3Lg45L+3pifwPYTDMt6C1GgJx
	KdIKSbbZ5i1G5M1MHwGY5d2yTZaXWg3Gn2kyLKul9/JgPhIRRDKaywFNsVRbkVQsnBWM
	O2fZAR7umNucx+zmPgOnnr+UCb9Bk/in6bbeJY4N2jb2iCgvI0a95KScd9r0Ol2ESar8
	Nqzg==
X-Received: by 10.31.52.207 with SMTP id b198mr48650330vka.77.1448771658547;
	Sat, 28 Nov 2015 20:34:18 -0800 (PST)
MIME-Version: 1.0
Received: by 10.31.84.198 with HTTP; Sat, 28 Nov 2015 20:33:59 -0800 (PST)
In-Reply-To: <87610l509v.fsf@foo.bar.baz>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
	<87fv0nko86.fsf@foo.bar.baz> <5638EE6E.3050901@redhat.com>
	<CA+8g5KHcMiMiGnQJ3ibhe2W=4crcy9g6jSyMnWo-T9E4uzm=Og@mail.gmail.com>
	<87twol1nqw.fsf@foo.bar.baz>
	<CA+8g5KFs5CKoAzUw8T45-f8f+0t93XzZnfWKfkfrYrc4DXYQHQ@mail.gmail.com>
	<87a8pz4haz.fsf@foo.bar.baz>
	<CA+8g5KF25c5oNrE4zGRjS3SQGt+VfitfWRrnOvPJEUnvzEspOw@mail.gmail.com>
	<87610l509v.fsf@foo.bar.baz>
From: Jim Meyering <jim@meyering.net>
Date: Sat, 28 Nov 2015 20:33:59 -0800
X-Google-Sender-Auth: doVdA05o8vDSwhhEBWXagJbq16U
Message-ID: <CA+8g5KEtEyxY_T2Mvo1o9kdMQhYCB1HuLh0NHmRq36ow23LToA@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: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 29 Nov 2015 04:35:08 -0000

On Sat, Nov 28, 2015 at 12:36 PM, Giuseppe Scrivano <gscrivano@gnu.org> wrote:
....
> As it is hopefully getting closer to be accepted, I am attaching the
> full series with the amended changes.  I've verified that each patch
> passes "make check" and "make syntax-check".

Thanks, I see no problem.
I can push as-is, but wondered if you wanted to merge
your 0005 patch into the others? Probably not worth the work.
Either way is fine.




From MAILER-DAEMON Sun Nov 29 08:46:13 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1a32Iu-0005XT-Vb
	for mharc-bug-diffutils@gnu.org; Sun, 29 Nov 2015 08:46:12 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49186)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a32Ip-0005XL-H3
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 08:46:11 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a32Ik-0006Ce-VQ
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 08:46:07 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:40893)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a32Ik-0006Ca-QP
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 08:46:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a32Ij-0003in-SJ
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 08:46:02 -0500
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: Sun, 29 Nov 2015 13:46:01 +0000
Resent-Message-ID: <handler.20062.B20062.144880475414290@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.144880475414290
	(code B ref 20062); Sun, 29 Nov 2015 13:46:01 +0000
Received: (at 20062) by debbugs.gnu.org; 29 Nov 2015 13:45:54 +0000
Received: from localhost ([127.0.0.1]:58834 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1a32IY-0003iM-Sl
	for submit@debbugs.gnu.org; Sun, 29 Nov 2015 08:45:53 -0500
Received: from mx1.redhat.com ([209.132.183.28]:43723)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <gscrivano@gnu.org>) id 1a32IA-0003hq-VR
	for 20062@debbugs.gnu.org; Sun, 29 Nov 2015 08:45:48 -0500
Received: from int-mx13.intmail.prod.int.phx2.redhat.com
	(int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26])
	by mx1.redhat.com (Postfix) with ESMTPS id B5171C0B7AC6;
	Sun, 29 Nov 2015 13:45:25 +0000 (UTC)
Received: from foo.bar.baz (vpn1-6-166.ams2.redhat.com [10.36.6.166])
	by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP
	id tATDjJoN009772
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256
	verify=NO); Sun, 29 Nov 2015 08:45:21 -0500
From: Giuseppe Scrivano <gscrivano@gnu.org>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
	<87fv0nko86.fsf@foo.bar.baz> <5638EE6E.3050901@redhat.com>
	<CA+8g5KHcMiMiGnQJ3ibhe2W=4crcy9g6jSyMnWo-T9E4uzm=Og@mail.gmail.com>
	<87twol1nqw.fsf@foo.bar.baz>
	<CA+8g5KFs5CKoAzUw8T45-f8f+0t93XzZnfWKfkfrYrc4DXYQHQ@mail.gmail.com>
	<87a8pz4haz.fsf@foo.bar.baz>
	<CA+8g5KF25c5oNrE4zGRjS3SQGt+VfitfWRrnOvPJEUnvzEspOw@mail.gmail.com>
	<87610l509v.fsf@foo.bar.baz>
	<CA+8g5KEtEyxY_T2Mvo1o9kdMQhYCB1HuLh0NHmRq36ow23LToA@mail.gmail.com>
Date: Sun, 29 Nov 2015 14:45:19 +0100
In-Reply-To: <CA+8g5KEtEyxY_T2Mvo1o9kdMQhYCB1HuLh0NHmRq36ow23LToA@mail.gmail.com>
	(Jim Meyering's message of "Sat, 28 Nov 2015 20:33:59 -0800")
Message-ID: <871tb85380.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.26
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
Errors-To: debbugs-submit-bounces@debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x
X-Received-From: 208.118.235.43
Cc: 20062@debbugs.gnu.org
Subject: [bug-diffutils] bug#20062: bug#20062: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 29 Nov 2015 13:46:12 -0000

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

Jim Meyering <jim@meyering.net> writes:

> On Sat, Nov 28, 2015 at 12:36 PM, Giuseppe Scrivano <gscrivano@gnu.org> wrote:
> ....
>> As it is hopefully getting closer to be accepted, I am attaching the
>> full series with the amended changes.  I've verified that each patch
>> passes "make check" and "make syntax-check".
>
> Thanks, I see no problem.
> I can push as-is, but wondered if you wanted to merge
> your 0005 patch into the others? Probably not worth the work.
> Either way is fine.

it was not much work as there were no conflicts to solve, so I splitted
0005 into 0001 and 0004.  I verified again that each step passes all the
tests.

Regards,
Giuseppe



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

>From 4b944653c3c27d99312f77813394a4c965c5c787 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/4] 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_color_context): Add function definition.
* src/diff.c: : Define COLOR_OPTION.
(specify_colors_style): New function.
(longopts): Add --color.
(main): Handle --color argument.
(option_help_msgid): Add usage string for --color.
* src/normal.c (print_normal_hunk): Set the color context.
* src/side.c (print_1sdiff_line): Likewise.
* src/util.c (print_1_line_nl): New function.
(print_1_line): Make it a wrapper of 'print_1_line_nl'.
(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.
(set_color_context): New function.
(sighandler): Likewise.  Copied from coreutils ls.
(stophandler): Likewise.  Copied from coreutils ls.
---
 doc/diffutils.texi |  21 ++++
 src/context.c      |  81 ++++++++++---
 src/diff.c         |  27 ++++-
 src/diff.h         |  28 +++++
 src/normal.c       |  30 ++++-
 src/side.c         |  15 +++
 src/util.c         | 327 +++++++++++++++++++++++++++++++++++++++++++++++------
 7 files changed, 471 insertions(+), 58 deletions(-)

diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index 091257f..b2c39da 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 specified.
+@item auto
+@vindex auto @r{color option}
+@cindex terminal, using color iff
+Use color only 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..46b5b1f 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_color_context (HEADER_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]);
     }
+  set_color_context (RESET_CONTEXT);
 }
 
 /* Print an edit script in context format.  */
@@ -205,14 +207,21 @@ pr_context_hunk (struct change *hunk)
   if (function)
     print_context_function (out, function);
 
-  fputs ("\n*** ", out);
+  putc ('\n', out);
+  set_color_context (LINE_NUMBER_CONTEXT);
+  fputs ("*** ", out);
   print_context_number_range (&files[0], first0, last0);
-  fputs (" ****\n", out);
+  fputs (" ****", out);
+  set_color_context (RESET_CONTEXT);
+  putc ('\n', out);
 
   if (changes & OLD)
     {
       struct change *next = hunk;
 
+      if (first0 <= last0)
+        set_color_context (DELETE_CONTEXT);
+
       for (i = first0; i <= last0; i++)
 	{
 	  /* Skip past changes that apply (in file 0)
@@ -225,23 +234,34 @@ 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 ? "!" : "-");
-
-	  print_1_line (prefix, &files[0].linbuf[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 ? "!" : "-");
+            }
+	  print_1_line_nl (prefix, &files[0].linbuf[i], true);
+          if (i == last0)
+            set_color_context (RESET_CONTEXT);
+          if (files[0].linbuf[i + 1][-1] == '\n')
+            putc ('\n', out);
 	}
     }
 
+  set_color_context (LINE_NUMBER_CONTEXT);
   fputs ("--- ", out);
   print_context_number_range (&files[1], first1, last1);
-  fputs (" ----\n", out);
+  fputs (" ----", out);
+  set_color_context (RESET_CONTEXT);
+  putc ('\n', out);
 
   if (changes & NEW)
     {
       struct change *next = hunk;
 
+      if (first1 <= last1)
+        set_color_context (ADD_CONTEXT);
+
       for (i = first1; i <= last1; i++)
 	{
 	  /* Skip past changes that apply (in file 1)
@@ -254,12 +274,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 ? "!" : "+");
-
-	  print_1_line (prefix, &files[1].linbuf[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 ? "!" : "+");
+            }
+	  print_1_line_nl (prefix, &files[1].linbuf[i], true);
+          if (i == last1)
+            set_color_context (RESET_CONTEXT);
+          if (files[1].linbuf[i + 1][-1] == '\n')
+            putc ('\n', out);
 	}
     }
 }
@@ -330,11 +355,13 @@ pr_unidiff_hunk (struct change *hunk)
   begin_output ();
   out = outfile;
 
+  set_color_context (LINE_NUMBER_CONTEXT);
   fputs ("@@ -", out);
   print_unidiff_number_range (&files[0], first0, last0);
   fputs (" +", out);
   print_unidiff_number_range (&files[1], first1, last1);
   fputs (" @@", out);
+  set_color_context (RESET_CONTEXT);
 
   if (function)
     print_context_function (out, function);
@@ -363,25 +390,43 @@ pr_unidiff_hunk (struct change *hunk)
 	  /* For each difference, first output the deleted part. */
 
 	  k = next->deleted;
+          if (k)
+            set_color_context (DELETE_CONTEXT);
+
 	  while (k--)
 	    {
 	      char const * const *line = &files[0].linbuf[i++];
 	      putc ('-', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
-	      print_1_line (NULL, line);
+	      print_1_line_nl (NULL, line, true);
+
+              if (!k)
+                set_color_context (RESET_CONTEXT);
+
+              if (line[1][-1] == '\n')
+                putc ('\n', out);
 	    }
 
 	  /* Then output the inserted part. */
 
 	  k = next->inserted;
-	  while (k--)
+          if (k)
+            set_color_context (ADD_CONTEXT);
+
+          while (k--)
 	    {
 	      char const * const *line = &files[1].linbuf[j++];
 	      putc ('+', out);
 	      if (initial_tab && ! (suppress_blank_empty && **line == '\n'))
 		putc ('\t', out);
-	      print_1_line (NULL, line);
+	      print_1_line_nl (NULL, line, true);
+
+              if (!k)
+                set_color_context (RESET_CONTEXT);
+
+              if (line[1][-1] == '\n')
+                putc ('\n', out);
 	    }
 
 	  /* We're done with this hunk, so on to the next! */
diff --git a/src/diff.c b/src/diff.c
index efd7e47..536f545 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..7bf7344 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
 };
+
+/* When colors should be used in the output.  */
+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;
 
@@ -383,6 +399,7 @@ extern void output_1_line (char const *, char const *, char const *,
 extern void perror_with_name (char const *);
 extern void pfatal_with_name (char const *) __attribute__((noreturn));
 extern void print_1_line (char const *, char const * const *);
+extern void print_1_line_nl (char const *, char const * const *, bool);
 extern void print_message_queue (void);
 extern void print_number_range (char, struct file_data *, lin, lin);
 extern void print_script (struct change *, struct change * (*) (struct change *),
@@ -390,3 +407,14 @@ 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 *);
+
+enum color_context
+{
+  HEADER_CONTEXT,
+  ADD_CONTEXT,
+  DELETE_CONTEXT,
+  RESET_CONTEXT,
+  LINE_NUMBER_CONTEXT,
+};
+
+extern void set_color_context (enum color_context color_context);
diff --git a/src/normal.c b/src/normal.c
index 721fd1a..e78e8ba 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -49,21 +49,43 @@ print_normal_hunk (struct change *hunk)
   begin_output ();
 
   /* Print out the line number header for this hunk */
+  set_color_context (LINE_NUMBER_CONTEXT);
   print_number_range (',', &files[0], first0, last0);
   fputc (change_letter[changes], outfile);
   print_number_range (',', &files[1], first1, last1);
+  set_color_context (RESET_CONTEXT);
   fputc ('\n', outfile);
 
   /* Print the lines that the first file has.  */
   if (changes & OLD)
-    for (i = first0; i <= last0; i++)
-      print_1_line ("<", &files[0].linbuf[i]);
+    {
+      if (first0 <= last0)
+        set_color_context (DELETE_CONTEXT);
+      for (i = first0; i <= last0; i++)
+        {
+          print_1_line_nl ("<", &files[0].linbuf[i], true);
+          if (i == last0)
+            set_color_context (RESET_CONTEXT);
+          if (files[0].linbuf[i + 1][-1] == '\n')
+            putc ('\n', outfile);
+        }
+    }
 
   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]);
+    {
+      if (first1 <= last1)
+        set_color_context (ADD_CONTEXT);
+      for (i = first1; i <= last1; i++)
+        {
+          print_1_line_nl (">", &files[1].linbuf[i], true);
+          if (i == last1)
+            set_color_context (RESET_CONTEXT);
+          if (files[1].linbuf[i + 1][-1] == '\n')
+            putc ('\n', outfile);
+        }
+    }
 }
diff --git a/src/side.c b/src/side.c
index 155512c..a0213c4 100644
--- a/src/side.c
+++ b/src/side.c
@@ -206,6 +206,18 @@ print_1sdiff_line (char const *const *left, char sep,
   size_t c2o = sdiff_column2_offset;
   size_t col = 0;
   bool put_newline = false;
+  bool color_to_reset = false;
+
+  if (sep == '<')
+    {
+      set_color_context (DELETE_CONTEXT);
+      color_to_reset = true;
+    }
+  else if (sep == '>')
+    {
+      set_color_context (ADD_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)
+    set_color_context (RESET_CONTEXT);
 }
 
 /* Print lines common to both files in side-by-side format.  */
diff --git a/src/util.c b/src/util.c
index 2d6d3fc..78b1a2d 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;
+
+      set_color_context (RESET_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.  */
@@ -630,6 +813,18 @@ print_script (struct change *script,
 void
 print_1_line (char const *line_flag, char const *const *line)
 {
+  print_1_line_nl (line_flag, line, false);
+}
+
+/* Print the text of a single line LINE,
+   flagging it with the characters in LINE_FLAG (which say whether
+   the line is inserted, deleted, changed, etc.).  LINE_FLAG must not
+   end in a blank, unless it is a single blank.  If SKIP_NL is set, then
+   the final '\n' is not printed.  */
+
+void
+print_1_line_nl (char const *line_flag, char const *const *line, bool skip_nl)
+{
   char const *base = line[0], *limit = line[1]; /* Help the compiler.  */
   FILE *out = outfile; /* Help the compiler some more.  */
   char const *flag_format = 0;
@@ -657,10 +852,13 @@ print_1_line (char const *line_flag, char const *const *line)
       fprintf (out, flag_format_1, line_flag_1);
     }
 
-  output_1_line (base, limit, flag_format, line_flag);
+  output_1_line (base, limit - (skip_nl && limit[-1] == '\n'), flag_format, line_flag);
 
   if ((!line_flag || line_flag[0]) && limit[-1] != '\n')
-    fprintf (out, "\n\\ %s\n", _("No newline at end of file"));
+    {
+      set_color_context (RESET_CONTEXT);
+      fprintf (out, "\n\\ %s\n", _("No newline at end of file"));
+    }
 }
 
 /* Output a line from BASE up to LIMIT.
@@ -672,8 +870,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,39 +892,85 @@ 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;
 
-	  case '\b':
-	    if (column == 0)
-	      continue;
-	    column--;
-	    putc (c, out);
-	    break;
+void
+set_color_context (enum color_context color_context)
+{
+  process_signals ();
+  if (colors_enabled)
+    {
+      switch (color_context)
+        {
+        case HEADER_CONTEXT:
+          fputs ("\x1B[1m", outfile);
+          break;
 
-	  default:
-	    column += isprint (c) != 0;
-	    putc (c, out);
-	    break;
-	  }
+        case LINE_NUMBER_CONTEXT:
+          fputs ("\x1B[36m", outfile);
+
+          break;
+
+        case ADD_CONTEXT:
+          fputs ("\x1B[32m", outfile);
+          break;
+
+        case DELETE_CONTEXT:
+          fputs ("\x1B[31m", outfile);
+          break;
+
+        case RESET_CONTEXT:
+          fputs ("\x1b[0m", outfile);
+          break;
+
+        default:
+          abort ();
+        }
     }
 }
 
-- 
2.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=0002-diff-add-palette.patch

>From 8ab5aeabc752dfc746ebd385d1ce569d96d051b5 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/4] diff: add --palette

* bootstrap (gnulib_modules): Add 'argmatch'.
* doc/diffutils.texi: Add documentation for --palette
* src/diff.h (set_color_palette): New prototype.
* src/diff.c (set_color_palette): New function.
(color_palette): New variable.
* src/utils.c: Include "argmatch.h".
(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_color_context): Use put_indicator instead of directly
outputting the sequence.
* po/POTFILES.in: Add 'lib/argmatch.c'
---
 bootstrap.conf     |   1 +
 doc/diffutils.texi |  34 +++++
 po/POTFILES.in     |   1 +
 src/diff.c         |   8 +
 src/diff.h         |   1 +
 src/util.c         | 424 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 6 files changed, 462 insertions(+), 7 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 9b2de22..3ab2c8b 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -19,6 +19,7 @@
 # gnulib modules used by this package.
 gnulib_modules='
 announce-gen
+argmatch
 binary-io
 c-stack
 config-h
diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index b2c39da..4ec9a0b 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3890,6 +3890,40 @@ if-then-else format.  @xref{Line Formats}.
 @itemx --show-c-function
 Show which C function each change is in.  @xref{C Function Headings}.
 
+@item --palette=@var{palette}
+Specify what color palette to use when colored output is enabled.  It
+defaults to @samp{rs=0:hd=1:ad=32:de=31:ln=36} for red deleted lines,
+green added lines, cyan line numbers, bold header.
+
+Supported capabilities are as follows.
+
+@table @code
+@item ad=32
+@vindex ad @r{capability}
+
+SGR substring for added lines.
+The default is green foreground.
+
+@item de=31
+@vindex de @r{capability}
+
+SGR substring for deleted lines.
+The default is red foreground.
+
+@item hd=1
+@vindex hd @r{capability}
+
+SGR substring for chunk header.
+The default is bold foreground.
+
+@item ln=36
+@vindex ln @r{capability}
+
+SGR substring for line numbers.
+The default is cyan foreground.
+@end table
+
+
 @item -q
 @itemx --brief
 Report only whether the files differ, not the details of the
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 74fb756..af39427 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -15,6 +15,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+lib/argmatch.c
 lib/c-stack.c
 lib/error.c
 lib/file-type.c
diff --git a/src/diff.c b/src/diff.c
index 536f545..46ac99d 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -140,6 +140,7 @@ enum
   CHANGED_GROUP_FORMAT_OPTION,
 
   COLOR_OPTION,
+  COLOR_PALETTE_OPTION,
 };
 
 static char const group_format_option[][sizeof "--unchanged-group-format"] =
@@ -196,6 +197,7 @@ static struct option const longopts[] =
   {"old-group-format", 1, 0, OLD_GROUP_FORMAT_OPTION},
   {"old-line-format", 1, 0, OLD_LINE_FORMAT_OPTION},
   {"paginate", 0, 0, 'l'},
+  {"palette", 1, 0, COLOR_PALETTE_OPTION},
   {"rcs", 0, 0, 'n'},
   {"recursive", 0, 0, 'r'},
   {"report-identical-files", 0, 0, 's'},
@@ -635,6 +637,10 @@ main (int argc, char **argv)
 	  specify_colors_style (optarg);
 	  break;
 
+	case COLOR_PALETTE_OPTION:
+	  set_color_palette (optarg);
+	  break;
+
 	default:
 	  try_help (NULL, NULL);
 	}
@@ -950,6 +956,8 @@ static char const * const option_help_msgid[] = {
   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_("    --palette=PALETTE    specify the colors to use when --color is active"),
+  N_("                           PALETTE is a colon-separated list terminfo capabilities"),
   "",
   N_("    --help               display this help and exit"),
   N_("-v, --version            output version information and exit"),
diff --git a/src/diff.h b/src/diff.h
index 7bf7344..6f1bb34 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -418,3 +418,4 @@ enum color_context
 };
 
 extern void set_color_context (enum color_context color_context);
+extern void set_color_palette (char const *palette);
diff --git a/src/util.c b/src/util.c
index 78b1a2d..1fa61fa 100644
--- a/src/util.c
+++ b/src/util.c
@@ -19,6 +19,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "diff.h"
+#include "argmatch.h"
 #include <dirname.h>
 #include <error.h>
 #include <system-quote.h>
@@ -310,6 +311,397 @@ 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 --palette argument; 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
+  };
+ARGMATCH_VERIFY (indicator_name, color_indicator);
+
+static char const *color_palette;
+
+void
+set_color_palette (char const *palette)
+{
+  color_palette = palette;
+}
+
+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 = color_palette) == NULL || *p == '\0')
+    return;
+
+  ext = NULL;
+  strcpy (label, "??");
+
+  /* This is an overly conservative estimate, but any possible
+     --palette 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 --palette"));
+      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 +715,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 ();
 }
@@ -938,42 +1333,57 @@ 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);
+}
+
+static enum color_context last_context = RESET_CONTEXT;
 
 void
 set_color_context (enum color_context color_context)
 {
   process_signals ();
-  if (colors_enabled)
+  if (colors_enabled && last_context != color_context)
     {
+      put_indicator (&color_indicator[C_LEFT]);
       switch (color_context)
         {
         case HEADER_CONTEXT:
-          fputs ("\x1B[1m", outfile);
+          put_indicator (&color_indicator[C_HEADER]);
           break;
 
         case LINE_NUMBER_CONTEXT:
-          fputs ("\x1B[36m", outfile);
-
+          put_indicator (&color_indicator[C_LINE]);
           break;
 
         case ADD_CONTEXT:
-          fputs ("\x1B[32m", outfile);
+          put_indicator (&color_indicator[C_ADD]);
           break;
 
         case DELETE_CONTEXT:
-          fputs ("\x1B[31m", outfile);
+          put_indicator (&color_indicator[C_DELETE]);
           break;
 
         case RESET_CONTEXT:
-          fputs ("\x1b[0m", outfile);
+          put_indicator (&color_indicator[C_RESET]);
           break;
 
         default:
           abort ();
         }
+      put_indicator (&color_indicator[C_RIGHT]);
+      last_context = color_context;
     }
 }
 
+
 char const change_letter[] = { 0, 'd', 'a', 'c' };
 
 /* Translate an internal line number (an index into diff's table of lines)
-- 
2.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0003-doc-mention-color-and-palette-in-NEWS.patch

>From 773498ed3956af73ae3caff69c62f3b84a632cca Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Mon, 2 Nov 2015 19:03:32 +0000
Subject: [PATCH 3/4] doc: mention --color and --palette in NEWS

---
 NEWS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/NEWS b/NEWS
index 7cdfedd..088f13b 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,13 @@ GNU diffutils NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** New features
+
+   diff accepts two new options --color and --palette to generate
+   and configure colored output.  --color takes an optional argument
+   specifying when to colorize a line: --color=always, --color=auto,
+   --color=never.  --palette is used to configure which colors are used.
+
 ** Bug fixes
 
   When binary files differ, diff now exits with status 1 as POSIX requires.
-- 
2.5.0


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0004-tests-Add-tests-for-color-and-palette.patch

>From 4a69b46c3d71dd7299cf5d3b1dde3ce6902d3afe Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivano@gnu.org>
Date: Mon, 2 Nov 2015 19:05:10 +0000
Subject: [PATCH 4/4] tests: Add tests for --color and --palette

* tests/colors: New file.
* tests/Makefile.am (TESTS): Add colors.
---
 tests/Makefile.am |   3 +-
 tests/colors      | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 1 deletion(-)
 create mode 100755 tests/colors

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 438fbdf..805ccc2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,7 +15,8 @@ TESTS = \
   no-newline-at-eof \
   stdin \
   strcoll-0-names \
-  filename-quoting
+  filename-quoting \
+  colors
 
 EXTRA_DIST = \
   $(TESTS) init.sh t-local.sh
diff --git a/tests/colors b/tests/colors
new file mode 100755
index 0000000..facfd8d
--- /dev/null
+++ b/tests/colors
@@ -0,0 +1,119 @@
+#!/bin/sh
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+TZ=UTC0
+export TZ
+
+fail=0
+
+echo a > a
+echo b > b
+
+epoch='1970-01-01 00:00:00'
+touch --date="$epoch" a b
+
+gen_exp_u()
+{
+    local tab=$(printf '\t')
+    local epoch_plus="$epoch.000000000 +0000"
+    local rs=$(printf "\e[${rs}m")
+    local hd=$(printf "\e[${hd}m")
+    local ad=$(printf "\e[${ad}m")
+    local de=$(printf "\e[${de}m")
+    local ln=$(printf "\e[${ln}m")
+    printf '%s' \
+"$hd--- a$tab$epoch_plus
++++ b$tab$epoch_plus
+$rs${ln}@@ -1 +1 @@$rs
+$de-a$rs
+$ad+b$rs
+"
+}
+
+gen_exp_c()
+{
+    local tab=$(printf '\t')
+    local epoch_posix_1003_1_2001="Thu Jan  1 00:00:00 1970"
+    local rs=$(printf "\e[${rs}m")
+    local hd=$(printf "\e[${hd}m")
+    local ad=$(printf "\e[${ad}m")
+    local de=$(printf "\e[${de}m")
+    local ln=$(printf "\e[${ln}m")
+    printf '%s' \
+"$hd*** a$tab$epoch_posix_1003_1_2001
+--- b$tab$epoch_posix_1003_1_2001
+$rs***************
+$ln*** 1 ****$rs
+$de! a$rs
+$ln--- 1 ----$rs
+$ad! b$rs
+"
+}
+
+gen_exp_default()
+{
+    printf '%s' \
+"1c1
+< a
+---
+> b
+"
+}
+
+gen_exp_default_colors()
+{
+    local rs=$(printf "\e[${rs}m")
+    local hd=$(printf "\e[${hd}m")
+    local ad=$(printf "\e[${ad}m")
+    local de=$(printf "\e[${de}m")
+    local ln=$(printf "\e[${ln}m")
+    printf '%s' \
+"${ln}1c1$rs
+$de< a$rs
+---
+$ad> b$rs
+"
+}
+
+# Compare with some known outputs
+
+rs=0 hd=1 ad=32 de=31 ln=36
+
+diff --color=auto a b > out
+test $? = 1 || fail=1
+gen_exp_default > exp || framework_failure_
+compare exp out || fail=1
+
+diff --color=never a b > out
+test $? = 1 || fail=1
+gen_exp_default > exp || framework_failure_
+compare exp out || fail=1
+
+diff a b > out
+test $? = 1 || fail=1
+gen_exp_default > exp || framework_failure_
+compare exp out || fail=1
+
+diff --color=always a b > out
+test $? = 1 || fail=1
+gen_exp_default_colors > exp || framework_failure_
+compare exp out || fail=1
+
+diff -u --color=always a b > out
+test $? = 1 || fail=1
+gen_exp_u > exp || framework_failure_
+compare exp out || fail=1
+
+diff -c --color=always a b > out
+test $? = 1 || fail=1
+gen_exp_c > exp || framework_failure_
+compare exp out || fail=1
+
+rs=0 hd=33 ad=34 de=35 ln=36
+diff -u --color=always --palette="rs=0:hd=33:ad=34:de=35:ln=36" a b > out
+test $? = 1 || fail=1
+gen_exp_u > exp || framework_failure_
+compare exp out || fail=1
+
+Exit $fail
-- 
2.5.0


--=-=-=--




From MAILER-DAEMON Sun Nov 29 11:42:08 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1a353A-0003MQ-AR
	for mharc-bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:42:08 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:37342)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a3538-0003LX-68
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:42:07 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a3534-0007RL-TT
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:42:06 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:41685)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a3534-0007RH-PN
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:42:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a3534-00081L-6x
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:42:02 -0500
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, 29 Nov 2015 16:42:02 +0000
Resent-Message-ID: <handler.20062.B20062.144881526230738@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.144881526230738
	(code B ref 20062); Sun, 29 Nov 2015 16:42:02 +0000
Received: (at 20062) by debbugs.gnu.org; 29 Nov 2015 16:41:02 +0000
Received: from localhost ([127.0.0.1]:59623 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1a3524-0007zW-Rh
	for submit@debbugs.gnu.org; Sun, 29 Nov 2015 11:41:01 -0500
Received: from mail-vk0-f46.google.com ([209.85.213.46]:34196)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>) id 1a351k-0007z6-Ee
	for 20062@debbugs.gnu.org; Sun, 29 Nov 2015 11:40:59 -0500
Received: by vkbs1 with SMTP id s1so89961998vkb.1
	for <20062@debbugs.gnu.org>; Sun, 29 Nov 2015 08:40:40 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:from:date:message-id
	:subject:to:cc:content-type;
	bh=j0F8sxs5jMqWaDaZDr+zQZMNmB+RHlj05+kwErRZS9M=;
	b=yd9OrNMnTqQ0MgMq93+ZDRzS0BF6JM3KEugVwEt3zmo4yaalZOmCMD+W1XfudjJ27Y
	DlXjfpnX87Gce9uIam4wBGvErvNi5qISoLEbnjivL5CIbJOmOgf9bfW5pv23c5pLatNs
	vPx54O+22RuUyDcE1yCl4+FYrA2Ugvvx9HPBiLaiEe+qBbjyF/JoJbEQIG4+mGnkLDqz
	Vr+c9e9s6u7jX+/B6HosOVUG31fiivf2bCxsqMQb/a9hNLOLKjQCc7GHm1qLsCQggekU
	2hT0vV/8KK0FQW2WxNUfeXkBy3TJWtaCx+T5I6A5RUqXcAfu2OWJAEJ+CG2v620n7BKl
	QiWw==
X-Received: by 10.31.152.78 with SMTP id a75mr50618485vke.55.1448815239893;
	Sun, 29 Nov 2015 08:40:39 -0800 (PST)
MIME-Version: 1.0
Received: by 10.31.84.198 with HTTP; Sun, 29 Nov 2015 08:40:20 -0800 (PST)
In-Reply-To: <871tb85380.fsf@foo.bar.baz>
References: <1425851791-29188-1-git-send-email-gscrivan@redhat.com>
	<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>
	<CA+8g5KFPawZax9+CrWxcAB=3Z-UZ4=Qsb6Pv+y4Ejc+X-_MD2A@mail.gmail.com>
	<CA+8g5KHbaktpT0dxCKVNs=LzLQXahhH33HD9z0H=OZtWEXaKxA@mail.gmail.com>
	<87bnbcrz2k.fsf@foo.bar.baz> <5637BAAC.8020301@redhat.com>
	<CA+8g5KEmGDGigM-kSnJNXcB98Wyda0uK4caVU+wE-rS3eEzhdQ@mail.gmail.com>
	<87fv0nko86.fsf@foo.bar.baz> <5638EE6E.3050901@redhat.com>
	<CA+8g5KHcMiMiGnQJ3ibhe2W=4crcy9g6jSyMnWo-T9E4uzm=Og@mail.gmail.com>
	<87twol1nqw.fsf@foo.bar.baz>
	<CA+8g5KFs5CKoAzUw8T45-f8f+0t93XzZnfWKfkfrYrc4DXYQHQ@mail.gmail.com>
	<87a8pz4haz.fsf@foo.bar.baz>
	<CA+8g5KF25c5oNrE4zGRjS3SQGt+VfitfWRrnOvPJEUnvzEspOw@mail.gmail.com>
	<87610l509v.fsf@foo.bar.baz>
	<CA+8g5KEtEyxY_T2Mvo1o9kdMQhYCB1HuLh0NHmRq36ow23LToA@mail.gmail.com>
	<871tb85380.fsf@foo.bar.baz>
From: Jim Meyering <jim@meyering.net>
Date: Sun, 29 Nov 2015 08:40:20 -0800
X-Google-Sender-Auth: mPfITxsoAOAPFXFMAXFNdfj7WMo
Message-ID: <CA+8g5KHX1B3Jte17s=JCB-GWmgAWP8Sxh+dk-1cYBQc6o6-dDQ@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: [PATCH] diff: add support for
	--color
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 29 Nov 2015 16:42:07 -0000

On Sun, Nov 29, 2015 at 5:45 AM, Giuseppe Scrivano <gscrivano@gnu.org> wrote:
> Jim Meyering <jim@meyering.net> writes:
>
>> On Sat, Nov 28, 2015 at 12:36 PM, Giuseppe Scrivano <gscrivano@gnu.org> wrote:
>> ....
>>> As it is hopefully getting closer to be accepted, I am attaching the
>>> full series with the amended changes.  I've verified that each patch
>>> passes "make check" and "make syntax-check".
>>
>> Thanks, I see no problem.
>> I can push as-is, but wondered if you wanted to merge
>> your 0005 patch into the others? Probably not worth the work.
>> Either way is fine.
>
> it was not much work as there were no conflicts to solve, so I splitted
> 0005 into 0001 and 0004.  I verified again that each step passes all the
> tests.

Good! Worthwhile after all. Thank you.
I have just pushed those commits.




From MAILER-DAEMON Sun Nov 29 11:44:08 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1a3556-0003lP-1G
	for mharc-bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:44:08 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:37663)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a3553-0003gI-Kl
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:44:06 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a3550-0007js-E0
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:44:05 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:41692)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a3550-0007jn-Ac
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:44:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a3550-00084b-5g
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:44:02 -0500
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, 29 Nov 2015 16:44:02 +0000
Resent-Message-ID: <handler.21945.B21945.144881539030963@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 21945
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: 21945@debbugs.gnu.org, Jim Meyering <jim@meyering.net>,
	muellste@math.hu-berlin.de
Received: via spool by 21945-submit@debbugs.gnu.org id=B21945.144881539030963
	(code B ref 21945); Sun, 29 Nov 2015 16:44:02 +0000
Received: (at 21945) by debbugs.gnu.org; 29 Nov 2015 16:43:10 +0000
Received: from localhost ([127.0.0.1]:59631 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1a3549-00083J-GT
	for submit@debbugs.gnu.org; Sun, 29 Nov 2015 11:43:09 -0500
Received: from mail-vk0-f42.google.com ([209.85.213.42]:36192)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>)
	id 1a3546-000837-LZ; Sun, 29 Nov 2015 11:43:07 -0500
Received: by vkay187 with SMTP id y187so89790576vka.3;
	Sun, 29 Nov 2015 08:43:06 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:from:date:message-id
	:subject:to:cc:content-type:content-transfer-encoding;
	bh=WGQR+rtV25P5c3SAvVYgl55Y70coPRIpFAvp6oImgEM=;
	b=ukWjjwpxgl/7m+gnWsIhB262LYUuE5634wptMqdWYHyYqglVKD7SSfsXIYRIiS3W36
	Y3IfMKdLsIPYUlze1Yf8VyJYz5BuwKC2js5nc373H5zfvpn5OjMNaCpAt0DlHhzDiDVu
	urV5nnrsYEwynnanNJuQgrQ1he4pcKO8timoOqg51zTEmgxjyWeYpfpX9sDqELT3eeIN
	dF201Kp+L42GaXDijdXtUYk+ZHOUeV+Hgxrz/cH1QuWIWI1Q5Z8IGfOIiNwZXMlygCSE
	ahYAPG4ROGBAmkbAPgvfd5ujesIeDKlQ9gRN+txHketyZST0veo7AQbjvH6IozgrK0uV
	vRig==
X-Received: by 10.31.52.207 with SMTP id b198mr49942969vka.77.1448815386285;
	Sun, 29 Nov 2015 08:43:06 -0800 (PST)
MIME-Version: 1.0
Received: by 10.31.84.198 with HTTP; Sun, 29 Nov 2015 08:42:46 -0800 (PST)
In-Reply-To: <CA+8g5KEbEE6RS9rbSr+=yRDuN=KFwECxS73VFWCfuq5=tj7jgg@mail.gmail.com>
References: <20151117105344.77aa242e@fuckup.fritz.box>
	<CA+8g5KEbEE6RS9rbSr+=yRDuN=KFwECxS73VFWCfuq5=tj7jgg@mail.gmail.com>
From: Jim Meyering <jim@meyering.net>
Date: Sun, 29 Nov 2015 08:42:46 -0800
X-Google-Sender-Auth: bzGZD4QIQJB9WAX1n2-tltuQrYI
Message-ID: <CA+8g5KFD+9zRGVAXkK1c8HbbtvE9HvxzfMPER3SRcqZtXqwCXA@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
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: 21945-done@debbugs.gnu.org
Subject: [bug-diffutils] bug#21945: bug#21945: bug#21945: Bug: Build
	dependency gperf
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 29 Nov 2015 16:44:06 -0000

On Sat, Nov 28, 2015 at 8:30 PM, Jim Meyering <jim@meyering.net> wrote:
> On Tue, Nov 17, 2015 at 1:53 AM, Stephan M=C3=BCller
> <muellste@math.hu-berlin.de> wrote:
>> Hello,
>>
>> building difftools (from Oct 2015) fails without gperf. A check for
>> gperf should be added to the configure script.
>>
>> I am not really into it, but autoconf should be able to recognize this
>> dependency itself? Any Ideas?
>
> Thank you for the report. That was a bug, indeed.
> The attached patch records the requirement in bootstrap.conf,
> so that those building from DVCS notice it. Others should not
> require gperf, because the gperf-generated files are always
> generated and up-to-date in a distribution tarball.

I have just pushed that patch.




From MAILER-DAEMON Sun Nov 29 11:44:08 2015
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1a3556-0003mM-Tw
	for mharc-bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:44:08 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:37664)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a3553-0003gJ-Ko
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:44:06 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a3550-0007k2-VR
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:44:05 -0500
Received: from debbugs.gnu.org ([208.118.235.43]:41693)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a3550-0007jy-SF
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:44:02 -0500
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1a3550-00084i-NP
	for bug-diffutils@gnu.org; Sun, 29 Nov 2015 11:44:02 -0500
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, 29 Nov 2015 16:44:02 +0000
Resent-Message-ID: <handler.21945.D21945.144881539030969@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 21945
X-GNU-PR-Package: diffutils
X-GNU-PR-Keywords: 
To: 21945@debbugs.gnu.org, Jim Meyering <jim@meyering.net>,
	muellste@math.hu-berlin.de
Received: via spool by 21945-done@debbugs.gnu.org id=D21945.144881539030969
	(code D ref 21945); Sun, 29 Nov 2015 16:44:02 +0000
Received: (at 21945-done) by debbugs.gnu.org; 29 Nov 2015 16:43:10 +0000
Received: from localhost ([127.0.0.1]:59633 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1a3549-00083M-Vj
	for submit@debbugs.gnu.org; Sun, 29 Nov 2015 11:43:10 -0500
Received: from mail-vk0-f42.google.com ([209.85.213.42]:36192)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <meyering@gmail.com>)
	id 1a3546-000837-LZ; Sun, 29 Nov 2015 11:43:07 -0500
Received: by vkay187 with SMTP id y187so89790576vka.3;
	Sun, 29 Nov 2015 08:43:06 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; 
	h=mime-version:sender:in-reply-to:references:from:date:message-id
	:subject:to:cc:content-type:content-transfer-encoding;
	bh=WGQR+rtV25P5c3SAvVYgl55Y70coPRIpFAvp6oImgEM=;
	b=ukWjjwpxgl/7m+gnWsIhB262LYUuE5634wptMqdWYHyYqglVKD7SSfsXIYRIiS3W36
	Y3IfMKdLsIPYUlze1Yf8VyJYz5BuwKC2js5nc373H5zfvpn5OjMNaCpAt0DlHhzDiDVu
	urV5nnrsYEwynnanNJuQgrQ1he4pcKO8timoOqg51zTEmgxjyWeYpfpX9sDqELT3eeIN
	dF201Kp+L42GaXDijdXtUYk+ZHOUeV+Hgxrz/cH1QuWIWI1Q5Z8IGfOIiNwZXMlygCSE
	ahYAPG4ROGBAmkbAPgvfd5ujesIeDKlQ9gRN+txHketyZST0veo7AQbjvH6IozgrK0uV
	vRig==
X-Received: by 10.31.52.207 with SMTP id b198mr49942969vka.77.1448815386285;
	Sun, 29 Nov 2015 08:43:06 -0800 (PST)
MIME-Version: 1.0
Received: by 10.31.84.198 with HTTP; Sun, 29 Nov 2015 08:42:46 -0800 (PST)
In-Reply-To: <CA+8g5KEbEE6RS9rbSr+=yRDuN=KFwECxS73VFWCfuq5=tj7jgg@mail.gmail.com>
References: <20151117105344.77aa242e@fuckup.fritz.box>
	<CA+8g5KEbEE6RS9rbSr+=yRDuN=KFwECxS73VFWCfuq5=tj7jgg@mail.gmail.com>
From: Jim Meyering <jim@meyering.net>
Date: Sun, 29 Nov 2015 08:42:46 -0800
X-Google-Sender-Auth: bzGZD4QIQJB9WAX1n2-tltuQrYI
Message-ID: <CA+8g5KFD+9zRGVAXkK1c8HbbtvE9HvxzfMPER3SRcqZtXqwCXA@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
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: 21945-done@debbugs.gnu.org
Subject: [bug-diffutils] bug#21945: bug#21945: bug#21945: Bug: Build
	dependency gperf
X-BeenThere: bug-diffutils@gnu.org
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 29 Nov 2015 16:44:06 -0000

On Sat, Nov 28, 2015 at 8:30 PM, Jim Meyering <jim@meyering.net> wrote:
> On Tue, Nov 17, 2015 at 1:53 AM, Stephan M=C3=BCller
> <muellste@math.hu-berlin.de> wrote:
>> Hello,
>>
>> building difftools (from Oct 2015) fails without gperf. A check for
>> gperf should be added to the configure script.
>>
>> I am not really into it, but autoconf should be able to recognize this
>> dependency itself? Any Ideas?
>
> Thank you for the report. That was a bug, indeed.
> The attached patch records the requirement in bootstrap.conf,
> so that those building from DVCS notice it. Others should not
> require gperf, because the gperf-generated files are always
> generated and up-to-date in a distribution tarball.

I have just pushed that patch.




