IDEA-44008 Applying unified patch adds an empty line at the end of file

(I saw it reproduced with rename refactoring of java classes)
This commit is contained in:
irengrig
2011-10-17 17:30:17 +04:00
parent 91cb0b7852
commit 2a785ae751
@@ -179,13 +179,32 @@ public class TextPatchBuilder {
}
}
}
checkPathEndLine(patch, c.getAfter());
} else if (! beforeRevision.getPath().equals(afterRevision.getPath())) {
result.add(buildMovedFile(myBasePath, beforeRevision, afterRevision, beforeLines));
final TextFilePatch movedPatch = buildMovedFile(myBasePath, beforeRevision, afterRevision, beforeLines);
checkPathEndLine(movedPatch, c.getAfter());
result.add(movedPatch);
}
}
return result;
}
private void checkPathEndLine(TextFilePatch filePatch, final AirContentRevision cr) throws VcsException {
if (cr == null) return;
if (filePatch.isDeletedFile() || filePatch.getAfterName() == null) return;
final List<PatchHunk> hunks = filePatch.getHunks();
if (hunks.isEmpty()) return;
final PatchHunk hunk = hunks.get(hunks.size() - 1);
final List<PatchLine> lines = hunk.getLines();
if (lines.isEmpty()) return;
final String contentAsString = cr.getContentAsString();
if (contentAsString == null) return;
if (! contentAsString.endsWith("\n")) {
lines.get(lines.size() - 1).setSuppressNewLine(true);
}
}
private static String[] tokenize(String text) {
return text.length() == 0 ? new String[]{text} : new LineTokenizer(text).execute();
}