package org.eclipse.jgit.internal.storage.dfs;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_MIN_BYTES_OBJ_SIZE_INDEX;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_PACK_SECTION;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
}
}
+ @Test
+ public void testObjectSizeIndexOnInsert() throws IOException {
+ db.getConfig().setInt(CONFIG_PACK_SECTION, null,
+ CONFIG_KEY_MIN_BYTES_OBJ_SIZE_INDEX, 0);
+
+ byte[] contents = Constants.encode("foo");
+ ObjectId fooId;
+ try (ObjectInserter ins = db.newObjectInserter()) {
+ fooId = ins.insert(Constants.OBJ_BLOB, contents);
+ ins.flush();
+ }
+
+ DfsReader reader = db.getObjectDatabase().newReader();
+ assertEquals(1, db.getObjectDatabase().listPacks().size());
+ DfsPackFile insertPack = db.getObjectDatabase().getPacks()[0];
+ assertEquals(PackSource.INSERT,
+ insertPack.getPackDescription().getPackSource());
+ assertTrue(insertPack.hasObjectSizeIndex(reader));
+ assertEquals(contents.length, insertPack.getIndexedObjectSize(reader, fooId));
+ }
+
private static String readString(ObjectLoader loader) throws IOException {
return RawParseUtils.decode(readStream(loader));
}
package org.eclipse.jgit.internal.storage.dfs;
import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX;
+import static org.eclipse.jgit.internal.storage.pack.PackExt.OBJECT_SIZE_INDEX;
import static org.eclipse.jgit.internal.storage.pack.PackExt.PACK;
import static org.eclipse.jgit.lib.Constants.OBJ_OFS_DELTA;
import static org.eclipse.jgit.lib.Constants.OBJ_REF_DELTA;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.storage.file.PackIndex;
import org.eclipse.jgit.internal.storage.file.PackIndexWriter;
+import org.eclipse.jgit.internal.storage.file.PackObjectSizeIndexWriter;
import org.eclipse.jgit.internal.storage.pack.PackExt;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.ObjectStream;
+import org.eclipse.jgit.storage.pack.PackConfig;
import org.eclipse.jgit.transport.PackedObjectInfo;
import org.eclipse.jgit.util.BlockList;
import org.eclipse.jgit.util.IO;
sortObjectsById();
PackIndex index = writePackIndex(packDsc, packHash, objectList);
+ PackConfig pConfig = new PackConfig(db.getRepository().getConfig());
+ if (pConfig.isWriteObjSizeIndex()) {
+ writeObjectSizeIndex(packDsc, objectList,
+ pConfig.getMinBytesForObjSizeIndex());
+ }
db.commitPack(Collections.singletonList(packDsc), null);
rollback = false;
PackIndexWriter.createVersion(out, INDEX_VERSION).write(list, packHash);
}
+ void writeObjectSizeIndex(DfsPackDescription pack,
+ List<PackedObjectInfo> packedObjs, int minSize) throws IOException {
+ try (DfsOutputStream os = db.writeFile(pack, PackExt.OBJECT_SIZE_INDEX);
+ CountingOutputStream cnt = new CountingOutputStream(os)) {
+ PackObjectSizeIndexWriter.createWriter(os, minSize)
+ .write(packedObjs);
+ pack.addFileExt(OBJECT_SIZE_INDEX);
+ pack.setBlockSize(OBJECT_SIZE_INDEX, os.blockSize());
+ pack.setFileSize(OBJECT_SIZE_INDEX, cnt.getCount());
+ }
+ }
+
private class PackStream extends OutputStream {
private final DfsOutputStream out;
private final MessageDigest md;