summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2023-11-15 10:25:22 -0800
committerIvan Frade <ifrade@google.com>2023-11-15 15:04:31 -0800
commitd3f711ca1ddc209827f0f52b203bfc880312fc81 (patch)
tree307b066f6d8df5c0f985009c2764c06af16caef5 /org.eclipse.jgit
parent8db605620b1f747d0fc9bfe1bf2ffb2525246802 (diff)
downloadjgit-d3f711ca1ddc209827f0f52b203bfc880312fc81.tar.gz
jgit-d3f711ca1ddc209827f0f52b203bfc880312fc81.zip
BitmapWalker: announce walked objects via listener interface
We want to know what objects had a bitmap in the walk, to see where do they sit in the commit history and evaluate our bitmap selection algorithm. Add a listener interface to the bitmap walker announcing the objects walked and whether they had bitmap. Change-Id: I956fe2ad927a500710d2cbe78ecd4d26f178c266
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmapWalker.java64
1 files changed, 62 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmapWalker.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmapWalker.java
index 8cd5eb2238..5060823571 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmapWalker.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmapWalker.java
@@ -48,6 +48,40 @@ public final class BitmapWalker {
private Bitmap prevBitmap;
/**
+ * Report events happening during the walk.
+ *
+ * @since 6.8
+ */
+ public interface BitmapWalkListener {
+
+ /**
+ * The object is in the walk, and it has a bitmap
+ *
+ * @param oid
+ * objectId with a bitmap in the bitmap index
+ */
+ default void onBitmapFound(ObjectId oid) {
+ // Nothing to do
+ }
+
+ /**
+ * The object is in the walk but doesn't have bitmap
+ *
+ * @param oid
+ * objectId without a bitmap in the bitmap index
+ */
+ default void onBitmapNotFound(ObjectId oid) {
+ // Nothing to do
+ }
+ }
+
+ private static final BitmapWalkListener NO_LISTENER = new BitmapWalkListener() {
+ // Default methods
+ };
+
+ private final BitmapWalkListener listener;
+
+ /**
* Create a BitmapWalker.
*
* @param walker walker to use when traversing the object graph.
@@ -56,9 +90,30 @@ public final class BitmapWalker {
*/
public BitmapWalker(
ObjectWalk walker, BitmapIndex bitmapIndex, ProgressMonitor pm) {
+ this(walker, bitmapIndex, pm, NO_LISTENER);
+ }
+
+ /**
+ * Create a BitmapWalker.
+ *
+ * @param walker
+ * walker to use when traversing the object graph.
+ * @param bitmapIndex
+ * index to obtain bitmaps from.
+ * @param pm
+ * progress monitor to report progress on.
+ * @param listener
+ * listener of event happening during the walk. Use
+ * {@link #NO_LISTENER} for a no-op listener.
+ *
+ * @since 6.8
+ */
+ public BitmapWalker(ObjectWalk walker, BitmapIndex bitmapIndex,
+ ProgressMonitor pm, BitmapWalkListener listener) {
this.walker = walker;
this.bitmapIndex = bitmapIndex;
this.pm = (pm == null) ? NullProgressMonitor.INSTANCE : pm;
+ this.listener = listener;
}
/**
@@ -140,6 +195,7 @@ public final class BitmapWalker {
Bitmap bitmap = bitmapIndex.getBitmap(obj);
if (bitmap != null) {
result.or(bitmap);
+ listener.onBitmapFound(obj);
}
}
@@ -178,8 +234,10 @@ public final class BitmapWalker {
for (ObjectId obj : start) {
Bitmap bitmap = bitmapIndex.getBitmap(obj);
- if (bitmap != null)
+ if (bitmap != null) {
bitmapResult.or(bitmap);
+ listener.onBitmapFound(obj);
+ }
}
boolean marked = false;
@@ -208,7 +266,8 @@ public final class BitmapWalker {
}
walker.setObjectFilter(new BitmapObjectFilter(bitmapResult));
- while (walker.next() != null) {
+ ObjectId oid;
+ while ((oid = walker.next()) != null) {
// Iterate through all of the commits. The BitmapRevFilter does
// the work.
//
@@ -220,6 +279,7 @@ public final class BitmapWalker {
// of bitmaps.
pm.update(1);
countOfBitmapIndexMisses++;
+ listener.onBitmapNotFound(oid);
}
RevObject ro;