Package org.eclipse.jgit.lib
Class ObjectReader
- java.lang.Object
-
- org.eclipse.jgit.lib.ObjectReader
-
- Direct Known Subclasses:
DfsReader
public abstract class ObjectReader extends java.lang.Object
Reads anObjectDatabase
for a single thread.Readers that can support efficient reuse of pack encoded objects should also implement the companion interface
ObjectReuseAsIs
.
-
-
Field Summary
Fields Modifier and Type Field Description static int
OBJ_ANY
Type hint indicating the caller doesn't know the type.
-
Constructor Summary
Constructors Constructor Description ObjectReader()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.BitmapIndex
getBitmapIndex()
An index that can be used to speed up ObjectWalks.<T extends ObjectId>
AsyncObjectSizeQueue<T>getObjectSize(java.lang.Iterable<T> objectIds, boolean reportMissing)
Asynchronous object size lookup.long
getObjectSize(AnyObjectId objectId, int typeHint)
Get only the size of an object.abstract java.util.Set<ObjectId>
getShallowCommits()
Returns IDs for those commits which should be considered as shallow.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.<T extends ObjectId>
AsyncObjectLoaderQueue<T>open(java.lang.Iterable<T> objectIds, boolean reportMissing)
Asynchronous object opening.ObjectLoader
open(AnyObjectId objectId)
Open an object from this database.abstract ObjectLoader
open(AnyObjectId objectId, int typeHint)
Open an object from this database.void
release()
Release any resources used by this reader.abstract java.util.Collection<ObjectId>
resolve(AbbreviatedObjectId id)
Resolve an abbreviated ObjectId to its full form.void
setAvoidUnreachableObjects(boolean avoid)
Advise the reader to avoid unreachable objects.void
walkAdviceBeginCommits(RevWalk walk, java.util.Collection<RevCommit> roots)
Advice from aRevWalk
that a walk is starting from these roots.void
walkAdviceBeginTrees(ObjectWalk ow, RevCommit min, RevCommit max)
Advice from anObjectWalk
that trees will be traversed.void
walkAdviceEnd()
Advice from that a walk is over.
-
-
-
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
-
-
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 java.io.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 toresolve(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:
java.io.IOException
- the object store cannot be read.
-
abbreviate
public AbbreviatedObjectId abbreviate(AnyObjectId objectId, int len) throws java.io.IOException
Obtain a unique abbreviation (prefix) of an object SHA-1. The returned abbreviation would expand back to the argument ObjectId when passed toresolve(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, 40].- Returns:
- SHA-1 abbreviation. If no matching objects exist in the repository, the abbreviation will match the minimum length.
- Throws:
java.io.IOException
- the object store cannot be read.
-
resolve
public abstract java.util.Collection<ObjectId> resolve(AbbreviatedObjectId id) throws java.io.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:
java.io.IOException
- the object store cannot be read.
-
has
public boolean has(AnyObjectId objectId) throws java.io.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:
java.io.IOException
- the object store cannot be accessed.
-
has
public boolean has(AnyObjectId objectId, int typeHint) throws java.io.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, e.g.Constants.OBJ_BLOB
;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.java.io.IOException
- the object store cannot be accessed.
-
open
public ObjectLoader open(AnyObjectId objectId) throws MissingObjectException, java.io.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.java.io.IOException
- the object store cannot be accessed.
-
open
public abstract ObjectLoader open(AnyObjectId objectId, int typeHint) throws MissingObjectException, IncorrectObjectTypeException, java.io.IOException
Open an object from this database.- Parameters:
objectId
- identity of the object to open.typeHint
- hint about the type of object being requested, e.g.Constants.OBJ_BLOB
;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.java.io.IOException
- the object store cannot be accessed.
-
getShallowCommits
public abstract java.util.Set<ObjectId> getShallowCommits() throws java.io.IOException
Returns IDs for those commits which should be considered as shallow.- Returns:
- IDs of shallow commits
- Throws:
java.io.IOException
-
open
public <T extends ObjectId> AsyncObjectLoaderQueue<T> open(java.lang.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, java.io.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, e.g.Constants.OBJ_BLOB
;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.java.io.IOException
- the object store cannot be accessed.
-
getObjectSize
public <T extends ObjectId> AsyncObjectSizeQueue<T> getObjectSize(java.lang.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, java.util.Collection<RevCommit> roots) throws java.io.IOException
Advice from aRevWalk
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:
java.io.IOException
- the reader cannot initialize itself to support the walk.
-
walkAdviceBeginTrees
public void walkAdviceBeginTrees(ObjectWalk ow, RevCommit min, RevCommit max) throws java.io.IOException
Advice from anObjectWalk
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:
java.io.IOException
- the reader cannot initialize itself to support the walk.
-
walkAdviceEnd
public void walkAdviceEnd()
Advice from that a walk is over.
-
setAvoidUnreachableObjects
public void setAvoidUnreachableObjects(boolean avoid)
Advise the reader to avoid unreachable objects.While enabled the reader will skip over anything previously proven to be unreachable. This may be dangerous in the face of concurrent writes.
- Parameters:
avoid
- true to avoid unreachable objects.- Since:
- 3.0
-
getBitmapIndex
public BitmapIndex getBitmapIndex() throws java.io.IOException
An index that can be used to speed up ObjectWalks.- Returns:
- the index or null if one does not exist.
- Throws:
java.io.IOException
- when the index fails to load- Since:
- 3.0
-
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.
-
-