From 8ea43193887fce9dadfe12b38536a720ca5ed203 Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Fri, 3 May 2013 11:45:36 -0700 Subject: 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 --- .../src/org/eclipse/jgit/merge/Merger.java | 34 ++++++++++++++++++++-- 1 file 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. + *

+ * 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(); } } -- cgit v1.2.3