diff --git a/platform/lvcs-impl/src/com/intellij/history/core/revisions/Difference.java b/platform/lvcs-impl/src/com/intellij/history/core/revisions/Difference.java index acadd30bfc55..9dd82d50b48a 100644 --- a/platform/lvcs-impl/src/com/intellij/history/core/revisions/Difference.java +++ b/platform/lvcs-impl/src/com/intellij/history/core/revisions/Difference.java @@ -22,7 +22,9 @@ import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.ByteBackedContentRevision; import com.intellij.openapi.vcs.changes.ContentRevision; +import com.intellij.openapi.vcs.changes.CurrentContentRevision; import com.intellij.openapi.vcs.history.VcsRevisionNumber; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.vcsUtil.VcsUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,11 +35,17 @@ public class Difference { private final boolean myIsFile; private final Entry myLeft; private final Entry myRight; + private final boolean myRightContentCurrent; public Difference(boolean isFile, Entry left, Entry right) { + this(isFile, left, right, false); + } + + public Difference(boolean isFile, Entry left, Entry right, boolean isRightContentCurrent) { myIsFile = isFile; myLeft = left; myRight = right; + myRightContentCurrent = isRightContentCurrent; } public boolean isFile() { @@ -57,10 +65,14 @@ public class Difference { } public ContentRevision getRightContentRevision(IdeaGateway gw) { + if (myRightContentCurrent) { + VirtualFile file = gw.findVirtualFile(getRight().getPath()); + if (file != null) return new CurrentContentRevision(VcsUtil.getFilePath(file)); + } return createContentRevision(getRight(), gw); } - private ContentRevision createContentRevision(final Entry e, final IdeaGateway gw) { + private static ContentRevision createContentRevision(final Entry e, final IdeaGateway gw) { if (e == null) return null; return new ByteBackedContentRevision() { diff --git a/platform/lvcs-impl/src/com/intellij/history/core/revisions/Revision.java b/platform/lvcs-impl/src/com/intellij/history/core/revisions/Revision.java index 074aa3f7a03d..24870b09eafb 100644 --- a/platform/lvcs-impl/src/com/intellij/history/core/revisions/Revision.java +++ b/platform/lvcs-impl/src/com/intellij/history/core/revisions/Revision.java @@ -56,6 +56,6 @@ public abstract class Revision { public abstract Entry findEntry(); public List getDifferencesWith(Revision right) { - return Entry.getDifferencesBetween(findEntry(), right.findEntry()); + return Entry.getDifferencesBetween(findEntry(), right.findEntry(), right instanceof CurrentRevision); } } diff --git a/platform/lvcs-impl/src/com/intellij/history/core/tree/DirectoryEntry.java b/platform/lvcs-impl/src/com/intellij/history/core/tree/DirectoryEntry.java index 086fc520c04b..21afb6bc07b5 100644 --- a/platform/lvcs-impl/src/com/intellij/history/core/tree/DirectoryEntry.java +++ b/platform/lvcs-impl/src/com/intellij/history/core/tree/DirectoryEntry.java @@ -136,11 +136,11 @@ public class DirectoryEntry extends Entry { } @Override - public void collectDifferencesWith(@NotNull Entry right, @NotNull List result) { + public void collectDifferencesWith(@NotNull Entry right, @NotNull List result, boolean isRightContentCurrent) { DirectoryEntry e = (DirectoryEntry)right; if (!getPath().equals(e.getPath())) { - result.add(new Difference(false, this, e)); + result.add(new Difference(false, this, e, isRightContentCurrent)); } // most often we have the same children, so try processing it directly @@ -154,7 +154,7 @@ public class DirectoryEntry extends Entry { Entry rightChildEntry = e.myChildren.get(commonIndex); if (childEntry.getNameId() == rightChildEntry.getNameId() && childEntry.isDirectory() == rightChildEntry.isDirectory()) { - childEntry.collectDifferencesWith(rightChildEntry, result); + childEntry.collectDifferencesWith(rightChildEntry, result, isRightContentCurrent); } else { break; } @@ -206,16 +206,16 @@ public class DirectoryEntry extends Entry { for (Entry child : e.myChildren) { if (uniqueNameIdToRightChildEntries.containsKey(child.getNameId())) { - child.collectCreatedDifferences(result); + child.collectCreatedDifferences(result, isRightContentCurrent); } } for (Entry child : myChildren) { if (uniqueNameIdToMyChildEntries.containsKey(child.getNameId())) { - child.collectDeletedDifferences(result); + child.collectDeletedDifferences(result, isRightContentCurrent); } else { Entry itsChild = myNameIdToRightChildEntries.get(child.getNameId()); - if (itsChild != null) child.collectDifferencesWith(itsChild, result); + if (itsChild != null) child.collectDifferencesWith(itsChild, result, isRightContentCurrent); } } } @@ -228,20 +228,20 @@ public class DirectoryEntry extends Entry { } @Override - protected void collectCreatedDifferences(@NotNull List result) { - result.add(new Difference(false, null, this)); + protected void collectCreatedDifferences(@NotNull List result, boolean isRightContentCurrent) { + result.add(new Difference(false, null, this, isRightContentCurrent)); for (Entry child : myChildren) { - child.collectCreatedDifferences(result); + child.collectCreatedDifferences(result, isRightContentCurrent); } } @Override - protected void collectDeletedDifferences(@NotNull List result) { - result.add(new Difference(false, this, null)); + protected void collectDeletedDifferences(@NotNull List result, boolean isRightContentCurrent) { + result.add(new Difference(false, this, null, isRightContentCurrent)); for (Entry child : myChildren) { - child.collectDeletedDifferences(result); + child.collectDeletedDifferences(result, isRightContentCurrent); } } } diff --git a/platform/lvcs-impl/src/com/intellij/history/core/tree/Entry.java b/platform/lvcs-impl/src/com/intellij/history/core/tree/Entry.java index 8b6a8acf432a..59004b7ddf2e 100644 --- a/platform/lvcs-impl/src/com/intellij/history/core/tree/Entry.java +++ b/platform/lvcs-impl/src/com/intellij/history/core/tree/Entry.java @@ -207,19 +207,23 @@ public abstract class Entry { } public static List getDifferencesBetween(Entry left, Entry right) { + return getDifferencesBetween(left, right, false); + } + + public static List getDifferencesBetween(Entry left, Entry right, boolean isRightContentCurrent) { List result = new SmartList<>(); - if (left == null) right.collectCreatedDifferences(result); - else if (right == null) left.collectDeletedDifferences(result); - else left.collectDifferencesWith(right, result); + if (left == null) right.collectCreatedDifferences(result, isRightContentCurrent); + else if (right == null) left.collectDeletedDifferences(result, isRightContentCurrent); + else left.collectDifferencesWith(right, result, isRightContentCurrent); return result; } - protected abstract void collectDifferencesWith(@NotNull Entry e, @NotNull List result); + protected abstract void collectDifferencesWith(@NotNull Entry e, @NotNull List result, boolean isRightContentCurrent); - protected abstract void collectCreatedDifferences(@NotNull List result); + protected abstract void collectCreatedDifferences(@NotNull List result, boolean isRightContentCurrent); - protected abstract void collectDeletedDifferences(@NotNull List result); + protected abstract void collectDeletedDifferences(@NotNull List result, boolean isRightContentCurrent); @Override public String toString() { diff --git a/platform/lvcs-impl/src/com/intellij/history/core/tree/FileEntry.java b/platform/lvcs-impl/src/com/intellij/history/core/tree/FileEntry.java index 20ce50ecccf3..b56ed5b1b1d5 100644 --- a/platform/lvcs-impl/src/com/intellij/history/core/tree/FileEntry.java +++ b/platform/lvcs-impl/src/com/intellij/history/core/tree/FileEntry.java @@ -97,21 +97,21 @@ public class FileEntry extends Entry { } @Override - public void collectDifferencesWith(@NotNull Entry e, @NotNull List result) { + public void collectDifferencesWith(@NotNull Entry e, @NotNull List result, boolean isRightContentCurrent) { if (getPath().equals(e.getPath()) && myContent.equals(e.getContent()) && isReadOnly == e.isReadOnly()) return; - result.add(new Difference(true, this, e)); + result.add(new Difference(true, this, e, isRightContentCurrent)); } @Override - protected void collectCreatedDifferences(@NotNull List result) { - result.add(new Difference(true, null, this)); + protected void collectCreatedDifferences(@NotNull List result, boolean isRightContentCurrent) { + result.add(new Difference(true, null, this, isRightContentCurrent)); } @Override - protected void collectDeletedDifferences(@NotNull List result) { - result.add(new Difference(true, this, null)); + protected void collectDeletedDifferences(@NotNull List result, boolean isRightContentCurrent) { + result.add(new Difference(true, this, null, isRightContentCurrent)); } } diff --git a/platform/platform-tests/testSrc/com/intellij/history/core/tree/EntryTest.java b/platform/platform-tests/testSrc/com/intellij/history/core/tree/EntryTest.java index fee982bbc352..f13c7fff5786 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/core/tree/EntryTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/core/tree/EntryTest.java @@ -60,17 +60,17 @@ public class EntryTest extends LocalHistoryTestCase { } @Override - public void collectDifferencesWith(@NotNull Entry e, @NotNull List result) { + public void collectDifferencesWith(@NotNull Entry e, @NotNull List result, boolean isRightContentCurrent) { throw new UnsupportedOperationException(); } @Override - protected void collectCreatedDifferences(@NotNull List result) { + protected void collectCreatedDifferences(@NotNull List result, boolean isRightContentCurrent) { throw new UnsupportedOperationException(); } @Override - protected void collectDeletedDifferences(@NotNull List result) { + protected void collectDeletedDifferences(@NotNull List result, boolean isRightContentCurrent) { throw new UnsupportedOperationException(); } }