diff --git a/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties b/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties index 375ee39ddd23..308d3279e7c6 100644 --- a/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties +++ b/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties @@ -114,6 +114,7 @@ hg4idea.merge.please-commit=Merged heads, please commit repository \"{0}\" hg4idea.error.invalidExecutable=\"{0}\" is not a valid mercurial executable hg4idea.integrate.other.head=Other head: {0} hg4idea.error.log.command.execution=Error during log command execution +hg4idea.branches.error.description=Couldn't collect information about branches hg4idea.dialog.login.password.required=Login and password required hg4idea.dialog.login.description=Login to {0} diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java index 7d978fc5e59f..04c40795f6d9 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgPusher.java @@ -21,7 +21,6 @@ import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.Consumer; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,7 +35,7 @@ import org.zmlx.hg4idea.ui.HgPushDialog; import org.zmlx.hg4idea.util.HgErrorUtil; import org.zmlx.hg4idea.util.HgUtil; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Matcher; @@ -66,7 +65,9 @@ public class HgPusher { } VirtualFile firstRepo = repositories.get(0); final List branches = getBranches(myProject, firstRepo); - + if (branches.isEmpty()) { + return; + } final AtomicReference pushCommand = new AtomicReference(); UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override @@ -94,14 +95,13 @@ public class HgPusher { @NotNull public static List getBranches(@NotNull Project project, @NotNull VirtualFile root) { - final List branchesList = new ArrayList(); - new HgTagBranchCommand(project, root).listBranches(new Consumer>() { - @Override - public void consume(final List branches) { - branchesList.addAll(branches); - } - }); - return branchesList; + HgCommandResult branchesResult = new HgTagBranchCommand(project, root).collectBranches(); + if (branchesResult == null) { + new HgCommandResultNotifier(project) + .notifyError(branchesResult, "Mercurial command failed", HgVcsMessages.message("hg4idea.branches.error.description")); + return Collections.emptyList(); + } + return HgTagBranchCommand.parseResult(branchesResult); } private static void push(final Project project, HgPushCommand command) { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgUpdateToAction.java b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgUpdateToAction.java index 83c5e202cd4f..f7951e5b7a28 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgUpdateToAction.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/action/HgUpdateToAction.java @@ -53,21 +53,9 @@ public class HgUpdateToAction extends HgAbstractGlobalAction { dialog.show(); if (dialog.isOK()) { FileDocumentManager.getInstance().saveAllDocuments(); - String updateToValue; - if (dialog.isBranchSelected() && dialog.getBranch() != null) { - updateToValue = dialog.getBranch().getName(); - } - else if (dialog.isTagSelected() && dialog.getTag() != null) { - updateToValue = dialog.getTag().getName(); - } - else if (dialog.isRevisionSelected()) { - updateToValue = dialog.getRevision(); - } - else { - new HgCommandResultNotifier(project).notifyError(null, "Update failed", "Couldn't execute Mercurial command"); - return;// hg execute command error occurs// - } - + String updateToValue = dialog.isBranchSelected() + ? dialog.getBranch().getName() + : dialog.isTagSelected() ? dialog.getTag().getName() : dialog.getRevision(); new Task.Backgroundable(project, HgVcsMessages.message("action.hg4idea.updateTo.description", updateToValue)) { @Override diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTagBranchCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTagBranchCommand.java index 202428d6adeb..b72897e6afe5 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTagBranchCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgTagBranchCommand.java @@ -14,13 +14,11 @@ 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.HgRevisionNumber; 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; @@ -57,29 +55,15 @@ public class HgTagBranchCommand { return output.get(0).trim(); } - public void listBranches(final Consumer> branchListConsumer) { - new HgCommandExecutor(project).execute(repo, "branches", null, new HgCommandResultHandler() { - @Override - public void process(@Nullable HgCommandResult result) { - if (result != null) { - branchListConsumer.consume(tokenize(result)); - } - } - }); + public HgCommandResult collectBranches() { + return new HgCommandExecutor(project).executeInCurrentThread(repo, "branches", null); } - public void listTags(final Consumer> tagListConsumer) { - new HgCommandExecutor(project).execute(repo, "tags", null, new HgCommandResultHandler() { - @Override - public void process(@Nullable HgCommandResult result) { - if (result != null) { - tagListConsumer.consume(tokenize(result)); - } - } - }); + public HgCommandResult collectTags() { + return new HgCommandExecutor(project).executeInCurrentThread(repo, "tags", null); } - private static List tokenize(HgCommandResult result) { + public static List parseResult(HgCommandResult result) { List branches = new LinkedList(); for (final String line : result.getOutputLines()) { Matcher matcher = BRANCH_LINE.matcher(line); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgMergeDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgMergeDialog.java index cadfeec91c74..e2b2a82678a6 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgMergeDialog.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgMergeDialog.java @@ -16,7 +16,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.Consumer; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.HgRevisionNumber; @@ -25,6 +24,7 @@ import org.zmlx.hg4idea.command.HgHeadsCommand; import org.zmlx.hg4idea.command.HgTagBranch; import org.zmlx.hg4idea.command.HgTagBranchCommand; import org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand; +import org.zmlx.hg4idea.execution.HgCommandResult; import javax.swing.*; import javax.swing.event.ChangeEvent; @@ -123,15 +123,13 @@ public class HgMergeDialog extends DialogWrapper { } private void loadTags(VirtualFile root) { - new HgTagBranchCommand(project, root).listTags(new Consumer>() { + HgCommandResult tagsResult = new HgTagBranchCommand(project, root).collectTags(); + assert tagsResult != null; + final List tags = HgTagBranchCommand.parseResult(tagsResult); + UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override - public void consume(final List tags) { - UIUtil.invokeAndWaitIfNeeded(new Runnable() { - @Override - public void run() { - tagSelector.setModel(new DefaultComboBoxModel(tags.toArray())); - } - }); + public void run() { + tagSelector.setModel(new DefaultComboBoxModel(tags.toArray())); } }); } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgUpdateToDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgUpdateToDialog.java index ecc5a406b3fd..e3c03be57a5e 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgUpdateToDialog.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgUpdateToDialog.java @@ -15,10 +15,10 @@ 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 com.intellij.util.ui.UIUtil; import org.zmlx.hg4idea.command.HgTagBranch; import org.zmlx.hg4idea.command.HgTagBranchCommand; +import org.zmlx.hg4idea.execution.HgCommandResult; import javax.swing.*; import javax.swing.event.ChangeEvent; @@ -124,15 +124,13 @@ public class HgUpdateToDialog extends DialogWrapper { } private void loadTags(VirtualFile root) { - new HgTagBranchCommand(project, root).listTags(new Consumer>() { + HgCommandResult tagsResult = new HgTagBranchCommand(project, root).collectTags(); + assert tagsResult != null; + final List tags = HgTagBranchCommand.parseResult(tagsResult); + UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override - public void consume(final List tags) { - UIUtil.invokeAndWaitIfNeeded(new Runnable() { - @Override - public void run() { - tagSelector.setModel(new DefaultComboBoxModel(tags.toArray())); - } - }); + public void run() { + tagSelector.setModel(new DefaultComboBoxModel(tags.toArray())); } }); } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUiUtil.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUiUtil.java index 703637931334..090a9f46178f 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUiUtil.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUiUtil.java @@ -22,8 +22,11 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Consumer; import com.intellij.util.containers.HashMap; import org.jetbrains.annotations.NotNull; +import org.zmlx.hg4idea.HgVcsMessages; +import org.zmlx.hg4idea.action.HgCommandResultNotifier; import org.zmlx.hg4idea.command.HgTagBranch; import org.zmlx.hg4idea.command.HgTagBranchCommand; +import org.zmlx.hg4idea.execution.HgCommandResult; import java.util.Collection; import java.util.List; @@ -42,15 +45,21 @@ public class HgUiUtil { @Override public void run(@NotNull ProgressIndicator indicator) { for (final VirtualFile repo : repos) { - new HgTagBranchCommand(project, repo).listBranches(new Consumer>() { - @Override - public void consume(final List branches) { - branchesForRepos.put(repo, branches); - } - }); + HgCommandResult result = new HgTagBranchCommand(project, repo).collectBranches(); + if (result == null) { + indicator.cancel(); + return; + } + branchesForRepos.put(repo, HgTagBranchCommand.parseResult(result)); } } + @Override + public void onCancel() { + new HgCommandResultNotifier(project) + .notifyError(null, "Mercurial command failed", HgVcsMessages.message("hg4idea.branches.error.description")); + } + @Override public void onSuccess() { successHandler.consume(branchesForRepos);