summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Borowitz <dborowitz@google.com>2013-05-03 11:45:36 -0700
committerShawn Pearce <spearce@spearce.org>2014-08-13 10:40:04 -0700
commit8ea43193887fce9dadfe12b38536a720ca5ed203 (patch)
treea2b01ebd9f709a641c7a61b7de8565e626f272a3
parent0ab3f43c8542c6c3b7604ac938bf3dcbcc12caa8 (diff)
downloadjgit-8ea43193887fce9dadfe12b38536a720ca5ed203.tar.gz
jgit-8ea43193887fce9dadfe12b38536a720ca5ed203.zip
Add a Merger.merge method that makes flushing optional
This allows callers performing multiple separate merges to reuse a single ObjectInserter without flushing the inserter on each iteration (which can be slow in the DFS case). Change-Id: Icaff7d2bc2c20c873ce5a7d9af5002da84ae1c2b
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java34
1 files changed, 32 insertions, 2 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 3adc28b2d9..d786a18ff2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java
@@ -153,6 +153,35 @@ public abstract class Merger {
* be written to the Repository.
*/
public boolean merge(final AnyObjectId... tips) throws IOException {
+ return merge(true, tips);
+ }
+
+ /**
+ * Merge together two or more 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.
+ *
+ * @since 3.5
+ * @param flush
+ * whether to flush the underlying object inserter when finished to
+ * store any content-merged blobs and virtual merged bases; if
+ * false, callers are responsible for flushing.
+ * @param tips
+ * source trees to be combined together. The merge base is not
+ * included in this set.
+ * @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 boolean flush, final AnyObjectId... tips)
+ throws IOException {
sourceObjects = new RevObject[tips.length];
for (int i = 0; i < tips.length; i++)
sourceObjects[i] = walk.parseAny(tips[i]);
@@ -172,11 +201,12 @@ public abstract class Merger {
try {
boolean ok = mergeImpl();
- if (ok)
+ if (ok && flush)
inserter.flush();
return ok;
} finally {
- inserter.release();
+ if (flush)
+ inserter.release();
reader.release();
}
}