summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJonathan Nieder2013-04-25 17:20:54 (EDT)
committer Jonathan Nieder2013-04-26 15:58:34 (EDT)
commit70e494f6498a59c95756b8acb6c19d366e17a313 (patch)
tree75c8ccfa00eaf6c83203e0d4ad16ed00bba3c9cd
parent3699ea648ef900ce845af61ab29f8225c530b60b (diff)
downloadjgit-70e494f6498a59c95756b8acb6c19d366e17a313.zip
jgit-70e494f6498a59c95756b8acb6c19d366e17a313.tar.gz
jgit-70e494f6498a59c95756b8acb6c19d366e17a313.tar.bz2
archive: Release resources before returningrefs/changes/23/12223/2
The only caller exits immediately after calling execute() so this shouldn't make a difference, but it's good practice and should make it easier to expose the functionality in a public API later. Change-Id: Ia6cd2ce8382f1a62e576409107fc5c9a6b321fb6
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java40
1 files changed, 22 insertions, 18 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java
index 963528d..9075cf0 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java
@@ -78,32 +78,36 @@ class Archive extends TextBuiltin {
@Override
protected void run() throws Exception {
- final TreeWalk walk = new TreeWalk(db);
- final ObjectReader reader = walk.getObjectReader();
final MutableObjectId idBuf = new MutableObjectId();
final Archiver fmt = formats.get(format);
- final ArchiveOutputStream outa = fmt.createArchiveOutputStream(outs);
if (tree == null)
throw die(CLIText.get().treeIsRequired);
- walk.reset();
- walk.addTree(tree);
- walk.setRecursive(true);
- while (walk.next()) {
- final String name = walk.getPathString();
- final FileMode mode = walk.getFileMode(0);
-
- if (mode == FileMode.TREE)
- // ZIP entries for directories are optional.
- // Leave them out, mimicking "git archive".
- continue;
+ final ArchiveOutputStream outa = fmt.createArchiveOutputStream(outs);
+ final TreeWalk walk = new TreeWalk(db);
+ final ObjectReader reader = walk.getObjectReader();
- walk.getObjectId(idBuf, 0);
- fmt.putEntry(name, mode, reader.open(idBuf), outa);
+ try {
+ walk.reset();
+ walk.addTree(tree);
+ walk.setRecursive(true);
+ while (walk.next()) {
+ final String name = walk.getPathString();
+ final FileMode mode = walk.getFileMode(0);
+
+ if (mode == FileMode.TREE)
+ // ZIP entries for directories are optional.
+ // Leave them out, mimicking "git archive".
+ continue;
+
+ walk.getObjectId(idBuf, 0);
+ fmt.putEntry(name, mode, reader.open(idBuf), outa);
+ }
+ } finally {
+ reader.release();
+ outa.close();
}
-
- outa.close();
}
static private void warnArchiveEntryModeIgnored(String name) {