Merge "Fix patch application WRT windows line endings."
This commit is contained in:
commit
ab439eed6e
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -178,6 +178,16 @@ public void testModifyZ() throws Exception {
|
||||||
b.getString(0, b.size(), false));
|
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 {
|
private static byte[] readFile(final String patchFile) throws IOException {
|
||||||
final InputStream in = DiffFormatterReflowTest.class
|
final InputStream in = DiffFormatterReflowTest.class
|
||||||
.getResourceAsStream(patchFile);
|
.getResourceAsStream(patchFile);
|
||||||
|
|
|
@ -238,13 +238,10 @@ private void apply(File f, FileHeader fh)
|
||||||
if (!isChanged(oldLines, newLines))
|
if (!isChanged(oldLines, newLines))
|
||||||
return; // don't touch the file
|
return; // don't touch the file
|
||||||
StringBuilder sb = new StringBuilder();
|
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) {
|
for (String l : newLines) {
|
||||||
sb.append(l);
|
// don't bother handling line endings - if it was windows, the \r is
|
||||||
if (eol != null)
|
// still there!
|
||||||
sb.append(eol);
|
sb.append(l).append('\n');
|
||||||
}
|
}
|
||||||
sb.deleteCharAt(sb.length() - 1);
|
sb.deleteCharAt(sb.length() - 1);
|
||||||
FileWriter fw = new FileWriter(f);
|
FileWriter fw = new FileWriter(f);
|
||||||
|
@ -252,7 +249,7 @@ private void apply(File f, FileHeader fh)
|
||||||
fw.close();
|
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())
|
if (ol.size() != nl.size())
|
||||||
return true;
|
return true;
|
||||||
for (int i = 0; i < ol.size(); i++)
|
for (int i = 0; i < ol.size(); i++)
|
||||||
|
|
Loading…
Reference in New Issue