- All Implemented Interfaces:
AutoCloseable
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close any resources held by this database.voidcreate()Initialize a new object database at this location.booleanexists()Does this database exist yet?fileFor(AnyObjectId objectId) Compute the location of a loose object file.longGet a quick, rough count of objects in this repository.final Filefinal FileGetter for the fieldpackDirectory.getPacks()final FileGetter for the fieldpreservedDirectory.Get the shallow commits of the current repositorybooleanhas(AnyObjectId objectId) Does the requested object exist in this database?Create a new cached database instance over this database.org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserterCreate a newObjectInserterto insert new objects.Create a new inserter that inserts all objects as pack files, not loose objects.Create a newObjectReaderto read existing objects.Add a single existing pack to the list of available pack files.voidsetShallowCommits(Set<ObjectId> shallowCommits) Update the shallow commits of the current repositorytoString()Methods inherited from class org.eclipse.jgit.lib.ObjectDatabase
open, open
-
Constructor Details
-
ObjectDirectory
public ObjectDirectory(Config cfg, File dir, File[] alternatePaths, FS fs, File shallowFile) throws IOException Initialize a reference to an on-disk object directory.- Parameters:
cfg- configuration this directory consults for write settings.dir- the location of theobjectsdirectory.alternatePaths- a list of alternate object directoriesfs- 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- Throws:
IOException- an alternate object cannot be opened.
-
-
Method Details
-
getDirectory
-
getPackDirectory
Getter for the field
packDirectory.- Returns:
- the location of the
packdirectory.
-
getPreservedDirectory
Getter for the field
preservedDirectory.- Returns:
- the location of the
preserveddirectory.
-
exists
public boolean exists()Description copied from class:ObjectDatabaseDoes this database exist yet?- Overrides:
existsin classObjectDatabase- Returns:
- true if this database is already created; false if the caller
should invoke
ObjectDatabase.create()to create this database location.
-
create
Description copied from class:ObjectDatabaseInitialize a new object database at this location.- Overrides:
createin classObjectDatabase- Throws:
IOException- the database could not be created.
-
newInserter
public org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter newInserter()Description copied from class:ObjectDatabaseCreate a newObjectInserterto insert new objects.The returned inserter is not itself thread-safe, but multiple concurrent inserter instances created from the same
ObjectDatabasemust be thread-safe.- Returns:
- writer the caller can use to create objects in this database.
-
newPackInserter
Create a new inserter that inserts all objects as pack files, not loose objects.- Returns:
- new inserter.
-
close
public void close()Description copied from class:ObjectDatabaseClose any resources held by this database.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein classObjectDatabase
-
getPacks
-
getApproximateObjectCount
public long getApproximateObjectCount()Description copied from class:ObjectDatabaseGet a quick, rough count of objects in this repository. Ignores loose objects. Returns-1if an exception occurs.- Specified by:
getApproximateObjectCountin classObjectDatabase- Returns:
- quick, rough count of objects in this repository,
-1if an exception occurs
-
getCommitGraph
-
openPack
Add a single existing pack to the list of available pack files.
- Throws:
IOException
-
toString
-
has
Description copied from class:ObjectDatabaseDoes 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.- Overrides:
hasin classObjectDatabase- Parameters:
objectId- identity of the object to test for existence of.- Returns:
- true if the specified object is stored in this database.
-
getShallowCommits
Description copied from class:ObjectDatabaseGet the shallow commits of the current repository- Overrides:
getShallowCommitsin classObjectDatabase- Returns:
- the shallow commits of the current repository
- Throws:
IOException- the database could not be read
-
setShallowCommits
Description copied from class:ObjectDatabaseUpdate the shallow commits of the current repository- Overrides:
setShallowCommitsin classObjectDatabase- Parameters:
shallowCommits- the new shallow commits- Throws:
IOException- the database could not be updated
-
fileFor
Compute the location of a loose object file. -
newCachedDatabase
Description copied from class:ObjectDatabaseCreate 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.- Overrides:
newCachedDatabasein classObjectDatabase- Returns:
- new cached database instance
-
newReader
Description copied from class:ObjectDatabaseCreate a newObjectReaderto read existing objects.The returned reader is not itself thread-safe, but multiple concurrent reader instances created from the same
ObjectDatabasemust be thread-safe.- Specified by:
newReaderin classObjectDatabase- Returns:
- reader the caller can use to load objects from this database.
-