From a54f14d1f1c8336fb584b374fcc7bedac44b023f Mon Sep 17 00:00:00 2001 From: irengrig Date: Tue, 27 Nov 2012 19:13:52 +0400 Subject: [PATCH] vcs: additionally review with kirill for annotations listeners --- .../vcs/actions/AnnotateToggleAction.java | 9 ++++++- .../vcs/changes/ChangeListsIndexes.java | 9 ++++++- ...VcsAnnotationLocalChangesListenerImpl.java | 2 +- plugins/git4idea/src/git4idea/GitVcs.java | 4 ++- .../GitRepositoryForAnnotationsListener.java | 9 ------- .../git4idea/test/GitTestUtil.java | 25 +++---------------- .../history/GitAnnotationsClosedTest.java | 22 ++++++++++++---- 7 files changed, 41 insertions(+), 39 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java index 04cc20e9376c..296cf8154821 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java @@ -46,6 +46,7 @@ import com.intellij.openapi.vcs.impl.UpToDateLineNumberProviderImpl; import com.intellij.openapi.vcs.impl.VcsBackgroundableActions; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.SortedList; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -191,7 +192,13 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware, Ann @Override public void run() { if (project.isDisposed()) return; - editor.getGutter().closeAllAnnotations(); + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + if (project.isDisposed()) return; + editor.getGutter().closeAllAnnotations(); + } + }); if (onCurrentRevision) { listener.unregisterAnnotation(file, fileAnnotation); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListsIndexes.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListsIndexes.java index 6a9efa210624..df1cdba7f736 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListsIndexes.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListsIndexes.java @@ -112,6 +112,13 @@ public class ChangeListsIndexes { } } + /** + * this method is called after each local changes refresh and collects all: + * - paths that are new in local changes + * - paths that are no more changed locally + * - paths that were and are changed, but base revision has changed (ex. external update) + * (for RemoteRevisionsCache and annotation listener) + */ public void getDelta(final ChangeListsIndexes newIndexes, final Set toRemove, Set toAdd, @@ -123,7 +130,7 @@ public class ChangeListsIndexes { final Set toAddSet = new HashSet(newKeySet); toRemoveSet.removeAll(newKeySet); toAddSet.removeAll(oldKeySet); - // those that + // those that modified oldKeySet.removeAll(toRemoveSet); for (String s : toRemoveSet) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsAnnotationLocalChangesListenerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsAnnotationLocalChangesListenerImpl.java index dacfad70f2fa..14ccaffb14e3 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsAnnotationLocalChangesListenerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsAnnotationLocalChangesListenerImpl.java @@ -60,7 +60,7 @@ public class VcsAnnotationLocalChangesListenerImpl implements Disposable, VcsAnn myProject = project; myLock = new Object(); myUpdateStuff = createUpdateStuff(); - myUpdater = new ZipperUpdater(ApplicationManager.getApplication().isUnitTestMode() ? 10 : 300, Alarm.ThreadToUse.SWING_THREAD, project); + myUpdater = new ZipperUpdater(ApplicationManager.getApplication().isUnitTestMode() ? 10 : 300, Alarm.ThreadToUse.OWN_THREAD, project); myConnection = myProject.getMessageBus().connect(); myLocalFileSystem = LocalFileSystem.getInstance(); myHandler = createHandler(); diff --git a/plugins/git4idea/src/git4idea/GitVcs.java b/plugins/git4idea/src/git4idea/GitVcs.java index fdc8519e1164..a24433ff65bf 100644 --- a/plugins/git4idea/src/git4idea/GitVcs.java +++ b/plugins/git4idea/src/git4idea/GitVcs.java @@ -344,7 +344,9 @@ public class GitVcs extends AbstractVcs { statusBar.addWidget(myBranchWidget, "after " + (SystemInfo.isMac ? "Encoding" : "InsertOverwrite"), myProject); } } - myRepositoryForAnnotationsListener = new GitRepositoryForAnnotationsListener(myProject); + if (myRepositoryForAnnotationsListener == null) { + myRepositoryForAnnotationsListener = new GitRepositoryForAnnotationsListener(myProject); + } ((GitCommitsSequentialIndex) ServiceManager.getService(GitCommitsSequentially.class)).activate(); } diff --git a/plugins/git4idea/src/git4idea/annotate/GitRepositoryForAnnotationsListener.java b/plugins/git4idea/src/git4idea/annotate/GitRepositoryForAnnotationsListener.java index a9dbd9620189..de8b2a84a559 100644 --- a/plugins/git4idea/src/git4idea/annotate/GitRepositoryForAnnotationsListener.java +++ b/plugins/git4idea/src/git4idea/annotate/GitRepositoryForAnnotationsListener.java @@ -15,12 +15,9 @@ */ package git4idea.annotate; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.changes.VcsAnnotationRefresher; -import com.intellij.openapi.vfs.VirtualFile; -import git4idea.GitUtil; import git4idea.GitVcs; import git4idea.repo.GitRepository; import git4idea.repo.GitRepositoryChangeListener; @@ -55,10 +52,4 @@ public class GitRepositoryForAnnotationsListener { } }; } - - public void imitateEvent(final VirtualFile root) { - assert ApplicationManager.getApplication().isUnitTestMode(); - final GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root); - myListener.repositoryChanged(repository); - } } diff --git a/plugins/git4idea/testFramework/git4idea/test/GitTestUtil.java b/plugins/git4idea/testFramework/git4idea/test/GitTestUtil.java index 334d5f1728b3..0a9000e19805 100644 --- a/plugins/git4idea/testFramework/git4idea/test/GitTestUtil.java +++ b/plugins/git4idea/testFramework/git4idea/test/GitTestUtil.java @@ -15,7 +15,6 @@ */ package git4idea.test; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PluginPathManager; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.project.Project; @@ -24,10 +23,6 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; -import com.intellij.openapi.vfs.newvfs.BulkFileListener; -import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent; -import git4idea.GitUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,7 +31,10 @@ import java.io.FilenameFilter; import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import static org.testng.Assert.*; @@ -245,19 +243,4 @@ public class GitTestUtil { public static String stringifyActualExpected(@NotNull Object actual, @NotNull Object expected) { return "\nExpected:\n" + expected + "\nActual:\n" + actual; } - - public static void imitateEvent(VirtualFile dir) { - final VirtualFile dotGit = GitUtil.findGitDir(dir); - assertNotNull(dotGit); - - final VirtualFile head = dotGit.findChild("HEAD"); - assertNotNull(head); - - final BulkFileListener listener = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES); - final VFileContentChangeEvent event = - new VFileContentChangeEvent(null, head, head.getModificationStamp() - 1, head.getModificationStamp(), true); - final List events = Collections.singletonList(event); - listener.before(events); - listener.after(events); - } } diff --git a/plugins/git4idea/tests/git4idea/history/GitAnnotationsClosedTest.java b/plugins/git4idea/tests/git4idea/history/GitAnnotationsClosedTest.java index 1ab619f98d98..2b23174bf38d 100644 --- a/plugins/git4idea/tests/git4idea/history/GitAnnotationsClosedTest.java +++ b/plugins/git4idea/tests/git4idea/history/GitAnnotationsClosedTest.java @@ -36,8 +36,8 @@ import com.intellij.openapi.vfs.VirtualFile; import git4idea.GitPlatformFacade; import git4idea.GitUtil; import git4idea.GitVcs; -import git4idea.annotate.GitRepositoryForAnnotationsListener; import git4idea.repo.GitFakeRepositoryManager; +import git4idea.repo.GitRepository; import git4idea.repo.GitRepositoryImpl; import git4idea.test.GitTest; import org.jetbrains.annotations.NonNls; @@ -121,7 +121,8 @@ public class GitAnnotationsClosedTest extends GitTest { myRepo.addCommit("external_commit"); - new GitRepositoryForAnnotationsListener(myProject).imitateEvent(myWorkingCopyDir); + registerGitRepository(); + imitateEvent(myWorkingCopyDir); sleep(100); // zipper-updater Assert.assertTrue(myFirstClosed); @@ -138,7 +139,8 @@ public class GitAnnotationsClosedTest extends GitTest { Assert.assertFalse(mySecondClosed); myRepo.checkout(head); - new GitRepositoryForAnnotationsListener(myProject).imitateEvent(myWorkingCopyDir); + registerGitRepository(); + imitateEvent(myWorkingCopyDir); sleep(100); // zipper-updater Assert.assertFalse(myFirstClosed); Assert.assertTrue(mySecondClosed); @@ -188,12 +190,16 @@ public class GitAnnotationsClosedTest extends GitTest { Assert.assertFalse(mySecondClosed); } + private void imitateEvent(final VirtualFile root) { + final GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root); + repository.update(); + } + private void imitInternalUpdate() { final ProjectLevelVcsManagerEx ex = ProjectLevelVcsManagerEx.getInstanceEx(myProject); ex.setDirectoryMappings(Collections.singletonList( new VcsDirectoryMapping(FileUtil.toSystemIndependentName(myWorkingCopyDir.getPath()), GitVcs.NAME))); - ((GitFakeRepositoryManager) GitUtil.getRepositoryManager(myProject)).add( - GitRepositoryImpl.getLightInstance(myWorkingCopyDir, myProject, ServiceManager.getService(myProject, GitPlatformFacade.class), myProject)); + registerGitRepository(); ex.getOptions(VcsConfiguration.StandardOption.UPDATE).setValue(false); final CommonUpdateProjectAction action = new CommonUpdateProjectAction(); action.getTemplatePresentation().setText("1"); @@ -214,6 +220,12 @@ public class GitAnnotationsClosedTest extends GitTest { sleep(100); // zipper updater } + private void registerGitRepository() { + ((GitFakeRepositoryManager) GitUtil.getRepositoryManager(myProject)).add( + GitRepositoryImpl + .getLightInstance(myWorkingCopyDir, myProject, ServiceManager.getService(myProject, GitPlatformFacade.class), myProject)); + } + private void annotateFirst(final VirtualFile first) throws VcsException { final VcsAnnotationLocalChangesListener listener = ProjectLevelVcsManager.getInstance(myProject).getAnnotationLocalChangesListener(); final FileAnnotation annotation = myVcs.getAnnotationProvider().annotate(first);