java.lang.Object
org.eclipse.jgit.internal.storage.file.Pack
All Implemented Interfaces:
Iterable<PackIndex.MutableEntry>
Direct Known Subclasses:
PackMidx

public class Pack extends Object implements Iterable<PackIndex.MutableEntry>
A Git version 2 pack file representation. A pack file contains Git objects in delta packed format yielding high compression of lots of object where some objects are similar.
  • Field Details

    • SORT

      public static final Comparator<Pack> SORT
      Sorts PackFiles to be most recently created to least recently created.
  • Constructor Details

    • Pack

      public Pack(Config cfg, File packFile, @Nullable PackFile bitmapIdxFile)
      Construct a reader for an existing, pre-indexed packfile.
      Parameters:
      cfg - configuration this directory consults for write settings.
      packFile - path of the .pack file holding the data.
      bitmapIdxFile - existing bitmap index file with the same base as the pack
  • Method Details

    • setPackChecksum

      protected void setPackChecksum(byte[] checksum)
      Set the checksum of this pack
      Parameters:
      checksum - the checksum
    • getCoveredPacks

      protected List<Pack> getCoveredPacks()
      Packs covered by this pack

      For regular packs, this list is empty. For midx packs, this list has the names of packs indexed by the midx.

      Returns:
      list of packs covered by this pack.
    • getPackFile

      public PackFile getPackFile()
      Get the File object which locates this pack on disk.
      Returns:
      the File object which locates this pack on disk.
    • getIndex

      public PackIndex getIndex() throws IOException
      Get the index for this pack file.
      Returns:
      the index for this pack file.
      Throws:
      IOException - if an IO error occurred
    • hasObjectSizeIndex

      public boolean hasObjectSizeIndex() throws IOException
      Get the object size index for this pack file
      Returns:
      the object size index for this pack file if it exists (null otherwise)
      Throws:
      IOException - problem reading the index
    • getObjectSizeIndexCount

      public long getObjectSizeIndexCount() throws IOException
      Number of objects in the object-size index of this pack
      Returns:
      number of objects in the index (0 if either the index is empty or it doesn't exist)
      Throws:
      IOException - if an IO error occurred while reading the index
    • getIndexedObjectSize

      public long getIndexedObjectSize(AnyObjectId id) throws IOException
      Return the size of the object from the object-size index. Caller MUST check that the pack has object-size index (hasObjectSizeIndex()) and that the pack contains the object.
      Parameters:
      id - object id of an object in the pack
      Returns:
      size of the object from the index. Negative if the object is not in the index.
      Throws:
      IOException - if an IO error occurred while reading the index
    • getPackName

      public String getPackName()
      Get name extracted from pack-*.pack pattern.
      Returns:
      name extracted from pack-*.pack pattern.
    • hasObject

      public boolean hasObject(AnyObjectId id) throws IOException
      Determine if an object is contained within the pack file.

      For performance reasons only the index file is searched; the main pack content is ignored entirely.

      Parameters:
      id - the object to look for. Must not be null.
      Returns:
      true if the object is in this pack; false otherwise.
      Throws:
      IOException - the index file cannot be loaded into memory.
    • shouldBeKept

      public boolean shouldBeKept()
      Determines whether a .keep file exists for this pack file.
      Returns:
      true if a .keep file exist.
    • close

      public static void close(Set<Pack> packs)
      Close the resources utilized by these pack files
      Parameters:
      packs - packs to close
    • close

      public void close()
      Close the resources utilized by this pack file
    • closeIndices

      protected void closeIndices()
      Clear the indexes referenced in this pack.

      Subclasses override this method to clear references to any index they add

    • iterator

      public Iterator<PackIndex.MutableEntry> iterator()

      Provide iterator over entries in associated pack index, that should also exist in this pack file. Objects returned by such iterator are mutable during iteration.

      Iterator returns objects in SHA-1 lexicographical order.

      Specified by:
      iterator in interface Iterable<PackIndex.MutableEntry>
      See Also:
    • fullyIncludedIn

      protected List<Pack> fullyIncludedIn(BitmapIndex.BitmapBuilder needBitmaps) throws IOException
      Return the pack if all its objects are included in the need bitmaps.
      Parameters:
      needBitmaps - bitmap with needed objects. Modified in this method: If a pack is fully included in the bitmap, the pack objects are removed from the bitmap.
      Returns:
      list of packs fully included in the bitmap
      Throws:
      IOException - an error reading the bitmap index of this pack
    • getReverseIdx

      protected PackReverseIndex getReverseIdx() throws IOException
      Get the reverse index of this pack
      Returns:
      a reverse index
      Throws:
      IOException - an error loading or calculating the reverse index.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • optionally

      protected <T> Optionally<T> optionally(T element)
      Wrap the reference in an Optionally
      Type Parameters:
      T - the type
      Parameters:
      element - reference
      Returns:
      Optionally with the reference inside