From e32ba2782b5ee537b38b38a110c58b95019fede6 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Tue, 31 Jan 2012 17:23:17 +0400 Subject: [PATCH] Git push: remove redundant unused "push all" case --- .../git4idea/src/git4idea/commands/Git.java | 13 ++-- .../src/git4idea/push/GitPushDialog.java | 36 ++--------- .../src/git4idea/push/GitPushSpec.java | 44 +------------ .../git4idea/src/git4idea/push/GitPusher.java | 63 ++++--------------- 4 files changed, 24 insertions(+), 132 deletions(-) diff --git a/plugins/git4idea/src/git4idea/commands/Git.java b/plugins/git4idea/src/git4idea/commands/Git.java index ebe5b02a9f0e..c52978d918dd 100644 --- a/plugins/git4idea/src/git4idea/commands/Git.java +++ b/plugins/git4idea/src/git4idea/commands/Git.java @@ -243,14 +243,11 @@ public class Git { for (GitLineHandlerListener listener : listeners) { h.addLineListener(listener); } - if (!pushSpec.isPushAll()) { - GitRemote remote = pushSpec.getRemote(); - LOG.assertTrue(remote != null, "Remote can't be null: " + pushSpec); - h.addParameters(remote.getName()); - GitBranch remoteBranch = pushSpec.getDest(); - String destination = remoteBranch.getName().replaceFirst(remote.getName() + "/", ""); - h.addParameters(pushSpec.getSource().getName() + ":" + destination); - } + GitRemote remote = pushSpec.getRemote(); + h.addParameters(remote.getName()); + GitBranch remoteBranch = pushSpec.getDest(); + String destination = remoteBranch.getName().replaceFirst(remote.getName() + "/", ""); + h.addParameters(pushSpec.getSource().getName() + ":" + destination); return run(h, true); } diff --git a/plugins/git4idea/src/git4idea/push/GitPushDialog.java b/plugins/git4idea/src/git4idea/push/GitPushDialog.java index 96159428b801..781dbae73e4e 100644 --- a/plugins/git4idea/src/git4idea/push/GitPushDialog.java +++ b/plugins/git4idea/src/git4idea/push/GitPushDialog.java @@ -35,8 +35,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -50,7 +48,6 @@ public class GitPushDialog extends DialogWrapper { private static final Logger LOG = Logger.getInstance(GitPushDialog.class); private static final String DEFAULT_REMOTE = "origin"; - private JComponent myRootPanel; private Project myProject; private final GitPusher myPusher; private final GitPushLog myListPanel; @@ -58,7 +55,6 @@ public class GitPushDialog extends DialogWrapper { private Map myPushSpecs; private final Collection myRepositories; private final JBLoadingPanel myLoadingPanel; - private final JCheckBox myPushAllCheckbox; private final Object COMMITS_LOADING_LOCK = new Object(); private final GitManualPushToBranch myRefspecPanel; private final AtomicReference myDestBranchInfoOnRefresh = new AtomicReference(); @@ -73,17 +69,6 @@ public class GitPushDialog extends DialogWrapper { myRepositories = GitRepositoryManager.getInstance(myProject).getRepositories(); myLoadingPanel = new JBLoadingPanel(new BorderLayout(), this.getDisposable()); - myPushAllCheckbox = new JCheckBox("Push all branches", false); - myPushAllCheckbox.setMnemonic('p'); - myPushAllCheckbox.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - loadCommitsInBackground(); - } - }); - /* hidden: it may confuse users, the target is not clear, hidden until really needed, - not removed completely because it is default behavior for 'git push' in command line. */ - myPushAllCheckbox.setVisible(false); myListPanel = new GitPushLog(myProject, myRepositories, new RepositoryCheckboxListener()); myRefspecPanel = new GitManualPushToBranch(myRepositories, new RefreshButtonListener()); @@ -100,19 +85,17 @@ public class GitPushDialog extends DialogWrapper { init(); setOKButtonText("Push"); setTitle("Git Push"); - } @Override protected JComponent createCenterPanel() { JPanel optionsPanel = new JPanel(new BorderLayout()); - optionsPanel.add(myPushAllCheckbox, BorderLayout.NORTH); optionsPanel.add(myRefspecPanel); - myRootPanel = new JPanel(new BorderLayout(0, 15)); - myRootPanel.add(createCommitListPanel(), BorderLayout.CENTER); - myRootPanel.add(optionsPanel, BorderLayout.SOUTH); - return myRootPanel; + JComponent rootPanel = new JPanel(new BorderLayout(0, 15)); + rootPanel.add(createCommitListPanel(), BorderLayout.CENTER); + rootPanel.add(optionsPanel, BorderLayout.SOUTH); + return rootPanel; } @@ -209,8 +192,7 @@ public class GitPushDialog extends DialogWrapper { @Nullable private String collectInfoToPush() { try { - boolean pushAll = myPushAllCheckbox.isSelected(); - myPushSpecs = pushAll ? pushSpecsForPushAll() : pushSpecsForCurrentOrEnteredBranches(); + myPushSpecs = pushSpecsForCurrentOrEnteredBranches(); myGitCommitsToPush = myPusher.collectCommitsToPush(myPushSpecs); return null; } @@ -280,14 +262,6 @@ public class GitPushDialog extends DialogWrapper { return null; } - private Map pushSpecsForPushAll() { - Map specs = new HashMap(); - for (GitRepository repository : myRepositories) { - specs.put(repository, GitPushSpec.pushAllSpec()); - } - return specs; - } - @Override public JComponent getPreferredFocusedComponent() { return myListPanel.getPreferredFocusComponent(); diff --git a/plugins/git4idea/src/git4idea/push/GitPushSpec.java b/plugins/git4idea/src/git4idea/push/GitPushSpec.java index 8389b5b9a248..7704ae94de95 100644 --- a/plugins/git4idea/src/git4idea/push/GitPushSpec.java +++ b/plugins/git4idea/src/git4idea/push/GitPushSpec.java @@ -15,7 +15,6 @@ */ package git4idea.push; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vcs.VcsException; import git4idea.GitBranch; @@ -26,40 +25,22 @@ import git4idea.repo.GitRepository; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.List; - /** * @author Kirill Likhodedov */ public class GitPushSpec { - private static final Logger LOG = Logger.getInstance(GitPushSpec.class); - - private final GitRemote myRemote; + @NotNull private final GitRemote myRemote; @NotNull private final GitBranch mySource; @NotNull private final GitBranch myDest; - private final boolean myPushAll; GitPushSpec(@NotNull GitRemote remote, @NotNull GitBranch source, @NotNull GitBranch dest) { myRemote = remote; mySource = source; myDest = dest; - myPushAll = false; - } - - private GitPushSpec() { - myRemote = null; - mySource = null; - myDest = null; - myPushAll = true; } - static GitPushSpec pushAllSpec() { - return new GitPushSpec(); - } - - @Nullable + @NotNull public GitRemote getRemote() { return myRemote; } @@ -74,27 +55,6 @@ public class GitPushSpec { return myDest; } - /** - * Parses the refspec to identify local branches that are to be pushed together with remote "destination" branches. - * @throws VcsException When looking for thacking branches. - * TODO read tracking information from the config file, i.e. getting rid from the possible exception here. - */ - @NotNull - static List getBranchesForPushAll(@NotNull GitRepository repository) throws VcsException { - List sourceDests = new ArrayList(); - for (GitBranch branch : repository.getBranches().getLocalBranches()) { - GitBranchPair forBranch = findSourceDestForBranch(repository, branch); - if (forBranch != null) { - sourceDests.add(forBranch); - } - } - return sourceDests; - } - - public boolean isPushAll() { - return myPushAll; - } - @Nullable private static GitBranchPair findSourceDestForBranch(GitRepository repository, GitBranch branch) throws VcsException { GitBranch trackedBranch = branch.tracked(repository.getProject(), repository.getRoot()); diff --git a/plugins/git4idea/src/git4idea/push/GitPusher.java b/plugins/git4idea/src/git4idea/push/GitPusher.java index fa9d72351f48..76e97da450e3 100644 --- a/plugins/git4idea/src/git4idea/push/GitPusher.java +++ b/plugins/git4idea/src/git4idea/push/GitPusher.java @@ -122,10 +122,7 @@ public final class GitPusher { } /** - * - * - * - * @param pushSpec which branches in which repositories should be pushed. + * @param pushSpecs which branches in which repositories should be pushed. * The most common situation is all repositories in the project with a single currently active branch for * each of them. * @throws VcsException if couldn't query 'git log' about commits to be pushed. @@ -155,11 +152,7 @@ public final class GitPusher { if (pushSpec == null) { continue; } - if (!pushSpec.isPushAll()) { - res.put(repository, Collections.singletonList(new GitBranchPair(pushSpec.getSource(), pushSpec.getDest()))); - } else { - res.put(repository, GitPushSpec.getBranchesForPushAll(repository)); - } + res.put(repository, Collections.singletonList(new GitBranchPair(pushSpec.getSource(), pushSpec.getDest()))); } return res; } @@ -306,51 +299,19 @@ public final class GitPusher { return GitSimplePushResult.notPushed(); } - if (pushSpec.isPushAll()) { - // TODO support pushing to different branches with http remotes from one and ssh from other. - // Currently it is a hack - get just one remote url and hope that others are the same type and the same server. - String remoteUrl = null; - for (GitBranch branch : commitsByBranch.getBranches()) { - if (remoteUrl != null) { - break; - } - try { - String remoteName = branch.getTrackedRemoteName(repository.getProject(), repository.getRoot()); - GitRemote remote = GitUtil.findRemoteByName(repository, remoteName); - if (remote != null) { - if (!remote.getPushUrls().isEmpty()) { - remoteUrl = remote.getPushUrls().iterator().next(); - } - } - } - catch (VcsException e) { - LOG.info(e); - } - } - - if (remoteUrl == null) { - return pushNatively(repository, pushSpec); - } - else { - return GitHttpAdapter.shouldUseJGit(remoteUrl) ? GitHttpAdapter.push(repository, null, remoteUrl, null) : pushNatively(repository, pushSpec); + GitRemote remote = pushSpec.getRemote(); + String httpUrl = null; + for (String pushUrl : remote.getPushUrls()) { + if (GitHttpAdapter.shouldUseJGit(pushUrl)) { + httpUrl = pushUrl; + break; // TODO support http and ssh urls in one origin } } + if (httpUrl != null) { + return GitHttpAdapter.push(repository, remote, httpUrl, formPushSpec(pushSpec, remote)); + } else { - GitRemote remote = pushSpec.getRemote(); - assert remote != null : "Remote can't be null for pushSpec " + pushSpec; - String httpUrl = null; - for (String pushUrl : remote.getPushUrls()) { - if (GitHttpAdapter.shouldUseJGit(pushUrl)) { - httpUrl = pushUrl; - break; // TODO support http and ssh urls in one origin - } - } - if (httpUrl != null) { - return GitHttpAdapter.push(repository, remote, httpUrl, formPushSpec(pushSpec, remote)); - } - else { - return pushNatively(repository, pushSpec); - } + return pushNatively(repository, pushSpec); } } -- 2.23.3