diff --git a/platform/lvcs-api/src/com/intellij/history/Label.java b/platform/lvcs-api/src/com/intellij/history/Label.java index 95ef54ace083..7ae95c27be27 100644 --- a/platform/lvcs-api/src/com/intellij/history/Label.java +++ b/platform/lvcs-api/src/com/intellij/history/Label.java @@ -16,12 +16,15 @@ package com.intellij.history; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; + public interface Label { Label NULL_INSTANCE = new Label() { @Override - public long getLabelChangeId() { - return -1; + public void revert(@NotNull Project project, @NotNull VirtualFile file) { } public ByteContent getByteContent(String path) { @@ -29,7 +32,7 @@ public interface Label { } }; - long getLabelChangeId(); + void revert(@NotNull Project project, @NotNull VirtualFile file); ByteContent getByteContent(String path); } diff --git a/platform/lvcs-api/src/com/intellij/history/LocalHistory.java b/platform/lvcs-api/src/com/intellij/history/LocalHistory.java index c61e974b4e41..701a784afd31 100644 --- a/platform/lvcs-api/src/com/intellij/history/LocalHistory.java +++ b/platform/lvcs-api/src/com/intellij/history/LocalHistory.java @@ -44,7 +44,4 @@ public abstract class LocalHistory { public abstract boolean isUnderControl(VirtualFile f); - public void revertToLabel(@NotNull Project project, @NotNull VirtualFile f, @NotNull Label label) { - } - } diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.java b/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.java index b98b5d73a8f8..d6509f542311 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryImpl.java @@ -193,8 +193,8 @@ public class LocalHistoryImpl extends LocalHistory implements ApplicationCompone private Label label(final LabelImpl impl) { return new Label() { @Override - public long getLabelChangeId() { - return impl.getLabelChangeId(); + public void revert(@NotNull Project project, @NotNull VirtualFile file) { + revertToLabel(project, file, impl); } @Override @@ -249,8 +249,7 @@ public class LocalHistoryImpl extends LocalHistory implements ApplicationCompone return myGateway; } - @Override - public void revertToLabel(@NotNull Project project, @NotNull VirtualFile f, @NotNull Label label) { + private void revertToLabel(@NotNull Project project, @NotNull VirtualFile f, LabelImpl impl) { if (!f.exists() || !f.isValid()) { notifyUser(project, String.format("File %s is not valid or doesn't exist", f.getName())); return; @@ -258,7 +257,7 @@ public class LocalHistoryImpl extends LocalHistory implements ApplicationCompone HistoryDialogModel dirHistoryModel = f.isDirectory() ? new DirectoryHistoryDialogModel(project, myGateway, myVcs, f) : new EntireFileHistoryDialogModel(project, myGateway, myVcs, f); - int leftRev = findRevisionIndexToRevert(dirHistoryModel, label); + int leftRev = findRevisionIndexToRevert(dirHistoryModel, impl); if (leftRev < 0) { notifyUser(project, String.format("Couldn't find label revision. Try to use local history dialog for %s and perform revert manually.", diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryUtil.java b/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryUtil.java index dce24c205986..6858f3dd2315 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryUtil.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/LocalHistoryUtil.java @@ -15,7 +15,7 @@ */ package com.intellij.history.integration; -import com.intellij.history.Label; +import com.intellij.history.core.LabelImpl; import com.intellij.history.core.revisions.ChangeRevision; import com.intellij.history.core.revisions.Revision; import com.intellij.history.integration.ui.models.HistoryDialogModel; @@ -28,7 +28,7 @@ import java.util.List; public class LocalHistoryUtil { - static int findRevisionIndexToRevert(@NotNull HistoryDialogModel dirHistoryModel, @NotNull Label label) { + static int findRevisionIndexToRevert(@NotNull HistoryDialogModel dirHistoryModel, @NotNull LabelImpl label) { List revs = dirHistoryModel.getRevisions(); for (int i = 0; i < revs.size(); i++) { final RevisionItem rev = revs.get(i); @@ -39,7 +39,7 @@ public class LocalHistoryUtil { return -1; } - static boolean isLabelRevision(@NotNull RevisionItem rev, @NotNull Label label) { + static boolean isLabelRevision(@NotNull RevisionItem rev, @NotNull LabelImpl label) { final long targetChangeId = label.getLabelChangeId(); return ContainerUtil.exists(rev.labels, new Condition() { @Override diff --git a/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/HistoryReverterToLabelTest.java b/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/HistoryReverterToLabelTest.java index a8178f422c0e..645d0ce5ddc0 100644 --- a/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/HistoryReverterToLabelTest.java +++ b/platform/platform-tests/testSrc/com/intellij/history/integration/revertion/HistoryReverterToLabelTest.java @@ -26,28 +26,29 @@ public class HistoryReverterToLabelTest extends IntegrationTestCase { public void testFileCreation() throws Exception { createChildData(myRoot, "first.txt"); - final LocalHistory localHistory = LocalHistory.getInstance(); - final Label testLabel = localHistory.putSystemLabel(myProject, "testLabel"); + final Label testLabel = LocalHistory.getInstance().putSystemLabel(myProject, "testLabel"); createChildData(myRoot, "foo.txt"); - localHistory.revertToLabel(myProject, myRoot, testLabel); + revertToLabel(testLabel, myRoot); assertNull(myRoot.findChild("foo.txt")); assertNotNull(myRoot.findChild("first.txt")); } + private void revertToLabel(Label testLabel, VirtualFile root) { + testLabel.revert(myProject, root); + } + public void testFileCreationAsFirstAction() throws Exception { - final LocalHistory localHistory = LocalHistory.getInstance(); - final Label testLabel = localHistory.putSystemLabel(myProject, "testLabel"); + final Label testLabel = LocalHistory.getInstance().putSystemLabel(myProject, "testLabel"); createChildData(myRoot, "foo.txt"); - localHistory.revertToLabel(myProject, myRoot, testLabel); + revertToLabel(testLabel, myRoot); assertNull(myRoot.findChild("foo.txt")); } public void testPutLabelAndRevertInstantly() throws IOException { VirtualFile f = createChildData(myRoot, "foo.txt"); setBinaryContent(f, new byte[]{123}, -1, 4000, this); - final LocalHistory localHistory = LocalHistory.getInstance(); - final Label testLabel = localHistory.putSystemLabel(myProject, "testLabel"); - localHistory.revertToLabel(myProject, myRoot, testLabel); + final Label testLabel = LocalHistory.getInstance().putSystemLabel(myProject, "testLabel"); + revertToLabel(testLabel, myRoot); f = myRoot.findChild("foo.txt"); assertNotNull(f); assertEquals(123, f.contentsToByteArray()[0]); @@ -57,10 +58,9 @@ public class HistoryReverterToLabelTest extends IntegrationTestCase { public void testFileDeletion() throws Exception { VirtualFile f = createChildData(myRoot, "foo.txt"); setBinaryContent(f, new byte[]{123}, -1, 4000, this); - final LocalHistory localHistory = LocalHistory.getInstance(); - final Label testLabel = localHistory.putSystemLabel(myProject, "testLabel"); + final Label testLabel = LocalHistory.getInstance().putSystemLabel(myProject, "testLabel"); delete(f); - localHistory.revertToLabel(myProject, myRoot, testLabel); + revertToLabel(testLabel, myRoot); f = myRoot.findChild("foo.txt"); assertNotNull(f); assertEquals(123, f.contentsToByteArray()[0]); @@ -69,11 +69,10 @@ public class HistoryReverterToLabelTest extends IntegrationTestCase { public void testFileDeletionWithContent() throws Exception { VirtualFile f = createChildData(myRoot, "foo.txt"); - final LocalHistory localHistory = LocalHistory.getInstance(); - final Label testLabel = localHistory.putSystemLabel(myProject, "testLabel"); + final Label testLabel = LocalHistory.getInstance().putSystemLabel(myProject, "testLabel"); setBinaryContent(f, new byte[]{123}, -1, 4000, this); delete(f); - localHistory.revertToLabel(myProject, myRoot, testLabel); + revertToLabel(testLabel, myRoot); f = myRoot.findChild("foo.txt"); assertNotNull(f); assertEquals(0, f.contentsToByteArray().length); @@ -90,7 +89,7 @@ public class HistoryReverterToLabelTest extends IntegrationTestCase { final Label testLabel2 = localHistory.putSystemLabel(myProject, "testLabel"); rename(f, "bar.txt"); - localHistory.revertToLabel(myProject, f, testLabel2); + revertToLabel(testLabel2, f); assertNotNull(myRoot.findChild("dir2")); dir = myRoot.findChild("dir2"); @@ -102,7 +101,7 @@ public class HistoryReverterToLabelTest extends IntegrationTestCase { assertEquals(123, f.contentsToByteArray()[0]); assertEquals(4000, f.getTimeStamp()); - localHistory.revertToLabel(myProject, myRoot, testLabel1); + revertToLabel(testLabel1, myRoot); assertNull(myRoot.findChild("dir2")); dir = myRoot.findChild("dir"); @@ -118,12 +117,11 @@ public class HistoryReverterToLabelTest extends IntegrationTestCase { VirtualFile f = createChildData(myRoot, "foo.txt"); int modificationStamp1 = -1; setBinaryContent(f, new byte[]{1}, modificationStamp1, 1000, this); - final LocalHistory localHistory = LocalHistory.getInstance(); - final Label testLabel = localHistory.putSystemLabel(myProject, "testLabel"); + final Label testLabel = LocalHistory.getInstance().putSystemLabel(myProject, "testLabel"); int modificationStamp = -1; setBinaryContent(f, new byte[]{2}, modificationStamp, 2000, this); setBinaryContent(f, new byte[]{3}, modificationStamp, 3000, this); - localHistory.revertToLabel(myProject, myRoot, testLabel); + revertToLabel(testLabel, myRoot); f = myRoot.findChild("foo.txt"); assertNotNull(f); assertEquals(1, f.contentsToByteArray()[0]); @@ -136,12 +134,11 @@ public class HistoryReverterToLabelTest extends IntegrationTestCase { setBinaryContent(f, new byte[]{1}, modificationStamp1, 1000, this); VirtualFile f2 = createChildData(myRoot, "foo2.txt"); setBinaryContent(f, new byte[]{1}, modificationStamp1, 1000, this); - final LocalHistory localHistory = LocalHistory.getInstance(); - final Label testLabel = localHistory.putSystemLabel(myProject, "testLabel"); + final Label testLabel = LocalHistory.getInstance().putSystemLabel(myProject, "testLabel"); int modificationStamp = -1; setBinaryContent(f, new byte[]{2}, modificationStamp, 2000, this); setBinaryContent(f2, new byte[]{3}, modificationStamp, 3000, this); - localHistory.revertToLabel(myProject, f, testLabel); + revertToLabel(testLabel, f); f = myRoot.findChild("foo.txt"); assertNotNull(f); assertEquals(1, f.contentsToByteArray()[0]); diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/UndoApplyPatchDialog.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/UndoApplyPatchDialog.java index 5c1bfe5cfc2d..908ce16ffe14 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/UndoApplyPatchDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/formove/UndoApplyPatchDialog.java @@ -16,7 +16,6 @@ package com.intellij.openapi.diff.impl.patch.formove; import com.intellij.history.Label; -import com.intellij.history.LocalHistory; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; @@ -75,7 +74,7 @@ class UndoApplyPatchDialog extends DialogWrapper { ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() { @Override public void run() { - LocalHistory.getInstance().revertToLabel(myProject, myProject.getBaseDir(), myBeforeLabel); + myBeforeLabel.revert(myProject, myProject.getBaseDir()); } }, "Rollback Applied Changes...", true, myProject); }