Class PackDirectory


  • class PackDirectory
    extends java.lang.Object
    Traditional file system packed objects directory handler.

    This is the Packs object representation for a Git object database, where objects are stored in compressed containers known as Packs.

    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
      • config

        private final Config config
      • directory

        private final java.io.File directory
    • Constructor Detail

      • PackDirectory

        PackDirectory​(Config config,
                      java.io.File directory)
        Initialize a reference to an on-disk 'pack' directory.
        Parameters:
        config - configuration this directory consults for write settings.
        directory - the location of the pack directory.
    • Method Detail

      • getDirectory

        java.io.File getDirectory()
        Getter for the field directory.
        Returns:
        the location of the pack directory.
      • create

        void create()
             throws java.io.IOException
        Throws:
        java.io.IOException
      • close

        void close()
      • getPacks

        java.util.Collection<Pack> getPacks()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • has

        boolean has​(AnyObjectId objectId)
        Does the requested object exist in this PackDirectory?
        Parameters:
        objectId - identity of the object to test for existence of.
        Returns:
        true if the specified object is stored in this PackDirectory.
      • getPack

        @Nullable
        Pack getPack​(AnyObjectId objectId)
        Get the Pack for the specified object if it is stored in this PackDirectory.
        Parameters:
        objectId - identity of the object to find the Pack for.
        Returns:
        Pack which contains the specified object or null if it is not stored in this PackDirectory.
      • resolve

        boolean resolve​(java.util.Set<ObjectId> matches,
                        AbbreviatedObjectId id,
                        int matchLimit)
        Find objects matching the prefix abbreviation.
        Parameters:
        matches - set to add any located ObjectIds to. This is an output parameter.
        id - prefix to search for.
        matchLimit - maximum number of results to return. At most this many ObjectIds should be added to matches before returning.
        Returns:
        true if the matches were exhausted before reaching maxLimit.
      • handlePackError

        private void handlePackError​(java.io.IOException e,
                                     Pack p)
      • doLogExponentialBackoff

        private boolean doLogExponentialBackoff​(int n)
        Parameters:
        n - count of consecutive failures
        Returns:
      • insert

        void insert​(Pack pack)
      • remove

        private void remove​(Pack deadPack)
      • indexOf

        private static int indexOf​(Pack[] list,
                                   Pack pack)
      • getPackFilesByExtById

        private java.util.Map<java.lang.String,​java.util.Map<PackExt,​PackFile>> getPackFilesByExtById()
        Scans the pack directory for PackFiles and returns them organized by their extensions and their pack ids Skips files in the directory that we cannot create a PackFile for.
        Returns:
        a map of PackFiles and PackExts keyed by pack ids