From bedf7d3c106756895fdc74fde4cf46d843d79530 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Tue, 18 Oct 2016 17:29:47 +0300 Subject: [PATCH] Remove unused logic of populating exceptions list It used to show errors from the list later, but that does't happen anymore. Show error manually when needed. In addition to that move tagging process to the modal task instead of freezing the UI. --- .../src/git4idea/actions/GitFetch.java | 4 +-- .../src/git4idea/actions/GitMergeAction.java | 3 +- .../git4idea/actions/GitRepositoryAction.java | 13 ++------- .../src/git4idea/actions/GitResetHead.java | 8 ++--- .../src/git4idea/actions/GitStash.java | 8 ++--- .../git4idea/src/git4idea/actions/GitTag.java | 17 ++++++----- .../src/git4idea/actions/GitUnstash.java | 4 +-- .../src/git4idea/ui/GitTagDialog.java | 29 ++++++++----------- 8 files changed, 35 insertions(+), 51 deletions(-) diff --git a/plugins/git4idea/src/git4idea/actions/GitFetch.java b/plugins/git4idea/src/git4idea/actions/GitFetch.java index 12f6ad919088..8283fefb2043 100644 --- a/plugins/git4idea/src/git4idea/actions/GitFetch.java +++ b/plugins/git4idea/src/git4idea/actions/GitFetch.java @@ -18,7 +18,6 @@ package git4idea.actions; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; import git4idea.GitUtil; import git4idea.GitVcs; @@ -38,8 +37,7 @@ public class GitFetch extends GitRepositoryAction { protected void perform(@NotNull final Project project, @NotNull final List gitRoots, - @NotNull final VirtualFile defaultRoot, - final List exceptions) throws VcsException { + @NotNull final VirtualFile defaultRoot) { GitVcs.runInBackground(new Task.Backgroundable(project, "Fetching...", true) { @Override public void run(@NotNull ProgressIndicator indicator) { diff --git a/plugins/git4idea/src/git4idea/actions/GitMergeAction.java b/plugins/git4idea/src/git4idea/actions/GitMergeAction.java index d723017b8836..ca3491519cfe 100644 --- a/plugins/git4idea/src/git4idea/actions/GitMergeAction.java +++ b/plugins/git4idea/src/git4idea/actions/GitMergeAction.java @@ -64,8 +64,7 @@ abstract class GitMergeAction extends GitRepositoryAction { protected void perform(@NotNull final Project project, @NotNull final List gitRoots, - @NotNull final VirtualFile defaultRoot, - final List exceptions) throws VcsException { + @NotNull final VirtualFile defaultRoot) { final DialogState dialogState = displayDialog(project, gitRoots, defaultRoot); if (dialogState == null) { return; diff --git a/plugins/git4idea/src/git4idea/actions/GitRepositoryAction.java b/plugins/git4idea/src/git4idea/actions/GitRepositoryAction.java index ebbf5b651aa7..79d07056b6f0 100644 --- a/plugins/git4idea/src/git4idea/actions/GitRepositoryAction.java +++ b/plugins/git4idea/src/git4idea/actions/GitRepositoryAction.java @@ -34,7 +34,6 @@ import org.jetbrains.annotations.CalledInAwt; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.List; import static com.intellij.util.ObjectUtils.notNull; @@ -54,13 +53,7 @@ public abstract class GitRepositoryAction extends DumbAwareAction { final VirtualFile defaultRoot = getDefaultRoot(project, roots, e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY)); - List exceptions = new ArrayList<>(); - try { - perform(project, roots, defaultRoot, exceptions); - } - catch (VcsException ex) { - exceptions.add(ex); - } + perform(project, roots, defaultRoot); } @NotNull @@ -128,13 +121,11 @@ public abstract class GitRepositoryAction extends DumbAwareAction { * @param project a context project * @param gitRoots a git roots that affect the current project (sorted by {@link VirtualFile#getPresentableUrl()}) * @param defaultRoot a guessed default root (based on the currently selected file list) - * @param exceptions a list of exceptions from running git * @throws VcsException if there is a problem with running git (this exception is considered to be added to the end of the exception list) */ protected abstract void perform(@NotNull Project project, @NotNull List gitRoots, - @NotNull VirtualFile defaultRoot, - List exceptions) throws VcsException; + @NotNull VirtualFile defaultRoot); @Override public void update(final AnActionEvent e) { diff --git a/plugins/git4idea/src/git4idea/actions/GitResetHead.java b/plugins/git4idea/src/git4idea/actions/GitResetHead.java index 653c1efb3e47..de19b14e40ba 100644 --- a/plugins/git4idea/src/git4idea/actions/GitResetHead.java +++ b/plugins/git4idea/src/git4idea/actions/GitResetHead.java @@ -18,7 +18,6 @@ package git4idea.actions; import com.intellij.dvcs.DvcsUtil; import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import git4idea.GitUtil; @@ -48,8 +47,7 @@ public class GitResetHead extends GitRepositoryAction { */ protected void perform(@NotNull Project project, @NotNull List gitRoots, - @NotNull VirtualFile defaultRoot, - List exceptions) throws VcsException { + @NotNull VirtualFile defaultRoot) { GitResetDialog d = new GitResetDialog(project, gitRoots, defaultRoot); if (!d.showAndGet()) { return; @@ -65,6 +63,8 @@ public class GitResetHead extends GitRepositoryAction { GitRepositoryManager manager = GitUtil.getRepositoryManager(project); manager.updateRepository(d.getGitRoot()); VfsUtil.markDirtyAndRefresh(true, true, false, d.getGitRoot()); - showErrors(project, getActionName(), exceptions); + if(!h.errors().isEmpty()) { + showErrors(project, getActionName(), h.errors()); + } } } diff --git a/plugins/git4idea/src/git4idea/actions/GitStash.java b/plugins/git4idea/src/git4idea/actions/GitStash.java index 3de0b338a525..2e1f13fd6c04 100644 --- a/plugins/git4idea/src/git4idea/actions/GitStash.java +++ b/plugins/git4idea/src/git4idea/actions/GitStash.java @@ -18,7 +18,6 @@ package git4idea.actions; import com.intellij.dvcs.DvcsUtil; import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.ChangeListManager; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -40,8 +39,7 @@ public class GitStash extends GitRepositoryAction { */ protected void perform(@NotNull final Project project, @NotNull final List gitRoots, - @NotNull final VirtualFile defaultRoot, - final List exceptions) throws VcsException { + @NotNull final VirtualFile defaultRoot) { final ChangeListManager changeListManager = ChangeListManager.getInstance(project); if (changeListManager.isFreezedWithNotification("Can not stash changes now")) return; GitStashDialog d = new GitStashDialog(project, gitRoots, defaultRoot); @@ -58,7 +56,9 @@ public class GitStash extends GitRepositoryAction { DvcsUtil.workingTreeChangeFinished(project, token); } VfsUtil.markDirtyAndRefresh(false, true, false, root); - showErrors(project, getActionName(), exceptions); + if(!h.errors().isEmpty()) { + showErrors(project, getActionName(), h.errors()); + } } /** diff --git a/plugins/git4idea/src/git4idea/actions/GitTag.java b/plugins/git4idea/src/git4idea/actions/GitTag.java index 50a986ed7534..c27b52394c69 100644 --- a/plugins/git4idea/src/git4idea/actions/GitTag.java +++ b/plugins/git4idea/src/git4idea/actions/GitTag.java @@ -15,8 +15,9 @@ */ package git4idea.actions; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; import git4idea.i18n.GitBundle; import git4idea.ui.GitTagDialog; @@ -42,13 +43,15 @@ public class GitTag extends GitRepositoryAction { */ protected void perform(@NotNull final Project project, @NotNull final List gitRoots, - @NotNull final VirtualFile defaultRoot, - final List exceptions) throws VcsException { + @NotNull final VirtualFile defaultRoot) { GitTagDialog d = new GitTagDialog(project, gitRoots, defaultRoot); - if (!d.showAndGet()) { - return; + if (d.showAndGet()) { + new Task.Modal(project, "Tagging...", true) { + @Override + public void run(@NotNull ProgressIndicator indicator) { + d.runAction(); + } + }.queue(); } - d.runAction(exceptions); - showErrors(project, getActionName(), exceptions); } } diff --git a/plugins/git4idea/src/git4idea/actions/GitUnstash.java b/plugins/git4idea/src/git4idea/actions/GitUnstash.java index 41e086979f90..6b14d4fa5879 100644 --- a/plugins/git4idea/src/git4idea/actions/GitUnstash.java +++ b/plugins/git4idea/src/git4idea/actions/GitUnstash.java @@ -16,7 +16,6 @@ package git4idea.actions; import com.intellij.openapi.project.Project; -import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.ChangeListManager; import com.intellij.openapi.vfs.VirtualFile; import git4idea.i18n.GitBundle; @@ -43,8 +42,7 @@ public class GitUnstash extends GitRepositoryAction { */ protected void perform(@NotNull final Project project, @NotNull final List gitRoots, - @NotNull final VirtualFile defaultRoot, - final List exceptions) throws VcsException { + @NotNull final VirtualFile defaultRoot) { final ChangeListManager changeListManager = ChangeListManager.getInstance(project); if (changeListManager.isFreezedWithNotification("Can not unstash changes now")) return; GitUnstashDialog.showUnstashDialog(project, gitRoots, defaultRoot); diff --git a/plugins/git4idea/src/git4idea/ui/GitTagDialog.java b/plugins/git4idea/src/git4idea/ui/GitTagDialog.java index e9d0b19b2e9d..441ed40f3c99 100644 --- a/plugins/git4idea/src/git4idea/ui/GitTagDialog.java +++ b/plugins/git4idea/src/git4idea/ui/GitTagDialog.java @@ -20,7 +20,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.VcsNotifier; import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.openapi.vfs.VirtualFile; @@ -156,10 +155,8 @@ public class GitTagDialog extends DialogWrapper { /** * Perform tagging according to selected options - * - * @param exceptions the list where exceptions are collected */ - public void runAction(final List exceptions) { + public void runAction() { final String message = myMessageTextArea.getText(); final boolean hasMessage = message.trim().length() != 0; final File messageFile; @@ -200,20 +197,18 @@ public class GitTagDialog extends DialogWrapper { if (object.length() != 0) { h.addParameters(object); } - try { - GitHandlerUtil.doSynchronously(h, GitBundle.getString("tagging.title"), h.printableCommandLine()); - VcsNotifier.getInstance(myProject).notifySuccess(myTagNameTextField.getText(), - "Created tag " + myTagNameTextField.getText() + " successfully."); - GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(getGitRoot()); - if (repository != null) { - repository.getRepositoryFiles().refresh(true); - } - else { - LOG.error("No repository registered for root: " + getGitRoot()); - } + GitHandlerUtil.doSynchronously(h, GitBundle.getString("tagging.title"), h.printableCommandLine()); + VcsNotifier.getInstance(myProject).notifySuccess(myTagNameTextField.getText(), + "Created tag " + myTagNameTextField.getText() + " successfully."); + GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(getGitRoot()); + if (repository != null) { + repository.getRepositoryFiles().refresh(true); } - finally { - exceptions.addAll(h.errors()); + else { + LOG.error("No repository registered for root: " + getGitRoot()); + } + if(!h.errors().isEmpty()) { + GitUIUtil.notifyImportantError(myProject, "Error rebasing", GitUIUtil.stringifyErrors(h.errors())); } } finally {