diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java index b6e9d319a..343dc11ae 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java @@ -104,26 +104,33 @@ final class LargePackedWholeObject extends ObjectLoader { /** {@inheritDoc} */ @Override public ObjectStream openStream() throws MissingObjectException, IOException { - InputStream in; - try (DfsReader ctx = db.newReader()) { + PackInputStream packIn; + DfsReader ctx = db.newReader(); + try { try { - in = new PackInputStream(pack, objectOffset + headerLength, ctx); + packIn = new PackInputStream( + pack, objectOffset + headerLength, ctx); + ctx = null; // owned by packIn } catch (IOException packGone) { // If the pack file cannot be pinned into the cursor, it // probably was repacked recently. Go find the object // again and open the stream from that location instead. - // ObjectId obj = pack.getReverseIdx(ctx).findObject(objectOffset); return ctx.open(obj, type).openStream(); } - - // Align buffer to inflater size, at a larger than default block. - // This reduces the number of context switches from the - // caller down into the pack stream inflation. - int bufsz = 8192; - in = new BufferedInputStream( - new InflaterInputStream(in, ctx.inflater(), bufsz), bufsz); - return new ObjectStream.Filter(type, size, in); + } finally { + if (ctx != null) { + ctx.close(); + } } + + // Align buffer to inflater size, at a larger than default block. + // This reduces the number of context switches from the + // caller down into the pack stream inflation. + int bufsz = 8192; + InputStream in = new BufferedInputStream( + new InflaterInputStream(packIn, packIn.ctx.inflater(), bufsz), + bufsz); + return new ObjectStream.Filter(type, size, in); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/PackInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/PackInputStream.java index d88011c3a..b859d9df3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/PackInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/PackInputStream.java @@ -47,7 +47,7 @@ import java.io.IOException; import java.io.InputStream; final class PackInputStream extends InputStream { - private final DfsReader ctx; + final DfsReader ctx; private final DfsPackFile pack;