Add getBaseCommit() to Merger

The Merger was was only exposing the merge base as an
AbstractTreeIterator. Since we need the merge base as
RevCommit to generate the merge result I expose it here.

Change-Id: Ibe846370a35ac9bdb0c97ce2e36b2287577fbcad
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
Christian Halstrick 2010-08-20 17:17:01 +02:00 committed by Shawn O. Pearce
parent c869f187b7
commit 0e7a38b60f
1 changed files with 22 additions and 3 deletions

View File

@ -176,27 +176,46 @@ public boolean merge(final AnyObjectId[] tips) throws IOException {
*/
protected AbstractTreeIterator mergeBase(final int aIdx, final int bIdx)
throws IOException {
RevCommit base = getBaseCommit(aIdx, bIdx);
return (base == null) ? new EmptyTreeIterator() : openTree(base.getTree());
}
/**
* Return the merge base of two commits.
*
* @param aIdx
* index of the first commit in {@link #sourceObjects}.
* @param bIdx
* index of the second commit in {@link #sourceObjects}.
* @return the merge base of two commits
* @throws IncorrectObjectTypeException
* one of the input objects is not a commit.
* @throws IOException
* objects are missing or multiple merge bases were found.
*/
public RevCommit getBaseCommit(final int aIdx, final int bIdx)
throws IncorrectObjectTypeException,
IOException {
if (sourceCommits[aIdx] == null)
throw new IncorrectObjectTypeException(sourceObjects[aIdx],
Constants.TYPE_COMMIT);
if (sourceCommits[bIdx] == null)
throw new IncorrectObjectTypeException(sourceObjects[bIdx],
Constants.TYPE_COMMIT);
walk.reset();
walk.setRevFilter(RevFilter.MERGE_BASE);
walk.markStart(sourceCommits[aIdx]);
walk.markStart(sourceCommits[bIdx]);
final RevCommit base = walk.next();
if (base == null)
return new EmptyTreeIterator();
return null;
final RevCommit base2 = walk.next();
if (base2 != null) {
throw new IOException(MessageFormat.format(JGitText.get().multipleMergeBasesFor
, sourceCommits[aIdx].name(), sourceCommits[bIdx].name()
, base.name(), base2.name()));
}
return openTree(base.getTree());
return base;
}
/**