[vcs]: getVcsRoot quick for branch widget (IDEA-144935 Blocking EDT waiting for git command)

* update widgets when mappings changes, not only one repository info changed
* add repository mappings changed topic to track when Repositories are already constructed and added to common VcsRepositoryManager storage;
* add appropriate Dvcs common repo mapping listener
This commit is contained in:
Nadya Zabrodina
2015-10-26 14:56:37 +03:00
parent 78643ec118
commit ee3e5f954d
7 changed files with 61 additions and 2 deletions
@@ -16,6 +16,7 @@
package com.intellij.dvcs;
import com.intellij.dvcs.push.PushSupport;
import com.intellij.dvcs.repo.AbstractRepositoryManager;
import com.intellij.dvcs.repo.RepoStateException;
import com.intellij.dvcs.repo.Repository;
import com.intellij.dvcs.repo.RepositoryManager;
@@ -275,6 +276,15 @@ public class DvcsUtil {
return repository != null ? repository : manager.getRepositoryForRoot(guessRootForVcs(project, vcs, defaultRootPathValue));
}
@Nullable
public static <T extends Repository> T guessCurrentRepositoryQuick(@NotNull Project project,
@NotNull AbstractRepositoryManager<T> manager,
@Nullable String defaultRootPathValue) {
T repository = manager.getRepositoryForRootQuick(guessVcsRoot(project, getSelectedFile(project)));
return repository != null ? repository
: manager.getRepositoryForRootQuick(guessRootForVcs(project, manager.getVcs(), defaultRootPathValue));
}
@Nullable
private static VirtualFile guessRootForVcs(@NotNull Project project, @Nullable AbstractVcs vcs, @Nullable String defaultRootPathValue) {
if (project.isDisposed()) return null;
@@ -105,4 +105,10 @@ public abstract class AbstractRepositoryManager<T extends Repository>
//noinspection unchecked
return vcsDir != null && vcsDir.exists() ? (T)repository : null;
}
@NotNull
public AbstractVcs getVcs() {
return myVcs;
}
}
@@ -30,6 +30,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.messages.Topic;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -41,6 +42,10 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
* extension point in a thread safe way.
*/
public class VcsRepositoryManager extends AbstractProjectComponent implements Disposable, VcsListener {
public static final Topic<VcsRepositoryMappingListener> VCS_REPOSITORY_MAPPING_UPDATED =
Topic.create("VCS repository mapping updated", VcsRepositoryMappingListener.class);
@NotNull private final ProjectLevelVcsManager myVcsManager;
@NotNull private final ReentrantReadWriteLock REPO_LOCK = new ReentrantReadWriteLock();
@@ -204,6 +209,7 @@ public class VcsRepositoryManager extends AbstractProjectComponent implements Di
finally {
REPO_LOCK.writeLock().unlock();
}
myProject.getMessageBus().syncPublisher(VCS_REPOSITORY_MAPPING_UPDATED).mappingChanged();
}
finally {
MODIFY_LOCK.unlock();
@@ -0,0 +1,21 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.dvcs.repo;
public interface VcsRepositoryMappingListener {
void mappingChanged();
}
@@ -16,6 +16,8 @@
package com.intellij.dvcs.ui;
import com.intellij.dvcs.repo.Repository;
import com.intellij.dvcs.repo.VcsRepositoryManager;
import com.intellij.dvcs.repo.VcsRepositoryMappingListener;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileEditorManager;
@@ -200,6 +202,7 @@ public abstract class DvcsStatusWidget<T extends Repository> extends EditorBased
StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
if (statusBar != null && !isDisposed()) {
statusBar.addWidget(widget, "after " + (SystemInfo.isMac ? "Encoding" : "InsertOverwrite"), project);
subscribeToMappingChanged();
subscribeToRepoChangeEvents(project);
update();
}
@@ -218,4 +221,14 @@ public abstract class DvcsStatusWidget<T extends Repository> extends EditorBased
}
});
}
private void subscribeToMappingChanged() {
myProject.getMessageBus().connect().subscribe(VcsRepositoryManager.VCS_REPOSITORY_MAPPING_UPDATED, new VcsRepositoryMappingListener() {
@Override
public void mappingChanged() {
LOG.debug("repository mappings changed");
updateLater();
}
});
}
}
@@ -15,6 +15,7 @@
*/
package git4idea.ui.branch;
import com.intellij.dvcs.DvcsUtil;
import com.intellij.dvcs.ui.DvcsStatusWidget;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.ListPopup;
@@ -47,7 +48,7 @@ public class GitBranchWidget extends DvcsStatusWidget<GitRepository> {
@Nullable
@Override
protected GitRepository guessCurrentRepository(@NotNull Project project) {
return GitBranchUtil.getCurrentRepository(project);
return DvcsUtil.guessCurrentRepositoryQuick(project, GitUtil.getRepositoryManager(project), mySettings.getRecentRootPath());
}
@NotNull
@@ -15,6 +15,7 @@
*/
package org.zmlx.hg4idea.status.ui;
import com.intellij.dvcs.DvcsUtil;
import com.intellij.dvcs.ui.DvcsStatusWidget;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.ListPopup;
@@ -52,7 +53,8 @@ public class HgStatusWidget extends DvcsStatusWidget<HgRepository> {
@Nullable
@Override
protected HgRepository guessCurrentRepository(@NotNull Project project) {
return HgUtil.getCurrentRepository(project);
return DvcsUtil.guessCurrentRepositoryQuick(project, HgUtil.getRepositoryManager(project),
HgProjectSettings.getInstance(project).getRecentRootPath());
}
@NotNull