class documentation

Pack index that is based on a file.

To do the loop it opens the file, and indexes first 256 4 byte groups with the first byte of the sha id. The value in the four byte group indexed is the end of the group that shares the same starting byte. Subtract one from the starting byte and index again to find the start of the group. The values are sorted by sha id within the group, so do the math to find the start and end offset and then bisect in to find if the value is present.

Method __eq__ Check equality with another FilePackIndex.
Method __init__ Create a pack index object.
Method __len__ Return the number of entries in this pack index.
Method calculate_checksum Calculate the SHA1 checksum over this pack index.
Method check Check that the stored checksum matches the actual checksum.
Method close Close the underlying file and any mmap.
Method get_pack_checksum Return the SHA1 checksum stored for the corresponding packfile.
Method get_stored_checksum Return the SHA1 checksum stored for this index.
Method iter_prefix Iterate over all SHA1s with the given prefix.
Method iterentries Iterate over the entries in this pack index.
Method object_offset Return the offset in to the corresponding packfile for the object.
Property path Return the path to this index file.
Method _itersha Iterate over all SHA1s in the index.
Method _object_offset See object_offset.
Method _read_fan_out_table Read the fan-out table from the index.
Method _unpack_crc32_checksum Unpack the crc32 checksum for the ith object from the index file.
Method _unpack_entry Unpack the i-th entry in the index file.
Method _unpack_name Unpack the i-th name from the index file.
Method _unpack_offset Unpack the i-th object offset from the index file.
Class Variable _fan_out_table Undocumented
Instance Variable _contents Undocumented
Instance Variable _file Undocumented
Instance Variable _filename Undocumented
Instance Variable _size Undocumented

Inherited from PackIndex:

Method __iter__ Iterate over the SHAs in this pack.
Method __ne__ Check if this pack index is not equal to another.
Method object_sha1 Return the SHA1 corresponding to the index in the pack file.
Method objects_sha1 Return the hex SHA1 over all the shas of all objects in this pack.
Class Variable object_format Undocumented
def __eq__(self, other: object) -> bool:

Check equality with another FilePackIndex.

def __init__(self, filename: str | os.PathLike[str], file: IO[bytes] | _GitFile | None = None, contents: bytes | mmap.mmap | None = None, size: int | None = None):

Create a pack index object.

Provide it with the name of the index file to consider, and it will map it whenever required.

def __len__(self) -> int:

Return the number of entries in this pack index.

def calculate_checksum(self) -> bytes:

Calculate the SHA1 checksum over this pack index.

Returns: This is a 20-byte binary digest

def check(self):

Check that the stored checksum matches the actual checksum.

def close(self):

Close the underlying file and any mmap.

def get_pack_checksum(self) -> bytes:

Return the SHA1 checksum stored for the corresponding packfile.

Returns: 20-byte binary digest

def get_stored_checksum(self) -> bytes:

Return the SHA1 checksum stored for this index.

Returns: 20-byte binary digest

def iter_prefix(self, prefix: bytes) -> Iterator[RawObjectID]:

Iterate over all SHA1s with the given prefix.

def iterentries(self) -> Iterator[PackIndexEntry]:

Iterate over the entries in this pack index.

Returns: iterator over tuples with object name, offset in packfile and
crc32 checksum.
def object_offset(self, sha: ObjectID | RawObjectID) -> int:

Return the offset in to the corresponding packfile for the object.

Given the name of an object it will return the offset that object lives at within the corresponding pack file. If the pack file doesn't have the object then None will be returned.

path: str =

Return the path to this index file.

def _itersha(self) -> Iterator[bytes]:

Iterate over all SHA1s in the index.

def _object_offset(self, sha: bytes) -> int:

See object_offset.

Parameters
sha:bytesA binary SHA string. (20 characters long)_
Returns
intUndocumented
def _read_fan_out_table(self, start_offset: int) -> list[int]:

Read the fan-out table from the index.

The fan-out table contains 256 entries mapping first byte values to the number of objects with SHA1s less than or equal to that byte.

Returns: List of 256 integers

Parameters
start_offset:intOffset in the file where the fan-out table starts
Returns
list[int]Undocumented
def _unpack_crc32_checksum(self, i: int) -> int | None:

Unpack the crc32 checksum for the ith object from the index file.

def _unpack_entry(self, i: int) -> PackIndexEntry:

Unpack the i-th entry in the index file.

Returns: Tuple with object name (SHA), offset in pack file and CRC32
checksum (if known).
def _unpack_name(self, i: int) -> bytes:

Unpack the i-th name from the index file.

def _unpack_offset(self, i: int) -> int:

Unpack the i-th object offset from the index file.

_contents =

Undocumented

_file: IO[bytes] | _GitFile =

Undocumented

_filename =

Undocumented

_size =

Undocumented