diff options
author | Dave Borowitz <dborowitz@google.com> | 2015-03-10 15:21:06 -0700 |
---|---|---|
committer | Dave Borowitz <dborowitz@google.com> | 2015-03-10 16:27:22 -0700 |
commit | 6f4281b11a63ae7834197e981f758a581254598f (patch) | |
tree | c1bacc4e1c137acd8324938a177b8b3318d71cce /org.eclipse.jgit | |
parent | 421e69a4a02c0b8aa82ca7421af10246f22c389a (diff) | |
download | jgit-6f4281b11a63ae7834197e981f758a581254598f.tar.gz jgit-6f4281b11a63ae7834197e981f758a581254598f.zip |
TreeWalk: Do not close reader passed explicitly to constructor
The TreeWalk(ObjectReader) constructor is explicitly to handle the case
where the caller is responsible for opening and closing the reader.
The reader should only be closed when it was created in the
TreeWalk(Repository) constructor.
Change-Id: I627681be80d69ea549f953255a64c7b3b68bcec9
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java index 3ecef453e6..a4d2d7e796 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java @@ -195,6 +195,8 @@ public class TreeWalk implements AutoCloseable { private final ObjectReader reader; + private final boolean closeReader; + private final MutableObjectId idBuffer = new MutableObjectId(); private TreeFilter filter; @@ -217,22 +219,30 @@ public class TreeWalk implements AutoCloseable { * Create a new tree walker for a given repository. * * @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) { - this(repo.newObjectReader()); + this(repo.newObjectReader(), true); } /** * Create a new tree walker for a given repository. * * @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) { + this(or, false); + } + + private TreeWalk(final ObjectReader or, final boolean closeReader) { reader = or; filter = TreeFilter.ALL; trees = NO_TREES; + this.closeReader = closeReader; } /** @return the reader this walker is using to load objects. */ @@ -261,7 +271,9 @@ public class TreeWalk implements AutoCloseable { */ @Override public void close() { - reader.close(); + if (closeReader) { + reader.close(); + } } /** |