[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [jgit-dev] JGit ApplyCommand
- From: Tomasz Zarna <tzarna@xxxxxxxxx>
- Date: Mon, 11 Jun 2012 17:50:37 +0200
- Delivered-to: firstname.lastname@example.org
Nice catch! Could you add a failing test which gets better with your
On Mon, Jun 11, 2012 at 5:32 PM, Markus Duft <markus.duft@xxxxxxxxxx> wrote:
> On 06/11/2012 05:26 PM, Markus Duft wrote:
>> On 06/11/2012 05:19 PM, Markus Duft wrote:
>>> I just got into some troubles, as i'm using ApplyCommand programmatically to apply patches to our repo - it destroyed line endings :/
>>> Here is what i found out:
>>> ApplyCommand uses RawText to extract lines from the given file to patch. RawText only supports UNIX style line endings. The File i want to patch has windows line endings. The patch in general has UNIX endings, but the hunk data (diff) to be applied has the windows line endings too (so that should all be ok).
>>> Now ApplyCommand extracts lines from the target file. Every line in the resulting array has \r as the last character. So far so good. Now after application of the patch, ApplyCommand calculates the target line ending it should use, by extracting the line ending from the first line of the source file. This is "\r\n" -> windows. Now it appends all lines + the line ending to a buffer, and writes that back to the file. The result is "\r\r\n" -> ARGH...
>>> There are two possible ways to fix this IMHO: either remove the \r in the first place, or don't fiddle with line endings at all and treat all as UNIX -> append '\n' only always, and don't detect it; both would result in the same (correct) output file.
>> sorry - command back; i just realized that removing \r makes the application fail ;) only way to resolve this is to only apply \n always. i'll push a change after more testing
> unit tests are ok, and field tests also showed good results on all patches i tried with the modified version:
>>> What would be the better one? i will push a change if you tell me.
>>> jgit-dev mailing list
>> jgit-dev mailing list
> jgit-dev mailing list