From 91cb0b7852a59767aa9ea28e0b85bbdc7f78d737 Mon Sep 17 00:00:00 2001 From: irengrig Date: Mon, 17 Oct 2011 14:54:53 +0400 Subject: [PATCH 1/2] Torn separators: reset connectors when recalculating --- .../highlighting/FragmentSeparatorsPositionConsumer.java | 5 +++++ .../diff/impl/highlighting/FragmentedDiffPanelState.java | 1 + 2 files changed, 6 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/FragmentSeparatorsPositionConsumer.java b/platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/FragmentSeparatorsPositionConsumer.java index fd94af918199..2bb3c7dccc91 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/FragmentSeparatorsPositionConsumer.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/FragmentSeparatorsPositionConsumer.java @@ -55,6 +55,11 @@ public class FragmentSeparatorsPositionConsumer { return myRight; } + public void clear() { + myLeft.clear(); + myRight.clear(); + } + public static class TornSeparator { private final int myLeftLine; private final int myRightLine; diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/FragmentedDiffPanelState.java b/platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/FragmentedDiffPanelState.java index e0e9dfc3df64..01836bcd5521 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/FragmentedDiffPanelState.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/impl/highlighting/FragmentedDiffPanelState.java @@ -92,6 +92,7 @@ public class FragmentedDiffPanelState extends DiffPanelState { public LineBlocks updateEditors() throws FilesTooBigForDiffException { resetMarkup(); + mySeparatorsPositionConsumer.clear(); if (myAppender1.getEditor() == null || myAppender2.getEditor() == null) { return LineBlocks.EMPTY; } From 2a785ae7512c9f686dd0ffe2d555e541ad61cb70 Mon Sep 17 00:00:00 2001 From: irengrig Date: Mon, 17 Oct 2011 17:28:52 +0400 Subject: [PATCH 2/2] IDEA-44008 Applying unified patch adds an empty line at the end of file (I saw it reproduced with rename refactoring of java classes) --- .../diff/impl/patch/TextPatchBuilder.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java b/platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java index 30f5a59f521c..440cef8bce68 100644 --- a/platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java +++ b/platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java @@ -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 hunks = filePatch.getHunks(); + if (hunks.isEmpty()) return; + final PatchHunk hunk = hunks.get(hunks.size() - 1); + final List 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(); }