From 30788537771e04acf98d775cae971484adfd3007 Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Wed, 10 Jan 2024 15:36:24 -0800 Subject: DfsInserter/PackParser: keep min size for index in the inserter Both, inserter and packparser read the minimum size for the object size index. The writing is invoked from both classes but done only by the inserter. Let the inserter read and handle the conf. Do this in the constructor and allow override so some paths can hardcode a value. Change-Id: I890cadd29678a53738761f4b0ab13020d6353f3e --- .../jgit/internal/storage/dfs/DfsInserter.java | 32 +++++++++++++++++----- .../jgit/internal/storage/dfs/DfsPackParser.java | 7 +---- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java index 2f8d964e0a..dfab7bab6f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java @@ -83,6 +83,8 @@ public class DfsInserter extends ObjectInserter { private boolean rollback; private boolean checkExisting = true; + private int minBytesForObjectSizeIndex = -1; + /** * Initialize a new inserter. * @@ -91,6 +93,8 @@ public class DfsInserter extends ObjectInserter { */ protected DfsInserter(DfsObjDatabase db) { this.db = db; + PackConfig pc = new PackConfig(db.getRepository().getConfig()); + this.minBytesForObjectSizeIndex = pc.getMinBytesForObjSizeIndex(); } /** @@ -109,6 +113,20 @@ public class DfsInserter extends ObjectInserter { this.compression = compression; } + /** + * Set minimum size for an object to be included in the object size index. + * + *

+ * Use 0 for all and -1 for nothing (the pack won't have object size index). + * + * @param minBytes + * only objects with size bigger or equal to this are included in + * the index. + */ + protected void setMinBytesForObjectSizeIndex(int minBytes) { + this.minBytesForObjectSizeIndex = minBytes; + } + @Override public DfsPackParser newPackParser(InputStream in) throws IOException { return new DfsPackParser(db, this, in); @@ -195,11 +213,7 @@ public class DfsInserter extends ObjectInserter { sortObjectsById(); PackIndex index = writePackIndex(packDsc, packHash, objectList); - PackConfig pConfig = new PackConfig(db.getRepository().getConfig()); - if (pConfig.isWriteObjSizeIndex()) { - writeObjectSizeIndex(packDsc, objectList, - pConfig.getMinBytesForObjSizeIndex()); - } + writeObjectSizeIndex(packDsc, objectList); db.commitPack(Collections.singletonList(packDsc), null); rollback = false; @@ -323,10 +337,14 @@ public class DfsInserter extends ObjectInserter { } void writeObjectSizeIndex(DfsPackDescription pack, - List packedObjs, int minSize) throws IOException { + List packedObjs) throws IOException { + if (minBytesForObjectSizeIndex < 0) { + return; + } try (DfsOutputStream os = db.writeFile(pack, PackExt.OBJECT_SIZE_INDEX); CountingOutputStream cnt = new CountingOutputStream(os)) { - PackObjectSizeIndexWriter.createWriter(os, minSize) + PackObjectSizeIndexWriter + .createWriter(os, minBytesForObjectSizeIndex) .write(packedObjs); pack.addFileExt(OBJECT_SIZE_INDEX); pack.setBlockSize(OBJECT_SIZE_INDEX, os.blockSize()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackParser.java index 8c7b0ec708..a38ce91ccd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackParser.java @@ -26,7 +26,6 @@ import org.eclipse.jgit.internal.storage.file.PackIndex; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ProgressMonitor; -import org.eclipse.jgit.storage.pack.PackConfig; import org.eclipse.jgit.transport.PackLock; import org.eclipse.jgit.transport.PackParser; import org.eclipse.jgit.transport.PackedObjectInfo; @@ -123,11 +122,7 @@ public class DfsPackParser extends PackParser { packDsc.setBlockSize(PACK, blockSize); writePackIndex(); - PackConfig pConfig = new PackConfig(objdb.getRepository().getConfig()); - if (pConfig.isWriteObjSizeIndex()) { - objins.writeObjectSizeIndex(packDsc, getSortedObjectList(null), - pConfig.getMinBytesForObjSizeIndex()); - } + objins.writeObjectSizeIndex(packDsc, getSortedObjectList(null)); objdb.commitPack(Collections.singletonList(packDsc), null); rollback = false; -- cgit v1.2.3