From ecfe287ecc76585c6af74b04524c0c09be56227b Mon Sep 17 00:00:00 2001 From: Irina Chernushina Date: Tue, 27 Jan 2009 15:15:04 +0300 Subject: [PATCH] VCS: refresh VFS under common lock after update, commit --- .../openapi/vcs/changes/ui/CommitHelper.java | 9 ++- .../vcs/update/RefreshVFsSynchronously.java | 64 ++++++++++++++++------ 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitHelper.java b/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitHelper.java index 9655110cf5..fce7d22815 100644 --- a/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitHelper.java +++ b/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitHelper.java @@ -17,13 +17,12 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Computable; import com.intellij.openapi.vcs.*; -import com.intellij.openapi.vcs.update.RefreshVFsSynchronously; import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vcs.changes.actions.MoveChangesToAnotherListAction; import com.intellij.openapi.vcs.changes.committed.CommittedChangesCache; import com.intellij.openapi.vcs.checkin.CheckinEnvironment; import com.intellij.openapi.vcs.checkin.CheckinHandler; -import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.openapi.vcs.update.RefreshVFsSynchronously; import com.intellij.util.Consumer; import com.intellij.util.ui.ConfirmationDialog; import org.jetbrains.annotations.NotNull; @@ -153,7 +152,11 @@ public class CommitHelper { finally { commitCompleted(processor.getVcsExceptions(), processor); processor.customRefresh(); - VirtualFileManager.getInstance().refresh(true, processor.postRefresh()); + ApplicationManager.getApplication().invokeLater(new Runnable() { + public void run() { + processor.postRefresh(); + } + }); } } diff --git a/vcs-impl/src/com/intellij/openapi/vcs/update/RefreshVFsSynchronously.java b/vcs-impl/src/com/intellij/openapi/vcs/update/RefreshVFsSynchronously.java index 87b8c3c509..d69003d1e4 100644 --- a/vcs-impl/src/com/intellij/openapi/vcs/update/RefreshVFsSynchronously.java +++ b/vcs-impl/src/com/intellij/openapi/vcs/update/RefreshVFsSynchronously.java @@ -5,12 +5,14 @@ import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Computable; +import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.util.Processor; +import com.intellij.util.concurrency.Semaphore; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; @@ -29,7 +31,11 @@ public class RefreshVFsSynchronously { } final int num = getFilesNum(updatedFiles); - UpdateFilesHelper.iterateFileGroupFilesDeletedOnServerFirst(updatedFiles, new MyRefreshCallback(num, progressIndicator)); + wrapIntoLock(new Runnable() { + public void run() { + UpdateFilesHelper.iterateFileGroupFilesDeletedOnServerFirst(updatedFiles, new MyRefreshCallback(num, progressIndicator)); + } + }); } private static int getFilesNum(final UpdatedFiles files) { @@ -86,23 +92,49 @@ public class RefreshVFsSynchronously { pi.setIndeterminate(false); } final double num = changes.size(); - int cnt = 0; - for (Change change : changes) { - if ((change.getBeforeRevision() != null) && - (change.isMoved() || change.isRenamed() || change.isIsReplaced() || (change.getAfterRevision() == null))) { - refreshDeletedOrReplaced(change.getBeforeRevision().getFile().getIOFile()); - } else if (change.getBeforeRevision() != null) { - refresh(change.getBeforeRevision().getFile().getIOFile()); - } - if (change.getAfterRevision() != null && (! Comparing.equal(change.getAfterRevision(), change.getBeforeRevision()))) { - refresh(change.getAfterRevision().getFile().getIOFile()); - } - if (pi != null) { - ++ cnt; - pi.setFraction(cnt/num); - pi.setText2("Refreshing: " + change.toString()); + + wrapIntoLock(new Runnable() { + public void run() { + int cnt = 0; + for (Change change : changes) { + if ((change.getBeforeRevision() != null) && + (change.isMoved() || change.isRenamed() || change.isIsReplaced() || (change.getAfterRevision() == null))) { + refreshDeletedOrReplaced(change.getBeforeRevision().getFile().getIOFile()); + } else if (change.getBeforeRevision() != null) { + refresh(change.getBeforeRevision().getFile().getIOFile()); + } + if (change.getAfterRevision() != null && (! Comparing.equal(change.getAfterRevision(), change.getBeforeRevision()))) { + refresh(change.getAfterRevision().getFile().getIOFile()); + } + if (pi != null) { + ++ cnt; + pi.setFraction(cnt/num); + pi.setText2("Refreshing: " + change.toString()); + } + } } + }); + } + + private static void wrapIntoLock(final Runnable runnable) { + final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); + if (indicator != null) { + indicator.startNonCancelableSection(); + indicator.setText(VcsBundle.message("progress.text.synchronizing.files")); + indicator.setText2(""); } + + final Semaphore semaphore = new Semaphore(); + semaphore.down(); + + ApplicationManager.getApplication().invokeLater(new Runnable() { + public void run() { + // common lock for all refreshes inside + runnable.run(); + semaphore.up(); + } + }); + semaphore.waitFor(); } private static class MyRefreshCallback implements UpdateFilesHelper.Callback { -- 2.11.4.GIT