aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2025-06-24 09:03:28 +0300
committerIvan Frade <ifrade@google.com>2025-06-24 22:52:26 +0300
commit1ffcbb98dbdbd831bfbd3f5e53c33f614493de10 (patch)
tree3416e6d205f8726e87e03445a5f7e76d5eae7465
parentf6bfc81cffa7453a5da335fe515e9193cef1eaf5 (diff)
downloadjgit-1ffcbb98dbdbd831bfbd3f5e53c33f614493de10.tar.gz
jgit-1ffcbb98dbdbd831bfbd3f5e53c33f614493de10.zip
DfsReader: return idx position when looking up object in packs
This is a preparatory change to avoid double lookup in the primary index when using the object size index. If we get the index position during the object lookup, we dont need to query the index again when looking up the size. Make "hasImpl" return the index position of the object in the pack (besides leaving "last" pointing to the pack). Move the "has" logic that checks "last" before other packs to a method we can reuse. Change-Id: I36d2b348971a642c54da3d3727c04d0134ca9eba
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java39
2 files changed, 30 insertions, 13 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
index 618969f62e..a4bd39741d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
@@ -442,6 +442,10 @@ public final class DfsPackFile extends BlockBasedFile {
return 0 < offset && !isCorrupt(offset);
}
+ int findIdxPosition(DfsReader ctx, AnyObjectId id) throws IOException {
+ return idx(ctx).findPosition(id);
+ }
+
/**
* Get an object from this pack.
*
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 216d155c3f..e0abfe5e0a 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
@@ -187,31 +187,44 @@ public class DfsReader extends ObjectReader implements ObjectReuseAsIs {
@Override
public boolean has(AnyObjectId objectId) throws IOException {
+ return findPack(objectId) >= 0;
+ }
+
+ private int findPack(AnyObjectId objectId) throws IOException {
if (last != null
- && !skipGarbagePack(last)
- && last.hasObject(this, objectId))
- return true;
+ && !skipGarbagePack(last)) {
+ int idxPos = last.findIdxPosition(this, objectId);
+ if (idxPos >= 0) {
+ return idxPos;
+ }
+ }
+
PackList packList = db.getPackList();
- if (hasImpl(packList, objectId)) {
- return true;
+ int idxPos = findInPackList(packList, objectId);
+ if (idxPos >= 0) {
+ return idxPos;
} else if (packList.dirty()) {
stats.scanPacks++;
- return hasImpl(db.scanPacks(packList), objectId);
+ idxPos = findInPackList(db.scanPacks(packList), objectId);
+ return idxPos;
}
- return false;
+ return -1;
}
- private boolean hasImpl(PackList packList, AnyObjectId objectId)
+ // Leave "last" pointing to the pack and return the idx position of the
+ // object (-1 if not found)
+ private int findInPackList(PackList packList, AnyObjectId objectId)
throws IOException {
for (DfsPackFile pack : packList.packs) {
if (pack == last || skipGarbagePack(pack))
continue;
- if (pack.hasObject(this, objectId)) {
+ int idxPos = pack.findIdxPosition(this, objectId);
+ if (idxPos >= 0) {
last = pack;
- return true;
+ return idxPos;
}
}
- return false;
+ return -1;
}
@Override
@@ -595,10 +608,10 @@ public class DfsReader extends ObjectReader implements ObjectReuseAsIs {
PackList packList = db.getPackList();
// hasImpl doesn't check "last", but leaves "last" pointing to the pack
// with the object
- if (hasImpl(packList, objectId)) {
+ if (findInPackList(packList, objectId) >= 0) {
return last;
} else if (packList.dirty()) {
- if (hasImpl(db.getPackList(), objectId)) {
+ if (findInPackList(db.getPackList(), objectId) >= 0) {
return last;
}
}