Classes for dealing with packed git objects.
A pack is a compact representation of a bunch of objects, stored using deltas where possible.
They have two parts, the pack file, which stores the data, and an index that tells you where the data is.
To find an object you look in all of the index files 'til you find a match for the object name. You then use the pointer got from this as a pointer in to the corresponding packfile.
Class |
|
Abstract iterator over pack data based on delta chains. |
Class |
|
Pack index that is based on a file. |
Class |
|
Pack index that is stored entirely in memory. |
Class |
|
A Git pack object. |
Class |
|
No class docstring; 0/3 instance variable, 1/4 method documented |
Class |
|
The data contained in a packfile. |
Class |
|
An index in to a packfile. |
Class |
|
Version 1 Pack Index file. |
Class |
|
Version 2 Pack Index file. |
Class |
|
Delta chain iterator that yields index entries. |
Class |
|
Delta chain iterator that yields ShaFile objects. |
Class |
|
Class to verify a pack stream as it is being read. |
Class |
|
Class to read a pack stream. |
Class |
|
Wrapper for file-like object that remembers the SHA1 of its data. |
Class |
|
Wrapper for file-like object that remembers the SHA1 of its data. |
Class |
|
Class encapsulating an object unpacked from a pack file. |
Exception |
|
Undocumented |
Function | apply |
Based on the similar function in git's patch-delta.c. |
Function | bisect |
Find a SHA in a data blob with sorted SHAs. |
Function | chunks |
Undocumented |
Function | compute |
Hash a portion of a file into a new SHA. |
Function | create |
Use python difflib to work out how to transform base_buf to target_buf. |
Function | deltify |
Generate deltas for pack objects. |
Function | iter |
Return the hexdigest of the SHA1 over a set of names. |
Function | load |
Load an index file by path. |
Function | load |
Load an index file from a file-like object. |
Function | obj |
Compute the SHA for a numeric type and object chunks. |
Function | pack |
Yield chunks for a pack header. |
Function | pack |
Generate chunks for a pack object. |
Function | pack |
Create a pack object header for the given object info. |
Function | pack |
Create pack data from objects |
Function | read |
Read the header of a pack file. |
Function | read |
Read zlib data from a buffer. |
Function | take |
Read bytes marked with most significant bit. |
Function | unpack |
Unpack a Git object. |
Function | write |
Write a new pack data file. |
Function | write |
Write a new pack data file. |
Function | write |
Write a pack header for the given number of objects. |
Function | write |
Write a new pack index file. |
Function | write |
Write a new pack index file. |
Function | write |
Write pack object to a file. |
Function | write |
Write a new pack data file. |
Constant | DEFAULT |
Undocumented |
Constant | DELTA |
Undocumented |
Constant | OFS |
Undocumented |
Constant | REF |
Undocumented |
Variable | has |
Undocumented |
Class | _ |
Helper for Pack.pack_tuples. |
Function | _compute |
Compute the size of a unresolved object for use with LRUSizeCache. |
Function | _delta |
Undocumented |
Function | _encode |
Undocumented |
Function | _load |
Undocumented |
Constant | _MAX |
Undocumented |
Constant | _ZLIB |
Undocumented |
Based on the similar function in git's patch-delta.c.
Parameters | |
src | Source buffer |
delta | Delta instructions |
Find a SHA in a data blob with sorted SHAs.
Returns: Index of the SHA, or None if it wasn't found
Parameters | |
start | Start index of range to search |
end | End index of range to search |
sha | Sha to find |
unpack | Callback to retrieve SHA by index |
Hash a portion of a file into a new SHA.
Returns: A new SHA object updated with data read from the file.
Parameters | |
f | A file-like object to read from that supports seek(). |
start | The offset in the file to start reading at. |
end | The offset in the file to end reading at, relative to the end of the file. |
buffer | A buffer size for reading. |
Use python difflib to work out how to transform base_buf to target_buf.
Parameters | |
base | Base buffer |
target | Target buffer |
Generate deltas for pack objects.
- Returns: Iterator over type_num, object id, delta_base, content
- delta_base is None for full text entries
Parameters | |
objects | An iterable of (object, path) tuples to deltify. |
window | Window size; None for default |
Return the hexdigest of the SHA1 over a set of names.
Returns: 40-byte hex sha1 digest
Parameters | |
iter | Iterator over string objects |
Load an index file by path.
Returns: A PackIndex loaded from the given path
Parameters | |
path | Path to the index file |
Load an index file from a file-like object.
Returns: A PackIndex loaded from the given file
Parameters | |
path | Path for the index file |
f | File-like object |
Generate chunks for a pack object.
Returns: Chunks
Parameters | |
type | Numeric type of the object |
object | Object to write |
compression | the zlib compression level |
Create a pack object header for the given object info.
Returns: A header for a packed object.
Parameters | |
type | Numeric type of the object. |
delta | Delta base offset or ref, or None for whole objects. |
size | Uncompressed object size. |
Create pack data from objects
Returns: Tuples with (type_num, hexdigest, delta base, object chunks)
Parameters | |
objects | Pack objects |
Read the header of a pack file.
- Returns: Tuple of (pack version, number of objects). If no data is
- available to read, returns (None, None).
Parameters | |
read | Read function |
Read zlib data from a buffer.
This function requires that the buffer have additional data following the compressed data, which is guaranteed to be the case for git pack files.
Returns: Leftover unused data from the decompression.
Parameters | |
read | Read function that returns at least one byte, but may return less than the requested size. |
unpacked | An UnpackedObject to write result data to. If its crc32 attr is not None, the CRC32 of the compressed bytes will be computed using this starting CRC32. After this function, will have the following attrs set: * comp_chunks (if include_comp is True) * decomp_chunks * decomp_len * crc32 |
include | If True, include compressed data in the result. |
buffer | Size of the read buffer. |
Raises | |
zlib.error | if a decompression error occurred. |
Unpack a Git object.
- Returns: A tuple of (unpacked, unused), where unused is the unused data
leftover from decompression, and unpacked in an UnpackedObject with the following attrs set:
- obj_chunks (for non-delta types)
- pack_type_num
- delta_base (for delta types)
- comp_chunks (if include_comp is True)
- decomp_chunks
- decomp_len
- crc32 (if compute_crc32 is True)
Parameters | |
read | Read function that blocks until the number of requested bytes are read. |
read | Read function that returns at least one byte, but may not return the number of bytes requested. |
compute | If True, compute the CRC32 of the compressed data. If False, the returned CRC32 will be None. |
include | If True, include compressed data in the result. |
zlib | An optional buffer size for zlib operations. |
Write a new pack data file.
Returns: Tuple with checksum of pack file and index file
Parameters | |
filename | Path to the new pack file (without .pack extension) |
objects | (object, path) tuple iterable to write. Should provide __len__ |
deltify | Whether to deltify pack objects |
delta | Delta window size |
compression | the zlib compression level |
Write a new pack data file.
Returns: Dict mapping id -> (offset, crc32 checksum), pack checksum
Parameters | |
write | Write function to use |
num | Number of records (defaults to len(records) if None) |
records | Iterator over type_num, object_id, delta_base, raw |
progress | Function to report progress to |
compression | the zlib compression level |
Write a new pack index file.
Returns: The SHA of the written index file
Parameters | |
f | A file-like object to write to |
entries | List of tuples with object name (sha), offset_in_pack, and crc32_checksum. |
pack | Checksum of the pack file. |
Write a new pack index file.
Returns: The SHA of the index file written
Parameters | |
f | File-like object to write to |
entries | List of tuples with object name (sha), offset_in_pack, and crc32_checksum. |
pack | Checksum of the pack file. |
Write pack object to a file.
Returns: Tuple with offset at which the object was written, and crc32
Parameters | |
write | Write function to use |
type | Numeric type of the object |
object | Object to write |
sha | Undocumented |
compression | the zlib compression level |
Write a new pack data file.
Returns: Dict mapping id -> (offset, crc32 checksum), pack checksum
Parameters | |
write | write function to use |
objects | Iterable of (object, path) tuples to write. Should provide __len__ |
delta | Sliding window size for searching for deltas; Set to None for default window size. |
deltify | Whether to deltify objects |
compression | the zlib compression level to use |