bugGNU patch - Bugs: bug #28133, patch: Cannot handle diffs with...

 
 

bug #28133: patch: Cannot handle diffs with CRLF line endings

Submitter:  Christoph Berg <myon>
Submitted:  Mon 30 Nov 2009 04:46:14 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 29 Dec 2009 07:04:20 PM UTC, comment #1: 

Commit ab59a14 fixed a bug in CRLF handling for normal diffs which you are running into here: the CR stripping heuristic should not have triggered here (only the < and > lines of the patch end in CRLF).

In case the entire patch has CRLF line endings, the CR stripping heuristic will trigger, but it can be explicitly disabled using the --binary option.

I have updated the documentation of the --binary option, hopefully that's an improvement:

--binary
 Write all files in binary mode, except for standard output
 and /dev/tty. When reading, disable the heuristic for
 transforming CRLF line endings into LF line endings. This
 option is needed on POSIX systems when applying patches
 generated on non-POSIX systems to non-POSIX files. (On POSIX
 systems, file reads and writes never transform line endings.
 On Windows, reads and writes do transform line endings by
 default, and patches should be generated by diff --binary when
 line endings are significant.)

Andreas Gruenbacher <agruen>
Group administrator
Mon 30 Nov 2009 04:46:14 PM UTC, original submission:  

From http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=484539 :

From: Christoph Biedl <debian.packages.hhqj@manchmal.in-ulm.de>
To: -email is unavailable-
Subject: patch: Cannot handle diffs with CRLF line endings
Date: Wed, 4 Jun 2008 21:20:36 +0200

Package: patch
Version: 2.5.9-5
Severity: normal

I had some trouble applying a patch that was created using diff between
two files with CRLF line endings.  That process is out of my control
and cannot be changed.

As far as I can tell, the created diff has CRLF line endings like the
files; patch however drops the CR first but fails find a matching line
in the file to be patched then as the CR still exists there.

How to repeat:

$ echo -e "foo\r\nbar\r\nbaz\r\n" > rev.1
$ echo -e "foo\r\nbAr\r\nbaz\r\n" > rev.2
$ diff rev.1 rev.2 >diff
$ patch rev.1 diff
(Stripping trailing CRs from patch.)
patching file rev.1
Hunk #1 FAILED at 2.
1 out of 1 hunk FAILED -- saving rejects to file rev.1.rej
$

Workaround: Remove the CR characters from to file to be patched before
running patch (tr -d '\r'), optionally also from the diff.

This cannot be cured easily as far as I can tell from the sources. Could
you please at least document it in the BUGS section so other people can
save the time I spent hunting down the problem?

Thanks,

    Christoph


Christoph Berg <myon>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by agruen (Posted a comment)
  • -email is unavailable- added by myon (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-12-29 agruen StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code