class documentation

An index in to a packfile.

Given a sha id of an object a pack index can tell you the location in the packfile of that object if it has it.

Method __eq__ Check equality with another PackIndex.
Method __iter__ Iterate over the SHAs in this pack.
Method __len__ Return the number of entries in this pack index.
Method __ne__ Check if this pack index is not equal to another.
Method check Check the consistency of this pack index.
Method close Close any open files.
Method get_pack_checksum Return the SHA1 checksum stored for the corresponding packfile.
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.
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
Method _itersha Yield all the SHA1's of the objects in the index, sorted.
Method _object_offset See object_offset.
def __eq__(self, other: object) -> bool:

Check equality with another PackIndex.

def __iter__(self) -> Iterator[ObjectID]:

Iterate over the SHAs in this pack.

def __len__(self) -> int:

Return the number of entries in this pack index.

def __ne__(self, other: object) -> bool:

Check if this pack index is not equal to another.

def check(self):

Check the consistency of this pack index.

def close(self):

Close any open files.

def get_pack_checksum(self) -> bytes | None:

Return the SHA1 checksum stored for the corresponding packfile.

Returns: 20-byte binary digest, or None if not available

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

Iterate over all SHA1s with the given prefix.

Returns: Iterator of matching SHA1s

Parameters
prefix:bytesBinary prefix to match
Returns
Iterator[RawObjectID]Undocumented
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.

def object_sha1(self, index: int) -> bytes:

Return the SHA1 corresponding to the index in the pack file.

def objects_sha1(self) -> bytes:

Return the hex SHA1 over all the shas of all objects in this pack.

Note: This is used for the filename of the pack.

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

Yield all the SHA1's of the objects in the index, sorted.

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

See object_offset.

Parameters
sha:bytesA binary SHA string. (20 characters long)_
Returns
intUndocumented