From MAILER-DAEMON Mon Sep 10 06:13:26 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TB0ze-0000UN-FC
	for mharc-bug-diffutils@gnu.org; Mon, 10 Sep 2012 06:13:26 -0400
Received: from eggs.gnu.org ([208.118.235.92]:58769)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <andreas.gruenbacher@gmail.com>) id 1TB0zX-0000Td-Kb
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 06:13:25 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <andreas.gruenbacher@gmail.com>) id 1TB0zR-000717-Mz
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 06:13:19 -0400
Received: from mail-lb0-f169.google.com ([209.85.217.169]:49900)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <andreas.gruenbacher@gmail.com>) id 1TB0zR-00070v-Fq
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 06:13:13 -0400
Received: by lbon3 with SMTP id n3so1119284lbo.0
	for <bug-diffutils@gnu.org>; Mon, 10 Sep 2012 03:13:11 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=mime-version:in-reply-to:references:date:message-id:subject:from:to
	:cc:content-type;
	bh=XhlreLnxCQPKxczGGZxWuD0YR6pVicIBRTEKWASgtS4=;
	b=VMU/8mFbGi+Gxx6A8B6j/PFV5qUQ+++zLBGy7E0OqyVJfQuE5o3Yz4qjh18ep7GxHd
	nMYoNF+MqQ22SG2irfgcEvlP8AqnrgCcNAWi8k6Dp7JVCtJhps6y51OC4MjCA453wVyN
	2PKkKlR0bNyv0FAFRHTo4ZGbu7AfjI/7kh6DfgWRLEZuDQLfcNnL1TSLNY1vuReexvlt
	RjtUmWXSRbkfUpKF6v77Cwr8L7WHt8YjcRL/Fmgn9gtLzp1FYSra1fY0GTuwXNpNV9Lq
	skFF8sCgTO1akfnjyqS5aBRvMO81OrVJuwgk9psZZJN3gDB8F5dIBfO6lR3aRvfjoECz
	FLsg==
MIME-Version: 1.0
Received: by 10.112.29.104 with SMTP id j8mr4730223lbh.127.1347271991753; Mon,
	10 Sep 2012 03:13:11 -0700 (PDT)
Received: by 10.112.54.180 with HTTP; Mon, 10 Sep 2012 03:13:11 -0700 (PDT)
In-Reply-To: <1344897046.13604.7.camel@schurl.lan>
References: <1344897046.13604.7.camel@schurl.lan>
Date: Mon, 10 Sep 2012 12:13:11 +0200
Message-ID: <CAHpGcMK97Mu6S1X6gge6iEGyFw_NEWxh+kxBUGdFWjMXvFORNw@mail.gmail.com>
From: =?ISO-8859-1?Q?Andreas_Gr=FCnbacher?= <andreas.gruenbacher@gmail.com>
To: Jim Meyering <jim@meyering.net>, Paul Eggert <eggert@cs.ucla.edu>
Content-Type: text/plain; charset=ISO-8859-1
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.85.217.169
Cc: bug-diffutils@gnu.org
Subject: Re: [bug-diffutils] [PATCH] diff: Encode file names with special
	characters
X-BeenThere: bug-diffutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
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, 10 Sep 2012 10:13:25 -0000

Jim And Paul,

2012/8/14 Andreas Gruenbacher <agruen@gnu.org>:
> Here is an updated version with a NEWS entry and a test case.

can one of you please review and apply this? I'd like this to happen
before the counterpart shows up in a GNU patch release.

Thanks,
Andreas


From MAILER-DAEMON Mon Sep 10 06:28:17 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TB1E0-0001gV-Vp
	for mharc-bug-diffutils@gnu.org; Mon, 10 Sep 2012 06:28:16 -0400
Received: from eggs.gnu.org ([208.118.235.92]:39998)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TB1Du-0001g5-75
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 06:28:15 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TB1Dt-0003Px-17
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 06:28:10 -0400
Received: from mx.meyering.net ([88.168.87.75]:43130)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>)
	id 1TB1Dk-0003Nh-Dx; Mon, 10 Sep 2012 06:28:00 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 95233601C8;
	Mon, 10 Sep 2012 12:27:59 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Andreas Gruenbacher <agruen@gnu.org>
In-Reply-To: <1344897046.13604.7.camel@schurl.lan> (Andreas Gruenbacher's
	message of "Tue, 14 Aug 2012 00:30:46 +0200")
References: <1344897046.13604.7.camel@schurl.lan>
Date: Mon, 10 Sep 2012 12:27:59 +0200
Message-ID: <87392qnpe8.fsf@rho.meyering.net>
Lines: 93
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: bug-diffutils@gnu.org
Subject: Re: [bug-diffutils] [PATCH] diff: Encode file names with special
	characters
X-BeenThere: bug-diffutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
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, 10 Sep 2012 10:28:16 -0000

Andreas Gruenbacher wrote:
> Here is an updated version with a NEWS entry and a test case.
>
> Note that the test case might not survive sending over email as it
> contains a special character.  Maybe the test case can be turned into
> plain text somehow and stay reasonably portable.
...
> * src/util.c (c_escape_char): New function.
> (c_escape): New function.
> (begin_output): Escape file names when needed.
> * src/context.c (print_context_header): New names parameter.
> (print_context_label): New name parameter.
> * src/diff.h (print_context_header): Change prototype.
> * tests/filename-quoting: New file.
> * NEWS: Document this change.
...
> +char *
> +c_escape (char const *str)
> +{
> +  char const *s;
> +  unsigned int plus = 0;
> +  bool must_quote = false;
> +
> +  for (s = str; *s; s++)
> +    {
> +      char c = *s;
> +
> +      if (c == ' ')
> +	{
> +	  must_quote = true;
> +	  continue;
> +	}
> +      switch (c_escape_char (*s))
> +	{
> +	  case 1:
> +	    plus += 3;
> +	    /* fall through */
> +	  case 0:
> +	    break;
> +	  default:
> +	    plus++;
> +	    break;
> +	}
> +    }

Thanks for doing this.  I've begun reviewing it.
Here's one change I would like to squash in,
to make this function static, to adjust a type,
to avoid an strlen call and to adjust code layout.
Ok with you?

diff --git a/src/util.c b/src/util.c
index c488a7d..c02d156 100644
--- a/src/util.c
+++ b/src/util.c
@@ -184,11 +184,11 @@ static char c_escape_char (char c)
   }
 }

-char *
+static char *
 c_escape (char const *str)
 {
   char const *s;
-  unsigned int plus = 0;
+  size_t plus = 0;
   bool must_quote = false;

   for (s = str; *s; s++)
@@ -215,9 +215,10 @@ c_escape (char const *str)

   if (must_quote || plus)
     {
-      char *buffer, *b;
+      size_t s_len = s - str;
+      char *buffer = xmalloc (s_len + plus + 3);
+      char *b = buffer;

-      b = buffer = xmalloc (strlen (str) + plus + 3);
       *b++ = '"';
       for (s = str; *s; s++)
 	{
@@ -245,8 +246,8 @@ c_escape (char const *str)
       *b = 0;
       return buffer;
     }
-  else
-    return (char *) str;
+
+  return (char *) str;
 }

 void


From MAILER-DAEMON Mon Sep 10 06:36:13 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TB1Lh-0004tf-OX
	for mharc-bug-diffutils@gnu.org; Mon, 10 Sep 2012 06:36:13 -0400
Received: from eggs.gnu.org ([208.118.235.92]:45509)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <agruen@gnu.org>) id 1TB1Lf-0004tY-IC
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 06:36:12 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <agruen@gnu.org>) id 1TB1LZ-0006La-UE
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 06:36:11 -0400
Received: from zimbra.linbit.com ([212.69.161.123]:47085)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <agruen@gnu.org>) id 1TB1LZ-0006LQ-NE
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 06:36:05 -0400
Received: from localhost (localhost [127.0.0.1])
	by zimbra.linbit.com (Postfix) with ESMTP id CB87A1B438C;
	Mon, 10 Sep 2012 12:36:01 +0200 (CEST)
X-Virus-Scanned: amavisd-new at zimbra.linbit.com
Received: from zimbra.linbit.com ([127.0.0.1])
	by localhost (zimbra.linbit.com [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id WmlIdLh9Nolb; Mon, 10 Sep 2012 12:36:01 +0200 (CEST)
Received: from [10.9.9.71] (tuerlsteher.linbit.com [86.59.100.100])
	by zimbra.linbit.com (Postfix) with ESMTPSA id A1F821B4386;
	Mon, 10 Sep 2012 12:36:01 +0200 (CEST)
Message-ID: <1347273361.21157.2.camel@gurkel.linbit>
From: Andreas Gruenbacher <agruen@gnu.org>
To: Jim Meyering <jim@meyering.net>
Date: Mon, 10 Sep 2012 12:36:01 +0200
In-Reply-To: <87392qnpe8.fsf@rho.meyering.net>
References: <1344897046.13604.7.camel@schurl.lan>
	<87392qnpe8.fsf@rho.meyering.net>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.4.3 (3.4.3-1.fc17) 
Mime-Version: 1.0
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3)
X-Received-From: 212.69.161.123
Cc: bug-diffutils@gnu.org
Subject: Re: [bug-diffutils] [PATCH] diff: Encode file names with special
	characters
X-BeenThere: bug-diffutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
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, 10 Sep 2012 10:36:12 -0000

Jim,

On Mon, 2012-09-10 at 12:27 +0200, Jim Meyering wrote:
> Here's one change I would like to squash in,
> to make this function static, to adjust a type,
> to avoid an strlen call and to adjust code layout.
> Ok with you?

Yep, thanks.

Andreas



From MAILER-DAEMON Mon Sep 10 07:47:29 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TB2Sf-000373-S7
	for mharc-bug-diffutils@gnu.org; Mon, 10 Sep 2012 07:47:29 -0400
Received: from eggs.gnu.org ([208.118.235.92]:36192)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TB2SW-00035x-Gg
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 07:47:26 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TB2SQ-0003Ff-QH
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 07:47:20 -0400
Received: from mx.meyering.net ([88.168.87.75]:43353)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>)
	id 1TB2SL-0003F6-W6; Mon, 10 Sep 2012 07:47:10 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 1BE7760096;
	Mon, 10 Sep 2012 13:47:09 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Andreas Gruenbacher <agruen@gnu.org>
In-Reply-To: <1344897046.13604.7.camel@schurl.lan> (Andreas Gruenbacher's
	message of "Tue, 14 Aug 2012 00:30:46 +0200")
References: <1344897046.13604.7.camel@schurl.lan>
Date: Mon, 10 Sep 2012 13:47:09 +0200
Message-ID: <87k3w2m75u.fsf@rho.meyering.net>
Lines: 34
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: bug-diffutils@gnu.org
Subject: Re: [bug-diffutils] [PATCH] diff: Encode file names with special
	characters
X-BeenThere: bug-diffutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
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, 10 Sep 2012 11:47:26 -0000

Andreas Gruenbacher wrote:
...
> Note that the test case might not survive sending over email as it
> contains a special character.  Maybe the test case can be turned into
> plain text somehow and stay reasonably portable.
...
> diff --git a/tests/filename-quoting b/tests/filename-quoting
> new file mode 100755
> index 0000000..d06ff60

I guess the ^A (0x01) was what you meant, but I'd suggest also
replacing a couple of TABs in nearby code.  I'll be happy to
include this change in your patch:

diff --git a/tests/filename-quoting b/tests/filename-quoting
index d06ff60..e3e9193 100755
--- a/tests/filename-quoting
+++ b/tests/filename-quoting
@@ -48,9 +48,12 @@ cat <<EOF > exp || fail=1
 +one
 EOF

-echo tab > "a/	" || fail=1
-echo one > "b/" || fail=1
-diff -u "a/	" "b/" > out 2> err; test $? = 1 || fail=1
+tab=$(printf '\t')
+x01=$(printf '\001')
+
+echo tab > "a/$tab"   || fail=1
+echo one > "b/$x01" || fail=1
+diff -u "a/$tab" "b/$x01" > out 2> err; test $? = 1 || fail=1
 # Remove date and time.
 sed -e 's/^\([-+*][-+*][-+*] [^	]*\)	.*/\1/' out > k; mv k out
 compare exp out || fail=1


From MAILER-DAEMON Mon Sep 10 08:14:30 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TB2so-0003GW-0w
	for mharc-bug-diffutils@gnu.org; Mon, 10 Sep 2012 08:14:30 -0400
Received: from eggs.gnu.org ([208.118.235.92]:45219)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <agruen@gnu.org>) id 1TB2sg-0003Dl-Q7
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 08:14:28 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <agruen@gnu.org>) id 1TB2sX-0003Vw-E6
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 08:14:22 -0400
Received: from zimbra.linbit.com ([212.69.161.123]:50209)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <agruen@gnu.org>) id 1TB2sX-0003Vj-7w
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 08:14:13 -0400
Received: from localhost (localhost [127.0.0.1])
	by zimbra.linbit.com (Postfix) with ESMTP id 041E91B4386;
	Mon, 10 Sep 2012 14:14:12 +0200 (CEST)
X-Virus-Scanned: amavisd-new at zimbra.linbit.com
Received: from zimbra.linbit.com ([127.0.0.1])
	by localhost (zimbra.linbit.com [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id dmaBbzmmABSN; Mon, 10 Sep 2012 14:14:11 +0200 (CEST)
Received: from [10.9.9.71] (tuerlsteher.linbit.com [86.59.100.100])
	by zimbra.linbit.com (Postfix) with ESMTPSA id DABA81B4385;
	Mon, 10 Sep 2012 14:14:11 +0200 (CEST)
Message-ID: <1347279251.21157.4.camel@gurkel.linbit>
From: Andreas Gruenbacher <agruen@gnu.org>
To: Jim Meyering <jim@meyering.net>
Date: Mon, 10 Sep 2012 14:14:11 +0200
In-Reply-To: <87k3w2m75u.fsf@rho.meyering.net>
References: <1344897046.13604.7.camel@schurl.lan>
	<87k3w2m75u.fsf@rho.meyering.net>
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.4.3 (3.4.3-1.fc17) 
Mime-Version: 1.0
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3)
X-Received-From: 212.69.161.123
Cc: bug-diffutils@gnu.org
Subject: Re: [bug-diffutils] [PATCH] diff: Encode file names with special
	characters
X-BeenThere: bug-diffutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
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, 10 Sep 2012 12:14:28 -0000

On Mon, 2012-09-10 at 13:47 +0200, Jim Meyering wrote:
> Andreas Gruenbacher wrote:
> ...
> > Note that the test case might not survive sending over email as it
> > contains a special character.  Maybe the test case can be turned into
> > plain text somehow and stay reasonably portable.
> ...
> > diff --git a/tests/filename-quoting b/tests/filename-quoting
> > new file mode 100755
> > index 0000000..d06ff60
> 
> I guess the ^A (0x01) was what you meant, but I'd suggest also
> replacing a couple of TABs in nearby code.  I'll be happy to
> include this change [...] in your patch

Great if the printf utility is portable enough to use here.

Thanks,
Andreas



From MAILER-DAEMON Mon Sep 10 08:41:17 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TB3Ij-0005Gi-7Y
	for mharc-bug-diffutils@gnu.org; Mon, 10 Sep 2012 08:41:17 -0400
Received: from eggs.gnu.org ([208.118.235.92]:34888)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TB3Ib-0005Ex-JX
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 08:41:15 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TB3IV-0004gr-7k
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 08:41:09 -0400
Received: from mx.meyering.net ([88.168.87.75]:43499)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>)
	id 1TB3IL-0004fO-Io; Mon, 10 Sep 2012 08:40:53 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 73ED060162;
	Mon, 10 Sep 2012 14:40:52 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Andreas Gruenbacher <agruen@gnu.org>
In-Reply-To: <1347279251.21157.4.camel@gurkel.linbit> (Andreas Gruenbacher's
	message of "Mon, 10 Sep 2012 14:14:11 +0200")
References: <1344897046.13604.7.camel@schurl.lan>
	<87k3w2m75u.fsf@rho.meyering.net>
	<1347279251.21157.4.camel@gurkel.linbit>
Date: Mon, 10 Sep 2012 14:40:52 +0200
Message-ID: <87ehmam4ob.fsf@rho.meyering.net>
Lines: 358
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: bug-diffutils@gnu.org
Subject: Re: [bug-diffutils] [PATCH] diff: Encode file names with special
	characters
X-BeenThere: bug-diffutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
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, 10 Sep 2012 12:41:15 -0000

Andreas Gruenbacher wrote:

> On Mon, 2012-09-10 at 13:47 +0200, Jim Meyering wrote:
>> Andreas Gruenbacher wrote:
>> ...
>> > Note that the test case might not survive sending over email as it
>> > contains a special character.  Maybe the test case can be turned into
>> > plain text somehow and stay reasonably portable.
>> ...
>> > diff --git a/tests/filename-quoting b/tests/filename-quoting
>> > new file mode 100755
>> > index 0000000..d06ff60
>>
>> I guess the ^A (0x01) was what you meant, but I'd suggest also
>> replacing a couple of TABs in nearby code.  I'll be happy to
>> include this change [...] in your patch
>
> Great if the printf utility is portable enough to use here.

It is.  But even if it were available only in POSIX-compliant shells,
we'd be ok with using it in diff's test scripts, because tests/init.sh
ensures that each test script is run using a shell that has a certain
minimal set of capabilities (if the initial shell is inadequate, it
searches for one that is good enough and re-exec's that one).

I've made one more change, this time to NEWS:

-  File names which contain spaces, double quotes, backslashes or control
-  characters are now encoded as double quoted C string literals in the diff
-  output.  The escape sequences \\, \", \a, \b, \f, \n, \r, \t, \v, and \ooo (a
-  three-digit octal number between 0 and 255) are used.
+  A file name containing spaces, double quotes, backslashes or control
+  characters is now encoded in a diff header as a double-quoted C string
+  literal.  The escape sequences \\, \", \a, \b, \f, \n, \r, \t, \v and
+  \ooo (a three-digit octal number between 0 and 255) are used.

Here's the final change-set:

>From e17295dc5529b252c269f12e081184bbde42d575 Mon Sep 17 00:00:00 2001
From: Andreas Gruenbacher <agruen@gnu.org>
Date: Tue, 14 Aug 2012 00:30:46 +0200
Subject: [PATCH] diff: encode file names with special characters

* src/util.c (c_escape_char): New function.
(c_escape): New function.
(begin_output): Escape file names when needed.
* src/context.c (print_context_header): New names parameter.
(print_context_label): New name parameter.
* src/diff.h (print_context_header): Change prototype.
* tests/filename-quoting: New file.
* NEWS: Document this change.
---
 NEWS                   |   5 +++
 src/context.c          |  13 ++++---
 src/diff.h             |   2 +-
 src/util.c             | 101 ++++++++++++++++++++++++++++++++++++++++++++++---
 tests/Makefile.am      |   3 +-
 tests/filename-quoting |  61 +++++++++++++++++++++++++++++
 6 files changed, 172 insertions(+), 13 deletions(-)
 create mode 100755 tests/filename-quoting

diff --git a/NEWS b/NEWS
index 567fa3d..ce0d8c2 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,11 @@ GNU diffutils NEWS                                    -*- outline -*-
   --new-file (-N) and --unidirectional-new-file now allow comparisons to "-".
   A standard input that's closed acts like a nonexistent file.

+  A file name containing spaces, double quotes, backslashes or control
+  characters is now encoded in a diff header as a double-quoted C string
+  literal.  The escape sequences \\, \", \a, \b, \f, \n, \r, \t, \v and
+  \ooo (a three-digit octal number between 0 and 255) are used.
+
 ** Packaging

   diffutils is now designed to build with Cygwin or MinGW rather than DJGPP.
diff --git a/src/context.c b/src/context.c
index b73d5c3..53aa203 100644
--- a/src/context.c
+++ b/src/context.c
@@ -40,6 +40,7 @@ static lin find_function_last_match;
 static void
 print_context_label (char const *mark,
 		     struct file_data *inf,
+		     char const *name,
 		     char const *label)
 {
   if (label)
@@ -70,24 +71,24 @@ print_context_label (char const *mark,
 	      sprintf (buf, "%"PRIuMAX".%.9d", sec, nsec);
 	    }
 	}
-      fprintf (outfile, "%s %s\t%s\n", mark, inf->name, buf);
+      fprintf (outfile, "%s %s\t%s\n", mark, name, buf);
     }
 }

 /* Print a header for a context diff, with the file names and dates.  */

 void
-print_context_header (struct file_data inf[], bool unidiff)
+print_context_header (struct file_data inf[], char const *const *names, bool unidiff)
 {
   if (unidiff)
     {
-      print_context_label ("---", &inf[0], file_label[0]);
-      print_context_label ("+++", &inf[1], file_label[1]);
+      print_context_label ("---", &inf[0], names[0], file_label[0]);
+      print_context_label ("+++", &inf[1], names[1], file_label[1]);
     }
   else
     {
-      print_context_label ("***", &inf[0], file_label[0]);
-      print_context_label ("---", &inf[1], file_label[1]);
+      print_context_label ("***", &inf[0], names[0], file_label[0]);
+      print_context_label ("---", &inf[1], names[1], file_label[1]);
     }
 }

diff --git a/src/diff.h b/src/diff.h
index 4b6595c..212a8d0 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -332,7 +332,7 @@ XTERN FILE *outfile;
 extern int diff_2_files (struct comparison *);

 /* context.c */
-extern void print_context_header (struct file_data[], bool);
+extern void print_context_header (struct file_data[], char const * const *, bool);
 extern void print_context_script (struct change *, bool);

 /* dir.c */
diff --git a/src/util.c b/src/util.c
index 38b33ef..868b7e8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -166,24 +166,110 @@ setup_output (char const *name0, char const *name1, bool recursive)
 static pid_t pr_pid;
 #endif

+static char c_escape_char (char c)
+{
+  switch (c) {
+    case '\a': return 'a';
+    case '\b': return 'b';
+    case '\t': return 't';
+    case '\n': return 'n';
+    case '\v': return 'v';
+    case '\f': return 'f';
+    case '\r': return 'r';
+    case '"': return '"';
+    case '\\': return '\\';
+    default:
+      return c < 32;
+  }
+}
+
+static char *
+c_escape (char const *str)
+{
+  char const *s;
+  size_t plus = 0;
+  bool must_quote = false;
+
+  for (s = str; *s; s++)
+    {
+      char c = *s;
+
+      if (c == ' ')
+	{
+	  must_quote = true;
+	  continue;
+	}
+      switch (c_escape_char (*s))
+	{
+	  case 1:
+	    plus += 3;
+	    /* fall through */
+	  case 0:
+	    break;
+	  default:
+	    plus++;
+	    break;
+	}
+    }
+
+  if (must_quote || plus)
+    {
+      size_t s_len = s - str;
+      char *buffer = xmalloc (s_len + plus + 3);
+      char *b = buffer;
+
+      *b++ = '"';
+      for (s = str; *s; s++)
+	{
+	  char c = *s;
+	  char escape = c_escape_char (c);
+
+	  switch (escape)
+	    {
+	      case 0:
+		*b++ = c;
+		break;
+	      case 1:
+		*b++ = '\\';
+		*b++ = ((c >> 6) & 03) + '0';
+		*b++ = ((c >> 3) & 07) + '0';
+		*b++ = ((c >> 0) & 07) + '0';
+		break;
+	      default:
+		*b++ = '\\';
+		*b++ = escape;
+		break;
+	    }
+	}
+      *b++ = '"';
+      *b = 0;
+      return buffer;
+    }
+
+  return (char *) str;
+}
+
 void
 begin_output (void)
 {
+  char *names[2];
   char *name;

   if (outfile != 0)
     return;

+  names[0] = c_escape (current_name0);
+  names[1] = c_escape (current_name1);
+
   /* Construct the header of this piece of diff.  */
-  name = xmalloc (strlen (current_name0) + strlen (current_name1)
-		  + strlen (switch_string) + 7);
+  name = xmalloc (strlen (names[0]) + strlen (names[1]) + strlen (switch_string) + 7);

   /* POSIX 1003.1-2001 specifies this format.  But there are some bugs in
      the standard: it says that we must print only the last component
      of the pathnames, and it requires two spaces after "diff" if
      there are no options.  These requirements are silly and do not
      match historical practice.  */
-  sprintf (name, "diff%s %s %s", switch_string, current_name0, current_name1);
+  sprintf (name, "diff%s %s %s", switch_string, names[0], names[1]);

   if (paginate)
     {
@@ -258,16 +344,21 @@ begin_output (void)
   switch (output_style)
     {
     case OUTPUT_CONTEXT:
-      print_context_header (files, false);
+      print_context_header (files, (char const *const *)names, false);
       break;

     case OUTPUT_UNIFIED:
-      print_context_header (files, true);
+      print_context_header (files, (char const *const *)names, true);
       break;

     default:
       break;
     }
+
+  if (names[0] != current_name0)
+    free (names[0]);
+  if (names[1] != current_name1)
+    free (names[1]);
 }

 /* Call after the end of output of diffs for one file.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index afc9aad..c9b59e5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -11,7 +11,8 @@ TESTS = \
   new-file \
   no-dereference \
   no-newline-at-eof \
-  stdin
+  stdin \
+  filename-quoting

 EXTRA_DIST = \
   $(TESTS) init.sh t-local.sh
diff --git a/tests/filename-quoting b/tests/filename-quoting
new file mode 100755
index 0000000..e3e9193
--- /dev/null
+++ b/tests/filename-quoting
@@ -0,0 +1,61 @@
+#!/bin/sh
+# filename quoting
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+fail=0
+
+cat <<EOF > exp- || fail=1
+diff -N -r "a/ " "b/ "
+0a1
+> space
+EOF
+
+cat <<EOF > exp--u || fail=1
+diff -N -r -u "a/ " "b/ "
+--- "a/ "
++++ "b/ "
+@@ -0,0 +1 @@
++space
+EOF
+
+cat <<EOF > exp--c || fail=1
+diff -N -r -c "a/ " "b/ "
+*** "a/ "
+--- "b/ "
+***************
+*** 0 ****
+--- 1 ----
++ space
+EOF
+
+mkdir a b
+echo space > "b/ " || fail=1
+for opt in '' -u -c; do
+  diff -N -r $opt a b > out 2> err; test $? = 1 || fail=1
+  # Remove date and time.
+  sed -e 's/^\([-+*][-+*][-+*] [^	]*\)	.*/\1/' out > k; mv k out
+  compare exp-$(echo $opt|tr ' ' _) out || fail=1
+done
+
+rm -f "b/ "
+
+cat <<EOF > exp || fail=1
+--- "a/\t"
++++ "b/\001"
+@@ -1 +1 @@
+-tab
++one
+EOF
+
+tab=$(printf '\t')
+x01=$(printf '\001')
+
+echo tab > "a/$tab"   || fail=1
+echo one > "b/$x01" || fail=1
+diff -u "a/$tab" "b/$x01" > out 2> err; test $? = 1 || fail=1
+# Remove date and time.
+sed -e 's/^\([-+*][-+*][-+*] [^	]*\)	.*/\1/' out > k; mv k out
+compare exp out || fail=1
+
+Exit $fail
--
1.7.12.289.g0ce9864


From MAILER-DAEMON Mon Sep 10 08:43:10 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TB3KY-0005RL-KQ
	for mharc-bug-diffutils@gnu.org; Mon, 10 Sep 2012 08:43:10 -0400
Received: from eggs.gnu.org ([208.118.235.92]:35383)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TB3KS-0005Ql-Oy
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 08:43:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1TB3KM-0005Aq-WA
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 08:43:04 -0400
Received: from mx.meyering.net ([88.168.87.75]:43505)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>)
	id 1TB3KH-0005A6-VN; Mon, 10 Sep 2012 08:42:54 -0400
Received: from rho.meyering.net (rho.meyering.net [127.0.0.1])
	by rho.meyering.net (Acme Bit-Twister) with ESMTP id 3D0B760162;
	Mon, 10 Sep 2012 14:42:53 +0200 (CEST)
From: Jim Meyering <jim@meyering.net>
To: Andreas Gruenbacher <agruen@gnu.org>
In-Reply-To: <1347279251.21157.4.camel@gurkel.linbit> (Andreas Gruenbacher's
	message of "Mon, 10 Sep 2012 14:14:11 +0200")
References: <1344897046.13604.7.camel@schurl.lan>
	<87k3w2m75u.fsf@rho.meyering.net>
	<1347279251.21157.4.camel@gurkel.linbit>
Date: Mon, 10 Sep 2012 14:42:53 +0200
Message-ID: <878vcim4ky.fsf@rho.meyering.net>
Lines: 79
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 88.168.87.75
Cc: bug-diffutils@gnu.org
Subject: Re: [bug-diffutils] [PATCH] diff: Encode file names with special
	characters
X-BeenThere: bug-diffutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
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, 10 Sep 2012 12:43:09 -0000

Andreas Gruenbacher wrote:

> On Mon, 2012-09-10 at 13:47 +0200, Jim Meyering wrote:
>> Andreas Gruenbacher wrote:
>> ...
>> > Note that the test case might not survive sending over email as it
>> > contains a special character.  Maybe the test case can be turned into
>> > plain text somehow and stay reasonably portable.
>> ...
>> > diff --git a/tests/filename-quoting b/tests/filename-quoting
>> > new file mode 100755
>> > index 0000000..d06ff60
>>
>> I guess the ^A (0x01) was what you meant, but I'd suggest also
>> replacing a couple of TABs in nearby code.  I'll be happy to
>> include this change [...] in your patch
>
> Great if the printf utility is portable enough to use here.

And since I noticed an xmalloc+sprintf combo while reviewing your
changes (your change merely modified an existing one), I wrote
this to replace that with a use of asprintf.  It is much more
maintainable that way:

>From 221383bcb1f9de839727b6ffd1b5a2b725314779 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Mon, 10 Sep 2012 12:18:59 +0200
Subject: [PATCH] maint: use xasprintf in place of xmalloc+sprintf

* bootstrap.conf (gnulib_modules): Add gnulib's xvasprintf module.
* src/util.c: Include "xvasprintf.h".
(begin_output): Use xasprintf in place of xmalloc+sprintf.
---
 bootstrap.conf | 1 +
 src/util.c     | 5 ++---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 3954c4d..81b318e 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -81,6 +81,7 @@ xalloc
 xfreopen
 xreadlink
 xstrtoumax
+xvasprintf
 '

 # Additional xgettext options to use.  Use "\\\newline" to break lines.
diff --git a/src/util.c b/src/util.c
index 868b7e8..c02d156 100644
--- a/src/util.c
+++ b/src/util.c
@@ -23,6 +23,7 @@
 #include <error.h>
 #include <system-quote.h>
 #include <xalloc.h>
+#include "xvasprintf.h"

 char const pr_program[] = PR_PROGRAM;

@@ -262,14 +263,12 @@ begin_output (void)
   names[1] = c_escape (current_name1);

   /* Construct the header of this piece of diff.  */
-  name = xmalloc (strlen (names[0]) + strlen (names[1]) + strlen (switch_string) + 7);
-
   /* POSIX 1003.1-2001 specifies this format.  But there are some bugs in
      the standard: it says that we must print only the last component
      of the pathnames, and it requires two spaces after "diff" if
      there are no options.  These requirements are silly and do not
      match historical practice.  */
-  sprintf (name, "diff%s %s %s", switch_string, names[0], names[1]);
+  name = xasprintf ("diff%s %s %s", switch_string, names[0], names[1]);

   if (paginate)
     {
--
1.7.12.289.g0ce9864


From MAILER-DAEMON Mon Sep 10 17:00:46 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TBB66-0003MJ-Ac
	for mharc-bug-diffutils@gnu.org; Mon, 10 Sep 2012 17:00:46 -0400
Received: from eggs.gnu.org ([208.118.235.92]:56048)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <eggert@cs.ucla.edu>) id 1TBB64-0003Jx-2U
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 17:00:44 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <eggert@cs.ucla.edu>) id 1TBB62-0003Bk-Nr
	for bug-diffutils@gnu.org; Mon, 10 Sep 2012 17:00:43 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:51436)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <eggert@cs.ucla.edu>)
	id 1TBB60-0003BC-S3; Mon, 10 Sep 2012 17:00:40 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
	by smtp.cs.ucla.edu (Postfix) with ESMTP id 499C639E8014;
	Mon, 10 Sep 2012 14:00:40 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
	by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id dVsl4+31ZHS1; Mon, 10 Sep 2012 14:00:40 -0700 (PDT)
Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200])
	by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 0148939E8008;
	Mon, 10 Sep 2012 14:00:39 -0700 (PDT)
Message-ID: <504E54F7.6000405@cs.ucla.edu>
Date: Mon, 10 Sep 2012 14:00:39 -0700
From: Paul Eggert <eggert@cs.ucla.edu>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:15.0) Gecko/20120828 Thunderbird/15.0
MIME-Version: 1.0
To: Jim Meyering <jim@meyering.net>
References: <1344897046.13604.7.camel@schurl.lan>
	<87k3w2m75u.fsf@rho.meyering.net>
	<1347279251.21157.4.camel@gurkel.linbit>
	<878vcim4ky.fsf@rho.meyering.net>
In-Reply-To: <878vcim4ky.fsf@rho.meyering.net>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3)
X-Received-From: 131.179.128.62
Cc: bug-diffutils@gnu.org
Subject: Re: [bug-diffutils] [PATCH] diff: Encode file names with special
	characters
X-BeenThere: bug-diffutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
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, 10 Sep 2012 21:00:45 -0000

On 09/10/2012 05:42 AM, Jim Meyering wrote:
> -  sprintf (name, "diff%s %s %s", switch_string, names[0], names[1]);
> +  name = xasprintf ("diff%s %s %s", switch_string, names[0], names[1]);
> 
>    if (paginate)

Could I suggest migrating that assignment to 'name'
so that it's inside the then-part of the 'if (paginate)'?
That way, the else-part can call printf instead of
xasprintf, without worrying about memory allocation,
and the memory allocation is needed only in the rare
case when the --paginate option is used.


From MAILER-DAEMON Wed Sep 12 10:22:53 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1TBnq9-0005ci-6T
	for mharc-bug-diffutils@gnu.org; Wed, 12 Sep 2012 10:22:53 -0400
Received: from eggs.gnu.org ([208.118.235.92]:60066)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <andreas.gruenbacher@gmail.com>) id 1TBnq1-0005cS-Kw
	for bug-diffutils@gnu.org; Wed, 12 Sep 2012 10:22:51 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <andreas.gruenbacher@gmail.com>) id 1TBnpv-0000Dt-VB
	for bug-diffutils@gnu.org; Wed, 12 Sep 2012 10:22:45 -0400
Received: from mail-lpp01m010-f41.google.com ([209.85.215.41]:63536)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <andreas.gruenbacher@gmail.com>)
	id 1TBnpn-0000Bz-57; Wed, 12 Sep 2012 10:22:31 -0400
Received: by lahd3 with SMTP id d3so1243386lah.0
	for <multiple recipients>; Wed, 12 Sep 2012 07:22:26 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=mime-version:sender:date:x-google-sender-auth:message-id:subject
	:from:to:cc:content-type;
	bh=MobATkDFdATVmm52/UlNNScNjqB+OYv1r1D9y9Ig9kU=;
	b=hCtJ5vqkF3ILt/9MNdIbYON89MevQCxPy4jXImoEcqwn9l2blQG8O2eL9FWMHsXELz
	pXwm0Lfe6aMm3dRZLs6PzAibx5FT/9wzz4TaoA2xuQ4J4bcgIdhcbz1ed+G0Aatdw0E9
	P0aCp2halcrMXrqS2lKY4ntnC9hpb8Pj6n0rRXqyCew8gcay5nHf4o6owoVyDoUMjp9G
	st3XzlGZQuK5v9DWPv6oXFqsB2gjJOBKR+z5tJ6UX3Hq6OklbfZtIm1Z0DyIcftq0Kea
	Hy6X6FkxG2y7+hSpeNEjq8hkUZ72WI4Z/q8Dq4pOKX1awqH3qd9NwQhSXuCiG/qDXqt4
	nu7g==
MIME-Version: 1.0
Received: by 10.112.30.34 with SMTP id p2mr7527499lbh.85.1347459746781; Wed,
	12 Sep 2012 07:22:26 -0700 (PDT)
Sender: andreas.gruenbacher@gmail.com
Received: by 10.112.54.180 with HTTP; Wed, 12 Sep 2012 07:22:26 -0700 (PDT)
Date: Wed, 12 Sep 2012 16:22:26 +0200
X-Google-Sender-Auth: 6he94XOzEmclUj_n9ldHneSi1D0
Message-ID: <CAHpGcMKsLkyrxDBe8t2owdjtkk0dnpONRrQDDB9UcdctSK35jg@mail.gmail.com>
From: =?ISO-8859-1?Q?Andreas_Gr=FCnbacher?= <agruen@gnu.org>
To: bug-patch@gnu.org
Content-Type: text/plain; charset=ISO-8859-1
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 209.85.215.41
Cc: bug-diffutils@gnu.org, git@vger.kernel.org
Subject: [bug-diffutils] GNU patch version 2.7 released
X-BeenThere: bug-diffutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: "All diffutils discussion." <bug-diffutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-diffutils>
List-Post: <mailto:bug-diffutils@gnu.org>
List-Help: <mailto:bug-diffutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-diffutils>,
	<mailto:bug-diffutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 12 Sep 2012 14:22:51 -0000

I am pleased to announce that version 2.7 of GNU patch has been
released. The following significant changes have happened since the
last stable release in December 2009:

* Support for most features of the "diff --git" format, including renames and
  copies, permission changes, and symlink diffs.  Binary diffs are not
  supported yet; patch will complain and skip them.

* Support for double-quoted filenames: when a filename starts with a double
  quote, it is interpreted as a C string literal.  The escape sequences \\, \",
  \a, \b, \f, \n, \r, \t, \v, and \ooo (a three-digit octal number between 0 and
  255) are recognized.

* Ignore destination file names that are absolute or that contain a component
  of "..".  This addresses CVE-2010-4651.

* Refuse to apply a normal patch to a symlink.  (Previous versions of patch
  were replacing the symlink with a regular file.)

* When trying to modify a read-only file, warn about the potential problem
  by default.  The --read-only command line option allows to change this
  behavior.

* Files to be deleted are deleted once the entire input has been processed, not
  immediately.  This fixes a bug with numbered backup files.

* When a timestamp specifies a time zone, honor that instead of assuming the
  local time zone (--set-date) or Universal Coordinated Time (--set-utc).

* Support for nanosecond precision timestamps.

* Patch no longer gets a failed assertion for certain mangled patches.

* Many portability and bug fixes.

Release tarballs are available at:

  ftp://ftp.gnu.org/gnu/patch/

Please report bugs or suggestions on the <bug-patch@gnu.org> mailing list, or
in the project's bug tracker on Savannah:

  http://savannah.gnu.org/projects/patch

Thanks,
Andreas


From MAILER-DAEMON Thu Sep 27 16:27:29 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1THKgD-0008LA-2r
	for mharc-bug-diffutils@gnu.org; Thu, 27 Sep 2012 16:27:29 -0400
Received: from eggs.gnu.org ([208.118.235.92]:34729)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bbell@robin.thebellsplace.net>) id 1THKIU-0002rU-Nw
	for bug-diffutils@gnu.org; Thu, 27 Sep 2012 16:03:02 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <bbell@robin.thebellsplace.net>) id 1THKIM-0008Uc-5u
	for bug-diffutils@gnu.org; Thu, 27 Sep 2012 16:02:58 -0400
Received: from srv08.macroped.com ([74.54.75.218]:51550)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bbell@robin.thebellsplace.net>) id 1THKIL-0008UY-VZ
	for bug-diffutils@gnu.org; Thu, 27 Sep 2012 16:02:50 -0400
Received: from c-75-68-118-125.hsd1.nh.comcast.net ([75.68.118.125]:55036
	helo=robin) by srv08.macroped.com with esmtp (Exim 4.77)
	(envelope-from <bbell@robin.thebellsplace.net>) id 1THJI2-0007pm-5z
	for bug-diffutils@gnu.org; Thu, 27 Sep 2012 14:58:26 -0400
Received: by robin (Postfix, from userid 1000)
	id F0915200A58; Thu, 27 Sep 2012 14:58:44 -0400 (EDT)
Date: Thu, 27 Sep 2012 14:58:44 -0400
From: Bob Bell <b_diffutils@thebellsplace.com>
To: bug-diffutils@gnu.org
Message-ID: <20120927185844.GK5273@robin.thebellsplace.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
X-Editor: Vim http://www.vim.org/
User-Agent: Mutt/1.5.21 (2010-09-15)
X-AntiAbuse: This header was added to track abuse,
	please include it with any abuse report
X-AntiAbuse: Primary Hostname - srv08.macroped.com
X-AntiAbuse: Original Domain - gnu.org
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - robin.thebellsplace.net
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3)
X-Received-From: 74.54.75.218
X-Mailman-Approved-At: Thu, 27 Sep 2012 16:27:27 -0400
Subject: [bug-diffutils] Getting all versions, but skipping overlaps
X-BeenThere: bug-diffutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
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, 27 Sep 2012 20:03:02 -0000

Recently, I've started using the "-A" option to merge / diff3, so that 
when there's a merge conflict, I get the "ancestor" version as well as 
both changes.  Not to overstate things, but I've found that this has 
completely transformed my experience resolving source code merge 
conflicts, as the information I have at hand is SO much more helpful.  
With regards to the diff3.c source code, I believe that the option that 
I really appreciate is "diff_2nd".

However, one thing I'd often still like to do is to ignore cases where 
there are identical changes made.  That is, for a block of code, there's 
a difference between FILEC and FILE0, as well as between FILEC and 
FILE1, but the blocks in FILE0 and FILE1 are identical.

When I use diff3 with "-A", this appears as a bracketed conflict, with 
the labelled blocks from FILEC and FILE1.  I don't get the "|||||||" 
marker or the identical block from FILE0, so it's fairly easy to 
identify this case.  But when resolving a merge, it still needs to be 
"cleaned up".

It appears that diff3 supports a "-x" or "-X" option to select 
"overlap_only", which would ignore these non-overlapping changes.  
However, the code enforces that I cannot select "-A" with either "-x" or 
"-X", and "-A" appears the only way to select "diff_2nd", so that it 
outputs the version of the block from FILE2/FILEC.  For example, I can 
pass "-m" and "-X", but then I will not get the block of code from 
FILEC, losing the information that I value so dearly.

In summary, I believe what I'd really like is to display the merges 
file, bracketing the conflicting changes, NOT including when FILE0 and 
FILE1 made identical changes, but when there *IS* a conflicting change, 
I'd like to see FILE0, FILE1 *and* FILE2/FILEC.

Is this possible?

Thanks,
Bob

P.S. I apologize for all the terminology I may have used incorrectly...


