class documentation

The data contained in a packfile.

Pack files can be accessed both sequentially for exploding a pack, and directly with the help of an index to retrieve a specific object.

The objects within are either complete or a delta against another.

The header is variable length. If the MSB of each byte is set then it indicates that the subsequent byte is still part of the header. For the first byte the next MS bits are the type, which tells you the type of object, and whether it is a delta. The LS byte is the lowest bits of the size. For each subsequent byte the LS 7 bits are the next MS bits of the size, i.e. the last byte of the header contains the MS bits of the size.

For the complete objects the data is stored as zlib deflated data. The size in the header is the uncompressed object size, so to uncompress you need to just keep feeding data to zlib until you get an object back, or it errors on bad data. This is done here by just giving the complete buffer from the start of the deflated object on. This is bad, but until I get mmap sorted out it will have to do.

Currently there are no integrity checks done. Also no attempt is made to try and detect the delta case, or a request for an object at the wrong position. It will all just throw a zlib or KeyError.

Class Method from_file Undocumented
Class Method from_path Undocumented
Method __enter__ Undocumented
Method __eq__ Undocumented
Method __exit__ Undocumented
Method __init__ Create a PackData object representing the pack in the given filename.
Method __len__ Returns the number of objects in this pack.
Method calculate_checksum Calculate the checksum for this pack.
Method check Check the consistency of this pack.
Method close Undocumented
Method create_index Create an index file for this data file.
Method create_index_v1 Create a version 1 file for this data file.
Method create_index_v2 Create a version 2 index file for this data file.
Method get_compressed_data_at Given offset in the packfile return compressed data that is there.
Method get_object_at Given an offset in to the packfile return the object that is there.
Method get_stored_checksum Return the expected checksum stored in this pack.
Method iterentries Yield entries summarizing the contents of this pack.
Method iterobjects Undocumented
Method sorted_entries Return entries in this pack, sorted by SHA.
Property filename Undocumented
Property path Undocumented
Method _get_size Undocumented
Method _iter_unpacked Undocumented
Instance Variable _file Undocumented
Instance Variable _filename Undocumented
Instance Variable _header_size Undocumented
Instance Variable _num_objects Undocumented
Instance Variable _offset_cache Undocumented
Instance Variable _size Undocumented
@classmethod
def from_file(cls, file, size=None):

Undocumented

@classmethod
def from_path(cls, path):

Undocumented

def __enter__(self):

Undocumented

def __eq__(self, other):

Undocumented

def __exit__(self, exc_type, exc_val, exc_tb):

Undocumented

def __init__(self, filename, file=None, size=None):

Create a PackData object representing the pack in the given filename.

The file must exist and stay readable until the object is disposed of. It must also stay the same size. It will be mapped whenever needed.

Currently there is a restriction on the size of the pack as the python mmap implementation is flawed.

def __len__(self):

Returns the number of objects in this pack.

def calculate_checksum(self):

Calculate the checksum for this pack.

Returns: 20-byte binary SHA1 digest

def check(self):

Check the consistency of this pack.

def close(self):

Undocumented

def create_index(self, filename, progress=None, version=2, resolve_ext_ref=None):

Create an index file for this data file.

Returns: Checksum of index file

Parameters
filenameIndex filename.
progressProgress report function
versionUndocumented
resolve_ext_refUndocumented
def create_index_v1(self, filename, progress=None, resolve_ext_ref=None):

Create a version 1 file for this data file.

Returns: Checksum of index file

Parameters
filenameIndex filename.
progressProgress report function
resolve_ext_refUndocumented
def create_index_v2(self, filename, progress=None, resolve_ext_ref=None):

Create a version 2 index file for this data file.

Returns: Checksum of index file

Parameters
filenameIndex filename.
progressProgress report function
resolve_ext_refUndocumented
def get_compressed_data_at(self, offset):

Given offset in the packfile return compressed data that is there.

Using the associated index the location of an object can be looked up, and then the packfile can be asked directly for that object using this function.

def get_object_at(self, offset):

Given an offset in to the packfile return the object that is there.

Using the associated index the location of an object can be looked up, and then the packfile can be asked directly for that object using this function.

def get_stored_checksum(self):

Return the expected checksum stored in this pack.

def iterentries(self, progress=None, resolve_ext_ref=None):

Yield entries summarizing the contents of this pack.

Returns: iterator of tuples with (sha, offset, crc32)

Parameters
progressProgress function, called with current and total object count.
resolve_ext_refUndocumented
def iterobjects(self, progress=None, compute_crc32=True):

Undocumented

def sorted_entries(self, progress=None, resolve_ext_ref=None):

Return entries in this pack, sorted by SHA.

Returns: Iterator of tuples with (sha, offset, crc32)

Parameters
progressProgress function, called with current and total object count
resolve_ext_refUndocumented
@property
filename =

Undocumented

@property
path =

Undocumented

def _get_size(self):

Undocumented

def _iter_unpacked(self):

Undocumented

_file =

Undocumented

_filename =

Undocumented

_header_size: int =

Undocumented

_num_objects =

Undocumented

_offset_cache =

Undocumented

_size =

Undocumented