Bug 259636 - [Patch] "Apply patch" adds an empty line at the end of a file
Summary: [Patch] "Apply patch" adds an empty line at the end of a file
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Compare (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows Vista
: P5 minor (vote)
Target Milestone: ---   Edit
Assignee: Platform-Compare-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-24 09:18 EST by Krzysztof Pog這dzi雟ki CLA
Modified: 2022-02-24 08:06 EST (History)
4 users (show)

See Also:


Attachments
example_v01 (125 bytes, text/plain)
2008-12-24 09:18 EST, Krzysztof Pog這dzi雟ki CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Krzysztof Pog這dzi雟ki CLA 2008-12-24 09:18:32 EST
Created attachment 121217 [details]
example_v01

There is a difference between Unix "patch" command and Eclipse "apply patch".
Steps to reproduce:
1. Take the example from attachment
2. Apply it in Eclipse to any empty file, using "Apply patch"
3. Apply it to empty file using Unix "patch" command

Result:
A. When using "Apply patch" You will get a file containing 2 lines, one with "xxx" and another one empty.
B. When using "patch" command You will get a file containing 1 line with "xxx" (no newline at end of file).

Unix 'diff' and 'patch' commands does not use '/no newline at end of file'
marker. They are using the basic '+' and '-' to give all the information.

So Eclipse 'apply patch' isn't fully compatible with Unix 'diff -u' command.
Comment 1 Krzysztof Pog這dzi雟ki CLA 2009-01-06 17:59:42 EST
Incomplete lines with GNU diff is described here:
http://www.network-theory.co.uk/docs/diff/Incomplete_Lines.html

According to:
http://www.network-theory.co.uk/docs/diff/Line_Formats.html
we may read:
"The default line format is ‘%l’ followed by a newline character"

Eclipse use as default '%L' line format, and this is the reason, why Eclipse and GNU diff aren't fully compatible.
Comment 2 Krzysztof Pog這dzi雟ki CLA 2009-01-06 18:02:11 EST
Sorry for problems with encoding.
Corrected line:
(...)
"The default line format is '%l' followed by a newline character"
(...)
Comment 3 Tomasz Zarna CLA 2009-01-13 04:10:33 EST
If you want to fix this issue I believe you should start from looking at the PatchReader[1] class. Then you could identify the piece of code responsible for processing the last line of a file in the patch. I guess we wouldn't get away with changing the way apply patch works but when you isolate the code for it we could replace it with something like this:

if (true) {
   // expect "no newline" marker at the end of a file
} else {
   // parse the patch using default settings for unified diff format
}

In the future we could replace the "true" with a preference or even invert the statement.

[1] org.eclipse.compare.internal.core.patch.PatchReader
Comment 4 Eclipse Webmaster CLA 2019-09-06 16:18:47 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 5 Eclipse Genie CLA 2022-02-24 08:06:42 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.