From b2abab271a3c8093cc8c2cf3d5daea7ed408b78c Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Thu, 14 Dec 2023 09:25:06 -0800 Subject: [PATCH] DfsReader: give subclasses visiblity over the pack bitmap index 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 --- .../jgit/internal/storage/dfs/DfsReader.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java index 3f0adcba1a..c722c06e9c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java @@ -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 getCommitGraph() throws IOException { for (DfsPackFile pack : db.getPacks()) { -- 2.39.5