summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2024-02-23 00:23:43 +0000
committerGerrit Code Review <support@gerrithub.io>2024-02-23 00:23:43 +0000
commiteaf03935b759820f93980e2658142d2793e94be9 (patch)
tree81258d54c89927201ad63dc1eb4f5fd6d8400a09 /org.eclipse.jgit/src/org
parenta00a50013e4360f7073fee48dbf24e733323b8df (diff)
parente4b95ee569a26607af3a3774123b609e0426ac9a (diff)
downloadjgit-eaf03935b759820f93980e2658142d2793e94be9.tar.gz
jgit-eaf03935b759820f93980e2658142d2793e94be9.zip
Merge "DfsReader#getObjectSize: use size index if possible"
Diffstat (limited to 'org.eclipse.jgit/src/org')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java49
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);