Skip to main content

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

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.

What would be the better one? i will push a change if you tell me.

Regards,
Markus


Back to the top