]> source.dussan.org Git - jgit.git/commitdiff
DfsReader: give subclasses visiblity over the pack bitmap index 78/1173678/5
authorIvan Frade <ifrade@google.com>
Thu, 14 Dec 2023 17:25:06 +0000 (09:25 -0800)
committerIvan Frade <ifrade@google.com>
Thu, 14 Dec 2023 23:42:44 +0000 (15:42 -0800)
Subclasses intercept many methods in DfsReader to capture metrics, but
they cannot record stats from PackBitmapIndex, as it is wrapped inside
a BitmapIndex.

Move the creation of the BitmapIndex to a protected method. Subclasses
can override it to e.g. read metrics from the index or set listeners to
the BitmapIndex.

Change-Id: I86c13b3ef88663d7faf59f2ec77df0a36b1627ed

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java

index 3f0adcba1a6ccf21a2f7577451aabd33384aef2c..c722c06e9c7f47fbad570f344480cf296ed38fef 100644 (file)
@@ -28,6 +28,7 @@ import java.util.Set;
 import java.util.zip.DataFormatException;
 import java.util.zip.Inflater;
 
+import org.eclipse.jgit.annotations.NonNull;
 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
 import org.eclipse.jgit.errors.MissingObjectException;
 import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
@@ -120,11 +121,23 @@ public class DfsReader extends ObjectReader implements ObjectReuseAsIs {
                for (DfsPackFile pack : db.getPacks()) {
                        PackBitmapIndex bitmapIndex = pack.getBitmapIndex(this);
                        if (bitmapIndex != null)
-                               return new BitmapIndexImpl(bitmapIndex);
+                               return createBitmapIndex(bitmapIndex);
                }
                return null;
        }
 
+       /**
+        * Give subclasses a chance to record pack index stats
+        *
+        * @param packBitmapIndex
+        *            packBitmapIndex found in a pack (never null)
+        * @return an instance of BitmapIndex
+        */
+       protected BitmapIndex createBitmapIndex(
+                       @NonNull PackBitmapIndex packBitmapIndex) {
+               return new BitmapIndexImpl(packBitmapIndex);
+       }
+
        @Override
        public Optional<CommitGraph> getCommitGraph() throws IOException {
                for (DfsPackFile pack : db.getPacks()) {