GitBranch: move getMergeBase to the only class using it

This commit is contained in:
Kirill Likhodedov
2012-10-18 17:53:56 +04:00
parent dc14e60134
commit e171fdf684
2 changed files with 15 additions and 19 deletions
@@ -21,7 +21,6 @@ import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
import git4idea.config.GitConfigUtil;
import git4idea.history.GitHistoryUtils;
import git4idea.repo.GitRepositoryFiles;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -200,19 +199,4 @@ public class GitBranch extends GitReference {
}
return new GitBranch(branch, remoteFlag);
}
/**
* Get a merge base between the current branch and specified branch.
*
* @param project the current project
* @param root the vcs root
* @param branch the branch
* @return the common commit or null if the there is no common commit
* @throws VcsException the exception
*/
@Nullable
public GitRevisionNumber getMergeBase(@NotNull Project project, @NotNull VirtualFile root, @NotNull GitBranch branch)
throws VcsException {
return GitHistoryUtils.getMergeBase(project, root, this.getFullName(), branch.getFullName());
}
}
@@ -25,12 +25,14 @@ import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
import com.intellij.util.containers.Convertor;
import git4idea.GitBranch;
import git4idea.GitBranchesSearcher;
import git4idea.GitRevisionNumber;
import git4idea.GitUtil;
import git4idea.commands.GitSimpleHandler;
import git4idea.history.GitHistoryUtils;
import git4idea.history.browser.SHAHash;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -50,7 +52,7 @@ public class GitOutgoingChangesProvider implements VcsOutgoingChangesProvider<Co
if (searcher.getLocal() == null || searcher.getRemote() == null) {
return new Pair<VcsRevisionNumber, List<CommittedChangeList>>(null, Collections.<CommittedChangeList>emptyList());
}
final GitRevisionNumber base = searcher.getLocal().getMergeBase(myProject, vcsRoot, searcher.getRemote());
final GitRevisionNumber base = getMergeBase(myProject, vcsRoot, searcher.getLocal(), searcher.getRemote());
if (base == null) {
return new Pair<VcsRevisionNumber, List<CommittedChangeList>>(null, Collections.<CommittedChangeList>emptyList());
}
@@ -82,7 +84,7 @@ public class GitOutgoingChangesProvider implements VcsOutgoingChangesProvider<Co
LOG.info("local or remote not found");
return null;
}
final GitRevisionNumber base = searcher.getLocal().getMergeBase(myProject, root, searcher.getRemote());
final GitRevisionNumber base = getMergeBase(myProject, root, searcher.getLocal(), searcher.getRemote());
LOG.debug("found base: " + ((base == null) ? null : base.asString()));
return base;
}
@@ -94,7 +96,7 @@ public class GitOutgoingChangesProvider implements VcsOutgoingChangesProvider<Co
}
final GitRevisionNumber base;
try {
base = searcher.getLocal().getMergeBase(myProject, vcsRoot, searcher.getRemote());
base = getMergeBase(myProject, vcsRoot, searcher.getLocal(), searcher.getRemote());
} catch (VcsException e) {
LOG.info(e);
return new ArrayList<Change>(localChanges);
@@ -133,4 +135,14 @@ public class GitOutgoingChangesProvider implements VcsOutgoingChangesProvider<Co
return null;
}
}
/**
* Get a merge base between the current branch and specified branch.
* @return the common commit or null if the there is no common commit
*/
@Nullable
private static GitRevisionNumber getMergeBase(@NotNull Project project, @NotNull VirtualFile root,
@NotNull GitBranch currentBranch, @NotNull GitBranch branch) throws VcsException {
return GitHistoryUtils.getMergeBase(project, root, currentBranch.getFullName(), branch.getFullName());
}
}