Browse Source

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>
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
94228bde22
  1. 3
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
  2. 35
      org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java
  3. 2
      org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java

3
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java

@ -753,7 +753,8 @@ public class TestRepository<R extends Repository> {
if (parents.isEmpty()) { if (parents.isEmpty()) {
DirCacheBuilder b = tree.builder(); DirCacheBuilder b = tree.builder();
parseBody(p); 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(); b.finish();
} }
parents.add(p); parents.add(p);

35
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java vendored

@ -50,7 +50,6 @@ import java.util.Arrays;
import org.eclipse.jgit.JGitText; import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.treewalk.AbstractTreeIterator; import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.CanonicalTreeParser; import org.eclipse.jgit.treewalk.CanonicalTreeParser;
@ -149,11 +148,12 @@ public class DirCacheBuilder extends BaseDirCacheEditor {
* as necessary. * as necessary.
* @param stage * @param stage
* stage of the entries when adding them. * stage of the entries when adding them.
* @param db * @param reader
* repository the tree(s) will be read from during recursive * reader the tree(s) will be read from during recursive
* traversal. This must be the same repository that the resulting * traversal. This must be the same repository that the resulting
* DirCache would be written out to (or used in) otherwise the * DirCache would be written out to (or used in) otherwise the
* caller is simply asking for deferred MissingObjectExceptions. * caller is simply asking for deferred MissingObjectExceptions.
* Caller is responsible for releasing this reader when done.
* @param tree * @param tree
* the tree to recursively add. This tree's contents will appear * the tree to recursively add. This tree's contents will appear
* under <code>pathPrefix</code>. The ObjectId must be that of a * 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. * a tree cannot be read to iterate through its entries.
*/ */
public void addTree(final byte[] pathPrefix, final int stage, public void addTree(final byte[] pathPrefix, final int stage,
final Repository db, final AnyObjectId tree) throws IOException { final ObjectReader reader, final AnyObjectId tree) throws IOException {
final ObjectReader reader = db.newObjectReader(); final TreeWalk tw = new TreeWalk(reader);
try { tw.reset();
final TreeWalk tw = new TreeWalk(reader); tw.addTree(new CanonicalTreeParser(pathPrefix, reader, tree
tw.reset(); .toObjectId()));
tw.addTree(new CanonicalTreeParser(pathPrefix, reader, tree tw.setRecursive(true);
.toObjectId())); if (tw.next()) {
tw.setRecursive(true); final DirCacheEntry newEntry = toEntry(stage, tw);
if (tw.next()) { beforeAdd(newEntry);
final DirCacheEntry newEntry = toEntry(stage, tw); fastAdd(newEntry);
beforeAdd(newEntry); while (tw.next())
fastAdd(newEntry); fastAdd(toEntry(stage, tw));
while (tw.next())
fastAdd(toEntry(stage, tw));
}
} finally {
reader.release();
} }
} }

2
org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java

@ -171,7 +171,7 @@ public class StrategySimpleTwoWayInCore extends ThreeWayMergeStrategy {
final AbstractTreeIterator i = getTree(tree); final AbstractTreeIterator i = getTree(tree);
if (i != null) { if (i != null) {
if (FileMode.TREE.equals(tw.getRawMode(tree))) { if (FileMode.TREE.equals(tw.getRawMode(tree))) {
builder.addTree(tw.getRawPath(), stage, db, tw builder.addTree(tw.getRawPath(), stage, reader, tw
.getObjectId(tree)); .getObjectId(tree));
} else { } else {
final DirCacheEntry e; final DirCacheEntry e;

Loading…
Cancel
Save