diff options
author | Ivan Frade <ifrade@google.com> | 2024-02-20 12:43:45 -0800 |
---|---|---|
committer | Ivan Frade <ifrade@google.com> | 2024-02-20 13:01:44 -0800 |
commit | e4b95ee569a26607af3a3774123b609e0426ac9a (patch) | |
tree | a0622eceb39a67c65cf375e416bcb07242efd18e /org.eclipse.jgit | |
parent | 90674ab152102b16081bd109d7f72bc37c4040ab (diff) | |
download | jgit-e4b95ee569a26607af3a3774123b609e0426ac9a.tar.gz jgit-e4b95ee569a26607af3a3774123b609e0426ac9a.zip |
DfsReader#getObjectSize: use size index if possible
getObjectSize reads the size from the first bytes of the object in the
pack, using IO. For blobs and depending on the configuration, the size
could be available in the object size index.
Try to get the size from the object size index if available. Read from
the pack otherwise.
Note that GC uses #getObjectSize from the existing pack to write the
next object size index.
Change-Id: Ia999290c06d061cb53aa8c0a2b28b1a9761567ef
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java index c722c06e9c..a342796cbe 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java @@ -503,30 +503,28 @@ public class DfsReader extends ObjectReader implements ObjectReuseAsIs { public long getObjectSize(AnyObjectId objectId, int typeHint) throws MissingObjectException, IncorrectObjectTypeException, IOException { - if (last != null && !skipGarbagePack(last)) { - long sz = last.getObjectSize(this, objectId); - if (0 <= sz) { - return sz; + DfsPackFile pack = findPackWithObject(objectId); + if (pack == null) { + if (typeHint == OBJ_ANY) { + throw new MissingObjectException(objectId.copy(), + JGitText.get().unknownObjectType2); } + throw new MissingObjectException(objectId.copy(), typeHint); } - PackList packList = db.getPackList(); - long sz = getObjectSizeImpl(packList, objectId); - if (0 <= sz) { - return sz; - } - if (packList.dirty()) { - sz = getObjectSizeImpl(packList, objectId); - if (0 <= sz) { - return sz; - } + if (typeHint != Constants.OBJ_BLOB || !pack.hasObjectSizeIndex(this)) { + return pack.getObjectSize(this, objectId); } - if (typeHint == OBJ_ANY) { - throw new MissingObjectException(objectId.copy(), - JGitText.get().unknownObjectType2); + long sz = pack.getIndexedObjectSize(this, objectId); + if (sz >= 0) { + stats.objectSizeIndexHit += 1; + return sz; } - throw new MissingObjectException(objectId.copy(), typeHint); + + // Object wasn't in the index + stats.objectSizeIndexMiss += 1; + return pack.getObjectSize(this, objectId); } @@ -582,21 +580,6 @@ public class DfsReader extends ObjectReader implements ObjectReuseAsIs { return null; } - private long getObjectSizeImpl(PackList packList, AnyObjectId objectId) - throws IOException { - for (DfsPackFile pack : packList.packs) { - if (pack == last || skipGarbagePack(pack)) { - continue; - } - long sz = pack.getObjectSize(this, objectId); - if (0 <= sz) { - last = pack; - return sz; - } - } - return -1; - } - @Override public DfsObjectToPack newObjectToPack(AnyObjectId objectId, int type) { return new DfsObjectToPack(objectId, type); |