diff options
author | Ivan Frade <ifrade@google.com> | 2024-01-10 15:36:24 -0800 |
---|---|---|
committer | Ivan Frade <ifrade@google.com> | 2024-01-11 09:49:23 -0800 |
commit | 30788537771e04acf98d775cae971484adfd3007 (patch) | |
tree | 710881bb2777385e6a0302e4e4b6023092e05967 /org.eclipse.jgit | |
parent | ef53cb8a9f15d5548bfbb3d4da479104c081e747 (diff) | |
download | jgit-30788537771e04acf98d775cae971484adfd3007.tar.gz jgit-30788537771e04acf98d775cae971484adfd3007.zip |
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
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java | 32 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/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. + * + * <p> + * 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<PackedObjectInfo> packedObjs, int minSize) throws IOException { + List<PackedObjectInfo> 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; |