org.eclipse.jgit.lib
Class ObjectReader

java.lang.Object
  extended by org.eclipse.jgit.lib.ObjectReader

public abstract class ObjectReader
extends Object

Reads an ObjectDatabase for a single thread.

Readers that can support efficient reuse of pack encoded objects should also implement the companion interface ObjectReuseAsIs.


Field Summary
static int OBJ_ANY
          Type hint indicating the caller doesn't know the type.
 
Constructor Summary
ObjectReader()
           
 
Method Summary
 AbbreviatedObjectId abbreviate(AnyObjectId objectId)
          Obtain a unique abbreviation (prefix) of an object SHA-1.
 AbbreviatedObjectId abbreviate(AnyObjectId objectId, int len)
          Obtain a unique abbreviation (prefix) of an object SHA-1.
 long getObjectSize(AnyObjectId objectId, int typeHint)
          Get only the size of an object.
<T extends ObjectId>
AsyncObjectSizeQueue<T>
getObjectSize(Iterable<T> objectIds, boolean reportMissing)
          Asynchronous object size lookup.
 boolean has(AnyObjectId objectId)
          Does the requested object exist in this database?
 boolean has(AnyObjectId objectId, int typeHint)
          Does the requested object exist in this database?
abstract  ObjectReader newReader()
          Construct a new reader from the same data.
 ObjectLoader open(AnyObjectId objectId)
          Open an object from this database.
abstract  ObjectLoader open(AnyObjectId objectId, int typeHint)
          Open an object from this database.
<T extends ObjectId>
AsyncObjectLoaderQueue<T>
open(Iterable<T> objectIds, boolean reportMissing)
          Asynchronous object opening.
 void release()
          Release any resources used by this reader.
abstract  Collection<ObjectId> resolve(AbbreviatedObjectId id)
          Resolve an abbreviated ObjectId to its full form.
 void walkAdviceBeginCommits(RevWalk walk, Collection<RevCommit> roots)
          Advice from a RevWalk that a walk is starting from these roots.
 void walkAdviceBeginTrees(ObjectWalk ow, RevCommit min, RevCommit max)
          Advice from an ObjectWalk that trees will be traversed.
 void walkAdviceEnd()
          Advice from that a walk is over.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OBJ_ANY

public static final int OBJ_ANY
Type hint indicating the caller doesn't know the type.

See Also:
Constant Field Values
Constructor Detail

ObjectReader

public ObjectReader()
Method Detail

newReader

public abstract ObjectReader newReader()
Construct a new reader from the same data.

Applications can use this method to build a new reader from the same data source, but for an different thread.

Returns:
a brand new reader, using the same data source.

abbreviate

public AbbreviatedObjectId abbreviate(AnyObjectId objectId)
                               throws IOException
Obtain a unique abbreviation (prefix) of an object SHA-1. This method uses a reasonable default for the minimum length. Callers who don't care about the minimum length should prefer this method. The returned abbreviation would expand back to the argument ObjectId when passed to resolve(AbbreviatedObjectId), assuming no new objects are added to this repository between calls.

Parameters:
objectId - object identity that needs to be abbreviated.
Returns:
SHA-1 abbreviation.
Throws:
IOException - the object store cannot be read.

abbreviate

public AbbreviatedObjectId abbreviate(AnyObjectId objectId,
                                      int len)
                               throws IOException
Obtain a unique abbreviation (prefix) of an object SHA-1. The returned abbreviation would expand back to the argument ObjectId when passed to resolve(AbbreviatedObjectId), assuming no new objects are added to this repository between calls. The default implementation of this method abbreviates the id to the minimum length, then resolves it to see if there are multiple results. When multiple results are found, the length is extended by 1 and resolve is tried again.

Parameters:
objectId - object identity that needs to be abbreviated.
len - minimum length of the abbreviated string. Must be in the range [2, ].
Returns:
SHA-1 abbreviation. If no matching objects exist in the repository, the abbreviation will match the minimum length.
Throws:
IOException - the object store cannot be read.

resolve

public abstract Collection<ObjectId> resolve(AbbreviatedObjectId id)
                                      throws IOException
Resolve an abbreviated ObjectId to its full form. This method searches for an ObjectId that begins with the abbreviation, and returns at least some matching candidates. If the returned collection is empty, no objects start with this abbreviation. The abbreviation doesn't belong to this repository, or the repository lacks the necessary objects to complete it. If the collection contains exactly one member, the abbreviation is (currently) unique within this database. There is a reasonably high probability that the returned id is what was previously abbreviated. If the collection contains 2 or more members, the abbreviation is not unique. In this case the implementation is only required to return at least 2 candidates to signal the abbreviation has conflicts. User friendly implementations should return as many candidates as reasonably possible, as the caller may be able to disambiguate further based on context. However since databases can be very large (e.g. 10 million objects) returning 625,000 candidates for the abbreviation "0" is simply unreasonable, so implementors should draw the line at around 256 matches.

Parameters:
id - abbreviated id to resolve to a complete identity. The abbreviation must have a length of at least 2.
Returns:
candidates that begin with the abbreviated identity.
Throws:
IOException - the object store cannot be read.

has

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

Parameters:
objectId - identity of the object to test for existence of.
Returns:
true if the specified object is stored in this database.
Throws:
IOException - the object store cannot be accessed.

has

public boolean has(AnyObjectId objectId,
                   int typeHint)
            throws IOException
Does the requested object exist in this database?

Parameters:
objectId - identity of the object to test for existence of.
typeHint - hint about the type of object being requested; OBJ_ANY if the object type is not known, or does not matter to the caller.
Returns:
true if the specified object is stored in this database.
Throws:
IncorrectObjectTypeException - typeHint was not OBJ_ANY, and the object's actual type does not match typeHint.
IOException - the object store cannot be accessed.

open

public ObjectLoader open(AnyObjectId objectId)
                  throws MissingObjectException,
                         IOException
Open an object from this database.

Parameters:
objectId - identity of the object to open.
Returns:
a ObjectLoader for accessing the object.
Throws:
MissingObjectException - the object does not exist.
IOException - the object store cannot be accessed.

open

public abstract ObjectLoader open(AnyObjectId objectId,
                                  int typeHint)
                           throws MissingObjectException,
                                  IncorrectObjectTypeException,
                                  IOException
Open an object from this database.

Parameters:
objectId - identity of the object to open.
typeHint - hint about the type of object being requested; OBJ_ANY if the object type is not known, or does not matter to the caller.
Returns:
a ObjectLoader for accessing the object.
Throws:
MissingObjectException - the object does not exist.
IncorrectObjectTypeException - typeHint was not OBJ_ANY, and the object's actual type does not match typeHint.
IOException - the object store cannot be accessed.

open

public <T extends ObjectId> AsyncObjectLoaderQueue<T> open(Iterable<T> objectIds,
                                                           boolean reportMissing)
Asynchronous object opening.

Type Parameters:
T - type of identifier being supplied.
Parameters:
objectIds - objects to open from the object store. The supplied collection must not be modified until the queue has finished.
reportMissing - if true missing objects are reported by calling failure with a MissingObjectException. This may be more expensive for the implementation to guarantee. If false the implementation may choose to report MissingObjectException, or silently skip over the object with no warning.
Returns:
queue to read the objects from.

getObjectSize

public long getObjectSize(AnyObjectId objectId,
                          int typeHint)
                   throws MissingObjectException,
                          IncorrectObjectTypeException,
                          IOException
Get only the size of an object.

The default implementation of this method opens an ObjectLoader. Databases are encouraged to override this if a faster access method is available to them.

Parameters:
objectId - identity of the object to open.
typeHint - hint about the type of object being requested; OBJ_ANY if the object type is not known, or does not matter to the caller.
Returns:
size of object in bytes.
Throws:
MissingObjectException - the object does not exist.
IncorrectObjectTypeException - typeHint was not OBJ_ANY, and the object's actual type does not match typeHint.
IOException - the object store cannot be accessed.

getObjectSize

public <T extends ObjectId> AsyncObjectSizeQueue<T> getObjectSize(Iterable<T> objectIds,
                                                                  boolean reportMissing)
Asynchronous object size lookup.

Type Parameters:
T - type of identifier being supplied.
Parameters:
objectIds - objects to get the size of from the object store. The supplied collection must not be modified until the queue has finished.
reportMissing - if true missing objects are reported by calling failure with a MissingObjectException. This may be more expensive for the implementation to guarantee. If false the implementation may choose to report MissingObjectException, or silently skip over the object with no warning.
Returns:
queue to read object sizes from.

walkAdviceBeginCommits

public void walkAdviceBeginCommits(RevWalk walk,
                                   Collection<RevCommit> roots)
                            throws IOException
Advice from a RevWalk that a walk is starting from these roots.

Parameters:
walk - the revision pool that is using this reader.
roots - starting points of the revision walk. The starting points have their headers parsed, but might be missing bodies.
Throws:
IOException - the reader cannot initialize itself to support the walk.

walkAdviceBeginTrees

public void walkAdviceBeginTrees(ObjectWalk ow,
                                 RevCommit min,
                                 RevCommit max)
                          throws IOException
Advice from an ObjectWalk that trees will be traversed.

Parameters:
ow - the object pool that is using this reader.
min - the first commit whose root tree will be read.
max - the last commit whose root tree will be read.
Throws:
IOException - the reader cannot initialize itself to support the walk.

walkAdviceEnd

public void walkAdviceEnd()
Advice from that a walk is over.


release

public void release()
Release any resources used by this reader.

A reader that has been released can be used again, but may need to be released after the subsequent usage.



Copyright © 2012. All Rights Reserved.