]> source.dussan.org Git - jgit.git/commitdiff
Add getBaseCommit() to Merger 56/1356/3
authorChristian Halstrick <christian.halstrick@sap.com>
Fri, 20 Aug 2010 15:17:01 +0000 (17:17 +0200)
committerShawn O. Pearce <spearce@spearce.org>
Fri, 27 Aug 2010 01:52:26 +0000 (18:52 -0700)
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>
org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java

index 68d60c0077f8e76333a9cf6cc321c36db950e2a5..1bfa269f2541fd505c84d555cc369332db7cb498 100644 (file)
@@ -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;
        }
 
        /**