aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2024-01-11 21:29:58 +0000
committerGerrit Code Review <support@gerrithub.io>2024-01-11 21:29:58 +0000
commit37cbd41a86b0062e66fb6cfbac7a797b046efeaa (patch)
treed8c1e0f6a400ace29cb16a331b0f1bc9ea2a8ef2
parentd16dba3afc2a755f752558557572332a4261c79a (diff)
parent30788537771e04acf98d775cae971484adfd3007 (diff)
downloadjgit-37cbd41a86b0062e66fb6cfbac7a797b046efeaa.tar.gz
jgit-37cbd41a86b0062e66fb6cfbac7a797b046efeaa.zip
Merge "DfsInserter/PackParser: keep min size for index in the inserter"
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java32
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackParser.java7
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;