public abstract class PackIndex extends Object implements Iterable<PackIndex.MutableEntry>
ObjectId
in a PackFile
.
Indexes are strictly redundant information in that we can rebuild all of the data held in the index file from the on disk representation of the pack file itself, but it is faster to access for random requests because data is stored by ObjectId.
Modifier and Type | Class and Description |
---|---|
static class |
PackIndex.MutableEntry
Represent mutable entry of pack index consisting of object id and offset
in pack (both mutable).
|
Modifier and Type | Field and Description |
---|---|
protected byte[] |
packChecksum
Footer checksum applied on the bottom of the pack file.
|
Constructor and Description |
---|
PackIndex() |
Modifier and Type | Method and Description |
---|---|
abstract long |
findCRC32(AnyObjectId objId)
Retrieve stored CRC32 checksum of the requested object raw-data
(including header).
|
abstract long |
findOffset(AnyObjectId objId)
Locate the file offset position for the requested object.
|
abstract long |
getObjectCount()
Obtain the total number of objects described by this index.
|
ObjectId |
getObjectId(int nthPosition)
Get ObjectId for the n-th object entry returned by
iterator() . |
abstract ObjectId |
getObjectId(long nthPosition)
Get ObjectId for the n-th object entry returned by
iterator() . |
abstract long |
getOffset64Count()
Obtain the total number of objects needing 64 bit offsets.
|
abstract boolean |
hasCRC32Support()
Check whether this index supports (has) CRC32 checksums for objects.
|
boolean |
hasObject(AnyObjectId id)
Determine if an object is contained within the pack file.
|
abstract Iterator<PackIndex.MutableEntry> |
iterator()
Provide iterator that gives access to index entries.
|
static PackIndex |
open(File idxFile)
Open an existing pack
.idx file for reading. |
static PackIndex |
read(InputStream fd)
Read an existing pack index file from a buffered stream.
|
abstract void |
resolve(Set<ObjectId> matches,
AbbreviatedObjectId id,
int matchLimit)
Find objects matching the prefix abbreviation.
|
protected byte[] packChecksum
public static PackIndex open(File idxFile) throws IOException
.idx
file for reading.
The format of the file will be automatically detected and a proper access implementation for that format will be constructed and returned to the caller. The file may or may not be held open by the returned instance.
idxFile
- existing pack .idx to read.FileNotFoundException
- the file does not exist.IOException
- the file exists but could not be read due to security errors,
unrecognized data version, or unexpected data corruption.public static PackIndex read(InputStream fd) throws IOException, CorruptObjectException
The format of the file will be automatically detected and a proper access implementation for that format will be constructed and returned to the caller. The file may or may not be held open by the returned instance.
fd
- stream to read the index file from. The stream must be
buffered as some small IOs are performed against the stream.
The caller is responsible for closing the stream.IOException
- the stream cannot be read.CorruptObjectException
- the stream does not contain a valid pack index.public boolean hasObject(AnyObjectId id)
id
- the object to look for. Must not be null.public abstract Iterator<PackIndex.MutableEntry> iterator()
Iterator returns objects in SHA-1 lexicographical order.
iterator
in interface Iterable<PackIndex.MutableEntry>
public abstract long getObjectCount()
public abstract long getOffset64Count()
public abstract ObjectId getObjectId(long nthPosition)
iterator()
.
This method is a constant-time replacement for the following loop:
Iterator<MutableEntry> eItr = index.iterator(); int curPosition = 0; while (eItr.hasNext() && curPosition++ < nthPosition) eItr.next(); ObjectId result = eItr.next().toObjectId();
nthPosition
- position within the traversal of iterator()
that the
caller needs the object for. The first returned
PackIndex.MutableEntry
is 0, the second is 1, etc.public final ObjectId getObjectId(int nthPosition)
iterator()
.
This method is a constant-time replacement for the following loop:
Iterator<MutableEntry> eItr = index.iterator(); int curPosition = 0; while (eItr.hasNext() && curPosition++ < nthPosition) eItr.next(); ObjectId result = eItr.next().toObjectId();
nthPosition
- unsigned 32 bit position within the traversal of
iterator()
that the caller needs the object for. The
first returned PackIndex.MutableEntry
is 0, the second is 1,
etc. Positions past 2**31-1 are negative, but still valid.public abstract long findOffset(AnyObjectId objId)
objId
- name of the object to locate within the pack.public abstract long findCRC32(AnyObjectId objId) throws MissingObjectException, UnsupportedOperationException
objId
- id of object to look forMissingObjectException
- when requested ObjectId was not found in this indexUnsupportedOperationException
- when this index doesn't support CRC32 checksumpublic abstract boolean hasCRC32Support()
public abstract void resolve(Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit) throws IOException
matches
- set to add any located ObjectIds to. This is an output
parameter.id
- prefix to search for.matchLimit
- maximum number of results to return. At most this many
ObjectIds should be added to matches before returning.IOException
- the index cannot be read.Copyright © 2015 Eclipse JGit Project. All rights reserved.