Browse Source

Merge "Fix patch application WRT windows line endings."

stable-2.3
Robin Rosenberg 12 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
ab439eed6e
  1. 10
      org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/NL1.patch
  2. 4
      org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/NL1_PostImage
  3. 4
      org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/NL1_PreImage
  4. 10
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
  5. 11
      org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java

10
org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/NL1.patch

@ -0,0 +1,10 @@
diff --git a/NL1 b/NL1
index 68abad7..b14088c 100644
--- a/NL1
+++ b/NL1
@@ -1,4 +1,4 @@
a
-b
+d
c

4
org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/NL1_PostImage

@ -0,0 +1,4 @@
a
d
c

4
org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/NL1_PreImage

@ -0,0 +1,4 @@
a
b
c

10
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java

@ -178,6 +178,16 @@ public class ApplyCommandTest extends RepositoryTestCase {
b.getString(0, b.size(), false));
}
@Test
public void testModifyNL1() throws Exception {
ApplyResult result = init("NL1");
assertEquals(1, result.getUpdatedFiles().size());
assertEquals(new File(db.getWorkTree(), "NL1"), result
.getUpdatedFiles().get(0));
checkFile(new File(db.getWorkTree(), "NL1"),
b.getString(0, b.size(), false));
}
private static byte[] readFile(final String patchFile) throws IOException {
final InputStream in = DiffFormatterReflowTest.class
.getResourceAsStream(patchFile);

11
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++)

Loading…
Cancel
Save