IDEA-59049 don't execute hg commands in AWT
authorKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Thu, 7 Apr 2011 12:25:15 +0000 (16:25 +0400)
committerKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Fri, 8 Apr 2011 10:22:19 +0000 (14:22 +0400)
* HgCommandExecutor#executeInCurrentThread for synchronous execution from pooled threads or Tasks. Assertion that the method is called not from AWT.
* HgCommandExecutor#execute(..., HgCommandResultHandler) for async execution on a pooled thread.
* All commands and their callers are reviewed and properly modified.
* HgVfsListener#needConfirmation temporary commented out, will be properly ported in the next commit.

52 files changed:
plugins/hg4idea/src/org/zmlx/hg4idea/HgRemoteStatusUpdater.java
plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java
plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java
plugins/hg4idea/src/org/zmlx/hg4idea/action/HgCreateTagAction.java
plugins/hg4idea/src/org/zmlx/hg4idea/action/HgInit.java
plugins/hg4idea/src/org/zmlx/hg4idea/action/HgMqRebaseAction.java
plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPullAction.java
plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPushAction.java
plugins/hg4idea/src/org/zmlx/hg4idea/action/HgRunConflictResolverAction.java
plugins/hg4idea/src/org/zmlx/hg4idea/action/HgSwitchWorkingDirectoryAction.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgAddCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgAnnotateCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCatCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgChangesetsCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCloneCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCommitCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgCopyCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgIdentifyCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgInitCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgLogCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgMQCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgMergeCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgMoveCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPullCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPushCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRebaseCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRemoteChangesetsCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRemoveCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgResolveCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRevertCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgRevisionsCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgShowConfigCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgStatusCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTagBranchCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTagCreateCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTrackFileNamesAccrossRevisionsCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgUpdateCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgWorkingCopyRevisionsCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java
plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandResultHandler.java [moved from plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandResultListener.java with 68% similarity]
plugins/hg4idea/src/org/zmlx/hg4idea/provider/HgChangeProvider.java
plugins/hg4idea/src/org/zmlx/hg4idea/provider/commit/HgCheckinEnvironment.java
plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgConflictResolver.java
plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgIntegrateEnvironment.java
plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java
plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgIntegrateDialog.java
plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPullDialog.java
plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgPushDialog.java
plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgRunConflictResolverDialog.java
plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgSwitchDialog.java
plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgPushTest.java
plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgUpdateTest.java

index ec43819f90174ae3094d1d5d13dd943705313e2a..935f87cea32ee5faa0e4142f3c5fe395d204c140 100644 (file)
@@ -68,7 +68,7 @@ class HgRemoteStatusUpdater implements HgUpdater {
           }
         }.queue();
       }
-    }, project.getDisposed());
+    });
   }
 
   private void updateChangesetStatus(Project project, VcsRoot[] roots, HgChangesetStatus status, boolean incoming) {
index 7ad4704f9206f93d630e1f752b1ddfc074218372..a7a79f50e418623e7729e5bbc123e57ca2c3dfc2 100644 (file)
@@ -146,22 +146,22 @@ public class HgVFSListener extends VcsVFSListener {
   protected VcsDeleteType needConfirmDeletion(VirtualFile file) {
     //// newly added files (which were added to the repo but never committed) should be removed from the VCS,
     //// but without user confirmation.
-    final FilePath filePath = VcsUtil.getFilePath(file.getPath());
-    final VirtualFile repo = HgUtil.getHgRootOrNull(myProject, filePath);
-    if (repo == null) {
-      return super.needConfirmDeletion(file);
-    }
-    final HgFile hgFile = new HgFile(repo, filePath);
-
-    final HgLogCommand logCommand = new HgLogCommand(myProject);
-    logCommand.setLogFile(true);
-    logCommand.setFollowCopies(false);
-    logCommand.setIncludeRemoved(true);
-    final List<HgFileRevision> localRevisions = logCommand.execute(hgFile, -1, true);
-    // file is newly added, if it doesn't have a history or if the last history action was deleting this file.
-    if (localRevisions == null || localRevisions.isEmpty() || localRevisions.get(0).getDeletedFiles().contains(hgFile.getRelativePath())) {
-      return VcsDeleteType.SILENT;
-    }
+    //final FilePath filePath = VcsUtil.getFilePath(file.getPath());
+    //final VirtualFile repo = HgUtil.getHgRootOrNull(myProject, filePath);
+    //if (repo == null) {
+    //  return super.needConfirmDeletion(file);
+    //}
+    //final HgFile hgFile = new HgFile(repo, filePath);
+    //
+    //final HgLogCommand logCommand = new HgLogCommand(myProject);
+    //logCommand.setLogFile(true);
+    //logCommand.setFollowCopies(false);
+    //logCommand.setIncludeRemoved(true);
+    //final List<HgFileRevision> localRevisions = logCommand.execute(hgFile, -1, true);
+    //// file is newly added, if it doesn't have a history or if the last history action was deleting this file.
+    //if (localRevisions == null || localRevisions.isEmpty() || localRevisions.get(0).getDeletedFiles().contains(hgFile.getRelativePath())) {
+    //  return VcsDeleteType.SILENT;
+    //}
     return VcsDeleteType.CONFIRM;
   }
 
index 294b6855d2d17bb75c70f5e9d41d043797668db4..bf1551d06c6cd4529fede8697e1bcb9d909f359e 100644 (file)
@@ -245,6 +245,13 @@ public class HgVcs extends AbstractVcs<CommittedChangeList> {
    * @return the prompthooks.py extension used for capturing prompts from Mercurial and requesting IDEA's user about authentication.
    */
   public @NotNull File getPromptHooksExtensionFile() {
+    if (myPromptHooksExtensionFile == null) {
+      // check that hooks are available
+      myPromptHooksExtensionFile = HgUtil.getTemporaryPythonFile("prompthooks");
+      if (myPromptHooksExtensionFile == null || !myPromptHooksExtensionFile.exists()) {
+        LOG.error("prompthooks.py Mercurial extension is not found. Please reinstall " + ApplicationNamesInfo.getInstance().getProductName());
+      }
+    }
     return myPromptHooksExtensionFile;
   }
 
@@ -255,12 +262,6 @@ public class HgVcs extends AbstractVcs<CommittedChangeList> {
       getExecutableValidator().checkExecutableAndShowDialogIfNeeded();
     }
 
-    // check that hooks are available
-    myPromptHooksExtensionFile = HgUtil.getTemporaryPythonFile("prompthooks");
-    if (myPromptHooksExtensionFile == null || !myPromptHooksExtensionFile.exists()) {
-      LOG.error("prompthooks.py Mercurial extension is not found. Please reinstall " + ApplicationNamesInfo.getInstance().getProductName());
-    }
-
     // status bar
     StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);
     if (statusBar != null) {
index a6139814b8e887c6b2050813843d4f4510efe551..af702917e2e18b091718d761d16dd80789c0090a 100644 (file)
@@ -14,9 +14,11 @@ package org.zmlx.hg4idea.action;
 
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.project.Project;
+import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.command.HgTagCreateCommand;
 import org.zmlx.hg4idea.execution.HgCommandException;
 import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.execution.HgCommandResultHandler;
 import org.zmlx.hg4idea.ui.HgTagDialog;
 
 import java.util.Collection;
@@ -44,10 +46,12 @@ public class HgCreateTagAction extends HgAbstractGlobalAction {
       }
 
       public void execute() throws HgCommandException {
-        HgCommandResult result =
-          new HgTagCreateCommand(project, dialog.getRepository(), dialog.getTagName()).execute();
-
-        new HgCommandResultNotifier(project).process(result);
+        new HgTagCreateCommand(project, dialog.getRepository(), dialog.getTagName()).execute(new HgCommandResultHandler() {
+          @Override
+          public void process(@Nullable HgCommandResult result) {
+            new HgCommandResultNotifier(project).process(result);
+          }
+        });
       }
     };
   }
index de16ba14e30fa72b5411c3d5dfbe0006ee8b7400..e745a7b0085e0251e4a877cd331583df3c046057 100644 (file)
@@ -5,7 +5,6 @@ import com.intellij.notification.NotificationType;
 import com.intellij.notification.Notifications;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.actionSystem.PlatformDataKeys;
-import com.intellij.openapi.actionSystem.Presentation;
 import com.intellij.openapi.project.DumbAwareAction;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectManager;
@@ -13,6 +12,7 @@ import com.intellij.openapi.vcs.ProjectLevelVcsManager;
 import com.intellij.openapi.vcs.VcsDirectoryMapping;
 import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.Consumer;
 import org.zmlx.hg4idea.HgUtil;
 import org.zmlx.hg4idea.HgVcs;
 import org.zmlx.hg4idea.HgVcsMessages;
@@ -53,6 +53,7 @@ public class HgInit extends DumbAwareAction {
     // check if the selected folder is not yet under mercurial and provide some options in that case
     final VirtualFile vcsRoot = HgUtil.getNearestHgRoot(selectedRoot);
     VirtualFile mapRoot = selectedRoot;
+    boolean needToCreateRepo = false;
     if (vcsRoot != null) {
       final HgInitAlreadyUnderHgDialog dialog = new HgInitAlreadyUnderHgDialog(myProject,
                                                    selectedRoot.getPresentableUrl(), vcsRoot.getPresentableUrl());
@@ -64,18 +65,23 @@ public class HgInit extends DumbAwareAction {
       if (dialog.getAnswer() == HgInitAlreadyUnderHgDialog.Answer.USE_PARENT_REPO) {
         mapRoot = vcsRoot;
       } else if (dialog.getAnswer() == HgInitAlreadyUnderHgDialog.Answer.CREATE_REPO_HERE) {
-        if (!createRepository(selectedRoot)) {
-          return;
-        }
+        needToCreateRepo = true;
       }
     } else { // no parent repository => creating the repository here.
-       if (!createRepository(selectedRoot)){
-         return;
-       }
+      needToCreateRepo = true;
+    }
+
+    if (needToCreateRepo) {
+      createRepository(selectedRoot, mapRoot); 
+    } else {
+      updateDirectoryMappings(mapRoot);
     }
+  }
 
-    // update vcs directory mappings if new repository was created inside the current project directory
-    if (myProject != null && (! myProject.isDefault()) && myProject.getBaseDir() != null && VfsUtil.isAncestor(myProject.getBaseDir(), mapRoot, false)) {
+  // update vcs directory mappings if new repository was created inside the current project directory
+  private void updateDirectoryMappings(VirtualFile mapRoot) {
+    if (myProject != null && (! myProject.isDefault()) && myProject.getBaseDir() != null && VfsUtil
+      .isAncestor(myProject.getBaseDir(), mapRoot, false)) {
       mapRoot.refresh(false, false);
       final String path = mapRoot.equals(myProject.getBaseDir()) ? "" : mapRoot.getPath();
       final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
@@ -103,14 +109,24 @@ public class HgInit extends DumbAwareAction {
     }
   }
 
-  private boolean createRepository(VirtualFile selectedRoot) {
-    final boolean succeeded = (new HgInitCommand(myProject)).execute(selectedRoot);
-    Notifications.Bus.notify(new Notification(HgVcs.NOTIFICATION_GROUP_ID,
-                                              HgVcsMessages.message(succeeded ? "hg4idea.init.created.notification.title" : "hg4idea.init.error.title"),
-                                              HgVcsMessages.message(succeeded ? "hg4idea.init.created.notification.description" : "hg4idea.init.error.description", 
-                                                                    selectedRoot.getPresentableUrl()),
-                                              succeeded ? NotificationType.INFORMATION : NotificationType.ERROR), myProject.isDefault() ? null : myProject);
-    return succeeded;
+  private void createRepository(final VirtualFile selectedRoot, final VirtualFile mapRoot) {
+    new HgInitCommand(myProject).execute(selectedRoot, new Consumer<Boolean>() {
+      @Override
+      public void consume(Boolean succeeded) {
+        if (succeeded) {
+          updateDirectoryMappings(mapRoot);
+        }
+        Notifications.Bus.notify(new Notification(HgVcs.NOTIFICATION_GROUP_ID,
+                                                  HgVcsMessages.message(
+                                                    succeeded ? "hg4idea.init.created.notification.title" : "hg4idea.init.error.title"),
+                                                  HgVcsMessages.message(succeeded
+                                                                        ? "hg4idea.init.created.notification.description"
+                                                                        : "hg4idea.init.error.description",
+                                                                        selectedRoot.getPresentableUrl()),
+                                                  succeeded ? NotificationType.INFORMATION : NotificationType.ERROR),
+                                 myProject.isDefault() ? null : myProject);
+      }
+    });
   }
   
-}
+}
\ No newline at end of file
index 279d68b7b01e5688c2fa158de240e2c20e8828a7..82b398ca848324ec4e4572fb2451370bdf927950 100644 (file)
@@ -15,8 +15,11 @@ package org.zmlx.hg4idea.action;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.apache.commons.lang.StringUtils;
+import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.HgFile;
 import org.zmlx.hg4idea.command.*;
+import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.execution.HgCommandResultHandler;
 import org.zmlx.hg4idea.provider.update.HgConflictResolver;
 import org.zmlx.hg4idea.ui.HgPullDialog;
 
@@ -57,23 +60,29 @@ public class HgMqRebaseAction extends HgAbstractGlobalAction {
         pullCommand.setSource(dialog.getSource());
         pullCommand.setRebase(true);
         pullCommand.setUpdate(false);
-        new HgCommandResultNotifier(project).process(pullCommand.execute());
 
-        String currentBranch = new HgTagBranchCommand(project, repository).getCurrentBranch();
-        if (StringUtils.isBlank(currentBranch)) {
-          return;
-        }
+        pullCommand.execute(new HgCommandResultHandler() {
+          @Override
+          public void process(@Nullable HgCommandResult result) {
+            new HgCommandResultNotifier(project).process(result);
 
-        new HgConflictResolver(project).resolve(repository);
+            String currentBranch = new HgTagBranchCommand(project, repository).getCurrentBranch();
+            if (StringUtils.isBlank(currentBranch)) {
+              return;
+            }
 
-        HgResolveCommand resolveCommand = new HgResolveCommand(project);
-        Map<HgFile, HgResolveStatusEnum> status = resolveCommand.list(repository);
+            new HgConflictResolver(project).resolve(repository);
 
-        if (status.containsValue(HgResolveStatusEnum.UNRESOLVED)) {
-          return;
-        }
+            HgResolveCommand resolveCommand = new HgResolveCommand(project);
+            Map<HgFile, HgResolveStatusEnum> status = resolveCommand.getListSynchronously(repository);
+
+            if (status.containsValue(HgResolveStatusEnum.UNRESOLVED)) {
+              return;
+            }
 
-        new HgRebaseCommand(project, repository).continueRebase();
+            new HgRebaseCommand(project, repository).continueRebase();
+          }
+        });
       }
     };
   }
index 5f79716fca9982edf3d835f4412f12d1db2bf72b..15d705be9c6c9ea3d149a307a232594302134903 100644 (file)
@@ -14,8 +14,10 @@ package org.zmlx.hg4idea.action;
 
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
+import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.command.HgPullCommand;
 import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.execution.HgCommandResultHandler;
 import org.zmlx.hg4idea.ui.HgPullDialog;
 
 import java.util.Collection;
@@ -49,8 +51,12 @@ public class HgPullAction extends HgAbstractGlobalAction {
         command.setSource(dialog.getSource());
         command.setRebase(false);
         command.setUpdate(false);
-        HgCommandResult result = command.execute();
-        new HgCommandResultNotifier(project).process(result);
+        command.execute(new HgCommandResultHandler() {
+          @Override
+          public void process(@Nullable HgCommandResult result) {
+            new HgCommandResultNotifier(project).process(result);
+          }
+        });
       }
     };
   }
index 3436e733d853dd491124d94db412bdca66b91d1b..838623bd217750c6bbef51e3af52a180713eb6ef 100644 (file)
@@ -14,7 +14,10 @@ package org.zmlx.hg4idea.action;
 
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
+import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.command.HgPushCommand;
+import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.execution.HgCommandResultHandler;
 import org.zmlx.hg4idea.ui.HgPushDialog;
 
 import java.util.Collection;
@@ -46,7 +49,12 @@ public class HgPushAction extends HgAbstractGlobalAction {
         command.setRevision(dialog.getRevision());
         command.setForce(dialog.isForce());
         command.setBranch(dialog.getBranch());
-        new HgCommandResultNotifier(project).process(command.execute());
+        command.execute(new HgCommandResultHandler() {
+          @Override
+          public void process(@Nullable HgCommandResult result) {
+            new HgCommandResultNotifier(project).process(result);
+          }
+        });
       }
     };
   }
index 71d5bd095f61b90cc43f0ac483e295cc68e075c1..7e6802a7c6a6ff76b4efb19fea3c8f9f4cbb7dae 100644 (file)
 // limitations under the License.
 package org.zmlx.hg4idea.action;
 
+import com.intellij.openapi.progress.ProgressIndicator;
+import com.intellij.openapi.progress.Task;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
+import org.jetbrains.annotations.NotNull;
 import org.zmlx.hg4idea.provider.update.HgConflictResolver;
 import org.zmlx.hg4idea.ui.HgRunConflictResolverDialog;
 
@@ -60,7 +63,12 @@ public class HgRunConflictResolverAction extends HgAbstractGlobalAction {
       }
 
       public void execute() {
-        new HgConflictResolver(project).resolve(repository);
+        new Task.Modal(project, "Mercurial resolves conflicts", false) {
+          @Override
+          public void run(@NotNull ProgressIndicator indicator) {
+            new HgConflictResolver(project).resolve(repository);
+          }
+        }.queue();
       }
     };
   }
index 781ac5d43d339a8b0f76aeae2db193de75d3dfff..d9d18ff94490a7f7b387bcb030c6236796438c74 100644 (file)
@@ -12,6 +12,7 @@
 // limitations under the License.
 package org.zmlx.hg4idea.action;
 
+import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.zmlx.hg4idea.HgVcs;
@@ -44,7 +45,7 @@ public class HgSwitchWorkingDirectoryAction extends HgAbstractGlobalAction {
       }
 
       public void execute() {
-        HgUpdateCommand command = new HgUpdateCommand(project, dialog.getRepository());
+        final HgUpdateCommand command = new HgUpdateCommand(project, dialog.getRepository());
         command.setClean(dialog.isRemoveLocalChanges());
         if (dialog.isRevisionSelected()) {
           command.setRevision(dialog.getRevision());
@@ -56,10 +57,14 @@ public class HgSwitchWorkingDirectoryAction extends HgAbstractGlobalAction {
           command.setRevision(dialog.getTag().getName());
         }
 
-        HgCommandResult result = command.execute();
-        new HgCommandResultNotifier(project).process(result);
-
-        project.getMessageBus().syncPublisher(HgVcs.BRANCH_TOPIC).update(project);
+        ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
+          @Override
+          public void run() {
+            HgCommandResult result = command.execute();
+            new HgCommandResultNotifier(project).process(result);
+            project.getMessageBus().syncPublisher(HgVcs.BRANCH_TOPIC).update(project);
+          }
+        });
       }
     };
   }
index 6a56a21a8938402654f68cb34d55f89c310ec391..7025c7f68227e0cde547ee1c8c0e0ffba809bec3 100644 (file)
@@ -49,7 +49,7 @@ public class HgAddCommand {
    */
   public void execute(@NotNull Collection<HgFile> hgFiles) {
     for(Map.Entry<VirtualFile, List<String>> entry : HgUtil.getRelativePathsByRepository(hgFiles).entrySet()) {
-      HgCommandExecutor.getInstance(myProject).execute(entry.getKey(), "add", entry.getValue());
+      new HgCommandExecutor(myProject).executeInCurrentThread(entry.getKey(), "add", entry.getValue());
     }
   }
 
index 38f58688d70a31df55b64645e71aae723d6e15ec..257367f385f3bc0b5936bbcefa662d54bd0930de 100644 (file)
@@ -46,10 +46,8 @@ public class HgAnnotateCommand {
   }
 
   public List<HgAnnotationLine> execute(@NotNull HgFile hgFile) {
-    HgCommandExecutor executor = HgCommandExecutor.getInstance(project);
-    HgCommandResult result = executor.execute(
-      hgFile.getRepo(), "annotate", Arrays.asList("-cqnudl", hgFile.getRelativePath())
-    );
+    HgCommandExecutor executor = new HgCommandExecutor(project);
+    HgCommandResult result = executor.executeInCurrentThread(hgFile.getRepo(), "annotate", Arrays.asList("-cqnudl", hgFile.getRelativePath()));
 
     List<HgAnnotationLine> annotations = new ArrayList<HgAnnotationLine>();
     for (String line : result.getOutputLines()) {
index c4cab53d31ac1a956ffd64954ed33e51c33b4e56..6b02f52a3d1c008177ae7e932147c0e6e9940b69 100644 (file)
@@ -36,8 +36,10 @@ public class HgCatCommand {
   @Nullable
   public String execute(HgFile hgFile, HgRevisionNumber vcsRevisionNumber, Charset charset) {
     final List<String> arguments = createArguments(vcsRevisionNumber, hgFile.getRelativePath());
-    final HgCommandExecutor executor = HgCommandExecutor.getInstance(myProject);
-    final HgCommandResult result = executor.execute(hgFile.getRepo(), Collections.<String>emptyList(), "cat", arguments, charset, true);
+    final HgCommandExecutor executor = new HgCommandExecutor(myProject);
+    executor.setOptions(Collections.<String>emptyList());
+    executor.setSilent(true);
+    final HgCommandResult result = executor.executeInCurrentThread(hgFile.getRepo(), "cat", arguments);
 
     if (result == null) { // in case of error
       return null;
index f042ecb1de4efbbec61c1ad25974f9326c3f7d99..261fdda52a77c302988881b6644087558e462b9d 100644 (file)
@@ -18,10 +18,9 @@ import com.intellij.openapi.vfs.VirtualFile;
 import org.apache.commons.lang.StringUtils;
 import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.HgRevisionNumber;
-import org.zmlx.hg4idea.execution.HgCommandResult;
 import org.zmlx.hg4idea.execution.HgCommandExecutor;
+import org.zmlx.hg4idea.execution.HgCommandResult;
 
-import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -85,8 +84,9 @@ public abstract class HgChangesetsCommand {
 
   @Nullable
   protected HgCommandResult executeCommand(VirtualFile repo, List<String> args) {
-    return HgCommandExecutor
-      .getInstance(project).execute(repo, HgCommandExecutor.DEFAULT_OPTIONS, command, args, Charset.defaultCharset(), isSilentCommand());
+    final HgCommandExecutor executor = new HgCommandExecutor(project);
+    executor.setSilent(isSilentCommand());
+    return executor.executeInCurrentThread(repo, command, args);
   }
 
   protected boolean isSilentCommand() {
index 4658940c4cc5bea3f162803dbbf0fc53dd65c297..e71e90b88e7c71892b5c604e90ee958b1e9519a9 100644 (file)
@@ -31,6 +31,6 @@ public class HgCloneCommand {
     final List<String> arguments = new ArrayList<String>(2);
     arguments.add(repositoryURL);
     arguments.add(directory);
-    return HgCommandExecutor.getInstance(project).execute(null, "clone", arguments);
+    return new HgCommandExecutor(project).executeInCurrentThread(null, "clone", arguments);
   }
 }
index 4a0c6682cce88a2c69f100b3be04324d8085125b..c4ac4d2e3ea629471b340b8a45cc63c6be060c36 100644 (file)
@@ -70,7 +70,7 @@ public class HgCommitCommand {
       for (HgFile hgFile : files) {
         parameters.add(hgFile.getRelativePath());
       }
-      ensureSuccess(HgCommandExecutor.getInstance(project).execute(repo, "commit", parameters));
+      ensureSuccess(new HgCommandExecutor(project).executeInCurrentThread(repo, "commit", parameters));
       project.getMessageBus().syncPublisher(HgVcs.REMOTE_TOPIC).update(project);
     } catch (IOException e) {
       LOG.info(e);
index d2b623a5b26f7f04705229eb29e05f78e0d01cfa..7b2ed5b9c4a043c8bca18ac31ef28401f575df48 100644 (file)
@@ -27,10 +27,9 @@ public class HgCopyCommand {
   }
 
   public void execute(HgFile source, HgFile target) {
-    HgCommandExecutor executor = HgCommandExecutor.getInstance(project);
+    HgCommandExecutor executor = new HgCommandExecutor(project);
     if (source.getRepo().equals(target.getRepo())) {
-      executor.execute(source.getRepo(), "copy",
-        Arrays.asList("--after", source.getRelativePath(), target.getRelativePath()));
+      executor.execute(source.getRepo(), "copy", Arrays.asList("--after", source.getRelativePath(), target.getRelativePath()), null);
     }
   }
 
index d33ead7d4d2790db8db2e401ca1c278c8b2794d5..f0d2e4d16572f3a6a3a6bbaec05bf08bfe86008f 100644 (file)
@@ -29,6 +29,6 @@ public class HgIdentifyCommand {
   public HgCommandResult execute() {
     final List<String> arguments = new LinkedList<String>();
     arguments.add(source);
-    return HgCommandExecutor.getInstance(project).execute(null, "identify", arguments);
+    return new HgCommandExecutor(project).executeInCurrentThread(null, "identify", arguments);
   }
 }
index 8cc81a780d647067e57e8f08c18cdd3415490b3d..b2a87ed6bb923d2b247549f2b4e81ebd462580c5 100644 (file)
@@ -2,10 +2,13 @@ package org.zmlx.hg4idea.command;
 
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.Consumer;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.HgErrorUtil;
-import org.zmlx.hg4idea.execution.HgCommandResult;
 import org.zmlx.hg4idea.execution.HgCommandExecutor;
+import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.execution.HgCommandResultHandler;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -21,11 +24,14 @@ public class HgInitCommand {
     myProject = project;
   }
 
-  public boolean execute(@NotNull VirtualFile repositoryRoot) {
+  public void execute(@NotNull VirtualFile repositoryRoot, final Consumer<Boolean> booleanResultHandler) {
     final List<String> args = new ArrayList<String>(1);
     args.add(repositoryRoot.getPath());
-    final HgCommandResult result = HgCommandExecutor.getInstance(myProject).execute(null, "init", args);
-    return result != null && !HgErrorUtil.isAbort(result);
+    new HgCommandExecutor(myProject).execute(null, "init", args, new HgCommandResultHandler() {
+      @Override public void process(@Nullable HgCommandResult result) {
+        booleanResultHandler.consume(result != null && !HgErrorUtil.isAbort(result));
+      }
+    });
   }
 
 }
index 4931b421bacc19209ab24f4e1afef2ce158abe4a..2a861b3dba50eb0ad6c1ad10ed2955909772b482 100644 (file)
@@ -66,7 +66,7 @@ public class HgLogCommand extends HgRevisionsCommand {
     if (logFile) {
       arguments.add(hgFile.getRelativePath());
     }
-    return executor.execute(repo, "log", arguments);
+    return executor.executeInCurrentThread(repo, "log", arguments);
   }
 
 }
index 762f6f4724b39d63ab54244147b06b04b06210a1..e871b18c3edd9049243c6c390abe3b53c0e276b6 100644 (file)
@@ -28,7 +28,7 @@ public class HgMQCommand {
   }
 
   public List<String> qapplied(@NotNull VirtualFile repo) {
-    return HgCommandExecutor.getInstance(project).execute(repo, "qapplied", null).getOutputLines();
+    return new HgCommandExecutor(project).executeInCurrentThread(repo, "qapplied", null).getOutputLines();
   }
 
 }
index 277f973003121e33a00b924c4e1b92c9258c6947..3737f14b6590bdeec21946f5206ae586d8fb979d 100644 (file)
@@ -15,6 +15,7 @@ package org.zmlx.hg4idea.command;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.apache.commons.lang.StringUtils;
+import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.execution.HgCommandExecutor;
 import org.zmlx.hg4idea.execution.HgCommandResult;
 
@@ -42,8 +43,9 @@ public class HgMergeCommand {
     this.revision = revision;
   }
 
+  @Nullable
   public HgCommandResult execute() {
-    HgCommandExecutor commandExecutor = HgCommandExecutor.getInstance(project);
+    HgCommandExecutor commandExecutor = new HgCommandExecutor(project);
     List<String> arguments = new LinkedList<String>();
     if (StringUtils.isNotBlank(revision)) {
       arguments.add("--rev");
@@ -51,7 +53,7 @@ public class HgMergeCommand {
     } else if (StringUtils.isNotBlank(branch)) {
       arguments.add(branch);
     }
-    return commandExecutor.execute(repo, "merge", arguments);
+    return commandExecutor.executeInCurrentThread(repo, "merge", arguments);
   }
 
 }
index d16f427e10a59c3a85d5d725b606c78195c903ea..6516a6084c81615d2fb584ab2d74f014c0a6e26c 100644 (file)
@@ -28,7 +28,7 @@ public class HgMoveCommand {
 
   public void execute(HgFile source, HgFile target) {
     if (source.getRepo().equals(target.getRepo())) {
-      HgCommandExecutor.getInstance(project).execute(source.getRepo(), "rename",
+      new HgCommandExecutor(project).executeInCurrentThread(source.getRepo(), "rename",
         Arrays.asList("--after", source.getRelativePath(), target.getRelativePath()));
     }
   }
index 15a8d3e7084897867ab16a6c4cd6dcc5eaed229d..fa9809ccc8e142ad971dbfed50fae0ab79bf4245 100644 (file)
@@ -16,9 +16,11 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.apache.commons.lang.StringUtils;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.HgVcs;
 import org.zmlx.hg4idea.execution.HgCommandExecutor;
 import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.execution.HgCommandResultHandler;
 
 import java.util.LinkedList;
 import java.util.List;
@@ -54,7 +56,7 @@ public class HgPullCommand {
     this.source = source;
   }
 
-  public HgCommandResult execute() {
+  public void execute(@Nullable final HgCommandResultHandler resultHandler) {
     List<String> arguments = new LinkedList<String>();
     if (update) {
       arguments.add("--update");
@@ -69,11 +71,15 @@ public class HgPullCommand {
 
     arguments.add(source);
 
-    HgCommandResult result = HgCommandExecutor.getInstance(project).execute(repo, "pull", arguments);
-
-    project.getMessageBus().syncPublisher(HgVcs.REMOTE_TOPIC).update(project);
-
-    return result;
+    new HgCommandExecutor(project).execute(repo, "pull", arguments, new HgCommandResultHandler() {
+      @Override
+      public void process(@Nullable HgCommandResult result) {
+        project.getMessageBus().syncPublisher(HgVcs.REMOTE_TOPIC).update(project);
+        if (resultHandler != null) {
+          resultHandler.process(result);
+        }
+      }
+    });
   }
 
 }
index 2ec26bbfcf991e3d8f7611bd081c76845ed47971..c241cca09e4af3ee7a6fe81b0536b1d57ba0d2ac 100644 (file)
@@ -16,9 +16,11 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.apache.commons.lang.StringUtils;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.HgVcs;
 import org.zmlx.hg4idea.execution.HgCommandExecutor;
 import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.execution.HgCommandResultHandler;
 
 import java.util.LinkedList;
 import java.util.List;
@@ -51,7 +53,7 @@ public class HgPushCommand {
     myBranch = branch;
   }
 
-  public HgCommandResult execute() {
+  public void execute(final HgCommandResultHandler resultHandler) {
     final List<String> arguments = new LinkedList<String>();
     if (StringUtils.isNotBlank(myRevision)) {
       arguments.add("-r");
@@ -66,9 +68,13 @@ public class HgPushCommand {
     }
     arguments.add(myDestination);
 
-    final HgCommandResult result = HgCommandExecutor.getInstance(myProject).execute(myRepo, "push", arguments);
-    myProject.getMessageBus().syncPublisher(HgVcs.REMOTE_TOPIC).update(myProject);
-    return result;
+    new HgCommandExecutor(myProject).execute(myRepo, "push", arguments, new HgCommandResultHandler() {
+      @Override
+      public void process(@Nullable HgCommandResult result) {
+        myProject.getMessageBus().syncPublisher(HgVcs.REMOTE_TOPIC).update(myProject);
+        resultHandler.process(result);
+      }
+    });
   }
 
 }
index 7cc3ed09ea5614709bc93983e0cf93468e4f0b0a..b91555d8a72fd40ccd37f4ce6290971bc41d33c7 100644 (file)
@@ -30,7 +30,7 @@ public class HgRebaseCommand {
   }
 
   public void continueRebase() {
-    HgCommandExecutor.getInstance(project).execute(repo, "rebase", Arrays.asList("--continue"));
+    new HgCommandExecutor(project).execute(repo, "rebase", Arrays.asList("--continue"), null);
   }
 
 }
index 77667096b3aa7741e86180c7db97784bf6ad0c57..2dedb57a86cb913bb79af3dee46c727b67ab77da 100644 (file)
@@ -53,7 +53,7 @@ public abstract class HgRemoteChangesetsCommand extends HgChangesetsCommand {
   @Override
   protected HgCommandResult executeCommand(VirtualFile repo, List<String> args) {
     String repositoryURL = new HgShowConfigCommand(project).getDefaultPath(repo);
-    HgCommandResult result = HgCommandExecutor.getInstance(project).execute(repo, command, args);
+    HgCommandResult result = new HgCommandExecutor(project).executeInCurrentThread(repo, command, args);
     if (result == HgCommandResult.CANCELLED) {
       final HgVcs vcs = HgVcs.getInstance(project);
       Notifications.Bus.notify(new Notification(HgVcs.NOTIFICATION_GROUP_ID, "Checking for incoming/outgoing changes disabled",
index 061b9d871b5a6f04ad0a8a05ebdb15347ed9c8a1..6f21cff6bcbbacfce3d8e76b5109a6a6ced1ecd9 100644 (file)
@@ -51,7 +51,7 @@ public class HgRemoveCommand {
     for( Map.Entry<VirtualFile, List<String>> entry : HgUtil.getRelativePathsByRepository(hgFiles).entrySet()) {
       List<String> filePaths = entry.getValue();
       filePaths.add(0, "--after");
-      HgCommandExecutor.getInstance(myProject).execute(entry.getKey(), "remove", filePaths);
+      new HgCommandExecutor(myProject).executeInCurrentThread(entry.getKey(), "remove", filePaths);
     }
   }
 
index bc47a3d58e584fc7d1e70aef5df47df2de88e691..18babd1be74a81e304483b6e9336d77e67c96f3b 100644 (file)
@@ -15,10 +15,13 @@ package org.zmlx.hg4idea.command;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vcs.FilePath;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.Consumer;
 import org.apache.commons.lang.StringUtils;
+import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.HgFile;
 import org.zmlx.hg4idea.execution.HgCommandExecutor;
 import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.execution.HgCommandResultHandler;
 
 import java.io.File;
 import java.util.Arrays;
@@ -36,15 +39,36 @@ public class HgResolveCommand {
     myProject = project;
   }
 
-  public Map<HgFile, HgResolveStatusEnum> list(VirtualFile repo) {
+
+  public Map<HgFile, HgResolveStatusEnum> getListSynchronously(VirtualFile repo) {
     if (repo == null) {
       return Collections.emptyMap();
     }
-    final HgCommandResult result = HgCommandExecutor.getInstance(myProject).execute(repo, "resolve", Arrays.asList("--list"));
+    final HgCommandResult result = new HgCommandExecutor(myProject).executeInCurrentThread(repo, "resolve", Arrays.asList("--list"));
     if (result == null) {
       return Collections.emptyMap();
     }
+    return handleResult(repo, result);
+  }
+
+  public void list(final VirtualFile repo, final Consumer<Map<HgFile, HgResolveStatusEnum>> resultHandler) {
+    if (repo == null) {
+      resultHandler.consume(Collections.<HgFile, HgResolveStatusEnum>emptyMap());
+    }
+    new HgCommandExecutor(myProject).execute(repo, "resolve", Arrays.asList("--list"), new HgCommandResultHandler() {
+      @Override
+      public void process(@Nullable HgCommandResult result) {
+        if (result == null) {
+          resultHandler.consume(Collections.<HgFile, HgResolveStatusEnum>emptyMap());
+        }
+
+        final Map<HgFile, HgResolveStatusEnum> resolveStatus = handleResult(repo, result);
+        resultHandler.consume(resolveStatus);
+      }
+    });
+  }
 
+  private static Map<HgFile, HgResolveStatusEnum> handleResult(VirtualFile repo, HgCommandResult result) {
     final Map<HgFile, HgResolveStatusEnum> resolveStatus = new HashMap<HgFile, HgResolveStatusEnum>();
     for (String line : result.getOutputLines()) {
       if (StringUtils.isBlank(line) || line.length() < ITEM_COUNT) {
@@ -60,11 +84,11 @@ public class HgResolveCommand {
   }
 
   public void markResolved(VirtualFile repo, VirtualFile path) {
-    HgCommandExecutor.getInstance(myProject).execute(repo, "resolve", Arrays.asList("--mark", path.getPath()));
+    new HgCommandExecutor(myProject).execute(repo, "resolve", Arrays.asList("--mark", path.getPath()), null);
   }
 
   public void markResolved(VirtualFile repo, FilePath path) {
-    HgCommandExecutor.getInstance(myProject).execute(repo, "resolve", Arrays.asList("--mark", path.getPath()));
+    new HgCommandExecutor(myProject).execute(repo, "resolve", Arrays.asList("--mark", path.getPath()), null);
   }
 
 }
\ No newline at end of file
index e5eb2ef211c58cbd18a345efa84782b64ccc6835..d81e13afd3c14a83c2de403e97887b1cc74b483d 100644 (file)
@@ -49,6 +49,6 @@ public class HgRevertCommand {
 
     ContainerUtil.addAll(arguments, hgFile.getRelativePath());
 
-    HgCommandExecutor.getInstance(project).execute(hgFile.getRepo(), "revert", arguments);
+    new HgCommandExecutor(project).execute(hgFile.getRepo(), "revert", arguments, null);
   }
 }
index 5ca903fea72ea614e694f9d481c6a846cb1fe443..3e5ee5319ce6cb3a61f183ad8e5120409e0e7ace 100644 (file)
@@ -71,7 +71,7 @@ abstract class HgRevisionsCommand {
       return Collections.emptyList();
     }
 
-    HgCommandExecutor hgCommandExecutor = HgCommandExecutor.getInstance(project);
+    HgCommandExecutor hgCommandExecutor = new HgCommandExecutor(project);
 
     String template = includeFiles ? LONG_TEMPLATE : SHORT_TEMPLATE;
     int itemCount = includeFiles ? LONG_ITEM_COUNT : SHORT_ITEM_COUNT;
index 6afbe92d1fc1bf01cea131b9d7d6045173c9e54c..2f668bdc334f7ee04e5b23772eb5c302a71c02bc 100644 (file)
@@ -15,10 +15,9 @@ package org.zmlx.hg4idea.command;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.apache.commons.lang.StringUtils;
-import org.zmlx.hg4idea.execution.HgCommandResult;
 import org.zmlx.hg4idea.execution.HgCommandExecutor;
+import org.zmlx.hg4idea.execution.HgCommandResult;
 
-import java.nio.charset.Charset;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -49,9 +48,9 @@ public class HgShowConfigCommand {
       return Collections.emptyMap();
     }
 
-    HgCommandResult result =
-      HgCommandExecutor
-        .getInstance(project).execute(repo, HgCommandExecutor.DEFAULT_OPTIONS, "showconfig", null, Charset.defaultCharset(), true);
+    final HgCommandExecutor executor = new HgCommandExecutor(project);
+    executor.setSilent(true);
+    HgCommandResult result = executor.executeInCurrentThread(repo, "showconfig", null);
 
     if (result == null) {
       return Collections.emptyMap();
index e057cd9bc3de85165f735555c20f7ca4a02b2491..b4a1cae8ea0a385231c002533e7b324da09b77eb 100644 (file)
@@ -16,8 +16,6 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.apache.commons.lang.StringUtils;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.HgChange;
 import org.zmlx.hg4idea.HgFile;
 import org.zmlx.hg4idea.HgFileStatusEnum;
@@ -26,7 +24,6 @@ import org.zmlx.hg4idea.execution.HgCommandExecutor;
 import org.zmlx.hg4idea.execution.HgCommandResult;
 
 import java.io.File;
-import java.nio.charset.Charset;
 import java.util.*;
 
 public class HgStatusCommand {
@@ -92,18 +89,12 @@ public class HgStatusCommand {
     return doExecute(repo, null);
   }
 
-  @Nullable
-  public HgChange execute(VirtualFile repo, @NotNull String file) {
-    Set<HgChange> changes = doExecute(repo, file);
-    return changes.isEmpty() ? null : changes.iterator().next();
-  }
-
   private Set<HgChange> doExecute(VirtualFile repo, String file) {
     if (repo == null) {
       return Collections.emptySet();
     }
 
-    HgCommandExecutor executor = HgCommandExecutor.getInstance(project);
+    HgCommandExecutor executor = new HgCommandExecutor(project);
 
     List<String> arguments = new LinkedList<String>();
     if (includeAdded) {
@@ -140,7 +131,8 @@ public class HgStatusCommand {
       arguments.add(file);
     }
 
-    HgCommandResult result = executor.execute(repo, HgCommandExecutor.DEFAULT_OPTIONS, "status", arguments, Charset.defaultCharset(), true);
+    executor.setSilent(true);
+    HgCommandResult result = executor.executeInCurrentThread(repo, "status", arguments);
     Set<HgChange> changes = new HashSet<HgChange>();
     HgChange previous = null;
     if (result == null) {
index 0dc809ddaa5fa34946cbe1eb3a05435955b412db..2e514307552d390980c92a5c1a75677901d5e056 100644 (file)
@@ -14,12 +14,14 @@ package org.zmlx.hg4idea.command;
 
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.Consumer;
 import org.apache.commons.lang.StringUtils;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.HgRevisionNumber;
-import org.zmlx.hg4idea.execution.HgCommandResult;
 import org.zmlx.hg4idea.execution.HgCommandExecutor;
+import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.execution.HgCommandResultHandler;
 
 import java.util.LinkedList;
 import java.util.List;
@@ -43,7 +45,7 @@ public class HgTagBranchCommand {
 
   @Nullable
   public String getCurrentBranch() {
-    HgCommandResult result = HgCommandExecutor.getInstance(project).execute(repo, "branch", null);
+    HgCommandResult result = new HgCommandExecutor(project).executeInCurrentThread(repo, "branch", null);
     if (result == null) {
       return null;
     }
@@ -54,12 +56,22 @@ public class HgTagBranchCommand {
     return StringUtils.trim(output.get(0));
   }
 
-  public List<HgTagBranch> listBranches() {
-    return tokenize(HgCommandExecutor.getInstance(project).execute(repo, "branches", null));
+  public void listBranches(final Consumer<List<HgTagBranch>> branchListConsumer) {
+    new HgCommandExecutor(project).execute(repo, "branches", null, new HgCommandResultHandler() {
+      @Override
+      public void process(@Nullable HgCommandResult result) {
+        branchListConsumer.consume(tokenize(result));
+      }
+    });
   }
 
-  public List<HgTagBranch> listTags() {
-    return tokenize(HgCommandExecutor.getInstance(project).execute(repo, "tags", null));
+  public void listTags(final Consumer<List<HgTagBranch>> tagListConsumer) {
+    new HgCommandExecutor(project).execute(repo, "tags", null, new HgCommandResultHandler() {
+      @Override
+      public void process(@Nullable HgCommandResult result) {
+        tagListConsumer.consume(tokenize(result));
+      }
+    });
   }
 
   private List<HgTagBranch> tokenize(HgCommandResult result) {
index 21a01e8059f9c0b9700acac46be0bddaa7da84ff..66f1c20f011b927ec63eb93e1f73ded77244aa61 100644 (file)
@@ -18,7 +18,7 @@ import org.apache.commons.lang.StringUtils;
 import org.jetbrains.annotations.NotNull;
 import org.zmlx.hg4idea.execution.HgCommandException;
 import org.zmlx.hg4idea.execution.HgCommandExecutor;
-import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.execution.HgCommandResultHandler;
 
 import java.util.Arrays;
 
@@ -34,11 +34,11 @@ public class HgTagCreateCommand {
     this.tagName = tagName;
   }
 
-  public HgCommandResult execute() throws HgCommandException {
+  public void execute(HgCommandResultHandler resultHandler) throws HgCommandException {
     if (StringUtils.isBlank(tagName)) {
       throw new HgCommandException("tag name is empty");
     }
-    return HgCommandExecutor.getInstance(project).execute(repo, "tag", Arrays.asList(tagName));
+    new HgCommandExecutor(project).execute(repo, "tag", Arrays.asList(tagName), resultHandler);
   }
 
 }
index 0ecfb458f1adfe6eb1d348e6fe28e99cb01c77aa..ee141ca08e9ae0acbc9816dcf73c8ef20094eff9 100644 (file)
@@ -57,7 +57,7 @@ class HgTrackFileNamesAccrossRevisionsCommand {
 
     arguments.add(hgFile.getRelativePath());
 
-    return executor.execute(repo, "log", arguments);
+    return executor.executeInCurrentThread(repo, "log", arguments);
   }
 
   public final String execute(HgFile hgFile, String currentRevision, String givenRevision, int limit) {
@@ -65,7 +65,7 @@ class HgTrackFileNamesAccrossRevisionsCommand {
       return null;
     }
 
-    HgCommandExecutor hgCommandExecutor = HgCommandExecutor.getInstance(project);
+    HgCommandExecutor hgCommandExecutor = new HgCommandExecutor(project);
     HgCommandResult result = execute(hgCommandExecutor, hgFile.getRepo(), limit, hgFile, currentRevision, givenRevision);
 
     String output = result.getRawOutput();
index 05a0f3d67882c09f26f93a44665dd126c0ba4694..693201bab5ec4c11065f70d7f339015ae219f0c4 100644 (file)
@@ -16,6 +16,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.apache.commons.lang.StringUtils;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.execution.HgCommandExecutor;
 import org.zmlx.hg4idea.execution.HgCommandResult;
 
@@ -48,6 +49,7 @@ public class HgUpdateCommand {
     this.clean = clean;
   }
 
+  @Nullable
   public HgCommandResult execute() {
     List<String> arguments = new LinkedList<String>();
     if (clean) {
@@ -61,7 +63,7 @@ public class HgUpdateCommand {
       arguments.add(branch);
     }
 
-    return HgCommandExecutor.getInstance(project).execute(repo, "update", arguments);
+    return new HgCommandExecutor(project).executeInCurrentThread(repo, "update", arguments);
   }
 
 }
index 4cf59b78f5a97084ff5821ed891245543e2bcd9e..f83ee80ce858315c35436353a2199a4d61c9b060 100644 (file)
@@ -129,10 +129,8 @@ public class HgWorkingCopyRevisionsCommand {
 
   @Nullable
   public HgRevisionNumber identify(@NotNull VirtualFile repo) {
-    HgCommandExecutor commandExecutor = HgCommandExecutor.getInstance(myProject);
-    HgCommandResult result = commandExecutor.execute(
-      repo, "identify", Arrays.asList("--num", "--id")
-    );
+    HgCommandExecutor commandExecutor = new HgCommandExecutor(myProject);
+    HgCommandResult result = commandExecutor.executeInCurrentThread(repo, "identify", Arrays.asList("--num", "--id"));
     if (result == null) {
       return HgRevisionNumber.NULL_REVISION_NUMBER;
     }
@@ -172,7 +170,7 @@ public class HgWorkingCopyRevisionsCommand {
     if (file != null) { // NB: this must be the last argument
       args.add(HgUtil.getOriginalFileName(file, ChangeListManager.getInstance(myProject)).getPath());
     }
-    final HgCommandResult result = HgCommandExecutor.getInstance(myProject).execute(repo, command, args);
+    final HgCommandResult result = new HgCommandExecutor(myProject).executeInCurrentThread(repo, command, args);
 
     if (result == null) {
       return new ArrayList<HgRevisionNumber>(0);
index ff26b1f6d1b38a851575ad97082e1892d528f149..9cb286d23436c10b5eaa97c88d44767cedb8e8a7 100644 (file)
@@ -53,10 +53,10 @@ public final class HgCommandExecutor {
   private boolean myIsSilent;
   private List<String> myOptions = DEFAULT_OPTIONS;
 
-  public HgCommandExecutor(Project project, HgGlobalSettings settings) {
+  public HgCommandExecutor(Project project) {
     myProject = project;
-    mySettings = settings;
     myVcs = HgVcs.getInstance(myProject);
+    mySettings = myVcs.getGlobalSettings();
     myValidator = myVcs.getExecutableValidator();
     myCharset = Charset.defaultCharset();
     myIsSilent = false;
@@ -70,30 +70,21 @@ public final class HgCommandExecutor {
     myIsSilent = isSilent;
   }
 
-  @Deprecated
-  public static HgCommandExecutor getInstance(Project project) {
-    return new HgCommandExecutor(project, HgVcs.getInstance(project).getGlobalSettings());
-  }
-
-  @Nullable
-  public HgCommandResult execute(VirtualFile repo, String operation, List<String> arguments) {
-    return execute(
-      repo, DEFAULT_OPTIONS, operation, arguments, Charset.defaultCharset(), false
-    );
+  public void execute(@Nullable final VirtualFile repo, final String operation, final List<String> arguments, @Nullable final HgCommandResultHandler handler) {
+    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
+      @Override
+      public void run() {
+        final HgCommandResult result = executeInCurrentThread(repo, operation, arguments);
+        if (handler != null) {
+          handler.process(result);
+        }
+      }
+    });
   }
 
   @Nullable
-  public HgCommandResult execute(final VirtualFile repo, final List<String> hgOptions, final String operation, final List<String> arguments, final Charset charset, final boolean silent) {
-      return executeOffOfEDT(repo, hgOptions, operation, arguments, charset, silent);
-  }
-
-  private HgCommandResult executeOffOfEDT(VirtualFile repo,
-                                          List<String> hgOptions,
-                                          String operation,
-                                          List<String> arguments,
-                                          Charset charset,
-                                          boolean silent) {
-//    assert !EventQueue.isDispatchThread();
+  public HgCommandResult executeInCurrentThread(@Nullable final VirtualFile repo, final String operation, final List<String> arguments) {
+    LOG.assertTrue(!ApplicationManager.getApplication().isDispatchThread());
     if (myProject.isDisposed()) {
       return null;
     }
@@ -133,7 +124,7 @@ public final class HgCommandExecutor {
       LOG.info("IOException during preparing command", e);
       return null;
     }
-    cmdLine.addAll(hgOptions);
+    cmdLine.addAll(myOptions);
     cmdLine.add(operation);
     if (arguments != null && arguments.size() != 0) {
       cmdLine.addAll(arguments);
@@ -142,12 +133,12 @@ public final class HgCommandExecutor {
     HgCommandResult result;
     try {
       String workingDir = repo != null ? repo.getPath() : null;
-      result = shellCommand.execute(cmdLine, workingDir, charset);
+      result = shellCommand.execute(cmdLine, workingDir, myCharset);
       if (!HgErrorUtil.isAuthorizationError(result)) {
         passReceiver.saveCredentials();
       }
     } catch (ShellCommandException e) {
-      if (!silent) {
+      if (!myIsSilent) {
         if (myValidator.checkExecutableAndNotifyIfNeeded()) {
           // if the problem was not with invalid executable - show error.
           showError(e);
@@ -173,7 +164,7 @@ public final class HgCommandExecutor {
             StringUtils.join(maskAuthInfoFromUrl(arguments), " "));
     myVcs.showMessageInConsole(cmdString, ConsoleViewContentType.NORMAL_OUTPUT.getAttributes());
     LOG.info(cmdString);
-    if (!silent) {
+    if (!myIsSilent) {
       myVcs.showMessageInConsole(result.getRawOutput(), ConsoleViewContentType.SYSTEM_OUTPUT.getAttributes());
       LOG.info(result.getRawOutput());
     }
@@ -183,6 +174,10 @@ public final class HgCommandExecutor {
     return result;
   }
 
+  public void setOptions(List<String> options) {
+    myOptions = options;
+  }
+
   /**
    * Strips possible authentication information from arguments passed to the command line
    * to prevent private information appear in the VCS console or logs.
similarity index 68%
rename from plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandResultListener.java
rename to plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandResultHandler.java
index a5c44688b18718457d0228cae95ea1d5f45e3cf3..d1dee96539de12be4a5ca2c6b2600c742e1e5604 100644 (file)
 // limitations under the License.
 package org.zmlx.hg4idea.execution;
 
-public interface HgCommandResultListener {
+import org.jetbrains.annotations.Nullable;
 
-  void process(HgCommandResult result);
+public interface HgCommandResultHandler {
+
+  HgCommandResultHandler DUMB = new HgCommandResultHandler() {
+    @Override
+    public void process(@Nullable HgCommandResult result) {
+    }
+  };
+
+  void process(@Nullable HgCommandResult result);
 
 }
index 91a73cd0242e9b5b2b2f8591990d635e5bc0787d..335eea912b0bdcb2463cb7dadd8537ef4e48e2f0 100644 (file)
@@ -88,7 +88,7 @@ public class HgChangeProvider implements ChangeProvider {
       return new HashSet<HgChange>();
     }
     sendChanges(builder, hgChanges,
-      new HgResolveCommand(myProject).list(repo),
+      new HgResolveCommand(myProject).getListSynchronously(repo),
       new HgWorkingCopyRevisionsCommand(myProject).identify(repo),
       new HgWorkingCopyRevisionsCommand(myProject).firstParent(repo)
     );
index 80e4992254d4dc90cd85f6cb44b8e4c749dbc542..0a85a46b1ea515e8ae436700957af56276b6681e 100644 (file)
@@ -177,13 +177,18 @@ public class HgCheckinEnvironment implements CheckinEnvironment {
   }
 
   public List<VcsException> scheduleUnversionedFilesForAddition(List<VirtualFile> files) {
-    HgAddCommand command = new HgAddCommand(project);
-    for (VirtualFile file : files) {
-      VirtualFile vcsRoot = VcsUtil.getVcsRootFor(project, file);
+    final HgAddCommand command = new HgAddCommand(project);
+    for (final VirtualFile file : files) {
+      final VirtualFile vcsRoot = VcsUtil.getVcsRootFor(project, file);
       if (vcsRoot == null) {
         continue;
       }
-      command.execute(new HgFile(vcsRoot, VfsUtil.virtualToIoFile(file)));
+      ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
+        @Override
+        public void run() {
+          command.execute(new HgFile(vcsRoot, VfsUtil.virtualToIoFile(file)));
+        }
+      });
     }
     return null;
   }
index d23d4ab9771cf71f24de31cad2ff632c919066ec..87e346646c3ea96a06a5aeb6ed267e7dc108f8ac 100644 (file)
@@ -13,6 +13,7 @@
 package org.zmlx.hg4idea.provider.update;
 
 import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vcs.AbstractVcsHelper;
 import com.intellij.openapi.vcs.update.FileGroup;
@@ -45,7 +46,7 @@ public final class HgConflictResolver {
   }
 
   public void resolve(final VirtualFile repo) {
-    Map<HgFile, HgResolveStatusEnum> resolves = new HgResolveCommand(myProject).list(repo);
+    Map<HgFile, HgResolveStatusEnum> resolves = new HgResolveCommand(myProject).getListSynchronously(repo);
     final List<VirtualFile> conflicts = new ArrayList<VirtualFile>();
     for (Map.Entry<HgFile, HgResolveStatusEnum> entry : resolves.entrySet()) {
       File file = entry.getKey().getFile();
@@ -72,11 +73,13 @@ public final class HgConflictResolver {
       return;
     }
 
-    if (!ApplicationManager.getApplication().isUnitTestMode()) {
-      final HgVcs vcs = HgVcs.getInstance(myProject);
-      if (vcs == null) { return; }
-      AbstractVcsHelper.getInstance(myProject).showMergeDialog(conflicts, vcs.getMergeProvider());
-    }
+    final HgVcs vcs = HgVcs.getInstance(myProject);
+    if (vcs == null) { return; }
+    ApplicationManager.getApplication().invokeAndWait(new Runnable() {
+      public void run() {
+        AbstractVcsHelper.getInstance(myProject).showMergeDialog(conflicts, vcs.getMergeProvider());
+      }
+    }, ModalityState.defaultModalityState());
   }
 
 }
index 2be3934e75c1b14ed6e38d51cd44ae0a390dd8b7..1a9b30e9aae269fbbce107ce42d1c33fb5b1b47b 100644 (file)
@@ -12,8 +12,6 @@
 // limitations under the License.
 package org.zmlx.hg4idea.provider.update;
 
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.options.Configurable;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.project.Project;
@@ -97,11 +95,7 @@ public class HgIntegrateEnvironment implements UpdateEnvironment {
           exceptions.add(warning);
         }
 
-        ApplicationManager.getApplication().invokeAndWait(new Runnable() {
-          public void run() {
-            new HgConflictResolver(project, updatedFiles).resolve(repo);
-          }
-        }, ModalityState.defaultModalityState());
+        new HgConflictResolver(project, updatedFiles).resolve(repo);
 
       } catch (VcsException e) {
         exceptions.add(e);
index d3c785b86e5bcb57c764bda1fc0e360df1521464..bd25ba3db6a879fcc6b75ba68c67eab320d6f05f 100644 (file)
@@ -12,8 +12,7 @@
 // limitations under the License.
 package org.zmlx.hg4idea.provider.update;
 
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.ModalityState;
+import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vcs.VcsException;
@@ -22,10 +21,12 @@ import com.intellij.openapi.vcs.update.UpdatedFiles;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.apache.commons.lang.StringUtils;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.*;
 import org.zmlx.hg4idea.command.*;
 import org.zmlx.hg4idea.execution.HgCommandException;
 import org.zmlx.hg4idea.execution.HgCommandResult;
+import org.zmlx.hg4idea.execution.HgCommandResultHandler;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -38,6 +39,7 @@ public class HgRegularUpdater implements HgUpdater {
   private final Project project;
   @NotNull private final VirtualFile repository;
   @NotNull private final UpdateConfiguration updateConfiguration;
+  private static final Logger LOG = Logger.getInstance(HgRegularUpdater.class);
 
   public HgRegularUpdater(Project project, @NotNull VirtualFile repository, @NotNull UpdateConfiguration configuration) {
     this.project = project;
@@ -197,11 +199,7 @@ public class HgRegularUpdater implements HgUpdater {
   }
 
   private void resolvePossibleConflicts(final UpdatedFiles updatedFiles) {
-    ApplicationManager.getApplication().invokeAndWait(new Runnable() {
-      public void run() {
-        new HgConflictResolver(project, updatedFiles).resolve(repository);
-      }
-    }, ModalityState.defaultModalityState());
+    new HgConflictResolver(project, updatedFiles).resolve(repository);
   }
 
   private Set<HgChange> getLocalChanges() {
@@ -218,7 +216,17 @@ public class HgRegularUpdater implements HgUpdater {
     hgPullCommand.setSource(new HgShowConfigCommand(project).getDefaultPath(repo));
     hgPullCommand.setUpdate(false);
     hgPullCommand.setRebase(false);
-    ensureSuccess(hgPullCommand.execute());
+    hgPullCommand.execute(new HgCommandResultHandler() {
+      @Override
+      public void process(@Nullable HgCommandResult result) {
+        try {
+          ensureSuccess(result);
+        }
+        catch (VcsException e) {
+          LOG.error(e);
+        }
+      }
+    });
   }
 
   private void update(@NotNull VirtualFile repo, ProgressIndicator indicator, UpdatedFiles updatedFiles, List<VcsException> warnings) throws VcsException {
index 004befd0d5cc6885da02f18a77a2a2dde73166e7..3d7cc84e25e8b1daa52f5f767a3afcaeb824cc10 100644 (file)
 // limitations under the License.
 package org.zmlx.hg4idea.ui;
 
+import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.options.Configurable;
 import com.intellij.openapi.options.ConfigurationException;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vcs.FilePath;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.Consumer;
 import org.jetbrains.annotations.Nls;
 import org.zmlx.hg4idea.HgRevisionNumber;
 import org.zmlx.hg4idea.HgVcsMessages;
@@ -135,35 +137,48 @@ public class HgIntegrateDialog implements Configurable {
   }
 
   private void loadBranches(VirtualFile root) {
-    List<HgTagBranch> branches = new HgTagBranchCommand(project, root).listBranches();
-    branchSelector.setModel(new DefaultComboBoxModel(branches.toArray()));
+    new HgTagBranchCommand(project, root).listBranches(new Consumer<List<HgTagBranch>>() {
+      @Override
+      public void consume(List<HgTagBranch> branches) {
+        branchSelector.setModel(new DefaultComboBoxModel(branches.toArray()));
+      }
+    });
   }
 
   private void loadTags(VirtualFile root) {
-    List<HgTagBranch> tags = new HgTagBranchCommand(project, root).listTags();
-    tagSelector.setModel(new DefaultComboBoxModel(tags.toArray()));
+    new HgTagBranchCommand(project, root).listTags(new Consumer<List<HgTagBranch>>() {
+      @Override
+      public void consume(List<HgTagBranch> tags) {
+        tagSelector.setModel(new DefaultComboBoxModel(tags.toArray()));
+      }
+    });
   }
 
-  private void loadHeads(VirtualFile root) {
-    List<HgRevisionNumber> heads = new HgHeadsCommand(project, root).execute();
-    if (heads.size() != 2) {
-      disableOtherHeadsChoice();
-      return;
-    }
-
-    otherHeadRadioButton.setVisible(true);
-    otherHeadLabel.setVisible(true);
-
-    HgRevisionNumber currentParent = new HgWorkingCopyRevisionsCommand(project).identify(root);
-    heads.remove(currentParent);
-
-    if (heads.size() == 1) {
-      otherHead = heads.get(0);
-      otherHeadLabel.setText(HgVcsMessages.message("hg4idea.integrate.other.head", otherHead.asString()));
-    } else {
-      //apparently we are not at one of the heads
-      disableOtherHeadsChoice();
-    }
+  private void loadHeads(final VirtualFile root) {
+    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
+      @Override
+      public void run() {
+        final List<HgRevisionNumber> heads = new HgHeadsCommand(project, root).execute();
+        if (heads.size() != 2) {
+          disableOtherHeadsChoice();
+          return;
+        }
+
+        otherHeadRadioButton.setVisible(true);
+        otherHeadLabel.setVisible(true);
+
+        HgRevisionNumber currentParent = new HgWorkingCopyRevisionsCommand(project).identify(root);
+        heads.remove(currentParent);
+
+        if (heads.size() == 1) {
+          otherHead = heads.get(0);
+          otherHeadLabel.setText(HgVcsMessages.message("hg4idea.integrate.other.head", otherHead.asString()));
+        } else {
+          //apparently we are not at one of the heads
+          disableOtherHeadsChoice();
+        }
+      }
+    });
   }
 
   private void disableOtherHeadsChoice() {
index 50a2d8d4bd471bf3fbed5538279771e448d1c468..2e70e4ab26b9a4341a4825950aec0d4298dc7235 100644 (file)
@@ -12,6 +12,7 @@
 // limitations under the License.
 package org.zmlx.hg4idea.ui;
 
+import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.vfs.VirtualFile;
@@ -82,11 +83,16 @@ public class HgPullDialog extends DialogWrapper {
   }
 
   private void onChangeRepository() {
-    VirtualFile repo = hgRepositorySelector.getRepository();
-    HgShowConfigCommand configCommand = new HgShowConfigCommand(project);
-    String defaultPath = configCommand.getDefaultPath(repo);
-    sourceTxt.setText(defaultPath);
-    onChangePullSource();
+    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
+      @Override
+      public void run() {
+        VirtualFile repo = hgRepositorySelector.getRepository();
+        HgShowConfigCommand configCommand = new HgShowConfigCommand(project);
+        String defaultPath = configCommand.getDefaultPath(repo);
+        sourceTxt.setText(defaultPath);
+        onChangePullSource();
+      }
+    });
   }
 
   private void onChangePullSource() {
index 425f2fe95a980aff9dcf432755ea31f9f7e0f0b8..941624d8c269050223280744f3c346a18c1d6ee8 100644 (file)
 // limitations under the License.
 package org.zmlx.hg4idea.ui;
 
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.Consumer;
 import org.apache.commons.lang.StringUtils;
 import org.jetbrains.annotations.Nullable;
 import org.zmlx.hg4idea.HgVcsMessages;
@@ -103,17 +106,36 @@ public class HgPushDialog extends DialogWrapper {
   }
 
   private void updateRepository() {
-    final VirtualFile repo = hgRepositorySelectorComponent.getRepository();
-    final HgShowConfigCommand configCommand = new HgShowConfigCommand(myProject);
-    final String defaultPath = configCommand.getDefaultPushPath(repo);
-    repositoryTxt.setText(defaultPath);
-    loadBranches(repo);
-    update();
+    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
+      @Override
+      public void run() {
+        final VirtualFile repo = hgRepositorySelectorComponent.getRepository();
+        final HgShowConfigCommand configCommand = new HgShowConfigCommand(myProject);
+        final String defaultPath = configCommand.getDefaultPushPath(repo);
+        loadBranches(repo);
+        ApplicationManager.getApplication().invokeLater(new Runnable() {
+          @Override
+          public void run() {
+            repositoryTxt.setText(defaultPath);
+            update();
+          }
+        }, ModalityState.stateForComponent(getRootPane()));
+      }
+    });
   }
 
   private void loadBranches(VirtualFile root) {
-    final List<HgTagBranch> branches = new HgTagBranchCommand(myProject, root).listBranches();
-    branchComboBox.setModel(new DefaultComboBoxModel(branches.toArray()));
+    new HgTagBranchCommand(myProject, root).listBranches(new Consumer<List<HgTagBranch>>() {
+      @Override
+      public void consume(final List<HgTagBranch> branches) {
+        ApplicationManager.getApplication().invokeLater(new Runnable() {
+          @Override
+          public void run() {
+            branchComboBox.setModel(new DefaultComboBoxModel(branches.toArray()));
+          }
+        }, ModalityState.stateForComponent(getRootPane()));
+      }
+    });
   }
 
   private void update() {
index 7cb564cd49f8178631d3237feff6665eac5eb6fb..94125cfceb67063178e61080f8a3ce9e276d9f01 100644 (file)
@@ -15,6 +15,7 @@ package org.zmlx.hg4idea.ui;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.Consumer;
 import org.zmlx.hg4idea.HgFile;
 import org.zmlx.hg4idea.command.HgResolveCommand;
 import org.zmlx.hg4idea.command.HgResolveStatusEnum;
@@ -61,18 +62,22 @@ public class HgRunConflictResolverDialog extends DialogWrapper {
   private void onChangeRepository() {
     VirtualFile repo = repositorySelector.getRepository();
     HgResolveCommand command = new HgResolveCommand(project);
-    Map<HgFile, HgResolveStatusEnum> status = command.list(repo);
-    DefaultListModel model = new DefaultListModel();
-    for (Map.Entry<HgFile, HgResolveStatusEnum> entry : status.entrySet()) {
-      if (entry.getValue() == HgResolveStatusEnum.UNRESOLVED) {
-        model.addElement(entry.getKey().getRelativePath());
+    command.list(repo, new Consumer<Map<HgFile, HgResolveStatusEnum>>() {
+      @Override
+      public void consume(Map<HgFile, HgResolveStatusEnum> status) {
+        DefaultListModel model = new DefaultListModel();
+        for (Map.Entry<HgFile, HgResolveStatusEnum> entry : status.entrySet()) {
+          if (entry.getValue() == HgResolveStatusEnum.UNRESOLVED) {
+            model.addElement(entry.getKey().getRelativePath());
+          }
+        }
+        setOKActionEnabled(!model.isEmpty());
+        if (model.isEmpty()) {
+          model.addElement("No conflicts to resolve");
+        }
+        conflictsList.setModel(model);
       }
-    }
-    setOKActionEnabled(!model.isEmpty());
-    if (model.isEmpty()) {
-      model.addElement("No conflicts to resolve");
-    }
-    conflictsList.setModel(model);
+    });
   }
 
 }
index 769947fd3ab41c9d208108a19326b9c45bee6dc2..6f6a1a3ba9bdd0ee807a5771b125bf4ca0d32f25 100644 (file)
@@ -15,6 +15,7 @@ package org.zmlx.hg4idea.ui;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.Consumer;
 import org.zmlx.hg4idea.command.HgTagBranch;
 import org.zmlx.hg4idea.command.HgTagBranchCommand;
 
@@ -115,13 +116,21 @@ public class HgSwitchDialog extends DialogWrapper {
   }
 
   private void loadBranches(VirtualFile root) {
-    List<HgTagBranch> branches = new HgTagBranchCommand(project, root).listBranches();
-    branchSelector.setModel(new DefaultComboBoxModel(branches.toArray()));
+    new HgTagBranchCommand(project, root).listBranches(new Consumer<List<HgTagBranch>>() {
+      @Override
+      public void consume(List<HgTagBranch> branches) {
+        branchSelector.setModel(new DefaultComboBoxModel(branches.toArray()));
+      }
+    });
   }
 
   private void loadTags(VirtualFile root) {
-    List<HgTagBranch> tags = new HgTagBranchCommand(project, root).listTags();
-    tagSelector.setModel(new DefaultComboBoxModel(tags.toArray()));
+    new HgTagBranchCommand(project, root).listTags(new Consumer<List<HgTagBranch>>() {
+      @Override
+      public void consume(List<HgTagBranch> tags) {
+        tagSelector.setModel(new DefaultComboBoxModel(tags.toArray()));
+      }
+    });
   }
 
   private boolean validateOptions() {
index 63fa013104791ea6de5d5549f21fb081c74bb1bf..d8ec05cedb9d64d0edd72b208f1036ec5527fbc4 100644 (file)
@@ -17,11 +17,9 @@ package org.zmlx.hg4idea.test;
 
 import com.intellij.openapi.vfs.VirtualFile;
 import org.testng.annotations.Test;
-import org.zmlx.hg4idea.execution.HgCommandResult;
-import org.zmlx.hg4idea.HgErrorUtil;
 import org.zmlx.hg4idea.command.HgPushCommand;
+import org.zmlx.hg4idea.execution.HgCommandResultHandler;
 
-import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotNull;
 
 /**
@@ -59,9 +57,7 @@ public class HgPushTest extends HgCollaborativeTest {
     myChangeListManager.commitFiles(vf);
 
     final HgPushCommand command = new HgPushCommand(myProject, myRepo.getDir(), myParentRepo.getDir().getUrl());
-    final HgCommandResult result = command.execute();
-    assertNotNull(result);
-    assertFalse(HgErrorUtil.isAbort(result));
+    command.execute(HgCommandResultHandler.DUMB);
 
     myParentRepo.update();
     assertNotNull(myParentRepo.getDir().findChild(AFILE));
index 94e5ab1de4ba8b1e2c8635ef4267d0e90b6923d6..0ffdce6dc60893800b5c0a680c9a175ad6b27086 100644 (file)
@@ -70,7 +70,7 @@ public class HgUpdateTest extends HgCollaborativeTest {
     HgPullCommand pull = new HgPullCommand(myProject, projectRepoVirtualFile);
     pull.setSource(new HgShowConfigCommand(myProject).getDefaultPath(projectRepoVirtualFile));
     pull.setUpdate(false);
-    pull.execute();
+    pull.execute(null);
 
     assertEquals( determineNumberOfIncomingChanges( projectRepo ), 0,
                   "The update operation should have pulled the incoming changes from the default repository." );