mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
git4idea: added getMergeBase() method and integrated it into outgoing changes provider
This commit is contained in:
@@ -287,4 +287,27 @@ public class GitBranch extends GitReference {
|
||||
}
|
||||
return new GitBranch(branch, false, 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 {
|
||||
GitSimpleHandler h = new GitSimpleHandler(project, root, GitHandler.MERGE_BASE);
|
||||
h.addParameters(this.getFullName(), branch.getFullName());
|
||||
String output = h.run().trim();
|
||||
if (output.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return GitRevisionNumber.resolve(project, root, output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Consumer;
|
||||
import git4idea.GitBranchesSearcher;
|
||||
import git4idea.GitRevisionNumber;
|
||||
import git4idea.GitUtil;
|
||||
import git4idea.commands.GitSimpleHandler;
|
||||
|
||||
@@ -24,18 +25,22 @@ public class GitOutgoingChangesProvider implements VcsOutgoingChangesProvider<Co
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
public Pair<VcsRevisionNumber, List<CommittedChangeList>> getOutgoingChanges(final VirtualFile vcsRoot, final boolean findRemote) throws VcsException {
|
||||
public Pair<VcsRevisionNumber, List<CommittedChangeList>> getOutgoingChanges(final VirtualFile vcsRoot, final boolean findRemote)
|
||||
throws VcsException {
|
||||
LOG.debug("getOutgoingChanges root: " + vcsRoot.getPath());
|
||||
final GitBranchesSearcher searcher = new GitBranchesSearcher(myProject, vcsRoot, findRemote);
|
||||
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());
|
||||
if (base == null) {
|
||||
return new Pair<VcsRevisionNumber, List<CommittedChangeList>>(null, Collections.<CommittedChangeList>emptyList());
|
||||
}
|
||||
final List<CommittedChangeList> lists = GitUtil.getLocalCommittedChanges(myProject, vcsRoot, new Consumer<GitSimpleHandler>() {
|
||||
public void consume(final GitSimpleHandler handler) {
|
||||
handler.addParameters(searcher.getRemote().getFullName() + "..HEAD");
|
||||
handler.addParameters(base.asString() + "..HEAD");
|
||||
}
|
||||
});
|
||||
return new Pair<VcsRevisionNumber, List<CommittedChangeList>>(null, lists);
|
||||
return new Pair<VcsRevisionNumber, List<CommittedChangeList>>(base, lists);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,6 +166,10 @@ public abstract class GitHandler {
|
||||
* The constant for git command {@value}
|
||||
*/
|
||||
@NonNls public static final String MERGE = "merge";
|
||||
/**
|
||||
* The constant for git command {@value}
|
||||
*/
|
||||
@NonNls public static final String MERGE_BASE = "merge-base";
|
||||
/**
|
||||
* The constant for git command {@value}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user