Class ObjectDirectory
- java.lang.Object
-
- org.eclipse.jgit.lib.ObjectDatabase
-
- org.eclipse.jgit.internal.storage.file.FileObjectDatabase
-
- org.eclipse.jgit.internal.storage.file.ObjectDirectory
-
public class ObjectDirectory extends FileObjectDatabase
Traditional file system basedObjectDatabase.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 asPackFiles.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 Classes Modifier and Type Class Description (package private) static classObjectDirectory.AlternateHandle(package private) static classObjectDirectory.AlternateRepository(package private) static classObjectDirectory.PackList-
Nested classes/interfaces inherited from class org.eclipse.jgit.internal.storage.file.FileObjectDatabase
FileObjectDatabase.InsertLooseObjectResult
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicReference<ObjectDirectory.AlternateHandle[]>alternatesprivate java.io.FilealternatesFileprivate Configconfigprivate FSfsprivate ObjectDirectory.AlternateHandlehandleprivate java.io.FileinfoDirectoryprivate static org.slf4j.LoggerLOGprivate static ObjectDirectory.PackListNO_PACKSprivate java.io.Fileobjectsprivate java.io.FilepackDirectory(package private) java.util.concurrent.atomic.AtomicReference<ObjectDirectory.PackList>packListprivate java.io.FilepreservedDirectoryprivate static intRESOLVE_ABBREV_LIMITMaximum number of candidates offered as resolutions of abbreviation.private java.util.Set<ObjectId>shallowCommitsIdsprivate java.io.FileshallowFileprivate FileSnapshotshallowFileSnapshotprivate UnpackedObjectCacheunpackedObjectCache
-
Constructor Summary
Constructors Constructor Description ObjectDirectory(Config cfg, java.io.File dir, java.io.File[] alternatePaths, FS fs, java.io.File shallowFile)Initialize a reference to an on-disk object directory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.util.Set<ObjectDirectory.AlternateHandle.Id>addMe(java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)voidclose()Close any resources held by this database.(package private) voidcloseAllPackHandles(java.io.File packFile)voidcreate()Initialize a new object database at this location.private booleandoLogExponentialBackoff(int n)booleanexists()Does this database exist yet?java.io.FilefileFor(AnyObjectId objectId)(package private) ObjectDirectory.AlternateHandle.IdgetAlternateId()(package private) ConfiggetConfig()java.io.FilegetDirectory()(package private) FSgetFS()private longgetLooseObjectSize(WindowCursor curs, AnyObjectId id)private longgetLooseSizeFromSelfOrAlternate(WindowCursor curs, AnyObjectId id, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)(package private) longgetObjectSize(WindowCursor curs, AnyObjectId id)java.io.FilegetPackDirectory()Getter for the fieldpackDirectory.private longgetPackedObjectSize(WindowCursor curs, AnyObjectId id)private longgetPackedSizeFromSelfOrAlternate(WindowCursor curs, AnyObjectId id, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)java.util.Collection<PackFile>getPacks()java.io.FilegetPreservedDirectory()Getter for the fieldpreservedDirectory.(package private) java.util.Set<ObjectId>getShallowCommits()private voidhandlePackError(java.io.IOException e, PackFile p)booleanhas(AnyObjectId objectId)Does the requested object exist in this database?private booleanhasLooseInSelfOrAlternate(AnyObjectId objectId, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)private booleanhasPackedInSelfOrAlternate(AnyObjectId objectId, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)(package private) booleanhasPackedObject(AnyObjectId objectId)private static intindexOf(PackFile[] list, PackFile pack)private voidinsertPack(PackFile pf)(package private) FileObjectDatabase.InsertLooseObjectResultinsertUnpackedObject(java.io.File tmp, ObjectId id, boolean createDuplicate)private java.util.Set<java.lang.String>listPackDirectory()private ObjectDirectory.AlternateHandle[]loadAlternates()(package private) ObjectDirectory.AlternateHandle[]myAlternates()ObjectDatabasenewCachedDatabase()Create a new cached database instance over this database.(package private) CachedObjectDirectorynewCachedFileObjectDatabase()ObjectDirectoryInserternewInserter()Create a newObjectInserterto insert new objects.PackInserternewPackInserter()Create a new inserter that inserts all objects as pack files, not loose objects.private static java.io.BufferedReaderopen(java.io.File f)private ObjectDirectory.AlternateHandleopenAlternate(java.io.File objdir)private ObjectDirectory.AlternateHandleopenAlternate(java.lang.String location)private ObjectLoaderopenLooseFromSelfOrAlternate(WindowCursor curs, AnyObjectId objectId, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)(package private) ObjectLoaderopenLooseObject(WindowCursor curs, AnyObjectId id)(package private) ObjectLoaderopenObject(WindowCursor curs, AnyObjectId objectId)PackFileopenPack(java.io.File pack)private ObjectLoaderopenPackedFromSelfOrAlternate(WindowCursor curs, AnyObjectId objectId, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)(package private) ObjectLoaderopenPackedObject(WindowCursor curs, AnyObjectId objectId)private voidremovePack(PackFile deadPack)(package private) voidresolve(java.util.Set<ObjectId> matches, AbbreviatedObjectId id)private voidresolve(java.util.Set<ObjectId> matches, AbbreviatedObjectId id, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)private static java.util.Map<java.lang.String,PackFile>reuseMap(ObjectDirectory.PackList old)private ObjectDirectory.PackListscanPacks(ObjectDirectory.PackList original)private ObjectDirectory.PackListscanPacksImpl(ObjectDirectory.PackList old)(package private) booleansearchPacksAgain(ObjectDirectory.PackList old)(package private) voidselectObjectRepresentation(PackWriter packer, ObjectToPack otp, WindowCursor curs)private voidselectObjectRepresentation(PackWriter packer, ObjectToPack otp, WindowCursor curs, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)java.lang.StringtoString()private FileObjectDatabase.InsertLooseObjectResulttryMove(java.io.File tmp, java.io.File dst, ObjectId id)-
Methods inherited from class org.eclipse.jgit.internal.storage.file.FileObjectDatabase
newReader
-
Methods inherited from class org.eclipse.jgit.lib.ObjectDatabase
open, open
-
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
NO_PACKS
private static final ObjectDirectory.PackList NO_PACKS
-
RESOLVE_ABBREV_LIMIT
private static final int RESOLVE_ABBREV_LIMIT
Maximum number of candidates offered as resolutions of abbreviation.- See Also:
- Constant Field Values
-
handle
private final ObjectDirectory.AlternateHandle handle
-
config
private final Config config
-
objects
private final java.io.File objects
-
infoDirectory
private final java.io.File infoDirectory
-
packDirectory
private final java.io.File packDirectory
-
preservedDirectory
private final java.io.File preservedDirectory
-
alternatesFile
private final java.io.File alternatesFile
-
fs
private final FS fs
-
alternates
private final java.util.concurrent.atomic.AtomicReference<ObjectDirectory.AlternateHandle[]> alternates
-
unpackedObjectCache
private final UnpackedObjectCache unpackedObjectCache
-
shallowFile
private final java.io.File shallowFile
-
shallowFileSnapshot
private FileSnapshot shallowFileSnapshot
-
shallowCommitsIds
private java.util.Set<ObjectId> shallowCommitsIds
-
packList
final java.util.concurrent.atomic.AtomicReference<ObjectDirectory.PackList> packList
-
-
Constructor Detail
-
ObjectDirectory
public ObjectDirectory(Config cfg, java.io.File dir, java.io.File[] alternatePaths, FS fs, java.io.File shallowFile) throws java.io.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:
java.io.IOException- an alternate object cannot be opened.
-
-
Method Detail
-
getDirectory
public final java.io.File getDirectory()
- Specified by:
getDirectoryin classFileObjectDatabase
-
getPackDirectory
public final java.io.File getPackDirectory()
Getter for the field
packDirectory.- Returns:
- the location of the
packdirectory.
-
getPreservedDirectory
public final java.io.File 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
public void create() throws java.io.IOExceptionInitialize a new object database at this location.- Overrides:
createin classObjectDatabase- Throws:
java.io.IOException- the database could not be created.
-
newInserter
public ObjectDirectoryInserter 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
public PackInserter 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 classObjectDatabase
-
getPacks
public java.util.Collection<PackFile> getPacks()
- Specified by:
getPacksin classFileObjectDatabase
-
openPack
public PackFile openPack(java.io.File pack) throws java.io.IOException
Add a single existing pack to the list of available pack files.
- Specified by:
openPackin classFileObjectDatabase- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
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.- 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.
-
hasPackedInSelfOrAlternate
private boolean hasPackedInSelfOrAlternate(AnyObjectId objectId, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)
-
hasLooseInSelfOrAlternate
private boolean hasLooseInSelfOrAlternate(AnyObjectId objectId, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)
-
hasPackedObject
boolean hasPackedObject(AnyObjectId objectId)
-
resolve
void resolve(java.util.Set<ObjectId> matches, AbbreviatedObjectId id) throws java.io.IOException
- Specified by:
resolvein classFileObjectDatabase- Throws:
java.io.IOException
-
resolve
private void resolve(java.util.Set<ObjectId> matches, AbbreviatedObjectId id, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) throws java.io.IOException
- Throws:
java.io.IOException
-
openObject
ObjectLoader openObject(WindowCursor curs, AnyObjectId objectId) throws java.io.IOException
- Specified by:
openObjectin classFileObjectDatabase- Throws:
java.io.IOException
-
openPackedFromSelfOrAlternate
private ObjectLoader openPackedFromSelfOrAlternate(WindowCursor curs, AnyObjectId objectId, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)
-
openLooseFromSelfOrAlternate
private ObjectLoader openLooseFromSelfOrAlternate(WindowCursor curs, AnyObjectId objectId, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) throws java.io.IOException
- Throws:
java.io.IOException
-
openPackedObject
ObjectLoader openPackedObject(WindowCursor curs, AnyObjectId objectId)
-
openLooseObject
ObjectLoader openLooseObject(WindowCursor curs, AnyObjectId id) throws java.io.IOException
- Specified by:
openLooseObjectin classFileObjectDatabase- Throws:
java.io.IOException
-
getObjectSize
long getObjectSize(WindowCursor curs, AnyObjectId id) throws java.io.IOException
- Specified by:
getObjectSizein classFileObjectDatabase- Throws:
java.io.IOException
-
getPackedSizeFromSelfOrAlternate
private long getPackedSizeFromSelfOrAlternate(WindowCursor curs, AnyObjectId id, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)
-
getLooseSizeFromSelfOrAlternate
private long getLooseSizeFromSelfOrAlternate(WindowCursor curs, AnyObjectId id, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) throws java.io.IOException
- Throws:
java.io.IOException
-
getPackedObjectSize
private long getPackedObjectSize(WindowCursor curs, AnyObjectId id)
-
getLooseObjectSize
private long getLooseObjectSize(WindowCursor curs, AnyObjectId id) throws java.io.IOException
- Throws:
java.io.IOException
-
selectObjectRepresentation
void selectObjectRepresentation(PackWriter packer, ObjectToPack otp, WindowCursor curs) throws java.io.IOException
- Specified by:
selectObjectRepresentationin classFileObjectDatabase- Throws:
java.io.IOException
-
selectObjectRepresentation
private void selectObjectRepresentation(PackWriter packer, ObjectToPack otp, WindowCursor curs, java.util.Set<ObjectDirectory.AlternateHandle.Id> skips) throws java.io.IOException
- Throws:
java.io.IOException
-
handlePackError
private void handlePackError(java.io.IOException e, PackFile p)
-
doLogExponentialBackoff
private boolean doLogExponentialBackoff(int n)
- Parameters:
n- count of consecutive failures- Returns:
-
insertUnpackedObject
FileObjectDatabase.InsertLooseObjectResult insertUnpackedObject(java.io.File tmp, ObjectId id, boolean createDuplicate) throws java.io.IOException
- Specified by:
insertUnpackedObjectin classFileObjectDatabase- Throws:
java.io.IOException
-
tryMove
private FileObjectDatabase.InsertLooseObjectResult tryMove(java.io.File tmp, java.io.File dst, ObjectId id) throws java.io.IOException
- Throws:
java.io.IOException
-
searchPacksAgain
boolean searchPacksAgain(ObjectDirectory.PackList old)
-
getConfig
Config getConfig()
- Specified by:
getConfigin classFileObjectDatabase
-
getFS
FS getFS()
- Specified by:
getFSin classFileObjectDatabase
-
getShallowCommits
java.util.Set<ObjectId> getShallowCommits() throws java.io.IOException
- Specified by:
getShallowCommitsin classFileObjectDatabase- Throws:
java.io.IOException
-
insertPack
private void insertPack(PackFile pf)
-
removePack
private void removePack(PackFile deadPack)
-
scanPacks
private ObjectDirectory.PackList scanPacks(ObjectDirectory.PackList original)
-
scanPacksImpl
private ObjectDirectory.PackList scanPacksImpl(ObjectDirectory.PackList old)
-
reuseMap
private static java.util.Map<java.lang.String,PackFile> reuseMap(ObjectDirectory.PackList old)
-
listPackDirectory
private java.util.Set<java.lang.String> listPackDirectory()
-
closeAllPackHandles
void closeAllPackHandles(java.io.File packFile)
-
myAlternates
ObjectDirectory.AlternateHandle[] myAlternates()
-
addMe
java.util.Set<ObjectDirectory.AlternateHandle.Id> addMe(java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)
-
loadAlternates
private ObjectDirectory.AlternateHandle[] loadAlternates() throws java.io.IOException
- Throws:
java.io.IOException
-
open
private static java.io.BufferedReader open(java.io.File f) throws java.io.IOException, java.io.FileNotFoundException- Throws:
java.io.IOExceptionjava.io.FileNotFoundException
-
openAlternate
private ObjectDirectory.AlternateHandle openAlternate(java.lang.String location) throws java.io.IOException
- Throws:
java.io.IOException
-
openAlternate
private ObjectDirectory.AlternateHandle openAlternate(java.io.File objdir) throws java.io.IOException
- Throws:
java.io.IOException
-
fileFor
public java.io.File fileFor(AnyObjectId objectId)
Compute the location of a loose object file.
- Specified by:
fileForin classFileObjectDatabase
-
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.- Overrides:
newCachedDatabasein classObjectDatabase- Returns:
- new cached database instance
-
newCachedFileObjectDatabase
CachedObjectDirectory newCachedFileObjectDatabase()
-
getAlternateId
ObjectDirectory.AlternateHandle.Id getAlternateId()
-
-