* [JGIT PATCH 1/2] Introduce ThreeWayMerge API
@ 2009-03-28 2:53 Shawn O. Pearce
2009-03-28 2:53 ` [JGIT PATCH 2/2] Add cherry picking and revert support to JGit Shawn O. Pearce
0 siblings, 1 reply; 2+ messages in thread
From: Shawn O. Pearce @ 2009-03-28 2:53 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
A 3-way merge (2 trees, and one common ancestor) is a specialized
type of merge which has a tighter restriction on its inputs. This
change refactors the merge API slightly to introduce this special
type, so we can add 3-way specific operations on the API.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
This is a quick two patch series to teach JGit enough to enable an
application to perform simple cherry-picks, much like we already
support doing simple merges.
I'm already using it in Gerrit Code Review to enable projects to
have a more "format-patch | am" style workflow over a "push; pull"
style of workflow, if they choose to do that.
.../src/org/spearce/jgit/merge/MergeStrategy.java | 2 +-
.../src/org/spearce/jgit/merge/Merger.java | 2 +-
.../jgit/merge/StrategySimpleTwoWayInCore.java | 11 +--
.../spearce/jgit/merge/ThreeWayMergeStrategy.java | 46 ++++++++++
.../src/org/spearce/jgit/merge/ThreeWayMerger.java | 89 ++++++++++++++++++++
5 files changed, 141 insertions(+), 9 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/ThreeWayMergeStrategy.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/ThreeWayMerger.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/MergeStrategy.java b/org.spearce.jgit/src/org/spearce/jgit/merge/MergeStrategy.java
index 66bd86c..5439e5c 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/merge/MergeStrategy.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/MergeStrategy.java
@@ -55,7 +55,7 @@
public static final MergeStrategy THEIRS = new StrategyOneSided("theirs", 1);
/** Simple strategy to merge paths, without simultaneous edits. */
- public static final MergeStrategy SIMPLE_TWO_WAY_IN_CORE = StrategySimpleTwoWayInCore.INSTANCE;
+ public static final ThreeWayMergeStrategy SIMPLE_TWO_WAY_IN_CORE = StrategySimpleTwoWayInCore.INSTANCE;
private static final HashMap<String, MergeStrategy> STRATEGIES = new HashMap<String, MergeStrategy>();
diff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java b/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java
index 100cc38..db3e329 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java
@@ -122,7 +122,7 @@ public ObjectWriter getObjectWriter() {
* one or more sources could not be read, or outputs could not
* be written to the Repository.
*/
- public final boolean merge(final AnyObjectId[] tips) throws IOException {
+ public boolean merge(final AnyObjectId[] tips) throws IOException {
sourceObjects = new RevObject[tips.length];
for (int i = 0; i < tips.length; i++)
sourceObjects[i] = walk.parseAny(tips[i]);
diff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java b/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java
index 3ebe397..9807644 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java
@@ -60,8 +60,8 @@
* trees will cause a merge conflict, as this strategy does not attempt to merge
* file contents.
*/
-public class StrategySimpleTwoWayInCore extends MergeStrategy {
- static final MergeStrategy INSTANCE = new StrategySimpleTwoWayInCore();
+public class StrategySimpleTwoWayInCore extends ThreeWayMergeStrategy {
+ static final ThreeWayMergeStrategy INSTANCE = new StrategySimpleTwoWayInCore();
/** Create a new instance of the strategy. */
protected StrategySimpleTwoWayInCore() {
@@ -74,11 +74,11 @@ public String getName() {
}
@Override
- public Merger newMerger(final Repository db) {
+ public ThreeWayMerger newMerger(final Repository db) {
return new InCoreMerger(db);
}
- private static class InCoreMerger extends Merger {
+ private static class InCoreMerger extends ThreeWayMerger {
private static final int T_BASE = 0;
private static final int T_OURS = 1;
@@ -101,9 +101,6 @@ InCoreMerger(final Repository local) {
@Override
protected boolean mergeImpl() throws IOException {
- if (sourceTrees.length != 2)
- return false;
-
tw.reset();
tw.addTree(mergeBase(0, 1));
tw.addTree(sourceTrees[0]);
diff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/ThreeWayMergeStrategy.java b/org.spearce.jgit/src/org/spearce/jgit/merge/ThreeWayMergeStrategy.java
new file mode 100644
index 0000000..848e80b
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/ThreeWayMergeStrategy.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2009, Google Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.merge;
+
+import org.spearce.jgit.lib.Repository;
+
+/** A merge strategy to merge 2 trees, using a common base ancestor tree. */
+public abstract class ThreeWayMergeStrategy extends MergeStrategy {
+ @Override
+ public abstract ThreeWayMerger newMerger(Repository db);
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/ThreeWayMerger.java b/org.spearce.jgit/src/org/spearce/jgit/merge/ThreeWayMerger.java
new file mode 100644
index 0000000..9d1621d
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/ThreeWayMerger.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2009, Google Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.merge;
+
+import java.io.IOException;
+
+import org.spearce.jgit.errors.IncorrectObjectTypeException;
+import org.spearce.jgit.lib.AnyObjectId;
+import org.spearce.jgit.lib.Repository;
+
+/** A merge of 2 trees, using a common base ancestor tree. */
+public abstract class ThreeWayMerger extends Merger {
+ /**
+ * Create a new merge instance for a repository.
+ *
+ * @param local
+ * the repository this merger will read and write data on.
+ */
+ protected ThreeWayMerger(final Repository local) {
+ super(local);
+ }
+
+ /**
+ * Merge together two tree-ish objects.
+ * <p>
+ * Any tree-ish may be supplied as inputs. Commits and/or tags pointing at
+ * trees or commits may be passed as input objects.
+ *
+ * @param a
+ * source tree to be combined together.
+ * @param b
+ * source tree to be combined together.
+ * @return true if the merge was completed without conflicts; false if the
+ * merge strategy cannot handle this merge or there were conflicts
+ * preventing it from automatically resolving all paths.
+ * @throws IncorrectObjectTypeException
+ * one of the input objects is not a commit, but the strategy
+ * requires it to be a commit.
+ * @throws IOException
+ * one or more sources could not be read, or outputs could not
+ * be written to the Repository.
+ */
+ public boolean merge(final AnyObjectId a, final AnyObjectId b)
+ throws IOException {
+ return merge(new AnyObjectId[] { a, b });
+ }
+
+ @Override
+ public boolean merge(final AnyObjectId[] tips) throws IOException {
+ if (tips.length != 2)
+ return false;
+ return super.merge(tips);
+ }
+}
--
1.6.2.1.471.g682837
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [JGIT PATCH 2/2] Add cherry picking and revert support to JGit
2009-03-28 2:53 [JGIT PATCH 1/2] Introduce ThreeWayMerge API Shawn O. Pearce
@ 2009-03-28 2:53 ` Shawn O. Pearce
0 siblings, 0 replies; 2+ messages in thread
From: Shawn O. Pearce @ 2009-03-28 2:53 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
A cherry-pick can be performed by a 3 way merge, where the base is
the parent of the commit you are cherry-picking, instead of using
the derived base from the commit graph.
By allowing the caller of a ThreeWayMerger to set the merge base
prior to invoking the merge method, we allow the caller to direct
us to execute a cherry-pick, or a revert.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../tst/org/spearce/jgit/merge/CherryPickTest.java | 149 ++++++++++++++++++++
.../src/org/spearce/jgit/merge/Merger.java | 18 +++-
.../jgit/merge/StrategySimpleTwoWayInCore.java | 2 +-
.../src/org/spearce/jgit/merge/ThreeWayMerger.java | 41 ++++++
.../spearce/jgit/treewalk/CanonicalTreeParser.java | 2 +-
5 files changed, 209 insertions(+), 3 deletions(-)
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/merge/CherryPickTest.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/merge/CherryPickTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/merge/CherryPickTest.java
new file mode 100644
index 0000000..78a5553
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/merge/CherryPickTest.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2009, Google Inc.
+ * Copyright (C) 2008, Robin Rosenberg
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.spearce.jgit.merge;
+
+import java.io.ByteArrayInputStream;
+
+import org.spearce.jgit.dircache.DirCache;
+import org.spearce.jgit.dircache.DirCacheBuilder;
+import org.spearce.jgit.dircache.DirCacheEntry;
+import org.spearce.jgit.lib.Commit;
+import org.spearce.jgit.lib.Constants;
+import org.spearce.jgit.lib.FileMode;
+import org.spearce.jgit.lib.ObjectId;
+import org.spearce.jgit.lib.ObjectWriter;
+import org.spearce.jgit.lib.PersonIdent;
+import org.spearce.jgit.lib.RepositoryTestCase;
+import org.spearce.jgit.treewalk.TreeWalk;
+
+public class CherryPickTest extends RepositoryTestCase {
+ public void testPick() throws Exception {
+ // B---O
+ // \----P---T
+ //
+ // Cherry-pick "T" onto "O". This shouldn't introduce "p-fail", which
+ // was created by "P", nor should it modify "a", which was done by "P".
+ //
+ final DirCache treeB = DirCache.read(db);
+ final DirCache treeO = DirCache.read(db);
+ final DirCache treeP = DirCache.read(db);
+ final DirCache treeT = DirCache.read(db);
+ {
+ final DirCacheBuilder b = treeB.builder();
+ final DirCacheBuilder o = treeO.builder();
+ final DirCacheBuilder p = treeP.builder();
+ final DirCacheBuilder t = treeT.builder();
+
+ b.add(makeEntry("a", FileMode.REGULAR_FILE));
+
+ o.add(makeEntry("a", FileMode.REGULAR_FILE));
+ o.add(makeEntry("o", FileMode.REGULAR_FILE));
+
+ p.add(makeEntry("a", FileMode.REGULAR_FILE, "q"));
+ p.add(makeEntry("p-fail", FileMode.REGULAR_FILE));
+
+ t.add(makeEntry("a", FileMode.REGULAR_FILE));
+ t.add(makeEntry("t", FileMode.REGULAR_FILE));
+
+ b.finish();
+ o.finish();
+ p.finish();
+ t.finish();
+ }
+
+ final ObjectWriter ow = new ObjectWriter(db);
+ final ObjectId B = commit(ow, treeB, new ObjectId[] {});
+ final ObjectId O = commit(ow, treeO, new ObjectId[] { B });
+ final ObjectId P = commit(ow, treeP, new ObjectId[] { B });
+ final ObjectId T = commit(ow, treeT, new ObjectId[] { P });
+
+ ThreeWayMerger twm = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
+ twm.setBase(P);
+ boolean merge = twm.merge(new ObjectId[] { O, T });
+ assertTrue(merge);
+
+ final TreeWalk tw = new TreeWalk(db);
+ tw.setRecursive(true);
+ tw.reset(twm.getResultTreeId());
+
+ assertTrue(tw.next());
+ assertEquals("a", tw.getPathString());
+ assertCorrectId(treeO, tw);
+
+ assertTrue(tw.next());
+ assertEquals("o", tw.getPathString());
+ assertCorrectId(treeO, tw);
+
+ assertTrue(tw.next());
+ assertEquals("t", tw.getPathString());
+ assertCorrectId(treeT, tw);
+
+ assertFalse(tw.next());
+ }
+
+ private void assertCorrectId(final DirCache treeT, final TreeWalk tw) {
+ assertEquals(treeT.getEntry(tw.getPathString()).getObjectId(), tw
+ .getObjectId(0));
+ }
+
+ private ObjectId commit(final ObjectWriter ow, final DirCache treeB,
+ final ObjectId[] parentIds) throws Exception {
+ final Commit c = new Commit(db);
+ c.setTreeId(treeB.writeTree(ow));
+ c.setAuthor(new PersonIdent("A U Thor", "a.u.thor", 1L, 0));
+ c.setCommitter(c.getAuthor());
+ c.setParentIds(parentIds);
+ c.setMessage("Tree " + c.getTreeId().name());
+ return ow.writeCommit(c);
+ }
+
+ private DirCacheEntry makeEntry(final String path, final FileMode mode)
+ throws Exception {
+ return makeEntry(path, mode, path);
+ }
+
+ private DirCacheEntry makeEntry(final String path, final FileMode mode,
+ final String content) throws Exception {
+ final DirCacheEntry ent = new DirCacheEntry(path);
+ ent.setFileMode(mode);
+ final byte[] contentBytes = Constants.encode(content);
+ ent.setObjectId(new ObjectWriter(db).computeBlobSha1(
+ contentBytes.length, new ByteArrayInputStream(contentBytes)));
+ return ent;
+ }
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java b/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java
index db3e329..2d5d44f 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java
@@ -179,9 +179,25 @@ protected AbstractTreeIterator mergeBase(final int aIdx, final int bIdx)
+ sourceCommits[bIdx].name() + "found:" + "\n "
+ base.name() + "\n " + base2.name());
}
+ return openTree(base.getTree());
+ }
+
+ /**
+ * Open an iterator over a tree.
+ *
+ * @param treeId
+ * the tree to scan; must be a tree (not a treeish).
+ * @return an iterator for the tree.
+ * @throws IncorrectObjectTypeException
+ * the input object is not a tree.
+ * @throws IOException
+ * the tree object is not found or cannot be read.
+ */
+ protected AbstractTreeIterator openTree(final AnyObjectId treeId)
+ throws IncorrectObjectTypeException, IOException {
final WindowCursor curs = new WindowCursor();
try {
- return new CanonicalTreeParser(null, db, base.getTree(), curs);
+ return new CanonicalTreeParser(null, db, treeId, curs);
} finally {
curs.release();
}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java b/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java
index 9807644..5d4447c 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java
@@ -102,7 +102,7 @@ InCoreMerger(final Repository local) {
@Override
protected boolean mergeImpl() throws IOException {
tw.reset();
- tw.addTree(mergeBase(0, 1));
+ tw.addTree(mergeBase());
tw.addTree(sourceTrees[0]);
tw.addTree(sourceTrees[1]);
diff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/ThreeWayMerger.java b/org.spearce.jgit/src/org/spearce/jgit/merge/ThreeWayMerger.java
index 9d1621d..6f041c1 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/merge/ThreeWayMerger.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/ThreeWayMerger.java
@@ -40,11 +40,16 @@
import java.io.IOException;
import org.spearce.jgit.errors.IncorrectObjectTypeException;
+import org.spearce.jgit.errors.MissingObjectException;
import org.spearce.jgit.lib.AnyObjectId;
import org.spearce.jgit.lib.Repository;
+import org.spearce.jgit.revwalk.RevTree;
+import org.spearce.jgit.treewalk.AbstractTreeIterator;
/** A merge of 2 trees, using a common base ancestor tree. */
public abstract class ThreeWayMerger extends Merger {
+ private RevTree baseTree;
+
/**
* Create a new merge instance for a repository.
*
@@ -56,6 +61,29 @@ protected ThreeWayMerger(final Repository local) {
}
/**
+ * Set the common ancestor tree.
+ *
+ * @param id
+ * common base treeish; null to automatically compute the common
+ * base from the input commits during
+ * {@link #merge(AnyObjectId, AnyObjectId)}.
+ * @throws IncorrectObjectTypeException
+ * the object is not a treeish.
+ * @throws MissingObjectException
+ * the object does not exist.
+ * @throws IOException
+ * the object could not be read.
+ */
+ public void setBase(final AnyObjectId id) throws MissingObjectException,
+ IncorrectObjectTypeException, IOException {
+ if (id != null) {
+ baseTree = walk.parseTree(id);
+ } else {
+ baseTree = null;
+ }
+ }
+
+ /**
* Merge together two tree-ish objects.
* <p>
* Any tree-ish may be supplied as inputs. Commits and/or tags pointing at
@@ -86,4 +114,17 @@ public boolean merge(final AnyObjectId[] tips) throws IOException {
return false;
return super.merge(tips);
}
+
+ /**
+ * Create an iterator to walk the merge base.
+ *
+ * @return an iterator over the caller-specified merge base, or the natural
+ * merge base of the two input commits.
+ * @throws IOException
+ */
+ protected AbstractTreeIterator mergeBase() throws IOException {
+ if (baseTree != null)
+ return openTree(baseTree);
+ return mergeBase(0, 1);
+ }
}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java
index 7f89cff..ec1cf10 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java
@@ -91,7 +91,7 @@ public CanonicalTreeParser() {
* a loose object or pack file could not be read.
*/
public CanonicalTreeParser(final byte[] prefix, final Repository repo,
- final ObjectId treeId, final WindowCursor curs)
+ final AnyObjectId treeId, final WindowCursor curs)
throws IncorrectObjectTypeException, IOException {
super(prefix);
reset(repo, treeId, curs);
--
1.6.2.1.471.g682837
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-03-28 2:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-28 2:53 [JGIT PATCH 1/2] Introduce ThreeWayMerge API Shawn O. Pearce
2009-03-28 2:53 ` [JGIT PATCH 2/2] Add cherry picking and revert support to JGit Shawn O. Pearce
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).