Top Description Inners Methods
org.eclipse.jgit.internal.storage.file

public Interface PackIndex

extends Iterable<PackIndex.MutableEntry>, ObjectIdSet
Known Direct Implementers
org.eclipse.jgit.internal.storage.file.PackIndexV1, org.eclipse.jgit.internal.storage.file.PackIndexV2
Imports
java.io.File, .FileNotFoundException, .IOException, .InputStream, java.text.MessageFormat, java.util.Iterator, .Set, org.eclipse.jgit.errors.CorruptObjectException, .MissingObjectException, .UnsupportedPackIndexVersionException, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.lib.AbbreviatedObjectId, .AnyObjectId, .MutableObjectId, .ObjectId, .ObjectIdSet, org.eclipse.jgit.util.IO, .NB, org.eclipse.jgit.util.io.SilentFileInputStream

Access path to locate objects by org.eclipse.jgit.lib.ObjectId in a org.eclipse.jgit.internal.storage.file.Pack.

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
PackIndex.EntriesIterator

Base implementation of the iterator over index entries.

public static class
PackIndex.MutableEntry

Represent mutable entry of pack index consisting of object id and offset in pack (both mutable).

Method Summary

Modifier and TypeMethod and Description
public default boolean
contains(AnyObjectId
the objectId to find
id
)

Implements org.eclipse.jgit.lib.ObjectIdSet.contains.

Returns true if the objectId is contained within the collection.

public long

Returns:

CRC32 checksum of specified object (at 32 less significant bits)
findCRC32
(AnyObjectId
id of object to look for
objId
)

Retrieve stored CRC32 checksum of the requested object raw-data (including header).

public long

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.
findOffset
(AnyObjectId
name of the object to locate within the pack.
objId
)

Locate the file offset position for the requested object.

public int

Returns:

position of the object-id in the lexicographically ordered list of ids stored in this index; -1 if the object does not exist in this index and is thus not stored in the associated pack.
findPosition
(AnyObjectId
name of the object to locate within the index
objId
)

Locate the position of this id in the list of object-ids in the index

public byte[]

Returns:

the checksum of the pack; caller must not modify it
getChecksum
()

Get pack checksum

public long

Returns:

number of objects in this index, and likewise in the associated pack that this index was generated from.
getObjectCount
()

Obtain the total number of objects described by this index.

public ObjectId

Returns:

the ObjectId for the corresponding entry.
getObjectId
(long
position within the traversal of iterator() that the caller needs the object for. The first returned org.eclipse.jgit.internal.storage.file.PackIndex.MutableEntry is 0, the second is 1, etc.
nthPosition
)

Get ObjectId for the n-th object entry returned by iterator().

public default ObjectId

Returns:

the ObjectId for the corresponding entry.
getObjectId
(int
unsigned 32 bit position within the traversal of iterator() that the caller needs the object for. The first returned org.eclipse.jgit.internal.storage.file.PackIndex.MutableEntry is 0, the second is 1, etc. Positions past 2**31-1 are negative, but still valid.
nthPosition
)

Get ObjectId for the n-th object entry returned by iterator().

public long

Returns:

the offset in a pack for the corresponding entry.
getOffset
(long
unsigned 32 bit position within the traversal of iterator() for which the caller needs the offset. The first returned MutableEntry is 0, the second is 1, etc. Positions past 2**31-1 are negative, but still valid.
nthPosition
)

Get offset in a pack for the n-th object entry returned by iterator().

public long

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.
getOffset64Count
()

Obtain the total number of objects needing 64 bit offsets.

public boolean

Returns:

true if CRC32 is stored, false otherwise
hasCRC32Support
()

Check whether this index supports (has) CRC32 checksums for objects.

public default boolean

Returns:

true if the object is listed in this index; false otherwise.
hasObject
(AnyObjectId
the object to look for. Must not be null.
id
)

Determine if an object is contained within the pack file.

private static boolean
isTOC(byte[] h)

public Iterator<PackIndex.MutableEntry>
iterator()

Redeclares java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public static PackIndex

Returns:

access implementation for the requested file.
open
(File
existing pack .idx to read.
idxFile
)

Open an existing pack .idx file for reading.

public static PackIndex

Returns:

a copy of the index in-memory.
read
(InputStream
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.
fd
)

Read an existing pack index file from a buffered stream.

public void
resolve(Set<ObjectId>
set to add any located ObjectIds to. This is an output parameter.
matches
,
AbbreviatedObjectId
prefix to search for.
id
,
int
maximum number of results to return. At most this many ObjectIds should be added to matches before returning.
matchLimit
)

Find objects matching the prefix abbreviation.

Inherited from java.lang.Iterable:
forEachspliterator

Method Detail

containsback to summary
public default boolean contains(AnyObjectId id)

Implements org.eclipse.jgit.lib.ObjectIdSet.contains.

Doc from org.eclipse.jgit.lib.ObjectIdSet.contains.

Returns true if the objectId is contained within the collection.

Parameters
id:AnyObjectId

the objectId to find

Returns:boolean

whether the collection contains the objectId.

Annotations
@Override
findCRC32back to summary
public long findCRC32(AnyObjectId objId) throws MissingObjectException, UnsupportedOperationException

Retrieve stored CRC32 checksum of the requested object raw-data (including header).

Parameters
objId:AnyObjectId

id of object to look for

Returns:long

CRC32 checksum of specified object (at 32 less significant bits)

Exceptions
MissingObjectException:
when requested ObjectId was not found in this index
UnsupportedOperationException:
when this index doesn't support CRC32 checksum
findOffsetback to summary
public long findOffset(AnyObjectId objId)

Locate the file offset position for the requested object.

Parameters
objId:AnyObjectId

name of the object to locate within the pack.

Returns:long

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.

findPositionback to summary
public int findPosition(AnyObjectId objId)

Locate the position of this id in the list of object-ids in the index

Parameters
objId:AnyObjectId

name of the object to locate within the index

Returns:int

position of the object-id in the lexicographically ordered list of ids stored in this index; -1 if the object does not exist in this index and is thus not stored in the associated pack.

getChecksumback to summary
public byte[] getChecksum()

Get pack checksum

Returns:byte[]

the checksum of the pack; caller must not modify it

Since
5.5
getObjectCountback to summary
public long getObjectCount()

Obtain the total number of objects described by this index.

Returns:long

number of objects in this index, and likewise in the associated pack that this index was generated from.

getObjectIdback to summary
public ObjectId getObjectId(long nthPosition)

Get ObjectId for the n-th object entry returned by 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();
Parameters
nthPosition:long

position within the traversal of iterator() that the caller needs the object for. The first returned org.eclipse.jgit.internal.storage.file.PackIndex.MutableEntry is 0, the second is 1, etc.

Returns:ObjectId

the ObjectId for the corresponding entry.

getObjectIdback to summary
public default ObjectId getObjectId(int nthPosition)

Get ObjectId for the n-th object entry returned by 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();
Parameters
nthPosition:int

unsigned 32 bit position within the traversal of iterator() that the caller needs the object for. The first returned org.eclipse.jgit.internal.storage.file.PackIndex.MutableEntry is 0, the second is 1, etc. Positions past 2**31-1 are negative, but still valid.

Returns:ObjectId

the ObjectId for the corresponding entry.

getOffsetback to summary
public long getOffset(long nthPosition)

Get offset in a pack for the n-th object entry returned by iterator().

Parameters
nthPosition:long

unsigned 32 bit position within the traversal of iterator() for which the caller needs the offset. The first returned MutableEntry is 0, the second is 1, etc. Positions past 2**31-1 are negative, but still valid.

Returns:long

the offset in a pack for the corresponding entry.

getOffset64Countback to summary
public long getOffset64Count()

Obtain the total number of objects needing 64 bit offsets.

Returns:long

number of objects in this index using a 64 bit offset; that is an object positioned after the 2 GB position within the file.

hasCRC32Supportback to summary
public boolean hasCRC32Support()

Check whether this index supports (has) CRC32 checksums for objects.

Returns:boolean

true if CRC32 is stored, false otherwise

hasObjectback to summary
public default boolean hasObject(AnyObjectId id)

Determine if an object is contained within the pack file.

Parameters
id:AnyObjectId

the object to look for. Must not be null.

Returns:boolean

true if the object is listed in this index; false otherwise.

isTOCback to summary
private static boolean isTOC(byte[] h)
iteratorback to summary
public Iterator<PackIndex.MutableEntry> iterator()

Redeclares java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

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.

Returns:Iterator<PackIndex.MutableEntry>

an Iterator.

Annotations
@Override
openback to summary
public static PackIndex open(File idxFile) throws IOException

Open an existing pack .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.

Parameters
idxFile:File

existing pack .idx to read.

Returns:PackIndex

access implementation for the requested file.

Exceptions
IOException:
the file exists but could not be read due to security errors, unrecognized data version, or unexpected data corruption.
FileNotFoundException:
the file does not exist.
readback to summary
public static PackIndex read(InputStream fd) throws IOException, CorruptObjectException

Read an existing pack index file from a buffered stream.

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.

Parameters
fd:InputStream

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.

Returns:PackIndex

a copy of the index in-memory.

Exceptions
IOException:
the stream cannot be read.
CorruptObjectException:
the stream does not contain a valid pack index.
resolveback to summary
public void resolve(Set<ObjectId> matches, AbbreviatedObjectId id, int matchLimit) throws IOException

Find objects matching the prefix abbreviation.

Parameters
matches:Set<ObjectId>

set to add any located ObjectIds to. This is an output parameter.

id:AbbreviatedObjectId

prefix to search for.

matchLimit:int

maximum number of results to return. At most this many ObjectIds should be added to matches before returning.

Exceptions
IOException:
the index cannot be read.
org.eclipse.jgit.internal.storage.file back to summary

public abstract Class PackIndex.EntriesIterator

extends Object
implements Iterator<PackIndex.MutableEntry>
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.internal.storage.file.PackIndex.EntriesIterator
All Implemented Interfaces
java.util.Iterator
Known Direct Subclasses
org.eclipse.jgit.internal.storage.file.PackIndexV1.EntriesIteratorV1, org.eclipse.jgit.internal.storage.file.PackIndexV2.EntriesIteratorV2

Base implementation of the iterator over index entries.

Field Summary

Modifier and TypeField and Description
private final PackIndex.MutableEntry
private final long
private long
returnedNumber

Counts number of entries accessed so far.

Constructor Summary

AccessConstructor and Description
protected
EntriesIterator(long
the number of objects in the PackFile.
objectCount
)

Construct an iterator that can move objectCount times forward.

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public PackIndex.MutableEntry
next()

Implements java.util.Iterator.next.

Implementation must update returnedNumber before returning element.

protected abstract void
readNext()

Used by subclasses to load the next entry into the MutableEntry.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

protected void
setIdBuffer(int[]
the raw data
raw
,
int
the index into raw
idx
)

Copies to the entry an ObjectId from the int buffer and position idx

protected void
setIdBuffer(byte[]
the raw data
raw
,
int
the index into raw
idx
)

Copies to the entry an ObjectId from the byte array at position idx.

protected void
setOffset(long
the offset in the pack file
offset
)

Sets the offset to the entry

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

entryback to summary
private final PackIndex.MutableEntry entry
objectCountback to summary
private final long objectCount
returnedNumberback to summary
private long returnedNumber

Counts number of entries accessed so far.

Constructor Detail

EntriesIteratorback to summary
protected EntriesIterator(long objectCount)

Construct an iterator that can move objectCount times forward.

Parameters
objectCount:long

the number of objects in the PackFile.

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public PackIndex.MutableEntry next()

Implements java.util.Iterator.next.

Implementation must update returnedNumber before returning element.

Returns:PackIndex.MutableEntry

Doc from java.util.Iterator.next.

the next element in the iteration

Annotations
@Override
readNextback to summary
protected abstract void readNext()

Used by subclasses to load the next entry into the MutableEntry.

Subclasses are expected to populate the entry with setIdBuffer and setOffset.

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override
setIdBufferback to summary
protected void setIdBuffer(int[] raw, int idx)

Copies to the entry an ObjectId from the int buffer and position idx

Parameters
raw:int[]

the raw data

idx:int

the index into raw

setIdBufferback to summary
protected void setIdBuffer(byte[] raw, int idx)

Copies to the entry an ObjectId from the byte array at position idx.

Parameters
raw:byte[]

the raw data

idx:int

the index into raw

setOffsetback to summary
protected void setOffset(long offset)

Sets the offset to the entry

Parameters
offset:long

the offset in the pack file

org.eclipse.jgit.internal.storage.file back to summary

public Class PackIndex.MutableEntry

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.internal.storage.file.PackIndex.MutableEntry

Represent mutable entry of pack index consisting of object id and offset in pack (both mutable).

Field Summary

Modifier and TypeField and Description
pack-priv final MutableObjectId
idBuffer

Buffer of the ObjectId visited by the EntriesIterator.

pack-priv long
offset

Offset into the packfile of the current object.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public PackIndex.MutableEntry

Returns:

a complete copy of this entry, that won't modify
cloneEntry
()

Clone the entry

public int

Returns:

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
compareBySha1To
(PackIndex.MutableEntry
Another mutable entry (probably from another index)
other
)

Similar to Comparable#compareTo(Object), using only the object id in the entry.

public void
copyOidTo(MutableObjectId
destination for the object id
dest
)

Copy the current ObjectId to dest

Like toObjectId(), but reusing the destination instead of creating a new ObjectId instance.

public long

Returns:

offset of this object in a pack file
getOffset
()

Returns offset for this index object entry

public String

Returns:

hex string describing the object id of this entry.
name
()

Get hex string representation of the entry's object id

public ObjectId

Returns:

a copy of the object id.
toObjectId
()

Create a copy of the object id

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

idBufferback to summary
pack-priv final MutableObjectId idBuffer

Buffer of the ObjectId visited by the EntriesIterator.

offsetback to summary
pack-priv long offset

Offset into the packfile of the current object.

Constructor Detail

MutableEntryback to summary
public MutableEntry()

Method Detail

cloneEntryback to summary
public PackIndex.MutableEntry cloneEntry()

Clone the entry

Returns:PackIndex.MutableEntry

a complete copy of this entry, that won't modify

compareBySha1Toback to summary
public int compareBySha1To(PackIndex.MutableEntry other)

Similar to Comparable#compareTo(Object), using only the object id in the entry.

Parameters
other:PackIndex.MutableEntry

Another mutable entry (probably from another index)

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

copyOidToback to summary
public void copyOidTo(MutableObjectId dest)

Copy the current ObjectId to dest

Like toObjectId(), but reusing the destination instead of creating a new ObjectId instance.

Parameters
dest:MutableObjectId

destination for the object id

getOffsetback to summary
public long getOffset()

Returns offset for this index object entry

Returns:long

offset of this object in a pack file

nameback to summary
public String name()

Get hex string representation of the entry's object id

Returns:String

hex string describing the object id of this entry.

toObjectIdback to summary
public ObjectId toObjectId()

Create a copy of the object id

Returns:ObjectId

a copy of the object id.