DfsInserter: populate full size on object insertion
We need the full size of the object to populate the object size index later. Save the size the PackedObjectInfo while adding objects to the pack. Then we don't need to re-read it from the pack at indexing time. Change-Id: I5bd7ad402df60b4637038def8ef7be2ab45faf87
This commit is contained in:
parent
12a4a4ccaa
commit
4d2a003b91
|
@ -29,11 +29,16 @@
|
||||||
import org.eclipse.jgit.junit.JGitTestUtil;
|
import org.eclipse.jgit.junit.JGitTestUtil;
|
||||||
import org.eclipse.jgit.junit.TestRng;
|
import org.eclipse.jgit.junit.TestRng;
|
||||||
import org.eclipse.jgit.lib.AbbreviatedObjectId;
|
import org.eclipse.jgit.lib.AbbreviatedObjectId;
|
||||||
|
import org.eclipse.jgit.lib.CommitBuilder;
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
|
import org.eclipse.jgit.lib.FileMode;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.lib.ObjectInserter;
|
import org.eclipse.jgit.lib.ObjectInserter;
|
||||||
import org.eclipse.jgit.lib.ObjectLoader;
|
import org.eclipse.jgit.lib.ObjectLoader;
|
||||||
import org.eclipse.jgit.lib.ObjectReader;
|
import org.eclipse.jgit.lib.ObjectReader;
|
||||||
|
import org.eclipse.jgit.lib.PersonIdent;
|
||||||
|
import org.eclipse.jgit.lib.TagBuilder;
|
||||||
|
import org.eclipse.jgit.lib.TreeFormatter;
|
||||||
import org.eclipse.jgit.util.IO;
|
import org.eclipse.jgit.util.IO;
|
||||||
import org.eclipse.jgit.util.RawParseUtils;
|
import org.eclipse.jgit.util.RawParseUtils;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -240,6 +245,50 @@ public void testNoCheckExisting() throws IOException {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testObjectSizePopulated() throws IOException {
|
||||||
|
// Blob
|
||||||
|
byte[] contents = Constants.encode("foo");
|
||||||
|
|
||||||
|
// Commit
|
||||||
|
PersonIdent person = new PersonIdent("Committer a", "jgit@eclipse.org");
|
||||||
|
CommitBuilder c = new CommitBuilder();
|
||||||
|
c.setAuthor(person);
|
||||||
|
c.setCommitter(person);
|
||||||
|
c.setTreeId(ObjectId
|
||||||
|
.fromString("45c4c6767a3945815371a7016532751dd558be40"));
|
||||||
|
c.setMessage("commit message");
|
||||||
|
|
||||||
|
// Tree
|
||||||
|
TreeFormatter treeBuilder = new TreeFormatter(2);
|
||||||
|
treeBuilder.append("filea", FileMode.REGULAR_FILE, ObjectId
|
||||||
|
.fromString("45c4c6767a3945815371a7016532751dd558be40"));
|
||||||
|
treeBuilder.append("fileb", FileMode.GITLINK, ObjectId
|
||||||
|
.fromString("1c458e25ca624bb8d4735bec1379a4a29ba786d0"));
|
||||||
|
|
||||||
|
// Tag
|
||||||
|
TagBuilder tagBuilder = new TagBuilder();
|
||||||
|
tagBuilder.setObjectId(
|
||||||
|
ObjectId.fromString("c97fe131649e80de55bd153e9a8d8629f7ca6932"),
|
||||||
|
Constants.OBJ_COMMIT);
|
||||||
|
tagBuilder.setTag("short name");
|
||||||
|
|
||||||
|
try (DfsInserter ins = (DfsInserter) db.newObjectInserter()) {
|
||||||
|
ObjectId aBlob = ins.insert(Constants.OBJ_BLOB, contents);
|
||||||
|
assertEquals(contents.length,
|
||||||
|
ins.objectMap.get(aBlob).getFullSize());
|
||||||
|
|
||||||
|
ObjectId aCommit = ins.insert(c);
|
||||||
|
assertEquals(174, ins.objectMap.get(aCommit).getFullSize());
|
||||||
|
|
||||||
|
ObjectId tree = ins.insert(treeBuilder);
|
||||||
|
assertEquals(66, ins.objectMap.get(tree).getFullSize());
|
||||||
|
|
||||||
|
ObjectId tag = ins.insert(tagBuilder);
|
||||||
|
assertEquals(76, ins.objectMap.get(tag).getFullSize());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String readString(ObjectLoader loader) throws IOException {
|
private static String readString(ObjectLoader loader) throws IOException {
|
||||||
return RawParseUtils.decode(readStream(loader));
|
return RawParseUtils.decode(readStream(loader));
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ public ObjectId insert(int type, byte[] data, int off, int len)
|
||||||
long offset = beginObject(type, len);
|
long offset = beginObject(type, len);
|
||||||
packOut.compress.write(data, off, len);
|
packOut.compress.write(data, off, len);
|
||||||
packOut.compress.finish();
|
packOut.compress.finish();
|
||||||
return endObject(id, offset);
|
return endObject(id, offset, len, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -148,16 +148,17 @@ public ObjectId insert(int type, long len, InputStream in)
|
||||||
md.update(Constants.encodeASCII(len));
|
md.update(Constants.encodeASCII(len));
|
||||||
md.update((byte) 0);
|
md.update((byte) 0);
|
||||||
|
|
||||||
while (0 < len) {
|
long inLength = len;
|
||||||
int n = in.read(buf, 0, (int) Math.min(buf.length, len));
|
while (0 < inLength) {
|
||||||
|
int n = in.read(buf, 0, (int) Math.min(buf.length, inLength));
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
throw new EOFException();
|
throw new EOFException();
|
||||||
md.update(buf, 0, n);
|
md.update(buf, 0, n);
|
||||||
packOut.compress.write(buf, 0, n);
|
packOut.compress.write(buf, 0, n);
|
||||||
len -= n;
|
inLength -= n;
|
||||||
}
|
}
|
||||||
packOut.compress.finish();
|
packOut.compress.finish();
|
||||||
return endObject(md.toObjectId(), offset);
|
return endObject(md.toObjectId(), offset, len, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] insertBuffer(long len) {
|
private byte[] insertBuffer(long len) {
|
||||||
|
@ -238,10 +239,12 @@ private long beginObject(int type, long len) throws IOException {
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObjectId endObject(ObjectId id, long offset) {
|
private ObjectId endObject(ObjectId id, long offset, long inflatedSize, int type) {
|
||||||
PackedObjectInfo obj = new PackedObjectInfo(id);
|
PackedObjectInfo obj = new PackedObjectInfo(id);
|
||||||
|
obj.setType(type);
|
||||||
obj.setOffset(offset);
|
obj.setOffset(offset);
|
||||||
obj.setCRC((int) packOut.crc32.getValue());
|
obj.setCRC((int) packOut.crc32.getValue());
|
||||||
|
obj.setFullSize(inflatedSize);
|
||||||
objectList.add(obj);
|
objectList.add(obj);
|
||||||
objectMap.addIfAbsent(obj);
|
objectMap.addIfAbsent(obj);
|
||||||
return id;
|
return id;
|
||||||
|
|
Loading…
Reference in New Issue