[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] JGit ApplyCommand

Hi Markus,

Nice catch! Could you add a failing test which gets better with your
fix applied?

Cheers,
Tomasz

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:
>>> Hey!
>>>
>>> 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:
>
> https://git.eclipse.org/r/#/c/6314/
>
> Regards,
> Markus
>
>>
>> Markus
>>
>>>
>>> What would be the better one? i will push a change if you tell me.
>>>
>>> Regards,
>>> Markus
>>> _______________________________________________
>>> jgit-dev mailing list
>>> jgit-dev@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/jgit-dev
>> _______________________________________________
>> jgit-dev mailing list
>> jgit-dev@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/jgit-dev
> _______________________________________________
> jgit-dev mailing list
> jgit-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/jgit-dev