Make HgPullCommand synchronous. This fixes IDEA-68096
authorKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Sun, 24 Apr 2011 13:09:08 +0000 (17:09 +0400)
committerKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Sun, 24 Apr 2011 13:18:19 +0000 (17:18 +0400)
plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPullAction.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPullCommand.java

index 32027ab8533d8921a6122e2c0d71c7a3172a1932..b8451f14fab7c36220726652983da3faf37e6ae6 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.command.HgPullCommand;
 import org.zmlx.hg4idea.ui.HgPullDialog;
 
@@ -42,13 +45,18 @@ public class HgPullAction extends HgAbstractGlobalAction {
       }
 
       public void execute() {
-        HgPullCommand command = new HgPullCommand(
+        final HgPullCommand command = new HgPullCommand(
           project, dialog.getRepository()
         );
         command.setSource(dialog.getSource());
         command.setRebase(false);
         command.setUpdate(false);
-        command.execute();
+        new Task.Backgroundable(project, "Pulling changes from " + dialog.getSource(), false){
+          @Override
+          public void run(@NotNull ProgressIndicator indicator) {
+            command.execute();
+          }
+        }.queue();
       }
     };
   }
index dc7a96cf2c11a8416519763a25607034cb61f671..bf2b1f8f92a946d3216502ebcf24c1c9c574287e 100644 (file)
@@ -18,11 +18,9 @@ import com.intellij.openapi.vcs.VcsException;
 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 org.zmlx.hg4idea.util.HgErrorUtil;
 import org.zmlx.hg4idea.util.HgUtil;
 
@@ -78,22 +76,18 @@ public class HgPullCommand {
 
     final HgCommandExecutor executor = new HgCommandExecutor(project);
     executor.setShowOutput(true);
-    executor.execute(repo, "pull", arguments, new HgCommandResultHandler() {
-      @Override
-      public void process(@Nullable HgCommandResult result) {
-        if (HgErrorUtil.isAuthorizationError(result)) {
-          HgUtil.notifyError(project, "Authorization required", "http authorization required for <code>" + source + "</code>");
-        } else if (HgErrorUtil.isAbort(result)) {
-          if (result != null) {
-            LOG.error(new VcsException(result.getRawError()));
-          } else {
-            LOG.error("Error handing result of 'hg pull' execution.");
-          }
-        } else {
-          project.getMessageBus().syncPublisher(HgVcs.REMOTE_TOPIC).update(project);
-        }
+    final HgCommandResult result = executor.executeInCurrentThread(repo, "pull", arguments);
+    if (HgErrorUtil.isAuthorizationError(result)) {
+      HgUtil.notifyError(project, "Authorization required", "http authorization required for <code>" + source + "</code>");
+    } else if (HgErrorUtil.isAbort(result)) {
+      if (result != null) {
+        LOG.error(new VcsException(result.getRawError()));
+      } else {
+        LOG.error("Error handing result of 'hg pull' execution.");
       }
-    });
+    } else {
+      project.getMessageBus().syncPublisher(HgVcs.REMOTE_TOPIC).update(project);
+    }
   }
 
 }