From a4274ce10a2ff8645679ce1b32fca74054172abc Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 2 Mar 2016 20:05:28 +0300 Subject: [PATCH] [hg] execute hg push synchronously and rename appropriate methods in Push Controller --- .../intellij/dvcs/push/PushController.java | 6 +-- .../zmlx/hg4idea/command/HgPushCommand.java | 16 ++----- .../src/org/zmlx/hg4idea/push/HgPusher.java | 45 +++++++++---------- .../org/zmlx/hg4idea/test/HgPushTest.java | 4 +- 4 files changed, 28 insertions(+), 43 deletions(-) diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java b/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java index 89c137ae70f2..618fdd8d6e2c 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java @@ -486,15 +486,15 @@ public class PushController implements Disposable { public void run(@NotNull ProgressIndicator indicator) { myPushSettings.saveExcludedRepoRoots(myExcludedRepositoryRoots); for (PushSupport support : myPushSupports) { - doPush(support, force); + doPushSynchronously(support, force); } } }; task.queue(); } - private void doPush(@NotNull PushSupport support, - boolean force) { + private void doPushSynchronously(@NotNull PushSupport support, + boolean force) { VcsPushOptionValue options = myDialog.getAdditionalOptionValue(support); Pusher pusher = support.getPusher(); Map> specs = collectPushSpecsForVcs(support); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPushCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPushCommand.java index c5318258e552..234c7adcdd92 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPushCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgPushCommand.java @@ -16,10 +16,8 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.HgVcs; import org.zmlx.hg4idea.execution.HgCommandResult; -import org.zmlx.hg4idea.execution.HgCommandResultHandler; import org.zmlx.hg4idea.execution.HgRemoteCommandExecutor; import java.util.LinkedList; @@ -63,7 +61,7 @@ public class HgPushCommand { myBookmarkName = bookmark; } - public void execute(final HgCommandResultHandler resultHandler) { + public HgCommandResult executeInCurrentThread() { final List arguments = new LinkedList(); if (!StringUtil.isEmptyOrSpaces(myRevision)) { arguments.add("-r"); @@ -87,15 +85,9 @@ public class HgPushCommand { final HgRemoteCommandExecutor executor = new HgRemoteCommandExecutor(myProject, myDestination); executor.setShowOutput(true); - executor.execute(myRepo, "push", arguments, new HgCommandResultHandler() { - @Override - public void process(@Nullable HgCommandResult result) { - if (!myProject.isDisposed()) { - myProject.getMessageBus().syncPublisher(HgVcs.REMOTE_TOPIC).update(myProject, null); - } - resultHandler.process(result); - } - }); + HgCommandResult result = executor.executeInCurrentThread(myRepo, "push", arguments); + myProject.getMessageBus().syncPublisher(HgVcs.REMOTE_TOPIC).update(myProject, null); + return result; } public VirtualFile getRepo() { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/push/HgPusher.java b/plugins/hg4idea/src/org/zmlx/hg4idea/push/HgPusher.java index e3c91e0103d9..976c2d7e47d7 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/push/HgPusher.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/push/HgPusher.java @@ -28,7 +28,6 @@ import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.action.HgCommandResultNotifier; import org.zmlx.hg4idea.command.HgPushCommand; import org.zmlx.hg4idea.execution.HgCommandResult; -import org.zmlx.hg4idea.execution.HgCommandResultHandler; import org.zmlx.hg4idea.repo.HgRepository; import java.util.List; @@ -70,35 +69,31 @@ public class HgPusher extends Pusher { else { pushCommand.setBranchName(branchName); } - push(project, pushCommand); + pushSynchronously(project, pushCommand); } } - public static void push(@NotNull final Project project, @NotNull HgPushCommand command) { + public static void pushSynchronously(@NotNull final Project project, @NotNull HgPushCommand command) { final VirtualFile repo = command.getRepo(); - command.execute(new HgCommandResultHandler() { - @Override - public void process(@Nullable HgCommandResult result) { - if (result == null) { - return; - } + HgCommandResult result = command.executeInCurrentThread(); + if (result == null) { + return; + } - if (result.getExitValue() == PUSH_SUCCEEDED_EXIT_VALUE) { - int commitsNum = getNumberOfPushedCommits(result); - String successTitle = "Pushed successfully"; - String successDescription = String.format("Pushed %d %s [%s]", commitsNum, StringUtil.pluralize("commit", commitsNum), - repo.getPresentableName()); - VcsNotifier.getInstance(project).notifySuccess(successTitle, successDescription); - } - else if (result.getExitValue() == NOTHING_TO_PUSH_EXIT_VALUE) { - VcsNotifier.getInstance(project).notifySuccess("Nothing to push"); - } - else { - new HgCommandResultNotifier(project).notifyError(result, "Push failed", - "Failed to push to [" + repo.getPresentableName() + "]"); - } - } - }); + if (result.getExitValue() == PUSH_SUCCEEDED_EXIT_VALUE) { + int commitsNum = getNumberOfPushedCommits(result); + String successTitle = "Pushed successfully"; + String successDescription = String.format("Pushed %d %s [%s]", commitsNum, StringUtil.pluralize("commit", commitsNum), + repo.getPresentableName()); + VcsNotifier.getInstance(project).notifySuccess(successTitle, successDescription); + } + else if (result.getExitValue() == NOTHING_TO_PUSH_EXIT_VALUE) { + VcsNotifier.getInstance(project).notifySuccess("Nothing to push"); + } + else { + new HgCommandResultNotifier(project).notifyError(result, "Push failed", + "Failed to push to [" + repo.getPresentableName() + "]"); + } } static int getNumberOfPushedCommits(@NotNull HgCommandResult result) { diff --git a/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgPushTest.java b/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgPushTest.java index d8ec05cedb9d..2f6c604d9193 100644 --- a/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgPushTest.java +++ b/plugins/hg4idea/testSrc/org/zmlx/hg4idea/test/HgPushTest.java @@ -18,7 +18,6 @@ package org.zmlx.hg4idea.test; import com.intellij.openapi.vfs.VirtualFile; import org.testng.annotations.Test; import org.zmlx.hg4idea.command.HgPushCommand; -import org.zmlx.hg4idea.execution.HgCommandResultHandler; import static org.testng.Assert.assertNotNull; @@ -56,8 +55,7 @@ public class HgPushTest extends HgCollaborativeTest { myChangeListManager.checkFilesAreInList(true, vf); myChangeListManager.commitFiles(vf); - final HgPushCommand command = new HgPushCommand(myProject, myRepo.getDir(), myParentRepo.getDir().getUrl()); - command.execute(HgCommandResultHandler.DUMB); + new HgPushCommand(myProject, myRepo.getDir(), myParentRepo.getDir().getUrl()).executeInCurrentThread(); myParentRepo.update(); assertNotNull(myParentRepo.getDir().findChild(AFILE));