DfsPackFile: asObjectIdSet() when only inclusion is needed.
For midx is complicated to implement the primary index. Some of the
callers use the primary index for inclusion (ignoring order or
offset). They can still do the object lookups at the pack level, but
that introduces extra instruction per object.
Offer a "asObjectIdSet" view of the pack to just check inclusion. This
works for regular packs and midxs and skips the extra instructions of
the pack checking if the index is loaded each time.
Change-Id: I72e6e6c4c5998c1e2acd5325bb0beabe6a6a6964
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackCompactor.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackCompactor.java
index 62a4c62..8860cce 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackCompactor.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackCompactor.java
@@ -156,11 +156,11 @@ public DfsPackCompactor exclude(ObjectIdSet set) {
* pack index cannot be loaded.
*/
public DfsPackCompactor exclude(DfsPackFile pack) throws IOException {
- final PackIndex idx;
+ final ObjectIdSet objectIdSet;
try (DfsReader ctx = (DfsReader) repo.newObjectReader()) {
- idx = pack.getPackIndex(ctx);
+ objectIdSet = pack.asObjectIdSet(ctx);
}
- return exclude(idx);
+ return exclude(objectIdSet);
}
/**
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 bbf3f87..ecc97e9 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
@@ -62,6 +62,7 @@
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectIdSet;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
@@ -253,6 +254,22 @@ public PackIndex getPackIndex(DfsReader ctx) throws IOException {
return idx(ctx);
}
+ /**
+ * Get a view of this packfile as a set of objects
+ * <p>
+ * To use when the caller only needs to check inclusion (without specific
+ * order or getting offsets).
+ *
+ * @param ctx
+ * reader context
+ * @return a view of this packfile as a set of objects
+ * @throws IOException
+ * cannot load the backing data from storage
+ */
+ public ObjectIdSet asObjectIdSet(DfsReader ctx) throws IOException {
+ return idx(ctx);
+ }
+
private PackIndex idx(DfsReader ctx) throws IOException {
if (index != null) {
return index;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFileMidx.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFileMidx.java
index 40afa1a..742fe6c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFileMidx.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFileMidx.java
@@ -38,6 +38,7 @@
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.BitmapIndex;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectIdSet;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.util.BlockList;
@@ -148,6 +149,12 @@ public PackIndex getPackIndex(DfsReader ctx) {
}
@Override
+ public ObjectIdSet asObjectIdSet(DfsReader ctx) throws IOException {
+ MultiPackIndex multiPackIndex = midx(ctx);
+ return objectId -> multiPackIndex.hasObject(objectId);
+ }
+
+ @Override
public PackReverseIndex getReverseIdx(DfsReader ctx) {
throw new IllegalStateException(
"Shouldn't use multipack index if the reverse index is needed"); //$NON-NLS-1$