@TestOnlt ChangeListManager.ensureUpToDate()
authorpeter <peter@jetbrains.com>
Fri, 20 Jan 2012 12:06:51 +0000 (13:06 +0100)
committerpeter <peter@jetbrains.com>
Fri, 20 Jan 2012 16:01:36 +0000 (17:01 +0100)
platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangeListManager.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/UpdateRequestsQueue.java
plugins/github/src/org/jetbrains/plugins/github/GithubShareAction.java

index 8147780363e92ffd3bcd2868945669fc999a724a..e225103eeb17354236855d1e7b28fde6baa49231 100644 (file)
@@ -26,6 +26,7 @@ import com.intellij.util.Consumer;
 import com.intellij.util.continuation.ContinuationPause;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.TestOnly;
 
 import java.io.File;
 import java.util.Collection;
@@ -46,6 +47,7 @@ public abstract class ChangeListManager implements ChangeListModification {
   public abstract void invokeAfterUpdate(final Runnable afterUpdate, final InvokeAfterUpdateMode mode, final String title,
                                          final Consumer<VcsDirtyScopeManager> dirtyScopeManager,
                                          final ModalityState state);
+  @TestOnly
   public abstract boolean ensureUpToDate(boolean canBeCanceled);
 
   public abstract List<LocalChangeList> getChangeListsCopy();
index 9333e029c6419889b3dd8e6abce7d927f5bdfd55..2973bd38895a6052e28c72b5f0bf3ae3120ef66f 100644 (file)
@@ -266,7 +266,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
    *
    * runnable is invoked on AWT thread
    */
-  public void invokeAfterUpdate(final Runnable afterUpdate, final InvokeAfterUpdateMode mode, final String title, final ModalityState state) {
+  public void invokeAfterUpdate(final Runnable afterUpdate, final InvokeAfterUpdateMode mode, @Nullable final String title, @Nullable final ModalityState state) {
     myUpdater.invokeAfterUpdate(afterUpdate, mode, title, null, state);
   }
 
index 16da589db02e989878697a7286b2b0fad9b642df..711b42da7d7e6f432a6f0669e9542c7ac646754b 100644 (file)
@@ -27,6 +27,7 @@ import com.intellij.openapi.vcs.ProjectLevelVcsManager;
 import com.intellij.util.Consumer;
 import com.intellij.util.concurrency.Semaphore;
 import com.intellij.util.io.storage.HeavyProcessLatch;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.util.ArrayList;
@@ -181,7 +182,7 @@ public class UpdateRequestsQueue {
   }
 
   public void invokeAfterUpdate(final Runnable afterUpdate, final InvokeAfterUpdateMode mode, final String title,
-                                final Consumer<VcsDirtyScopeManager> dirtyScopeManagerFiller, final ModalityState state) {
+                                @Nullable final Consumer<VcsDirtyScopeManager> dirtyScopeManagerFiller, final ModalityState state) {
     LOG.debug("invokeAfterUpdate for project: " + myProject.getName());
     final CallbackData data = CallbackData.create(afterUpdate, title, state, mode, myProject);
 
index e043f207ba3e6bf4042ad03e69b31f9fad5f4121..ad6a814c7b1f0534afff12337a8b004bab3832b8 100644 (file)
@@ -20,10 +20,12 @@ import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vcs.VcsOutgoingChangesProvider;
 import com.intellij.openapi.vcs.changes.ChangeListManager;
 import com.intellij.openapi.vcs.changes.ChangeListManagerImpl;
+import com.intellij.openapi.vcs.changes.InvokeAfterUpdateMode;
 import com.intellij.openapi.vcs.changes.actions.RefreshAction;
 import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
 import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.concurrency.Semaphore;
 import com.intellij.util.containers.HashSet;
 import git4idea.GitDeprecatedRemote;
 import git4idea.GitUtil;
@@ -260,8 +262,21 @@ public class GithubShareAction extends DumbAwareAction {
             files2Add.add(readmeFile);
           }
           final ChangeListManagerImpl changeListManager = (ChangeListManagerImpl)ChangeListManager.getInstance(project);
+
           // Force update
-          changeListManager.ensureUpToDate(false);
+          final Semaphore semaphore = new Semaphore();
+          semaphore.up();
+          changeListManager.invokeAfterUpdate(new Runnable() {
+            @Override
+            public void run() {
+              semaphore.down();
+            }
+          }, InvokeAfterUpdateMode.SILENT, null, null);
+          if (!semaphore.waitFor(30000)) {
+            exceptionRef.set(new VcsException("Too long VCS update"));
+            return;
+          }
+
           for (VirtualFile file : changeListManager.getUnversionedFiles()) {
             if (file.getPath().contains(".idea")) {
               continue;