Class PackIndexV2
- java.lang.Object
-
- org.eclipse.jgit.internal.storage.file.PackIndex
-
- org.eclipse.jgit.internal.storage.file.PackIndexV2
-
- All Implemented Interfaces:
java.lang.Iterable<PackIndex.MutableEntry>
,ObjectIdSet
class PackIndexV2 extends PackIndex
Support for the pack index v2 format.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
PackIndexV2.EntriesIteratorV2
-
Nested classes/interfaces inherited from class org.eclipse.jgit.internal.storage.file.PackIndex
PackIndex.EntriesIterator, PackIndex.MutableEntry
-
-
Field Summary
Fields Modifier and Type Field Description private byte[][]
crc32
256 arrays of the CRC-32 of objects, matchingnames
.private static int
FANOUT
private long[]
fanoutTable
private static long
IS_O64
(package private) int[][]
names
256 arrays of contiguous object names.private static byte[]
NO_BYTES
private static int[]
NO_INTS
private long
objectCnt
(package private) byte[][]
offset32
256 arrays of the 32 bit offset data, matchingnames
.(package private) byte[]
offset64
64 bit offset table.-
Fields inherited from class org.eclipse.jgit.internal.storage.file.PackIndex
packChecksum
-
-
Constructor Summary
Constructors Constructor Description PackIndexV2(java.io.InputStream fd)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private int
binarySearchLevelTwo(AnyObjectId objId, int levelOne)
long
findCRC32(AnyObjectId objId)
Retrieve stored CRC32 checksum of the requested object raw-data (including header).private int
findLevelOne(long nthPosition)
long
findOffset(AnyObjectId objId)
Locate the file offset position for the requested object.private int
getLevelTwo(long nthPosition, int levelOne)
long
getObjectCount()
Obtain the total number of objects described by this index.ObjectId
getObjectId(long nthPosition)
Get ObjectId for the n-th object entry returned byPackIndex.iterator()
.private long
getOffset(int levelOne, int levelTwo)
long
getOffset(long nthPosition)
Get offset in a pack for the n-th object entry returned byPackIndex.iterator()
.long
getOffset64Count()
Obtain the total number of objects needing 64 bit offsets.boolean
hasCRC32Support()
Check whether this index supports (has) CRC32 checksums for objects.private static int
idOffset(int p)
java.util.Iterator<PackIndex.MutableEntry>
iterator()
void
resolve(java.util.Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit)
Find objects matching the prefix abbreviation.-
Methods inherited from class org.eclipse.jgit.internal.storage.file.PackIndex
contains, getChecksum, getObjectId, hasObject, open, read
-
-
-
-
Field Detail
-
IS_O64
private static final long IS_O64
- See Also:
- Constant Field Values
-
FANOUT
private static final int FANOUT
- See Also:
- Constant Field Values
-
NO_INTS
private static final int[] NO_INTS
-
NO_BYTES
private static final byte[] NO_BYTES
-
objectCnt
private long objectCnt
-
fanoutTable
private final long[] fanoutTable
-
names
int[][] names
256 arrays of contiguous object names.
-
offset32
byte[][] offset32
256 arrays of the 32 bit offset data, matchingnames
.
-
crc32
private byte[][] crc32
256 arrays of the CRC-32 of objects, matchingnames
.
-
offset64
byte[] offset64
64 bit offset table.
-
-
Method Detail
-
getObjectCount
public long getObjectCount()
Obtain the total number of objects described by this index.- Specified by:
getObjectCount
in classPackIndex
- Returns:
- number of objects in this index, and likewise in the associated pack that this index was generated from.
-
getOffset64Count
public long getOffset64Count()
Obtain the total number of objects needing 64 bit offsets.- Specified by:
getOffset64Count
in classPackIndex
- Returns:
- number of objects in this index using a 64 bit offset; that is an object positioned after the 2 GB position within the file.
-
findLevelOne
private int findLevelOne(long nthPosition)
-
getLevelTwo
private int getLevelTwo(long nthPosition, int levelOne)
-
getObjectId
public ObjectId getObjectId(long nthPosition)
Get ObjectId for the n-th object entry returned byPackIndex.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();
- Specified by:
getObjectId
in classPackIndex
- Parameters:
nthPosition
- position within the traversal ofPackIndex.iterator()
that the caller needs the object for. The first returnedPackIndex.MutableEntry
is 0, the second is 1, etc.- Returns:
- the ObjectId for the corresponding entry.
-
getOffset
public long getOffset(long nthPosition)
Get offset in a pack for the n-th object entry returned byPackIndex.iterator()
.- Specified by:
getOffset
in classPackIndex
- Parameters:
nthPosition
- unsigned 32 bit position within the traversal ofPackIndex.iterator()
for which the caller needs the offset. The first returnedPackIndex.MutableEntry
is 0, the second is 1, etc. Positions past 2**31-1 are negative, but still valid.- Returns:
- the offset in a pack for the corresponding entry.
-
findOffset
public long findOffset(AnyObjectId objId)
Locate the file offset position for the requested object.- Specified by:
findOffset
in classPackIndex
- Parameters:
objId
- name of the object to locate within the pack.- Returns:
- offset of the object's header and compressed content; -1 if the object does not exist in this index and is thus not stored in the associated pack.
-
getOffset
private long getOffset(int levelOne, int levelTwo)
-
findCRC32
public long findCRC32(AnyObjectId objId) throws MissingObjectException
Retrieve stored CRC32 checksum of the requested object raw-data (including header).- Specified by:
findCRC32
in classPackIndex
- Parameters:
objId
- id of object to look for- Returns:
- CRC32 checksum of specified object (at 32 less significant bits)
- Throws:
MissingObjectException
- when requested ObjectId was not found in this index
-
hasCRC32Support
public boolean hasCRC32Support()
Check whether this index supports (has) CRC32 checksums for objects.- Specified by:
hasCRC32Support
in classPackIndex
- Returns:
- true if CRC32 is stored, false otherwise
-
iterator
public java.util.Iterator<PackIndex.MutableEntry> iterator()
Provide iterator that gives access to index entries. Note, that iterator returns reference to mutable object, the same reference in each call - for performance reason. If client needs immutable objects, it must copy returned object on its own.
Iterator returns objects in SHA-1 lexicographical order.
- Specified by:
iterator
in interfacejava.lang.Iterable<PackIndex.MutableEntry>
- Specified by:
iterator
in classPackIndex
-
resolve
public void resolve(java.util.Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit) throws java.io.IOException
Find objects matching the prefix abbreviation.- Specified by:
resolve
in classPackIndex
- Parameters:
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.- Throws:
java.io.IOException
- the index cannot be read.
-
idOffset
private static int idOffset(int p)
-
binarySearchLevelTwo
private int binarySearchLevelTwo(AnyObjectId objId, int levelOne)
-
-