delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/03/16/14:15:49

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=0.4 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
From: David Eisner <deisner AT gmail DOT com>
Date: Tue, 16 Mar 2010 15:15:13 -0400
Message-ID: <5ef8ba411003161215g7844d7edi6412ca57e5eb6e3d@mail.gmail.com>
Subject: Patch, diff, and line-endings
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

I'm running into a problem when applying patches.  Here's a toy
example.  I have a file, test.txt, with a one line change. I use diff
-u to generate a patch, and then I use patch to apply it.

With unix-style line-endings (\n), everything works fine:

$ file {a,b}/test.txt
a/test.txt: ASCII text
b/test.txt: ASCII text
$ diff -u a/test.txt b/test.txt > unix.patch
$ cat unix.patch
--- a/test.txt  2010-03-16 14:22:03.299682800 -0400
+++ b/test.txt  2010-03-16 14:21:32.749628100 -0400
@@ -1,3 +1,3 @@
 This is
-a 3 line
+a three line
 file
$ patch --verbose --dry-run -p0 < unix.patch
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- a/test.txt 2010-03-16 14:22:03.299682800 -0400
|+++ b/test.txt 2010-03-16 14:21:32.749628100 -0400
--------------------------
Patching file a/test.txt using Plan A...
Hunk #1 succeeded at 1.
done
$

But with dos-style line-endings (\r\n), the patch fails:

$ file {a,b}/test.txt
a/test.txt: ASCII text, with CRLF line terminators
b/test.txt: ASCII text, with CRLF line terminators
$ diff -u a/test.txt b/test.txt > dos.patch
$ cat dos.patch
--- a/test.txt  2010-03-16 14:23:44.863838200 -0400
+++ b/test.txt  2010-03-16 14:23:52.424594200 -0400
@@ -1,3 +1,3 @@
 This is
-a 3 line
+a three line
 file
$ patch --verbose --dry-run -p0 < dos.patch
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- a/test.txt 2010-03-16 14:23:44.863838200 -0400
|+++ b/test.txt 2010-03-16 14:23:52.424594200 -0400
--------------------------
Patching file a/test.txt using Plan A...
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file a/test.txt.rej
done
$

Shouldn't this work, regardless of the line-ending type?  Note that I
have my filesystems mounted in binary mode (the default), not text
mode. Should this matter?

I'm using Cygwin 1.7.1 on Vista SP2, and the latest Cygwin versions of
diff (2.8.7) and patch (2.5.8).

I repeated the same experiment on a Solaris 10 box with GNU diff 2.8.1
and GNU patch 2.5.4, and it worked fine, with both unix- and dos-style
line endings.

-David

-- 
David Eisner     http://cradle.brokenglass.com

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019