aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorDave Borowitz <dborowitz@google.com>2013-05-03 10:54:38 -0700
committerShawn Pearce <spearce@spearce.org>2014-08-13 10:39:57 -0700
commit0ab3f43c8542c6c3b7604ac938bf3dcbcc12caa8 (patch)
tree0b02ed8011c96efdbe98005ab706ef8296a90918 /org.eclipse.jgit
parente1856dbf44a91112e6b2a5d185128f46fe0d8116 (diff)
downloadjgit-0ab3f43c8542c6c3b7604ac938bf3dcbcc12caa8.tar.gz
jgit-0ab3f43c8542c6c3b7604ac938bf3dcbcc12caa8.zip
Teach mergers to use ObjectInserter.newReader()
This allows the RecursiveMerger to iteratively create new merge bases without necessarily flushing packs to storage in the DFS case; flushing only need happen at the end of the whole merge process. Since Merger's walk now depends on its inserter, we need to construct an inserter at Merger construction time. This should not be a significant increase in overhead since unused inserters don't use any resources (beyond a reference to the Repository). We also must release and recreate the walk whenever setObjectInserter is called, which can break usages where setObjectInserter is called in the middle of stateful operations on the walk. No usages of this method within JGit currently do this; the inserter is only ever set before any stateful walk operations happen. Change-Id: I9682a6aa4a2c37dccef8e163f132ddb791d79103
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java31
1 files changed, 14 insertions, 17 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 ffe80aacd4..3adc28b2d9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java
@@ -72,10 +72,10 @@ public abstract class Merger {
protected final Repository db;
/** Reader to support {@link #walk} and other object loading. */
- protected final ObjectReader reader;
+ protected ObjectReader reader;
/** A RevWalk for computing merge bases, or listing incoming commits. */
- protected final RevWalk walk;
+ protected RevWalk walk;
private ObjectInserter inserter;
@@ -96,7 +96,8 @@ public abstract class Merger {
*/
protected Merger(final Repository local) {
db = local;
- reader = db.newObjectReader();
+ inserter = db.newObjectInserter();
+ reader = inserter.newReader();
walk = new RevWalk(reader);
}
@@ -107,14 +108,8 @@ public abstract class Merger {
return db;
}
- /**
- * @return an object writer to create objects in {@link #getRepository()}.
- * If no inserter has been set on this instance, one will be created
- * and returned by all future calls.
- */
+ /** @return an object writer to create objects in {@link #getRepository()}. */
public ObjectInserter getObjectInserter() {
- if (inserter == null)
- inserter = getRepository().newObjectInserter();
return inserter;
}
@@ -122,17 +117,20 @@ public abstract class Merger {
* Set the inserter this merger will use to create objects.
* <p>
* If an inserter was already set on this instance (such as by a prior set,
- * or a prior call to {@link #getObjectInserter()}), the prior inserter will
- * be released first.
+ * or a prior call to {@link #getObjectInserter()}), the prior inserter as
+ * well as the in-progress walk will be released.
*
* @param oi
* the inserter instance to use. Must be associated with the
* repository instance returned by {@link #getRepository()}.
*/
public void setObjectInserter(ObjectInserter oi) {
- if (inserter != null)
- inserter.release();
+ walk.release();
+ reader.release();
+ inserter.release();
inserter = oi;
+ reader = oi.newReader();
+ walk = new RevWalk(reader);
}
/**
@@ -174,12 +172,11 @@ public abstract class Merger {
try {
boolean ok = mergeImpl();
- if (ok && inserter != null)
+ if (ok)
inserter.flush();
return ok;
} finally {
- if (inserter != null)
- inserter.release();
+ inserter.release();
reader.release();
}
}