From a1348ddcec3913fb19a1443f511012be96a1cf7d Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Mon, 1 Aug 2011 18:48:21 +0400 Subject: [PATCH] GitRepository: no refresh, only update --- .../src/git4idea/repo/GitRepository.java | 14 ++++------- .../git4idea/repo/GitRepositoryManager.java | 9 ------- .../git4idea/update/GitUpdateLikeProcess.java | 25 ++++++++++++++++--- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/plugins/git4idea/src/git4idea/repo/GitRepository.java b/plugins/git4idea/src/git4idea/repo/GitRepository.java index 375690788904..0e7fcf04e89b 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepository.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepository.java @@ -38,7 +38,11 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; *

*

* The GitRepository is updated "externally" by the {@link git4idea.repo.GitRepositoryUpdater}, when correspondent .git service files - * change. To force the update procedure call {@link #refresh()}. + * change. To force asynchronous update, it is enough to call {@link VirtualFile#refresh(boolean, boolean) refresh} on the root directory. + *

+ *

+ * To make a synchronous update of the repository call {@link #update(TrackedTopic...)} and specify + * which topics should be updated. Updating requires reading from disk, so updating {@link GitRepository.TrackedTopic.ALL} may take some time. *

*

* Other components may subscribe to GitRepository changes via the {@link #GIT_REPO_CHANGE} {@link Topic} @@ -223,14 +227,6 @@ public final class GitRepository implements Disposable { connection.subscribe(GIT_REPO_CHANGE, listener); } - /** - * Refreshes the .git directory asynchronously. - * Call this method after performing write operations on the Git repository: such as commit, fetch, reset, etc. - */ - public void refresh() { - myGitDir.refresh(true, true); - } - /** * Synchronously updates the GitRepository by reading information from the specified topics. */ diff --git a/plugins/git4idea/src/git4idea/repo/GitRepositoryManager.java b/plugins/git4idea/src/git4idea/repo/GitRepositoryManager.java index 918da2085762..aafac9e7e8c3 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepositoryManager.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepositoryManager.java @@ -124,15 +124,6 @@ public final class GitRepositoryManager extends AbstractProjectComponent impleme } } - /** - * Asynchronously refreshes all {@link GitRepository GitRepositories}. - */ - public void refreshAllRepositories() { - for (GitRepository repository : getRepositories()) { - repository.refresh(); - } - } - /** * Synchronously updates the specified information about Git repository under the given root. * @param root root directory of the Git repository. diff --git a/plugins/git4idea/src/git4idea/update/GitUpdateLikeProcess.java b/plugins/git4idea/src/git4idea/update/GitUpdateLikeProcess.java index 46a3cb8a1d4e..cb1dd8776794 100644 --- a/plugins/git4idea/src/git4idea/update/GitUpdateLikeProcess.java +++ b/plugins/git4idea/src/git4idea/update/GitUpdateLikeProcess.java @@ -23,6 +23,7 @@ import com.intellij.openapi.project.ex.ProjectManagerEx; import com.intellij.openapi.vcs.changes.ChangeListManager; import com.intellij.util.continuation.*; import com.intellij.util.ui.UIUtil; +import git4idea.repo.GitRepository; import git4idea.repo.GitRepositoryManager; /** @@ -33,14 +34,17 @@ import git4idea.repo.GitRepositoryManager; public abstract class GitUpdateLikeProcess { public static final String GIT_UPDATING = "Git: updating"; public static final String REASON = "Local changes are not available until Git update is finished."; + private final Project myProject; - private GeneralSettings myGeneralSettings; - private ProjectManagerEx myProjectManager; + private final GeneralSettings myGeneralSettings; + private final ProjectManagerEx myProjectManager; + private final GitRepositoryManager myRepositoryManager; public GitUpdateLikeProcess(final Project project) { myProject = project; myGeneralSettings = GeneralSettings.getInstance(); myProjectManager = ProjectManagerEx.getInstanceEx(); + myRepositoryManager = GitRepositoryManager.getInstance(project); } public void execute() { @@ -71,7 +75,6 @@ public abstract class GitUpdateLikeProcess { myProjectManager.unblockReloadingProjectOnExternalChanges(); myGeneralSettings.setSaveOnFrameDeactivation(saveOnFrameDeactivation); myGeneralSettings.setSyncOnFrameActivation(syncOnFrameDeactivation); - GitRepositoryManager.getInstance(myProject).refreshAllRepositories(); changeListManager.letGo(); } }; @@ -87,11 +90,25 @@ public abstract class GitUpdateLikeProcess { public void run(final ContinuationContext context) { runImpl(context); } - }, returnFlagsBack}; + }, + new TaskDescriptor(GIT_UPDATING, Where.POOLED) { + @Override + public void run(ContinuationContext context) { + updateRepositories(); + } + }, + returnFlagsBack + }; returnFlagsBack.setHaveMagicCure(true); initContext.next(next); continuation.run(initContext.getList()); } + private void updateRepositories() { + for (GitRepository repo: myRepositoryManager.getRepositories()) { + repo.update(GitRepository.TrackedTopic.ALL); + } + } + protected abstract void runImpl(ContinuationContext context); }