Browse Source

Use try-with-resources in DfsGarbageCollector.writePack

Change-Id: I9a73125581b4d760b733fd045c3436c2aaaab730
stable-4.5
Shawn Pearce 8 years ago
parent
commit
a1ca13e09c
  1. 20
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java

20
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java

@ -386,38 +386,28 @@ public class DfsGarbageCollector {
private DfsPackDescription writePack(PackSource source, PackWriter pw,
ProgressMonitor pm) throws IOException {
DfsOutputStream out;
DfsPackDescription pack = repo.getObjectDatabase().newPack(source);
newPackDesc.add(pack);
out = objdb.writeFile(pack, PACK);
try {
try (DfsOutputStream out = objdb.writeFile(pack, PACK)) {
pw.writePack(pm, pm, out);
pack.addFileExt(PACK);
} finally {
out.close();
}
out = objdb.writeFile(pack, INDEX);
try {
CountingOutputStream cnt = new CountingOutputStream(out);
try (DfsOutputStream out = objdb.writeFile(pack, INDEX);
CountingOutputStream cnt = new CountingOutputStream(out)) {
pw.writeIndex(cnt);
pack.addFileExt(INDEX);
pack.setFileSize(INDEX, cnt.getCount());
pack.setIndexVersion(pw.getIndexVersion());
} finally {
out.close();
}
if (pw.prepareBitmapIndex(pm)) {
out = objdb.writeFile(pack, BITMAP_INDEX);
try {
CountingOutputStream cnt = new CountingOutputStream(out);
try (DfsOutputStream out = objdb.writeFile(pack, BITMAP_INDEX);
CountingOutputStream cnt = new CountingOutputStream(out)) {
pw.writeBitmapIndex(cnt);
pack.addFileExt(BITMAP_INDEX);
pack.setFileSize(BITMAP_INDEX, cnt.getCount());
} finally {
out.close();
}
}

Loading…
Cancel
Save