Browse Source

Add a release() method to SubmoduleWalk

We need a way to release the underlying TreeWalk. Also, use this
method to release walks from the static factory methods on error or
when submodules are not found.

Change-Id: I6bedc2db78bcd577aef2cfe6715bb981a26dcfd7
stable-2.1
Dave Borowitz 13 years ago
parent
commit
458f64c6ea
  1. 41
      org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java

41
org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java

@ -102,12 +102,18 @@ public class SubmoduleWalk {
public static SubmoduleWalk forPath(Repository repository, public static SubmoduleWalk forPath(Repository repository,
AnyObjectId treeId, String path) throws IOException { AnyObjectId treeId, String path) throws IOException {
SubmoduleWalk generator = new SubmoduleWalk(repository); SubmoduleWalk generator = new SubmoduleWalk(repository);
generator.setTree(treeId); try {
PathFilter filter = PathFilter.create(path); generator.setTree(treeId);
generator.setFilter(filter); PathFilter filter = PathFilter.create(path);
while (generator.next()) generator.setFilter(filter);
if (filter.isDone(generator.walk)) while (generator.next())
return generator; if (filter.isDone(generator.walk))
return generator;
} catch (IOException e) {
generator.release();
throw e;
}
generator.release();
return null; return null;
} }
@ -124,12 +130,18 @@ public class SubmoduleWalk {
public static SubmoduleWalk forPath(Repository repository, public static SubmoduleWalk forPath(Repository repository,
AbstractTreeIterator iterator, String path) throws IOException { AbstractTreeIterator iterator, String path) throws IOException {
SubmoduleWalk generator = new SubmoduleWalk(repository); SubmoduleWalk generator = new SubmoduleWalk(repository);
generator.setTree(iterator); try {
PathFilter filter = PathFilter.create(path); generator.setTree(iterator);
generator.setFilter(filter); PathFilter filter = PathFilter.create(path);
while (generator.next()) generator.setFilter(filter);
if (filter.isDone(generator.walk)) while (generator.next())
return generator; if (filter.isDone(generator.walk))
return generator;
} catch (IOException e) {
generator.release();
throw e;
}
generator.release();
return null; return null;
} }
@ -511,4 +523,9 @@ public class SubmoduleWalk {
String url = getModulesUrl(); String url = getModulesUrl();
return url != null ? getSubmoduleRemoteUrl(repository, url) : null; return url != null ? getSubmoduleRemoteUrl(repository, url) : null;
} }
/** Release any resources used by this walker's reader. */
public void release() {
walk.release();
}
} }

Loading…
Cancel
Save