]> source.dussan.org Git - jgit.git/commitdiff
BitmapWalker: do not revisit objects in bitmap 86/111086/8
authorJonathan Tan <jonathantanmy@google.com>
Thu, 2 Nov 2017 01:20:54 +0000 (18:20 -0700)
committerJonathan Tan <jonathantanmy@google.com>
Fri, 10 Nov 2017 23:41:31 +0000 (15:41 -0800)
Currently, BitmapWalker walks through every object returned by the
internal ObjectWalk, regardless of whether that object has already
been marked in the bitmap. Set an object filter to ensure that only
bitmap-unmarked objects are walked through.

Change-Id: I22a8874b1e571df3c33643b365036d95f52fe7c7
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BitmapWalker.java

index 787cf3588e48ffb3bed02c023e877800e6b4b3ab..4f4de540ba418168c319204c60578dcd24bde838 100644 (file)
@@ -50,12 +50,14 @@ import org.eclipse.jgit.errors.IncorrectObjectTypeException;
 import org.eclipse.jgit.errors.MissingObjectException;
 import org.eclipse.jgit.internal.revwalk.AddToBitmapFilter;
 import org.eclipse.jgit.internal.revwalk.AddUnseenToBitmapFilter;
+import org.eclipse.jgit.lib.AnyObjectId;
+import org.eclipse.jgit.lib.BitmapIndex;
 import org.eclipse.jgit.lib.BitmapIndex.Bitmap;
 import org.eclipse.jgit.lib.BitmapIndex.BitmapBuilder;
-import org.eclipse.jgit.lib.BitmapIndex;
 import org.eclipse.jgit.lib.NullProgressMonitor;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ProgressMonitor;
+import org.eclipse.jgit.revwalk.filter.ObjectFilter;
 
 /**
  * Helper class to do ObjectWalks with pack index bitmaps.
@@ -200,6 +202,7 @@ public final class BitmapWalker {
                                walker.setRevFilter(
                                                new AddUnseenToBitmapFilter(seen, bitmapResult));
                        }
+                       walker.setObjectFilter(new BitmapObjectFilter(bitmapResult));
 
                        while (walker.next() != null) {
                                // Iterate through all of the commits. The BitmapRevFilter does
@@ -224,4 +227,22 @@ public final class BitmapWalker {
 
                return bitmapResult;
        }
+
+       /**
+        * Filter that excludes objects already in the given bitmap.
+        */
+       static class BitmapObjectFilter extends ObjectFilter {
+               private final BitmapBuilder bitmap;
+
+               BitmapObjectFilter(BitmapBuilder bitmap) {
+                       this.bitmap = bitmap;
+               }
+
+               @Override
+               public final boolean include(ObjectWalk walker, AnyObjectId objid)
+                       throws MissingObjectException, IncorrectObjectTypeException,
+                              IOException {
+                       return !bitmap.contains(objid);
+               }
+       }
 }