From d3f711ca1ddc209827f0f52b203bfc880312fc81 Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Wed, 15 Nov 2023 10:25:22 -0800 Subject: [PATCH] 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 --- .../eclipse/jgit/revwalk/BitmapWalker.java | 64 ++++++++++++++++++- 1 file 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 8cd5eb223..506082357 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmapWalker.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmapWalker.java @@ -47,6 +47,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. * @@ -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 BitmapBuilder findObjects(Iterable start, BitmapBuild Bitmap bitmap = bitmapIndex.getBitmap(obj); if (bitmap != null) { result.or(bitmap); + listener.onBitmapFound(obj); } } @@ -178,8 +234,10 @@ private BitmapBuilder findObjectsWalk(Iterable start, Bitmap 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 @@ private BitmapBuilder findObjectsWalk(Iterable start, Bitmap } 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 @@ private BitmapBuilder findObjectsWalk(Iterable start, Bitmap // of bitmaps. pm.update(1); countOfBitmapIndexMisses++; + listener.onBitmapNotFound(oid); } RevObject ro;