Class ObjectDirectory

  • All Implemented Interfaces:

    public class ObjectDirectory
    extends ObjectDatabase
    Traditional file system based ObjectDatabase.

    This is the classical object database representation for a Git repository, where objects are stored loose by hashing them into directories by their ObjectId, or are stored in compressed containers known as Packs.

    Optionally an object database can reference one or more alternates; other ObjectDatabase instances that are searched in addition to the current database.

    Databases are divided into two halves: a half that is considered to be fast to search (the PackFiles), and a half that is considered to be slow to search (loose objects). When alternates are present the fast half is fully searched (recursively through all alternates) before the slow half is considered.

    • Constructor Detail

      • ObjectDirectory

        public ObjectDirectory​(Config cfg,
                               File dir,
                               File[] alternatePaths,
                               FS fs,
                               File shallowFile)
                        throws IOException
        Initialize a reference to an on-disk object directory.
        cfg - configuration this directory consults for write settings.
        dir - the location of the objects directory.
        alternatePaths - a list of alternate object directories
        fs - the file system abstraction which will be necessary to perform certain file system operations.
        shallowFile - file which contains IDs of shallow commits, null if shallow commits handling should be turned off
        IOException - an alternate object cannot be opened.
    • Method Detail

      • getDirectory

        public final File getDirectory()
      • getPackDirectory

        public final File getPackDirectory()

        Getter for the field packDirectory.

        the location of the pack directory.
      • getPreservedDirectory

        public final File getPreservedDirectory()

        Getter for the field preservedDirectory.

        the location of the preserved directory.
      • exists

        public boolean exists()
        Does this database exist yet?
        exists in class ObjectDatabase
        true if this database is already created; false if the caller should invoke ObjectDatabase.create() to create this database location.
      • newInserter

        public newInserter()
        Create a new ObjectInserter to insert new objects.

        The returned inserter is not itself thread-safe, but multiple concurrent inserter instances created from the same ObjectDatabase must be thread-safe.

        writer the caller can use to create objects in this database.
      • newPackInserter

        public PackInserter newPackInserter()
        Create a new inserter that inserts all objects as pack files, not loose objects.
        new inserter.
      • getApproximateObjectCount

        public long getApproximateObjectCount()
        Get a quick, rough count of objects in this repository. Ignores loose objects. Returns -1 if an exception occurs.
        Specified by:
        getApproximateObjectCount in class ObjectDatabase
        quick, rough count of objects in this repository, -1 if an exception occurs
      • openPack

        public Pack openPack​(File pack)
                      throws IOException

        Add a single existing pack to the list of available pack files.

      • has

        public boolean has​(AnyObjectId objectId)
        Does the requested object exist in this database?

        This is a one-shot call interface which may be faster than allocating a ObjectDatabase.newReader() to perform the lookup.

        has in class ObjectDatabase
        objectId - identity of the object to test for existence of.
        true if the specified object is stored in this database.
      • fileFor

        public File fileFor​(AnyObjectId objectId)
        Compute the location of a loose object file.
      • newCachedDatabase

        public ObjectDatabase newCachedDatabase()
        Create a new cached database instance over this database. This instance might optimize queries by caching some information about database. So some modifications done after instance creation might fail to be noticed.
        newCachedDatabase in class ObjectDatabase
        new cached database instance
      • newReader

        public ObjectReader newReader()
        Create a new ObjectReader to read existing objects.

        The returned reader is not itself thread-safe, but multiple concurrent reader instances created from the same ObjectDatabase must be thread-safe.

        Specified by:
        newReader in class ObjectDatabase
        reader the caller can use to load objects from this database.