diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java index 031ea2b20..a716845b4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java @@ -610,19 +610,22 @@ public class PackWriter { * stream. */ public void writePack(OutputStream packStream) throws IOException { - if ((reuseDeltas || reuseObjects) && reuseSupport != null) - searchForReuse(); - - out = new PackOutputStream(packStream, isDeltaBaseAsOffset()); - - writeMonitor.beginTask(WRITING_OBJECTS_PROGRESS, getObjectsNumber()); - out.writeFileHeader(PACK_VERSION_GENERATED, getObjectsNumber()); - writeObjects(); - writeChecksum(); - - out = null; - reader.release(); - writeMonitor.endTask(); + try { + if ((reuseDeltas || reuseObjects) && reuseSupport != null) + searchForReuse(); + + out = new PackOutputStream(packStream, isDeltaBaseAsOffset()); + + int cnt = getObjectsNumber(); + writeMonitor.beginTask(WRITING_OBJECTS_PROGRESS, cnt); + out.writeFileHeader(PACK_VERSION_GENERATED, cnt); + writeObjects(); + writeChecksum(); + writeMonitor.endTask(); + } finally { + out = null; + reader.release(); + } } private void searchForReuse() throws IOException {