Class ObjectDirectory
- 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class(package private) static classNested classes/interfaces inherited from class org.eclipse.jgit.internal.storage.file.FileObjectDatabase
FileObjectDatabase.InsertLooseObjectResult -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicReference<ObjectDirectory.AlternateHandle[]>private final Fileprivate final Configprivate final FSprivate final ObjectDirectory.AlternateHandleprivate final Fileprivate final LooseObjectsprivate final Fileprivate final PackDirectoryprivate final PackDirectoryprivate static final intMaximum number of candidates offered as resolutions of abbreviation.private final Fileprivate FileSnapshot -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) Set<ObjectDirectory.AlternateHandle.Id>voidclose()Close any resources held by this database.(package private) voidcloseAllPackHandles(File packFile) 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.(package private) ObjectDirectory.AlternateHandle.IdlongGet a quick, rough count of objects in this repository.(package private) Configfinal File(package private) FSgetFS()private longgetLooseSizeFromSelfOrAlternate(WindowCursor curs, AnyObjectId id, Set<ObjectDirectory.AlternateHandle.Id> skips) (package private) longgetObjectSize(WindowCursor curs, AnyObjectId id) private longfinal FileGetter for the fieldpackDirectory.private longgetPackedSizeFromSelfOrAlternate(WindowCursor curs, AnyObjectId id, Set<ObjectDirectory.AlternateHandle.Id> skips) getPacks()final FileGetter for the fieldpreservedDirectory.booleanhas(AnyObjectId objectId) Does the requested object exist in this database?private booleanhasLooseInSelfOrAlternate(AnyObjectId objectId, Set<ObjectDirectory.AlternateHandle.Id> skips) private booleanhasPackedInSelfOrAlternate(AnyObjectId objectId, Set<ObjectDirectory.AlternateHandle.Id> skips) (package private) booleanhasPackedObject(AnyObjectId objectId) private booleanhasPackedOrLooseInSelfOrAlternate(AnyObjectId objectId) (package private) FileObjectDatabase.InsertLooseObjectResultinsertUnpackedObject(File tmp, ObjectId id, boolean createDuplicate) private ObjectDirectory.AlternateHandle[](package private) ObjectDirectory.AlternateHandle[]Create a new cached database instance over this database.(package private) CachedObjectDirectoryCreate a newObjectInserterto insert new objects.Create a new inserter that inserts all objects as pack files, not loose objects.private static BufferedReaderprivate ObjectDirectory.AlternateHandleopenAlternate(File objdir) private ObjectDirectory.AlternateHandleopenAlternate(String location) private ObjectLoaderopenLooseFromSelfOrAlternate(WindowCursor curs, AnyObjectId objectId, Set<ObjectDirectory.AlternateHandle.Id> skips) (package private) ObjectLoaderopenLooseObject(WindowCursor curs, AnyObjectId id) (package private) ObjectLoaderopenObject(WindowCursor curs, AnyObjectId objectId) private ObjectLoaderopenObjectWithoutRestoring(WindowCursor curs, AnyObjectId objectId) private ObjectLoaderopenPackedFromSelfOrAlternate(WindowCursor curs, AnyObjectId objectId, Set<ObjectDirectory.AlternateHandle.Id> skips) (package private) ObjectLoaderopenPackedObject(WindowCursor curs, AnyObjectId objectId) (package private) voidresolve(Set<ObjectId> matches, AbbreviatedObjectId id) private voidresolve(Set<ObjectId> matches, AbbreviatedObjectId id, Set<ObjectDirectory.AlternateHandle.Id> skips) private booleanprivate booleanrestoreFromSelf(AnyObjectId objectId) private booleanrestoreFromSelfOrAlternate(AnyObjectId objectId, Set<ObjectDirectory.AlternateHandle.Id> skips) (package private) voidselectObjectRepresentation(PackWriter packer, ObjectToPack otp, WindowCursor curs) private voidselectObjectRepresentation(PackWriter packer, ObjectToPack otp, WindowCursor curs, Set<ObjectDirectory.AlternateHandle.Id> skips) toString()Methods inherited from class org.eclipse.jgit.internal.storage.file.FileObjectDatabase
newReaderMethods inherited from class org.eclipse.jgit.lib.ObjectDatabase
open, open
-
Field Details
-
RESOLVE_ABBREV_LIMIT
private static final int RESOLVE_ABBREV_LIMITMaximum number of candidates offered as resolutions of abbreviation.- See Also:
-
handle
-
config
-
objects
-
infoDirectory
-
loose
-
packed
-
preserved
-
alternatesFile
-
fs
-
alternates
-
shallowFile
-
shallowFileSnapshot
-
shallowCommitsIds
-
-
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
- Specified by:
getDirectoryin classFileObjectDatabase
-
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()Does 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
Initialize a new object database at this location.- Overrides:
createin classObjectDatabase- Throws:
IOException- the database could not be created.
-
newInserter
Create 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.- Overrides:
newInserterin classFileObjectDatabase- 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()Close any resources held by this database.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein classObjectDatabase
-
getPacks
- Specified by:
getPacksin classFileObjectDatabase
-
getApproximateObjectCount
public long getApproximateObjectCount()Get 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
-
openPack
Add a single existing pack to the list of available pack files.
- Specified by:
openPackin classFileObjectDatabase- Throws:
IOException
-
toString
-
has
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.- 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.
-
hasPackedOrLooseInSelfOrAlternate
-
hasPackedInSelfOrAlternate
private boolean hasPackedInSelfOrAlternate(AnyObjectId objectId, Set<ObjectDirectory.AlternateHandle.Id> skips) -
hasLooseInSelfOrAlternate
private boolean hasLooseInSelfOrAlternate(AnyObjectId objectId, Set<ObjectDirectory.AlternateHandle.Id> skips) -
hasPackedObject
-
resolve
- Specified by:
resolvein classFileObjectDatabase- Throws:
IOException
-
resolve
private void resolve(Set<ObjectId> matches, AbbreviatedObjectId id, Set<ObjectDirectory.AlternateHandle.Id> skips) throws IOException - Throws:
IOException
-
openObject
- Specified by:
openObjectin classFileObjectDatabase- Throws:
IOException
-
openObjectWithoutRestoring
private ObjectLoader openObjectWithoutRestoring(WindowCursor curs, AnyObjectId objectId) throws IOException - Throws:
IOException
-
openPackedFromSelfOrAlternate
private ObjectLoader openPackedFromSelfOrAlternate(WindowCursor curs, AnyObjectId objectId, Set<ObjectDirectory.AlternateHandle.Id> skips) -
openLooseFromSelfOrAlternate
private ObjectLoader openLooseFromSelfOrAlternate(WindowCursor curs, AnyObjectId objectId, Set<ObjectDirectory.AlternateHandle.Id> skips) throws IOException - Throws:
IOException
-
openPackedObject
-
openLooseObject
- Specified by:
openLooseObjectin classFileObjectDatabase- Throws:
IOException
-
getObjectSize
- Specified by:
getObjectSizein classFileObjectDatabase- Throws:
IOException
-
getObjectSizeWithoutRestoring
- Throws:
IOException
-
getPackedSizeFromSelfOrAlternate
private long getPackedSizeFromSelfOrAlternate(WindowCursor curs, AnyObjectId id, Set<ObjectDirectory.AlternateHandle.Id> skips) -
getLooseSizeFromSelfOrAlternate
private long getLooseSizeFromSelfOrAlternate(WindowCursor curs, AnyObjectId id, Set<ObjectDirectory.AlternateHandle.Id> skips) throws IOException - Throws:
IOException
-
selectObjectRepresentation
void selectObjectRepresentation(PackWriter packer, ObjectToPack otp, WindowCursor curs) throws IOException - Specified by:
selectObjectRepresentationin classFileObjectDatabase- Throws:
IOException
-
selectObjectRepresentation
private void selectObjectRepresentation(PackWriter packer, ObjectToPack otp, WindowCursor curs, Set<ObjectDirectory.AlternateHandle.Id> skips) throws IOException - Throws:
IOException
-
restoreFromSelfOrAlternate
private boolean restoreFromSelfOrAlternate(AnyObjectId objectId, Set<ObjectDirectory.AlternateHandle.Id> skips) -
restoreFromSelf
-
restore
-
insertUnpackedObject
FileObjectDatabase.InsertLooseObjectResult insertUnpackedObject(File tmp, ObjectId id, boolean createDuplicate) throws IOException - Specified by:
insertUnpackedObjectin classFileObjectDatabase- Throws:
IOException
-
getConfig
Config getConfig()- Specified by:
getConfigin classFileObjectDatabase
-
getFS
FS getFS()- Specified by:
getFSin classFileObjectDatabase
-
getShallowCommits
- Specified by:
getShallowCommitsin classFileObjectDatabase- Throws:
IOException
-
closeAllPackHandles
-
myAlternates
ObjectDirectory.AlternateHandle[] myAlternates() -
addMe
-
loadAlternates
- Throws:
IOException
-
open
- Throws:
IOExceptionFileNotFoundException
-
openAlternate
- Throws:
IOException
-
openAlternate
- Throws:
IOException
-
fileFor
Compute the location of a loose object file.- Specified by:
fileForin classFileObjectDatabase
-
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.- Overrides:
newCachedDatabasein classObjectDatabase- Returns:
- new cached database instance
-
newCachedFileObjectDatabase
CachedObjectDirectory newCachedFileObjectDatabase() -
getAlternateId
ObjectDirectory.AlternateHandle.Id getAlternateId()
-