This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch, diff, and line-endings


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]