Merge "archive: Release resources before returning"

This commit is contained in:
Shawn Pearce 2013-04-26 16:06:25 -04:00 committed by Gerrit Code Review @ Eclipse.org
commit 543b8560ac
1 changed files with 21 additions and 17 deletions

View File

@ -78,15 +78,17 @@ class Archive extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
final TreeWalk walk = new TreeWalk(db);
final ObjectReader reader = walk.getObjectReader();
final MutableObjectId idBuf = new MutableObjectId(); final MutableObjectId idBuf = new MutableObjectId();
final Archiver fmt = formats.get(format); final Archiver fmt = formats.get(format);
final ArchiveOutputStream outa = fmt.createArchiveOutputStream(outs);
if (tree == null) if (tree == null)
throw die(CLIText.get().treeIsRequired); throw die(CLIText.get().treeIsRequired);
final ArchiveOutputStream outa = fmt.createArchiveOutputStream(outs);
final TreeWalk walk = new TreeWalk(db);
final ObjectReader reader = walk.getObjectReader();
try {
walk.reset(); walk.reset();
walk.addTree(tree); walk.addTree(tree);
walk.setRecursive(true); walk.setRecursive(true);
@ -102,9 +104,11 @@ protected void run() throws Exception {
walk.getObjectId(idBuf, 0); walk.getObjectId(idBuf, 0);
fmt.putEntry(name, mode, reader.open(idBuf), outa); fmt.putEntry(name, mode, reader.open(idBuf), outa);
} }
} finally {
reader.release();
outa.close(); outa.close();
} }
}
static private void warnArchiveEntryModeIgnored(String name) { static private void warnArchiveEntryModeIgnored(String name) {
System.err.println(MessageFormat.format( // System.err.println(MessageFormat.format( //