Class DfsPackFile


  • public final class DfsPackFile
    extends BlockBasedFile
    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 Detail

      • initLock

        private final java.lang.Object initLock
        Lock for initialization of index and corruptObjects.

        This lock ensures only one thread can perform the initialization work.

      • index

        private volatile PackIndex index
        Index mapping ObjectId to position within the pack stream.
      • bitmapIndex

        private volatile PackBitmapIndex bitmapIndex
        Index of compressed bitmap mapping entire object graph.
      • corruptObjects

        private volatile LongList corruptObjects
        Objects we have tried to read, and discovered to be corrupt.

        The list is allocated after the first corruption is found, and filled in as more entries are discovered. Typically this list is never used, as pack files do not usually contain corrupt objects.

    • Constructor Detail

      • DfsPackFile

        DfsPackFile​(DfsBlockCache cache,
                    DfsPackDescription desc)
        Construct a reader for an existing, packfile.
        Parameters:
        cache - cache that owns the pack data.
        desc - description of the pack within the DFS.
    • Method Detail

      • getPackDescription

        public DfsPackDescription getPackDescription()
        Get description that was originally used to configure this pack file.
        Returns:
        description that was originally used to configure this pack file.
      • isIndexLoaded

        public boolean isIndexLoaded()
        Whether the pack index file is loaded and cached in memory.
        Returns:
        whether the pack index file is loaded and cached in memory.
      • setPackIndex

        void setPackIndex​(PackIndex idx)
      • getPackIndex

        public PackIndex getPackIndex​(DfsReader ctx)
                               throws java.io.IOException
        Get the PackIndex for this PackFile.
        Parameters:
        ctx - reader context to support reading from the backing store if the index is not already loaded in memory.
        Returns:
        the PackIndex.
        Throws:
        java.io.IOException - the pack index is not available, or is corrupt.
      • idx

        private PackIndex idx​(DfsReader ctx)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • isGarbage

        final boolean isGarbage()
      • getBitmapIndex

        PackBitmapIndex getBitmapIndex​(DfsReader ctx)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • hasObject

        public boolean hasObject​(DfsReader ctx,
                                 AnyObjectId id)
                          throws java.io.IOException
        Check if an object is stored within this pack.
        Parameters:
        ctx - reader context to support reading from the backing store if the index is not already loaded in memory.
        id - object to be located.
        Returns:
        true if the object exists in this pack; false if it does not.
        Throws:
        java.io.IOException - the pack index is not available, or is corrupt.
      • get

        ObjectLoader get​(DfsReader ctx,
                         AnyObjectId id)
                  throws java.io.IOException
        Get an object from this pack.
        Parameters:
        ctx - temporary working space associated with the calling thread.
        id - the object to obtain from the pack. Must not be null.
        Returns:
        the object loader for the requested object if it is contained in this pack; null if the object was not found.
        Throws:
        java.io.IOException - the pack file or the index could not be read.
      • findOffset

        long findOffset​(DfsReader ctx,
                        AnyObjectId id)
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • getObjectCount

        long getObjectCount​(DfsReader ctx)
                     throws java.io.IOException
        Obtain the total number of objects available in this pack. This method relies on pack index, giving number of effectively available objects.
        Parameters:
        ctx - current reader for the calling thread.
        Returns:
        number of objects in index of this pack, likewise in this pack
        Throws:
        java.io.IOException - the index file cannot be loaded into memory.
      • decompress

        private byte[] decompress​(long position,
                                  int sz,
                                  DfsReader ctx)
                           throws java.io.IOException,
                                  java.util.zip.DataFormatException
        Throws:
        java.io.IOException
        java.util.zip.DataFormatException
      • copyPackAsIs

        void copyPackAsIs​(PackOutputStream out,
                          DfsReader ctx)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • copyPackBypassCache

        private long copyPackBypassCache​(PackOutputStream out,
                                         ReadableChannel rc)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • packfileIsTruncated

        private java.io.IOException packfileIsTruncated()
      • readFully

        private void readFully​(long position,
                               byte[] dstbuf,
                               int dstoff,
                               int cnt,
                               DfsReader ctx)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • load

        ObjectLoader load​(DfsReader ctx,
                          long pos)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getDeltaHeader

        byte[] getDeltaHeader​(DfsReader wc,
                              long pos)
                       throws java.io.IOException,
                              java.util.zip.DataFormatException
        Throws:
        java.io.IOException
        java.util.zip.DataFormatException
      • getObjectType

        int getObjectType​(DfsReader ctx,
                          long pos)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getObjectSize

        long getObjectSize​(DfsReader ctx,
                           AnyObjectId id)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • getObjectSize

        long getObjectSize​(DfsReader ctx,
                           long pos)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • isCorrupt

        boolean isCorrupt​(long offset)
      • setCorrupt

        private void setCorrupt​(long offset)