Class PackIndexMerger

java.lang.Object
org.eclipse.jgit.internal.storage.midx.PackIndexMerger

public class PackIndexMerger extends Object
Collect the stats and offers an iterator over the union of n-pack indexes.

The multipack index is a list of (sha1, packid, offset) ordered by sha1. We can build it from the individual pack indexes (sha1, offset) ordered by sha1, with a simple merge ignoring duplicates.

This class encapsulates the merging logic and precalculates the stats that the index needs (like total count of objects). To limit memory consumption, it does the merge as it goes during the iteration and iterators use mutable entries. The stats of the combined index are calculated in an iteration at construction time.

  • Method Details

    • builder

      public static PackIndexMerger.Builder builder()
      Create a builder
      Returns:
      an empty builder
    • getUniqueObjectCount

      public int getUniqueObjectCount()
      Object count of the merged index (i.e. without duplicates)
      Returns:
      object count of the merged index
    • bySha1Iterator

      public MultiPackIndex.MidxIterator bySha1Iterator()
      Iterator over the merged indexes in sha1 order without duplicates

      This always returns the same iterator resetted. We don't support two iterators over this merged data.

      The returned entry in the iterator is mutable, callers should NOT keep a reference to it.

      Returns:
      an iterator in sha1 order without duplicates.