Hg pull: handle result in HgPullCommand commonly.
authorKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Sun, 24 Apr 2011 11:49:07 +0000 (15:49 +0400)
committerKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Sun, 24 Apr 2011 12:13:04 +0000 (16:13 +0400)
In the case of auth error, show the notification.
Don't check for incoming/outgoing changes if pull finished with an error.

plugins/hg4idea/src/org/zmlx/hg4idea/action/HgMqRebaseAction.java
plugins/hg4idea/src/org/zmlx/hg4idea/action/HgPullAction.java
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPullCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java
plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgUpdateTest.java

index 6757d873c33632c1c7ca9c3b0d711f693216d405..f000e6719a63bff45a1f3fe2202e8ebd722ddfad 100644 (file)
@@ -14,18 +14,13 @@ 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.command.HgMQCommand;
+import org.zmlx.hg4idea.command.HgPullCommand;
 import org.zmlx.hg4idea.ui.HgPullDialog;
 
 import java.util.Collection;
-import java.util.Map;
 
+// TODO unsued code. Keeping until MQ extension will be supported
 public class HgMqRebaseAction extends HgAbstractGlobalAction {
 
   protected HgGlobalCommandBuilder getHgGlobalCommandBuilder(final Project project) {
@@ -61,28 +56,28 @@ public class HgMqRebaseAction extends HgAbstractGlobalAction {
         pullCommand.setRebase(true);
         pullCommand.setUpdate(false);
 
-        pullCommand.execute(new HgCommandResultHandler() {
-          @Override
-          public void process(@Nullable HgCommandResult result) {
-            new HgCommandResultNotifier(project).process(result, null, null);
-
-            String currentBranch = new HgTagBranchCommand(project, repository).getCurrentBranch();
-            if (StringUtils.isBlank(currentBranch)) {
-              return;
-            }
-
-            new HgConflictResolver(project).resolve(repository);
-
-            HgResolveCommand resolveCommand = new HgResolveCommand(project);
-            Map<HgFile, HgResolveStatusEnum> status = resolveCommand.getListSynchronously(repository);
-
-            if (status.containsValue(HgResolveStatusEnum.UNRESOLVED)) {
-              return;
-            }
-
-            new HgRebaseCommand(project, repository).continueRebase();
-          }
-        });
+        //pullCommand.execute(new HgCommandResultHandler() {
+        //  @Override
+        //  public void process(@Nullable HgCommandResult result) {
+        //    new HgCommandResultNotifier(project).process(result, null, null);
+        //
+        //    String currentBranch = new HgTagBranchCommand(project, repository).getCurrentBranch();
+        //    if (StringUtils.isBlank(currentBranch)) {
+        //      return;
+        //    }
+        //
+        //    new HgConflictResolver(project).resolve(repository);
+        //
+        //    HgResolveCommand resolveCommand = new HgResolveCommand(project);
+        //    Map<HgFile, HgResolveStatusEnum> status = resolveCommand.getListSynchronously(repository);
+        //
+        //    if (status.containsValue(HgResolveStatusEnum.UNRESOLVED)) {
+        //      return;
+        //    }
+        //
+        //    new HgRebaseCommand(project, repository).continueRebase();
+        //  }
+        //});
       }
     };
   }
index 25da45b3e8887913bdd1109800a9e271edcf4df2..32027ab8533d8921a6122e2c0d71c7a3172a1932 100644 (file)
@@ -14,10 +14,7 @@ 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;
@@ -51,12 +48,7 @@ public class HgPullAction extends HgAbstractGlobalAction {
         command.setSource(dialog.getSource());
         command.setRebase(false);
         command.setUpdate(false);
-        command.execute(new HgCommandResultHandler() {
-          @Override
-          public void process(@Nullable HgCommandResult result) {
-            new HgCommandResultNotifier(project).process(result, null, null);
-          }
-        });
+        command.execute();
       }
     };
   }
index c3843396948ba5e0c8a56131e1a826e2ec0c5a47..dc7a96cf2c11a8416519763a25607034cb61f671 100644 (file)
@@ -12,7 +12,9 @@
 // limitations under the License.
 package org.zmlx.hg4idea.command;
 
+import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vfs.VirtualFile;
 import org.apache.commons.lang.StringUtils;
 import org.jetbrains.annotations.NotNull;
@@ -21,6 +23,8 @@ 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;
 
 import java.util.LinkedList;
 import java.util.List;
@@ -34,6 +38,7 @@ public class HgPullCommand {
   private String revision;
   private boolean update = true;
   private boolean rebase = !update;
+  private static final Logger LOG = Logger.getInstance(HgPullCommand.class);
   
   public HgPullCommand(Project project, @NotNull VirtualFile repo) {
     this.project = project;
@@ -56,7 +61,7 @@ public class HgPullCommand {
     this.source = source;
   }
 
-  public void execute(@Nullable final HgCommandResultHandler resultHandler) {
+  public void execute() {
     List<String> arguments = new LinkedList<String>();
     if (update) {
       arguments.add("--update");
@@ -76,9 +81,16 @@ public class HgPullCommand {
     executor.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);
+        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);
         }
       }
     });
index bd25ba3db6a879fcc6b75ba68c67eab320d6f05f..a5396afbd844d0a0b660e9e56d6453a4a390f9e9 100644 (file)
@@ -21,12 +21,10 @@ 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;
@@ -213,20 +211,11 @@ public class HgRegularUpdater implements HgUpdater {
     throws VcsException {
     indicator.setText2(HgVcsMessages.message("hg4idea.progress.pull.with.update"));
     HgPullCommand hgPullCommand = new HgPullCommand(project, repo);
-    hgPullCommand.setSource(new HgShowConfigCommand(project).getDefaultPath(repo));
+    final String defaultPath = new HgShowConfigCommand(project).getDefaultPath(repo);
+    hgPullCommand.setSource(defaultPath);
     hgPullCommand.setUpdate(false);
     hgPullCommand.setRebase(false);
-    hgPullCommand.execute(new HgCommandResultHandler() {
-      @Override
-      public void process(@Nullable HgCommandResult result) {
-        try {
-          ensureSuccess(result);
-        }
-        catch (VcsException e) {
-          LOG.error(e);
-        }
-      }
-    });
+    hgPullCommand.execute();
   }
 
   private void update(@NotNull VirtualFile repo, ProgressIndicator indicator, UpdatedFiles updatedFiles, List<VcsException> warnings) throws VcsException {
index 0ffdce6dc60893800b5c0a680c9a175ad6b27086..94e5ab1de4ba8b1e2c8635ef4267d0e90b6923d6 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(null);
+    pull.execute();
 
     assertEquals( determineNumberOfIncomingChanges( projectRepo ), 0,
                   "The update operation should have pulled the incoming changes from the default repository." );