org.eclipse.jgit.storage.file
Class ObjectDirectory

java.lang.Object
  extended by org.eclipse.jgit.lib.ObjectDatabase
      extended by org.eclipse.jgit.storage.file.ObjectDirectory

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 PackFiles.

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
ObjectDirectory(Config cfg, File dir, File[] alternatePaths, FS fs)
          Initialize a reference to an on-disk object directory.
 
Method Summary
 void close()
          Close any resources held by this database.
 void create()
          Initialize a new object database at this location.
 boolean exists()
          Does this database exist yet?
 File fileFor(AnyObjectId objectId)
          Compute the location of a loose object file.
 File getDirectory()
           
 Collection<PackFile> getPacks()
           
 boolean has(AnyObjectId objectId)
          Does the requested object exist in this database?
 ObjectDatabase newCachedDatabase()
          Create a new cached database instance over this database.
 org.eclipse.jgit.storage.file.ObjectDirectoryInserter newInserter()
          Create a new ObjectInserter to insert new objects.
 ObjectReader newReader()
          Create a new ObjectReader to read existing objects.
 PackFile openPack(File pack, File idx)
          Add a single existing pack to the list of available pack files.
 String toString()
           
 
Methods inherited from class org.eclipse.jgit.lib.ObjectDatabase
open, open
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectDirectory

public ObjectDirectory(Config cfg,
                       File dir,
                       File[] alternatePaths,
                       FS fs)
                throws IOException
Initialize a reference to an on-disk object directory.

Parameters:
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.
Throws:
IOException - an alternate object cannot be opened.
Method Detail

getDirectory

public final File getDirectory()
Returns:
the location of the objects directory.

exists

public boolean exists()
Description copied from class: ObjectDatabase
Does this database exist yet?

Overrides:
exists in class ObjectDatabase
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 IOException
Description copied from class: ObjectDatabase
Initialize a new object database at this location.

Overrides:
create in class ObjectDatabase
Throws:
IOException - the database could not be created.

newInserter

public org.eclipse.jgit.storage.file.ObjectDirectoryInserter newInserter()
Description copied from class: ObjectDatabase
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.

Returns:
writer the caller can use to create objects in this database.

close

public void close()
Description copied from class: ObjectDatabase
Close any resources held by this database.

Specified by:
close in class ObjectDatabase

fileFor

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

Parameters:
objectId - identity of the loose object to map to the directory.
Returns:
location of the object, if it were to exist as a loose object.

getPacks

public Collection<PackFile> getPacks()
Returns:
unmodifiable collection of all known pack files local to this directory. Most recent packs are presented first. Packs most likely to contain more recent objects appear before packs containing objects referenced by commits further back in the history of the repository.

openPack

public PackFile openPack(File pack,
                         File idx)
                  throws IOException
Add a single existing pack to the list of available pack files.

Parameters:
pack - path of the pack file to open.
idx - path of the corresponding index file.
Returns:
the pack that was opened and added to the database.
Throws:
IOException - index file could not be opened, read, or is not recognized as a Git pack file index.

toString

public String toString()
Overrides:
toString in class Object

newCachedDatabase

public ObjectDatabase newCachedDatabase()
Description copied from class: ObjectDatabase
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:
newCachedDatabase in class ObjectDatabase
Returns:
new cached database instance

newReader

public ObjectReader newReader()
Description copied from class: ObjectDatabase
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
Returns:
reader the caller can use to load objects from this database.

has

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

Alternates (if present) are searched automatically.

Overrides:
has in class ObjectDatabase
Parameters:
objectId - identity of the object to test for existence of.
Returns:
true if the specified object is stored in this database, or any of the alternate databases.


Copyright © 2012. All Rights Reserved.