git: extract method GitBrancher.getInstance

This commit is contained in:
Aleksey Pivovarov
2017-01-23 11:53:28 +03:00
parent 65dcc13159
commit 2620cc9ad4
7 changed files with 23 additions and 23 deletions
@@ -15,7 +15,6 @@
*/
package git4idea.actions;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.vcs.log.Hash;
import git4idea.branch.GitBrancher;
import git4idea.repo.GitRepository;
@@ -27,7 +26,7 @@ public class GitCheckoutRevisionAction extends GitLogSingleCommitAction {
@Override
protected void actionPerformed(@NotNull GitRepository repository, @NotNull Hash commit) {
GitBrancher brancher = ServiceManager.getService(repository.getProject(), GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(repository.getProject());
brancher.checkout(commit.asString(), false, Collections.singletonList(repository), null);
}
@@ -15,7 +15,6 @@
*/
package git4idea.actions;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.vcs.log.Hash;
import git4idea.branch.GitBrancher;
@@ -33,7 +32,7 @@ public class GitCreateNewBranchAction extends GitLogSingleCommitAction {
Project project = repository.getProject();
String name = getNewBranchNameFromUser(project, singleton(repository), "Checkout New Branch From " + commit.toShortString());
if (name != null) {
GitBrancher brancher = ServiceManager.getService(project, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(project);
brancher.checkoutNewBranchStartingFrom(name, commit.asString(), singletonList(repository), null);
}
}
@@ -15,6 +15,8 @@
*/
package git4idea.branch;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import git4idea.repo.GitRepository;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -30,6 +32,9 @@ import java.util.List;
* @author Kirill Likhodedov
*/
public interface GitBrancher {
static GitBrancher getInstance(@NotNull Project project) {
return ServiceManager.getService(project, GitBrancher.class);
}
/**
* <p>Checks out a new branch in background.
@@ -20,7 +20,6 @@ import com.intellij.notification.Notification;
import com.intellij.notification.NotificationAction;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
@@ -349,7 +348,7 @@ class GitDeleteBranchOperation extends GitBranchOperation {
new Task.Backgroundable(myProject, "Deleting Remote Branch " + myBranchName + "...") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
GitBrancher brancher = ServiceManager.getService(getProject(), GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(getProject());
for (String remoteBranch : myTrackedBranches.keySet()) {
brancher.deleteRemoteBranch(remoteBranch, new ArrayList<>(myTrackedBranches.get(remoteBranch)));
}
@@ -19,7 +19,6 @@ import com.intellij.dvcs.DvcsUtil;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationListener;
import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
@@ -163,7 +162,7 @@ class GitMergeOperation extends GitBranchOperation {
UIUtil.invokeLaterIfNeeded(new Runnable() { // bg process needs to be started from the EDT
@Override
public void run() {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.deleteBranch(myBranchToMerge, new ArrayList<>(getRepositories()));
}
});
@@ -386,7 +385,7 @@ class GitMergeOperation extends GitBranchOperation {
public void hyperlinkUpdate(@NotNull Notification notification,
@NotNull HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED && event.getDescription().equalsIgnoreCase("delete")) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.deleteBranch(myBranchToMerge, new ArrayList<>(getRepositories()));
}
}
@@ -15,7 +15,6 @@
*/
package git4idea.history.wholeTree;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.InputValidator;
import com.intellij.openapi.ui.Messages;
@@ -58,7 +57,7 @@ public class GitCreateNewTag {
}
});
if (name != null) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.createNewTag(name, myReference, Collections.singletonList(myRepository), myCallInAwtAfterExecution);
}
}
@@ -101,7 +101,7 @@ class GitBranchPopupActions {
public void actionPerformed(AnActionEvent e) {
final String name = GitBranchUtil.getNewBranchNameFromUser(myProject, myRepositories, "Create New Branch");
if (name != null) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.checkoutNewBranch(name, myRepositories);
reportUsage("git.branch.create.new");
}
@@ -128,7 +128,7 @@ class GitBranchPopupActions {
String reference = Messages
.showInputDialog(myProject, "Enter reference (branch, tag) name or commit hash:", "Checkout", null);
if (reference != null) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.checkout(reference, true, myRepositories, null);
reportUsage("git.branch.checkout.revision");
}
@@ -222,7 +222,7 @@ class GitBranchPopupActions {
@Override
public void actionPerformed(AnActionEvent e) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.checkout(myBranchName, false, myRepositories, null);
reportUsage("git.branch.checkout.local");
}
@@ -246,7 +246,7 @@ class GitBranchPopupActions {
.showInputDialog(myProject, "New branch name:", "Checkout New Branch From " + myBranchName,
null, "", GitNewBranchNameValidator.newInstance(myRepositories));
if (name != null) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.checkoutNewBranchStartingFrom(name, myBranchName, myRepositories, null);
}
reportUsage("git.checkout.as.new.branch");
@@ -271,7 +271,7 @@ class GitBranchPopupActions {
"Rename Branch " + myCurrentBranchName, null,
myCurrentBranchName, GitNewBranchNameValidator.newInstance(myRepositories));
if (newName != null) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.renameBranch(myCurrentBranchName, newName, myRepositories);
reportUsage("git.branch.rename");
}
@@ -292,7 +292,7 @@ class GitBranchPopupActions {
@Override
public void actionPerformed(AnActionEvent e) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.deleteBranch(myBranchName, myRepositories);
reportUsage("git.branch.delete.local");
}
@@ -358,7 +358,7 @@ class GitBranchPopupActions {
final String name = Messages.showInputDialog(myProject, "New branch name:", "Checkout Remote Branch", null,
guessBranchName(), GitNewBranchNameValidator.newInstance(myRepositories));
if (name != null) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.checkoutNewBranchStartingFrom(name, myRemoteBranchName, myRepositories, null);
reportUsage("git.branch.checkout.remote");
}
@@ -386,7 +386,7 @@ class GitBranchPopupActions {
@Override
public void actionPerformed(AnActionEvent e) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.deleteRemoteBranch(myBranchName, myRepositories);
reportUsage("git.branch.delete.remote");
}
@@ -411,7 +411,7 @@ class GitBranchPopupActions {
@Override
public void actionPerformed(AnActionEvent e) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.compare(myBranchName, myRepositories, mySelectedRepository);
reportUsage("git.branch.compare");
}
@@ -435,7 +435,7 @@ class GitBranchPopupActions {
@Override
public void actionPerformed(AnActionEvent e) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.merge(myBranchName, deleteOnMerge(), myRepositories);
reportUsage("git.branch.merge");
}
@@ -462,7 +462,7 @@ class GitBranchPopupActions {
@Override
public void actionPerformed(AnActionEvent e) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.rebase(myRepositories, myBranchName);
reportUsage("git.branch.rebase");
}
@@ -483,7 +483,7 @@ class GitBranchPopupActions {
@Override
public void actionPerformed(AnActionEvent e) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.rebaseOnCurrent(myRepositories, myBranchName);
reportUsage("git.branch.checkout.with.rebase");
}