org.eclipse.jgit.lib
Class ObjectDirectory

java.lang.Object
  extended by org.eclipse.jgit.lib.ObjectDatabase
      extended by org.eclipse.jgit.lib.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.


Field Summary
 
Fields inherited from class org.eclipse.jgit.lib.ObjectDatabase
NO_ALTERNATES
 
Constructor Summary
ObjectDirectory(java.io.File dir)
          Initialize a reference to an on-disk object directory.
 
Method Summary
 void closeSelf()
          Close any resources held by this database only; ignoring alternates.
 void create()
          Initialize a new object database at this location.
 boolean exists()
          Does this database exist yet?
 java.io.File fileFor(AnyObjectId objectId)
          Compute the location of a loose object file.
 java.io.File getDirectory()
           
protected  boolean hasObject1(AnyObjectId objectId)
          Fast half of ObjectDatabase.hasObject(AnyObjectId).
protected  boolean hasObject2(java.lang.String objectName)
          Slow half of ObjectDatabase.hasObject(AnyObjectId).
protected  ObjectDatabase[] loadAlternates()
          Load the list of alternate databases into memory.
protected  ObjectLoader openObject1(WindowCursor curs, AnyObjectId objectId)
          Fast half of ObjectDatabase.openObject(WindowCursor, AnyObjectId).
protected  ObjectLoader openObject2(WindowCursor curs, java.lang.String objectName, AnyObjectId objectId)
          Slow half of ObjectDatabase.openObject(WindowCursor, AnyObjectId).
 void openPack(java.io.File pack, java.io.File idx)
          Add a single existing pack to the list of available pack files.
 java.lang.String toString()
           
protected  boolean tryAgain1()
           
 
Methods inherited from class org.eclipse.jgit.lib.ObjectDatabase
close, closeAlternates, closeAlternates, getAlternates, hasObject, openObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectDirectory

public ObjectDirectory(java.io.File dir)
Initialize a reference to an on-disk object directory.

Parameters:
dir - the location of the objects directory.
Method Detail

getDirectory

public final java.io.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 java.io.IOException
Description copied from class: ObjectDatabase
Initialize a new object database at this location.

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

closeSelf

public void closeSelf()
Description copied from class: ObjectDatabase
Close any resources held by this database only; ignoring alternates.

To fully close this database and its referenced alternates, the caller should instead invoke ObjectDatabase.close().

Overrides:
closeSelf in class ObjectDatabase

fileFor

public java.io.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.

openPack

public void openPack(java.io.File pack,
                     java.io.File idx)
              throws java.io.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.
Throws:
java.io.IOException - index file could not be opened, read, or is not recognized as a Git pack file index.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hasObject1

protected boolean hasObject1(AnyObjectId objectId)
Description copied from class: ObjectDatabase
Fast half of ObjectDatabase.hasObject(AnyObjectId).

Specified by:
hasObject1 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.

openObject1

protected ObjectLoader openObject1(WindowCursor curs,
                                   AnyObjectId objectId)
                            throws java.io.IOException
Description copied from class: ObjectDatabase
Fast half of ObjectDatabase.openObject(WindowCursor, AnyObjectId).

Specified by:
openObject1 in class ObjectDatabase
Parameters:
curs - temporary working space associated with the calling thread.
objectId - identity of the object to open.
Returns:
a ObjectLoader for accessing the data of the named object, or null if the object does not exist.
Throws:
java.io.IOException

hasObject2

protected boolean hasObject2(java.lang.String objectName)
Description copied from class: ObjectDatabase
Slow half of ObjectDatabase.hasObject(AnyObjectId).

Overrides:
hasObject2 in class ObjectDatabase
Parameters:
objectName - identity of the object to test for existence of.
Returns:
true if the specified object is stored in this database.

openObject2

protected ObjectLoader openObject2(WindowCursor curs,
                                   java.lang.String objectName,
                                   AnyObjectId objectId)
                            throws java.io.IOException
Description copied from class: ObjectDatabase
Slow half of ObjectDatabase.openObject(WindowCursor, AnyObjectId).

Overrides:
openObject2 in class ObjectDatabase
Parameters:
curs - temporary working space associated with the calling thread.
objectName - name of the object to open.
objectId - identity of the object to open.
Returns:
a ObjectLoader for accessing the data of the named object, or null if the object does not exist.
Throws:
java.io.IOException

tryAgain1

protected boolean tryAgain1()
Overrides:
tryAgain1 in class ObjectDatabase
Returns:
true if the fast-half search should be tried again.

loadAlternates

protected ObjectDatabase[] loadAlternates()
                                   throws java.io.IOException
Description copied from class: ObjectDatabase
Load the list of alternate databases into memory.

This method is invoked by ObjectDatabase.getAlternates() if the alternate list has not yet been populated, or if ObjectDatabase.closeAlternates() has been called on this instance and the alternate list is needed again.

If the alternate array is empty, implementors should consider using the constant ObjectDatabase.NO_ALTERNATES.

Overrides:
loadAlternates in class ObjectDatabase
Returns:
the alternate list for this database.
Throws:
java.io.IOException - the alternate list could not be accessed. The empty alternate array ObjectDatabase.NO_ALTERNATES will be assumed by the caller.