aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm/src
diff options
context:
space:
mode:
authorShawn Pearce <sop@google.com>2013-04-26 16:06:25 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2013-04-26 16:06:25 -0400
commit543b8560ac41a32f1ef0e5dbc8d0fca51c3c34e9 (patch)
tree9dd7b94e27c483694bc8479245c514c84d029c05 /org.eclipse.jgit.pgm/src
parent2af9a4c7b1b2581fd55722d69185d5be114f84e2 (diff)
parent70e494f6498a59c95756b8acb6c19d366e17a313 (diff)
downloadjgit-543b8560ac41a32f1ef0e5dbc8d0fca51c3c34e9.tar.gz
jgit-543b8560ac41a32f1ef0e5dbc8d0fca51c3c34e9.zip
Merge "archive: Release resources before returning"
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
-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 963528d106..9075cf068b 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) {