Merge "archive: Release resources before returning"
This commit is contained in:
commit
543b8560ac
|
@ -78,32 +78,36 @@ 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);
|
||||||
|
|
||||||
walk.reset();
|
final ArchiveOutputStream outa = fmt.createArchiveOutputStream(outs);
|
||||||
walk.addTree(tree);
|
final TreeWalk walk = new TreeWalk(db);
|
||||||
walk.setRecursive(true);
|
final ObjectReader reader = walk.getObjectReader();
|
||||||
while (walk.next()) {
|
|
||||||
final String name = walk.getPathString();
|
|
||||||
final FileMode mode = walk.getFileMode(0);
|
|
||||||
|
|
||||||
if (mode == FileMode.TREE)
|
try {
|
||||||
// ZIP entries for directories are optional.
|
walk.reset();
|
||||||
// Leave them out, mimicking "git archive".
|
walk.addTree(tree);
|
||||||
continue;
|
walk.setRecursive(true);
|
||||||
|
while (walk.next()) {
|
||||||
|
final String name = walk.getPathString();
|
||||||
|
final FileMode mode = walk.getFileMode(0);
|
||||||
|
|
||||||
walk.getObjectId(idBuf, 0);
|
if (mode == FileMode.TREE)
|
||||||
fmt.putEntry(name, mode, reader.open(idBuf), outa);
|
// 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) {
|
static private void warnArchiveEntryModeIgnored(String name) {
|
||||||
|
|
Loading…
Reference in New Issue