Pass the PackOutputStream down the call stack

Rather than storing this in an instance member, pass it down the
calling stack.  Its cleaner, we don't have to poke the stream as
a temporary field, and then unset it.

Change-Id: I0fd323371bc12edb10f0493bf11885d7057aeb13
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
Shawn O. Pearce 2010-06-28 10:44:09 -07:00
parent 1ad2feb7b3
commit f288c27e46
1 changed files with 16 additions and 16 deletions

View File

@ -183,8 +183,6 @@ public class PackWriter {
private final Repository db; private final Repository db;
private PackOutputStream out;
private final Deflater deflater; private final Deflater deflater;
private ProgressMonitor initMonitor; private ProgressMonitor initMonitor;
@ -613,14 +611,14 @@ public void writePack(OutputStream packStream) throws IOException {
if ((reuseDeltas || reuseObjects) && reuseSupport != null) if ((reuseDeltas || reuseObjects) && reuseSupport != null)
searchForReuse(); searchForReuse();
out = new PackOutputStream(packStream, isDeltaBaseAsOffset()); final PackOutputStream out = new PackOutputStream(packStream,
isDeltaBaseAsOffset());
writeMonitor.beginTask(WRITING_OBJECTS_PROGRESS, getObjectsNumber()); writeMonitor.beginTask(WRITING_OBJECTS_PROGRESS, getObjectsNumber());
out.writeFileHeader(PACK_VERSION_GENERATED, getObjectsNumber()); out.writeFileHeader(PACK_VERSION_GENERATED, getObjectsNumber());
writeObjects(); writeObjects(out);
writeChecksum(); writeChecksum(out);
out = null;
reader.release(); reader.release();
writeMonitor.endTask(); writeMonitor.endTask();
} }
@ -644,25 +642,26 @@ private void searchForReuse() throws IOException {
initMonitor.endTask(); initMonitor.endTask();
} }
private void writeObjects() throws IOException { private void writeObjects(PackOutputStream out) throws IOException {
for (List<ObjectToPack> list : objectsLists) { for (List<ObjectToPack> list : objectsLists) {
for (ObjectToPack otp : list) { for (ObjectToPack otp : list) {
if (writeMonitor.isCancelled()) if (writeMonitor.isCancelled())
throw new IOException( throw new IOException(
JGitText.get().packingCancelledDuringObjectsWriting); JGitText.get().packingCancelledDuringObjectsWriting);
if (!otp.isWritten()) if (!otp.isWritten())
writeObject(otp); writeObject(out, otp);
} }
} }
} }
private void writeObject(final ObjectToPack otp) throws IOException { private void writeObject(PackOutputStream out, final ObjectToPack otp)
throws IOException {
if (otp.isWritten()) if (otp.isWritten())
return; // We shouldn't be here. return; // We shouldn't be here.
otp.markWantWrite(); otp.markWantWrite();
if (otp.isDeltaRepresentation()) if (otp.isDeltaRepresentation())
writeBaseFirst(otp); writeBaseFirst(out, otp);
out.resetCRC32(); out.resetCRC32();
otp.setOffset(out.length()); otp.setOffset(out.length());
@ -690,12 +689,13 @@ private void writeObject(final ObjectToPack otp) throws IOException {
// If we reached here, reuse wasn't possible. // If we reached here, reuse wasn't possible.
// //
writeWholeObjectDeflate(otp); writeWholeObjectDeflate(out, otp);
otp.setCRC(out.getCRC32()); otp.setCRC(out.getCRC32());
writeMonitor.update(1); writeMonitor.update(1);
} }
private void writeBaseFirst(final ObjectToPack otp) throws IOException { private void writeBaseFirst(PackOutputStream out, final ObjectToPack otp)
throws IOException {
ObjectToPack baseInPack = otp.getDeltaBase(); ObjectToPack baseInPack = otp.getDeltaBase();
if (baseInPack != null) { if (baseInPack != null) {
if (!baseInPack.isWritten()) { if (!baseInPack.isWritten()) {
@ -708,7 +708,7 @@ private void writeBaseFirst(final ObjectToPack otp) throws IOException {
redoSearchForReuse(otp); redoSearchForReuse(otp);
reuseDeltas = true; reuseDeltas = true;
} else { } else {
writeObject(baseInPack); writeObject(out, baseInPack);
} }
} }
} else if (!thin) { } else if (!thin) {
@ -728,8 +728,8 @@ private void redoSearchForReuse(final ObjectToPack otp) throws IOException,
reuseSupport.selectObjectRepresentation(this, otp); reuseSupport.selectObjectRepresentation(this, otp);
} }
private void writeWholeObjectDeflate(final ObjectToPack otp) private void writeWholeObjectDeflate(PackOutputStream out,
throws IOException { final ObjectToPack otp) throws IOException {
final ObjectLoader loader = reader.openObject(otp, otp.getType()); final ObjectLoader loader = reader.openObject(otp, otp.getType());
final byte[] data = loader.getCachedBytes(); final byte[] data = loader.getCachedBytes();
out.writeHeader(otp, data.length); out.writeHeader(otp, data.length);
@ -745,7 +745,7 @@ private void writeWholeObjectDeflate(final ObjectToPack otp)
} while (!deflater.finished()); } while (!deflater.finished());
} }
private void writeChecksum() throws IOException { private void writeChecksum(PackOutputStream out) throws IOException {
packcsum = out.getDigest(); packcsum = out.getDigest();
out.write(packcsum); out.write(packcsum);
} }