diff options
author | Markus Duft <markus.duft@salomon.at> | 2012-06-12 07:02:58 +0200 |
---|---|---|
committer | Robin Rosenberg <robin.rosenberg@dewire.com> | 2013-01-19 13:29:02 +0100 |
commit | 3d18f65af1341bc1ebc8c5c1e92726d701e5a55e (patch) | |
tree | 4574852ddd65687155c6e99dd3a6cca163441606 /org.eclipse.jgit/src/org/eclipse | |
parent | 3f0176aea6e77cb39be35f091100f8874693593d (diff) | |
download | jgit-3d18f65af1341bc1ebc8c5c1e92726d701e5a55e.tar.gz jgit-3d18f65af1341bc1ebc8c5c1e92726d701e5a55e.zip |
Fix patch application WRT windows line endings.
Previously the result of an application would have been \r\r\n in the
case of windows line endings, as RawText does not touch the \r, and
ApplyCommand adds "\r\n" if this is the ending of the first line in the
target file. Only always adding \n should be ok, since \r\n would be the
result if the file and the patch include windows line endings.
Also add according test.
Change-Id: Ibd4c4948d81bd1c511ecf5fd6c906444930d236e
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java index 2147a2e5c4..6a945e4d39 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java @@ -238,13 +238,10 @@ public class ApplyCommand extends GitCommand<ApplyResult> { if (!isChanged(oldLines, newLines)) return; // don't touch the file StringBuilder sb = new StringBuilder(); - final String eol = rt.size() == 0 - || (rt.size() == 1 && rt.isMissingNewlineAtEnd()) ? "\n" : rt //$NON-NLS-1$ - .getLineDelimiter(); for (String l : newLines) { - sb.append(l); - if (eol != null) - sb.append(eol); + // don't bother handling line endings - if it was windows, the \r is + // still there! + sb.append(l).append('\n'); } sb.deleteCharAt(sb.length() - 1); FileWriter fw = new FileWriter(f); @@ -252,7 +249,7 @@ public class ApplyCommand extends GitCommand<ApplyResult> { fw.close(); } - private boolean isChanged(List<String> ol, List<String> nl) { + private static boolean isChanged(List<String> ol, List<String> nl) { if (ol.size() != nl.size()) return true; for (int i = 0; i < ol.size(); i++) |