vcs: additionally review with kirill for annotations listeners

This commit is contained in:
irengrig
2012-11-27 19:13:52 +04:00
parent b1fc355f71
commit a54f14d1f1
7 changed files with 41 additions and 39 deletions
@@ -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);
}
@@ -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<BaseRevision> toRemove,
Set<BaseRevision> toAdd,
@@ -123,7 +130,7 @@ public class ChangeListsIndexes {
final Set<String> toAddSet = new HashSet<String>(newKeySet);
toRemoveSet.removeAll(newKeySet);
toAddSet.removeAll(oldKeySet);
// those that
// those that modified
oldKeySet.removeAll(toRemoveSet);
for (String s : toRemoveSet) {
@@ -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();
+3 -1
View File
@@ -344,7 +344,9 @@ public class GitVcs extends AbstractVcs<CommittedChangeList> {
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();
}
@@ -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);
}
}
@@ -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<VFileContentChangeEvent> events = Collections.singletonList(event);
listener.before(events);
listener.after(events);
}
}
@@ -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);