Bug 116023

Summary: [Patch] Create Patch ignores lines at end of file
Product: [Eclipse Project] Platform Reporter: Philip Mayer <eclipsetalk2>
Component: CVSAssignee: Tomasz Zarna <tomasz.zarna>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: benno.baumgartner, markus.kell.r, martinae, pawel.pogorzelski1, tobias_widmer
Version: 3.2   
Target Milestone: 3.5 M2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Fix v01
none
mylyn/context/zip none

Description Philip Mayer CLA 2005-11-11 10:17:19 EST
Build id: I20051108-1011

Steps:
1. Create a java class in a cvs project. Leave a new line (CR) after the last
"}" in the file. Create a patch for the file. 
2. Remove the newline after the last "}" in the file. Create a patch again.

-> Observe: Both(!) patches do not include the new line (CR) at the end of the file.

Now, re-apply the patches. In both cases (obviously, since the patch files are
identical), a new line (CR) is added after the last "}".

I would expect newlines to be exactly the way they were when creating a patch
and re-applying it. This is a problem when providing patches with new files for
refactoring test cases, as the resulting files do not match anymore.
Comment 1 Markus Keller CLA 2007-05-23 12:37:58 EDT
Just stumbled over this again. A target milestone of 3.4 would be much appreciated.
Comment 2 Michael Valenta CLA 2007-05-23 13:26:45 EDT
OK
Comment 3 Markus Keller CLA 2007-05-23 13:40:56 EDT
Thanks :-)
Comment 4 Szymon Brandys CLA 2008-05-09 04:23:11 EDT
Mass update - removing 3.4 target. This was one of the bugs marked for
investigation (and potential fixing) in 3.4 but we ran out of time. Please ping
on the bug if fixing it would be really important for 3.4, and does not require
API changes or feature work.
Comment 5 Markus Keller CLA 2008-05-21 12:51:02 EDT
Please fix for 3.5. We fall into this trap in every release cycle (this time, it was bug 102020).
Comment 6 Tomasz Zarna CLA 2008-08-12 07:15:14 EDT
Created attachment 109774 [details]
Fix v01

The problem here was caused by the fact that when adding new files fileReader#readLine used in DiffOperation#addFileToDiff gave us no information if a read line had a line ending character. The patch changes it, so the last line for an added file is now carefully scanned (char by char) and if it doesn't have CR or LF an extra line is added which informs about that fact (ie "\ \ No newline at end of file").

There is one more thing, the patching mechanism (LineReader to be more precise) uses a flag called "ignoreSingleCR" which when set to true doesn't treat single CR's as line delimiters. I turned this off, but I think it should has the same value as the one used while patching (which is on "to be consistent with command line patch").
Comment 7 Tomasz Zarna CLA 2008-08-12 07:15:20 EDT
Created attachment 109775 [details]
mylyn/context/zip
Comment 8 Tomasz Zarna CLA 2008-08-19 06:38:10 EDT
Released to HEAD. Please let me know if this fixes the issues you had, have or would have when creating patches.
Comment 9 Pawel Pogorzelski CLA 2008-09-18 11:25:15 EDT
Verified on build I20080918-0100.