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()) {
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);

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.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));
}
}

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);
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;

Loading…
Cancel
Save