diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-06-29 09:30:29 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-06-29 09:30:29 -0700 |
commit | 94228bde22debe6ffeb5a374690f023290fc6fd2 (patch) | |
tree | b61552a0dbc5151ebfd1041fa9a6afe1edd924bd | |
parent | d6e975f71ba366466f456b9988f1241bef18c3dc (diff) | |
download | jgit-94228bde22debe6ffeb5a374690f023290fc6fd2.tar.gz jgit-94228bde22debe6ffeb5a374690f023290fc6fd2.zip |
Use ObjectReader in DirCacheBuilder.addTree
Rather than building a custom reader, have the caller supply us one.
Change-Id: Ief2b5a6b1b75f05c8a6bc732a60d4d1041dd8254
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
3 files changed, 18 insertions, 22 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java index 96b616889c..3c58271257 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java @@ -753,7 +753,8 @@ public class TestRepository<R extends Repository> { if (parents.isEmpty()) { DirCacheBuilder b = tree.builder(); parseBody(p); - b.addTree(new byte[0], DirCacheEntry.STAGE_0, db, p.getTree()); + b.addTree(new byte[0], DirCacheEntry.STAGE_0, pool + .getObjectReader(), p.getTree()); b.finish(); } parents.add(p); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java index ab75138434..5665002dc7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java @@ -50,7 +50,6 @@ import java.util.Arrays; import org.eclipse.jgit.JGitText; import org.eclipse.jgit.lib.AnyObjectId; -import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.treewalk.AbstractTreeIterator; import org.eclipse.jgit.treewalk.CanonicalTreeParser; @@ -149,11 +148,12 @@ public class DirCacheBuilder extends BaseDirCacheEditor { * as necessary. * @param stage * stage of the entries when adding them. - * @param db - * repository the tree(s) will be read from during recursive + * @param reader + * reader the tree(s) will be read from during recursive * traversal. This must be the same repository that the resulting * DirCache would be written out to (or used in) otherwise the * caller is simply asking for deferred MissingObjectExceptions. + * Caller is responsible for releasing this reader when done. * @param tree * the tree to recursively add. This tree's contents will appear * under <code>pathPrefix</code>. The ObjectId must be that of a @@ -163,23 +163,18 @@ public class DirCacheBuilder extends BaseDirCacheEditor { * a tree cannot be read to iterate through its entries. */ public void addTree(final byte[] pathPrefix, final int stage, - final Repository db, final AnyObjectId tree) throws IOException { - final ObjectReader reader = db.newObjectReader(); - try { - final TreeWalk tw = new TreeWalk(reader); - tw.reset(); - tw.addTree(new CanonicalTreeParser(pathPrefix, reader, tree - .toObjectId())); - tw.setRecursive(true); - if (tw.next()) { - final DirCacheEntry newEntry = toEntry(stage, tw); - beforeAdd(newEntry); - fastAdd(newEntry); - while (tw.next()) - fastAdd(toEntry(stage, tw)); - } - } finally { - reader.release(); + final ObjectReader reader, final AnyObjectId tree) throws IOException { + final TreeWalk tw = new TreeWalk(reader); + tw.reset(); + tw.addTree(new CanonicalTreeParser(pathPrefix, reader, tree + .toObjectId())); + tw.setRecursive(true); + if (tw.next()) { + final DirCacheEntry newEntry = toEntry(stage, tw); + beforeAdd(newEntry); + fastAdd(newEntry); + while (tw.next()) + fastAdd(toEntry(stage, tw)); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java index 86ba724746..29342a7308 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java @@ -171,7 +171,7 @@ public class StrategySimpleTwoWayInCore extends ThreeWayMergeStrategy { final AbstractTreeIterator i = getTree(tree); if (i != null) { if (FileMode.TREE.equals(tw.getRawMode(tree))) { - builder.addTree(tw.getRawPath(), stage, db, tw + builder.addTree(tw.getRawPath(), stage, reader, tw .getObjectId(tree)); } else { final DirCacheEntry e; |