From ca2c57b2ec5400db9c9446056b001a83adc5ccd8 Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Tue, 28 Dec 2021 14:23:40 -0800 Subject: PackWriter: offer to write an object-size index for the pack PackWriter callers tell the writer what do the want to include in the pack and invoke #writePack(). Afterwards, they can invoke #writeIndex() to write the corresponding pack index. Mirror this for the object-size index, adding a #writeObjectSizeIndex() method. Change-Id: Ic319975c72c239cd6488303f7d4cced797e6fe00 --- .../jgit/internal/storage/pack/PackWriter.java | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'org.eclipse.jgit') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java index d42d348a1c..bad572459a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java @@ -61,6 +61,7 @@ import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.storage.file.PackBitmapIndexBuilder; import org.eclipse.jgit.internal.storage.file.PackBitmapIndexWriterV1; import org.eclipse.jgit.internal.storage.file.PackIndexWriter; +import org.eclipse.jgit.internal.storage.file.PackObjectSizeIndexWriter; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AsyncObjectSizeQueue; import org.eclipse.jgit.lib.BatchingProgressMonitor; @@ -1091,6 +1092,50 @@ public class PackWriter implements AutoCloseable { stats.timeWriting += System.currentTimeMillis() - writeStart; } + /** + * Create an object size index file for the contents of the pack file just + * written. + *

+ * Called after + * {@link #writePack(ProgressMonitor, ProgressMonitor, OutputStream)} that + * populates the list of objects to pack and before + * {@link #writeBitmapIndex(OutputStream)} that destroys it. + *

+ * Writing this index is only required for local pack storage. Packs sent on + * the network do not need to create an object size index. + * + * @param objIdxStream + * output for the object size index data. Caller is responsible + * for closing this stream. + * @throws IOException + * errors while writing + */ + public void writeObjectSizeIndex(OutputStream objIdxStream) + throws IOException { + if (config.getMinBytesForObjSizeIndex() < 0) { + return; + } + + long writeStart = System.currentTimeMillis(); + // We only need to populate the size of blobs + AsyncObjectSizeQueue sizeQueue = reader + .getObjectSize(objectsLists[OBJ_BLOB], /* reportMissing= */false); + try { + while (sizeQueue.next()) { + ObjectToPack otp = sizeQueue.getCurrent(); + long sz = sizeQueue.getSize(); + otp.setFullSize(sz); + } + } finally { + sizeQueue.release(); + } + PackObjectSizeIndexWriter iw = PackObjectSizeIndexWriter.createWriter( + objIdxStream, config.getMinBytesForObjSizeIndex()); + // All indexed objects because their positions must match primary index order + iw.write(sortByName()); + stats.timeWriting += System.currentTimeMillis() - writeStart; + } + /** * Create a bitmap index file to match the pack file just written. *

-- cgit v1.2.3