diff options
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); |