From 0eb0a81f9a65afd8f2b1f7e7f05d39267b5d6cbd Mon Sep 17 00:00:00 2001
From: Kirill Likhodedov
Date: Thu, 15 Nov 2012 16:19:06 +0100
Subject: [PATCH] [git] Reverting unfinished changes for push.
There are some problems there that can't be fixed soon, so we don't want this in release.
This commit reverts the range 50a427639^..d81998d --author=Likhodedov
---
.../util/concurrency/QueueProcessor.java | 6 -
plugins/git4idea/src/git4idea/GitLogger.java | 1 -
.../src/git4idea/branch/GitBranchPair.java | 59 ++------
.../git4idea/src/git4idea/commands/Git.java | 4 +-
.../src/git4idea/commands/GitImpl.java | 4 +-
.../src/git4idea/push/GitCommitsByBranch.java | 15 +-
.../git4idea/push/GitManualPushToBranch.java | 49 +++---
.../push/GitOutgoingCommitsCollector.java | 139 +++++++++++-------
.../src/git4idea/push/GitPushDialog.java | 68 +++------
.../src/git4idea/push/GitPushLog.java | 31 ++--
.../src/git4idea/push/GitPushSpec.java | 89 +++++++++++
.../src/git4idea/push/GitPushSpecs.java | 58 ++------
.../src/git4idea/push/GitPushUtil.java | 28 ++--
.../git4idea/src/git4idea/push/GitPusher.java | 31 ++--
.../src/git4idea/update/GitMergeUpdater.java | 2 +-
.../src/git4idea/update/GitRebaseUpdater.java | 2 +-
.../src/git4idea/update/GitUpdater.java | 2 +-
.../git4idea/test/GitTestImpl.groovy | 4 +-
.../git4idea/test/MockGit.groovy | 4 +-
.../git4idea/push/GitPushSpecTest.groovy | 3 +-
20 files changed, 304 insertions(+), 295 deletions(-)
create mode 100644 plugins/git4idea/src/git4idea/push/GitPushSpec.java
diff --git a/platform/platform-api/src/com/intellij/util/concurrency/QueueProcessor.java b/platform/platform-api/src/com/intellij/util/concurrency/QueueProcessor.java
index fcbc18b02127..0688214c0ae1 100644
--- a/platform/platform-api/src/com/intellij/util/concurrency/QueueProcessor.java
+++ b/platform/platform-api/src/com/intellij/util/concurrency/QueueProcessor.java
@@ -251,12 +251,6 @@ public class QueueProcessor {
}
}
- public boolean hasPendingJobs() {
- synchronized (myQueue) {
- return !myQueue.isEmpty();
- }
- }
-
private static class MyOverrideEquals {
private final Object myDelegate;
diff --git a/plugins/git4idea/src/git4idea/GitLogger.java b/plugins/git4idea/src/git4idea/GitLogger.java
index b66514a61bf8..56df1d8ca9ca 100644
--- a/plugins/git4idea/src/git4idea/GitLogger.java
+++ b/plugins/git4idea/src/git4idea/GitLogger.java
@@ -22,7 +22,6 @@ import com.intellij.openapi.diagnostic.Logger;
*/
public class GitLogger {
- public static final Logger CORE_LOG = Logger.getInstance("GitCore");
public static final Logger PUSH_LOG = Logger.getInstance("GitPush");
}
diff --git a/plugins/git4idea/src/git4idea/branch/GitBranchPair.java b/plugins/git4idea/src/git4idea/branch/GitBranchPair.java
index eb5ea6c0eee0..822188af295b 100644
--- a/plugins/git4idea/src/git4idea/branch/GitBranchPair.java
+++ b/plugins/git4idea/src/git4idea/branch/GitBranchPair.java
@@ -15,74 +15,33 @@
*/
package git4idea.branch;
-import com.intellij.openapi.diagnostic.Logger;
import git4idea.GitLocalBranch;
-import git4idea.GitLogger;
import git4idea.GitRemoteBranch;
-import git4idea.repo.GitRepository;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
- * Holder for a Git branch and the branch it is "connected" with.
- * Usually it is the tracked branch, but may any other (for example, when pushing to an alternative branch).
+ * Holder for Git branch and the branch it is "connected" with. It is tracked branch or so called "matched" branch.
*
* @author Kirill Likhodedov
*/
public class GitBranchPair {
+ private @NotNull GitLocalBranch myBranch;
+ private @Nullable GitRemoteBranch myDestBranch;
- private static final Logger LOG = GitLogger.CORE_LOG;
-
- @NotNull private GitLocalBranch mySource;
- @Nullable private GitRemoteBranch myDest;
-
- public GitBranchPair(@NotNull GitLocalBranch source, @Nullable GitRemoteBranch destination) {
- mySource = source;
- myDest = destination;
+ public GitBranchPair(@NotNull GitLocalBranch branch, @Nullable GitRemoteBranch destination) {
+ myBranch = branch;
+ myDestBranch = destination;
}
@NotNull
- public static GitBranchPair findCurrentAnTracked(@NotNull GitRepository repository) {
- repository.update();
- GitLocalBranch currentBranch = repository.getCurrentBranch();
- LOG.assertTrue(currentBranch != null, "Push shouldn't be available in the detached HEAD state");
- return new GitBranchPair(currentBranch, currentBranch.findTrackedBranch(repository));
- }
-
- @NotNull
- public GitLocalBranch getSource() {
- return mySource;
+ public GitLocalBranch getBranch() {
+ return myBranch;
}
@Nullable
public GitRemoteBranch getDest() {
- return myDest;
- }
-
- @Override
- public String toString() {
- String dest = myDest == null ? "nowhere" : myDest.getFullName();
- return mySource.getName() + "->" + dest;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- GitBranchPair spec = (GitBranchPair)o;
-
- if (myDest != null ? !myDest.equals(spec.myDest) : spec.myDest != null) return false;
- if (!mySource.equals(spec.mySource)) return false;
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = mySource.hashCode();
- result = 31 * result + (myDest != null ? myDest.hashCode() : 0);
- return result;
+ return myDestBranch;
}
}
diff --git a/plugins/git4idea/src/git4idea/commands/Git.java b/plugins/git4idea/src/git4idea/commands/Git.java
index 7ed7a120adb8..c9fc7f0555c7 100644
--- a/plugins/git4idea/src/git4idea/commands/Git.java
+++ b/plugins/git4idea/src/git4idea/commands/Git.java
@@ -18,8 +18,8 @@ package git4idea.commands;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
-import git4idea.branch.GitBranchPair;
import git4idea.history.browser.GitCommit;
+import git4idea.push.GitPushSpec;
import git4idea.repo.GitRepository;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -95,7 +95,7 @@ public interface Git {
@NotNull GitLineHandlerListener... listeners);
@NotNull
- GitCommandResult push(@NotNull GitRepository repository, @NotNull GitBranchPair pushSpec,
+ GitCommandResult push(@NotNull GitRepository repository, @NotNull GitPushSpec pushSpec,
@NotNull GitLineHandlerListener... listeners);
@NotNull
diff --git a/plugins/git4idea/src/git4idea/commands/GitImpl.java b/plugins/git4idea/src/git4idea/commands/GitImpl.java
index 696a285091cf..de95c73907f4 100644
--- a/plugins/git4idea/src/git4idea/commands/GitImpl.java
+++ b/plugins/git4idea/src/git4idea/commands/GitImpl.java
@@ -25,9 +25,9 @@ import com.intellij.util.ExceptionUtil;
import com.intellij.vcsUtil.VcsFileUtil;
import git4idea.GitBranch;
import git4idea.GitExecutionException;
-import git4idea.branch.GitBranchPair;
import git4idea.history.GitHistoryUtils;
import git4idea.history.browser.GitCommit;
+import git4idea.push.GitPushSpec;
import git4idea.repo.GitRemote;
import git4idea.repo.GitRepository;
import org.jetbrains.annotations.NotNull;
@@ -368,7 +368,7 @@ public class GitImpl implements Git {
@Override
@NotNull
- public GitCommandResult push(@NotNull GitRepository repository, @NotNull GitBranchPair pushSpec,
+ public GitCommandResult push(@NotNull GitRepository repository, @NotNull GitPushSpec pushSpec,
@NotNull GitLineHandlerListener... listeners) {
GitRemote remote = pushSpec.getDest().getRemote();
GitBranch remoteBranch = pushSpec.getDest();
diff --git a/plugins/git4idea/src/git4idea/push/GitCommitsByBranch.java b/plugins/git4idea/src/git4idea/push/GitCommitsByBranch.java
index decd9b91251c..7133f4dba8eb 100644
--- a/plugins/git4idea/src/git4idea/push/GitCommitsByBranch.java
+++ b/plugins/git4idea/src/git4idea/push/GitCommitsByBranch.java
@@ -78,15 +78,12 @@ final class GitCommitsByBranch {
return new GitCommitsByBranch(res);
}
- boolean hasAnythingToPush() {
- Collection allCommits = new ArrayList();
- for (GitPushBranchInfo info : myCommitsByBranch.values()) {
- if (info.getType() == GitPushBranchInfo.Type.NEW_BRANCH || info.getType() == GitPushBranchInfo.Type.NO_TRACKED_OR_TARGET) {
- return true;
- }
- allCommits.addAll(info.getCommits());
+ @NotNull
+ public Collection getAllCommits() {
+ Collection commits = new ArrayList();
+ for (GitPushBranchInfo branchInfo : myCommitsByBranch.values()) {
+ commits.addAll(branchInfo.getCommits());
}
- return !allCommits.isEmpty();
+ return commits;
}
-
}
diff --git a/plugins/git4idea/src/git4idea/push/GitManualPushToBranch.java b/plugins/git4idea/src/git4idea/push/GitManualPushToBranch.java
index 512c175df5a1..52e928511a64 100644
--- a/plugins/git4idea/src/git4idea/push/GitManualPushToBranch.java
+++ b/plugins/git4idea/src/git4idea/push/GitManualPushToBranch.java
@@ -15,17 +15,19 @@
*/
package git4idea.push;
+import com.intellij.icons.AllIcons;
+import com.intellij.openapi.actionSystem.*;
+import com.intellij.openapi.actionSystem.impl.ActionButton;
+import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.ui.ListCellRendererWrapper;
import com.intellij.ui.components.JBLabel;
-import com.intellij.ui.components.JBTextField;
import com.intellij.util.ui.GridBag;
import com.intellij.util.ui.UIUtil;
import git4idea.repo.GitRemote;
+import git4idea.repo.GitRepository;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
import java.awt.*;
import java.util.Collection;
@@ -36,6 +38,8 @@ class GitManualPushToBranch extends JPanel {
private final JTextField myDestBranchTextField;
private final JBLabel myComment;
+ private final GitPushLogRefreshAction myRefreshAction;
+ private final JComponent myRefreshButton;
private final RemoteSelector myRemoteSelector;
private final JComponent myRemoteSelectorComponent;
private boolean myMultiRepositoryProject;
@@ -44,25 +48,20 @@ class GitManualPushToBranch extends JPanel {
super();
myMultiRepositoryProject = multiRepositoryProject;
- myDestBranchTextField = new JBTextField(20);
- myDestBranchTextField.getDocument().addDocumentListener(new DocumentListener() {
- @Override
- public void insertUpdate(DocumentEvent e) {
- performOnRefresh.run();
- }
-
- @Override
- public void removeUpdate(DocumentEvent e) {
- performOnRefresh.run();
- }
-
- @Override
- public void changedUpdate(DocumentEvent e) {
- performOnRefresh.run();
- }
- });
+ myDestBranchTextField = new JTextField(20);
myComment = new JBLabel("This will apply to all selected repositories", UIUtil.ComponentStyle.SMALL);
+
+ myRefreshAction = new GitPushLogRefreshAction() {
+ @Override public void actionPerformed(AnActionEvent e) {
+ performOnRefresh.run();
+ }
+ };
+ myRefreshButton = new ActionButton(myRefreshAction, myRefreshAction.getTemplatePresentation(), myRefreshAction.getTemplatePresentation().getText(), ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE);
+ myRefreshButton.setFocusable(true);
+ final ShortcutSet shortcutSet = ActionManager.getInstance().getAction(IdeActions.ACTION_REFRESH).getShortcutSet();
+ myRefreshAction.registerCustomShortcutSet(shortcutSet, myRefreshButton);
+
myRemoteSelector = new RemoteSelector();
myRemoteSelectorComponent = myRemoteSelector.createComponent();
@@ -80,12 +79,11 @@ class GitManualPushToBranch extends JPanel {
.setDefaultInsets(new Insets(0, 0, UIUtil.DEFAULT_VGAP, 5))
;
JLabel targetBranchLabel = new JBLabel("Target branch: ");
- targetBranchLabel.setDisplayedMnemonic('b');
- targetBranchLabel.setLabelFor(myDestBranchTextField);
panel.add(targetBranchLabel, g.nextLine().next());
panel.add(myRemoteSelectorComponent, g.next());
panel.add(myDestBranchTextField, g.next());
+ panel.add(myRefreshButton, g.next());
if (myMultiRepositoryProject) {
panel.add(myComment, g.nextLine().insets(0, 0, 0, 0).coverLine());
}
@@ -160,4 +158,11 @@ class GitManualPushToBranch extends JPanel {
}
+ private abstract static class GitPushLogRefreshAction extends DumbAwareAction {
+
+ GitPushLogRefreshAction() {
+ super("Refresh commit list", "Refresh commit list", AllIcons.Actions.Refresh);
+ }
+ }
+
}
diff --git a/plugins/git4idea/src/git4idea/push/GitOutgoingCommitsCollector.java b/plugins/git4idea/src/git4idea/push/GitOutgoingCommitsCollector.java
index e38f2815e649..ab56b6b2df24 100644
--- a/plugins/git4idea/src/git4idea/push/GitOutgoingCommitsCollector.java
+++ b/plugins/git4idea/src/git4idea/push/GitOutgoingCommitsCollector.java
@@ -15,13 +15,12 @@
*/
package git4idea.push;
+import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vcs.VcsException;
-import com.intellij.util.Consumer;
-import com.intellij.util.concurrency.QueueProcessor;
import git4idea.*;
import git4idea.branch.GitBranchPair;
import git4idea.history.GitHistoryUtils;
@@ -36,13 +35,16 @@ import java.util.concurrent.TimeUnit;
/**
* Collects outgoing commits (commits to be pushed) for all repositories and holds this information.
*
- *
The contract of the current implementation (probably, some or the limitations will be removed in the future):
+ *
The contract of the current implementations (probably, some or the limitations will be removed in the future):
*
*
If you want to request outgoing commits (and force refresh, even if they were previously collected),
- * call {@link #collect(GitPushSpecs, ResultHandler)}. {@link GitPushDialog} should do it to get the up-to-date list of commits to push.
- *
If you want just to get the list of outgoing commits, but not sure if the list is ready, call
- * {@link #waitForCompletionAndGetCommits()} and {@link #getCommits() get commits}.
- * It will collect commits if they were not collected yet.
+ * call {@link #collect(ResultHandler)}. {@link GitPushDialog} should do it to get the up-to-date list of commits to push.
+ *
If you want to get the list of outgoing commits, but not sure if the list is ready, call
+ * {@link #waitForCompletionAndGetCommits(boolean)} and {@link #getCommits() get commits}.
+ * It will collect commits if they were not collected yet. It won't refresh the list if
+ * commits were collected, unless you specify the {@code refresh} parameter to it.
+ * The latter is needed, when pushing without opening a push dialog (Commit & Push and if this behavior is switched on in the
+ * settings): otherwise we will get the list of commits requested by previous push dialog, which might be very out-of-date.
*
*
*
@@ -52,68 +54,99 @@ class GitOutgoingCommitsCollector {
private static final Logger LOG = GitLogger.PUSH_LOG;
- @NotNull private final QueueProcessor myProcessor = new QueueProcessor(new Collector());
+ @NotNull private final Project myProject;
+ @NotNull private final GitPlatformFacade myPlatformFacade;
+
+ @NotNull private State myState;
@NotNull private final Object STATE_LOCK = new Object();
- @NotNull private final Queue myResultHandlers = new ArrayDeque();
+ @NotNull private final Queue completionHandlers = new ArrayDeque();
+ private int refreshWaiters;
@NotNull private GitCommitsByRepoAndBranch myCommits = GitCommitsByRepoAndBranch.empty();
@Nullable private String myError;
/**
- * Individual locks for threads which request {@link #waitForCompletionAndGetCommits()}.
+ * Individual locks for threads which request {@link #waitForCompletionAndGetCommits(boolean)}.
*/
@NotNull private final ThreadLocal