From 0e7a38b60fbb88db4c61fd185ec17416540463d2 Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Fri, 20 Aug 2010 17:17:01 +0200 Subject: [PATCH] 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 Signed-off-by: Matthias Sohn Signed-off-by: Shawn O. Pearce --- .../src/org/eclipse/jgit/merge/Merger.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java index 68d60c007..1bfa269f2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java @@ -176,27 +176,46 @@ public abstract class Merger { */ 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; } /**