Browse Source

Merge changes I627681be,I334034a2

* changes:
  TreeWalk: Do not close reader passed explicitly to constructor
  TreeWalk: Stop using deprecated ObjectReader#release()
stable-4.0
Shawn Pearce 10 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
0f51246b0e
  1. 23
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java

23
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java

@ -157,11 +157,8 @@ public class TreeWalk implements AutoCloseable {
public static TreeWalk forPath(final Repository db, final String path, public static TreeWalk forPath(final Repository db, final String path,
final AnyObjectId... trees) throws MissingObjectException, final AnyObjectId... trees) throws MissingObjectException,
IncorrectObjectTypeException, CorruptObjectException, IOException { IncorrectObjectTypeException, CorruptObjectException, IOException {
ObjectReader reader = db.newObjectReader(); try (ObjectReader reader = db.newObjectReader()) {
try {
return forPath(reader, path, trees); return forPath(reader, path, trees);
} finally {
reader.release();
} }
} }
@ -198,6 +195,8 @@ public class TreeWalk implements AutoCloseable {
private final ObjectReader reader; private final ObjectReader reader;
private final boolean closeReader;
private final MutableObjectId idBuffer = new MutableObjectId(); private final MutableObjectId idBuffer = new MutableObjectId();
private TreeFilter filter; private TreeFilter filter;
@ -220,22 +219,30 @@ public class TreeWalk implements AutoCloseable {
* Create a new tree walker for a given repository. * Create a new tree walker for a given repository.
* *
* @param repo * @param repo
* the repository the walker will obtain data from. * the repository the walker will obtain data from. An
* ObjectReader will be created by the walker, and will be closed
* when the walker is closed.
*/ */
public TreeWalk(final Repository repo) { public TreeWalk(final Repository repo) {
this(repo.newObjectReader()); this(repo.newObjectReader(), true);
} }
/** /**
* Create a new tree walker for a given repository. * Create a new tree walker for a given repository.
* *
* @param or * @param or
* the reader the walker will obtain tree data from. * the reader the walker will obtain tree data from. The reader
* is not closed when the walker is closed.
*/ */
public TreeWalk(final ObjectReader or) { public TreeWalk(final ObjectReader or) {
this(or, false);
}
private TreeWalk(final ObjectReader or, final boolean closeReader) {
reader = or; reader = or;
filter = TreeFilter.ALL; filter = TreeFilter.ALL;
trees = NO_TREES; trees = NO_TREES;
this.closeReader = closeReader;
} }
/** @return the reader this walker is using to load objects. */ /** @return the reader this walker is using to load objects. */
@ -264,8 +271,10 @@ public class TreeWalk implements AutoCloseable {
*/ */
@Override @Override
public void close() { public void close() {
if (closeReader) {
reader.close(); reader.close();
} }
}
/** /**
* Get the currently configured filter. * Get the currently configured filter.

Loading…
Cancel
Save