class documentation

A git SHA file.

Class Method from_file Get the contents of a SHA file on disk.
Class Method from_path Open a SHA file from disk.
Class Method from_string Create a ShaFile from a string.
Static Method from_raw_chunks Creates an object of the indicated type from the raw chunks given.
Static Method from_raw_string Creates an object of the indicated type from the raw string given.
Method __bytes__ Return raw string serialization of this object.
Method __eq__ Return True if the SHAs of the two objects match.
Method __hash__ Return unique hash for this object.
Method __init__ Initialize a ShaFile.
Method __le__ Check whether SHA of this object is less than or equal to the other.
Method __lt__ Return whether SHA of this object is less than the other.
Method __ne__ Check whether this object does not match the other.
Method __repr__ Return string representation of this object.
Method as_legacy_object Return string representing the object in the experimental format.
Method as_legacy_object_chunks Return chunks representing the object in the experimental format.
Method as_pretty_string Return a string representing this object, fit for display.
Method as_raw_chunks Return chunks with serialization of the object.
Method as_raw_string Return raw string with serialization of the object.
Method check Check this object for internal consistency.
Method copy Create a new copy of this SHA1 object from its raw string.
Method get_id Get the hex SHA of this object using the specified hash algorithm.
Method raw_length Returns the length of the raw string of this object.
Method set_raw_chunks Set the contents of this object from a list of chunks.
Method set_raw_string Set the contents of this object from a serialized string.
Method sha The SHA object that is the name of this object.
Class Variable __slots__ Undocumented
Class Variable type_name Undocumented
Class Variable type_num Undocumented
Instance Variable object_format Undocumented
Property id The hex SHA1 of this object.
Class Method _is_legacy_object Undocumented
Class Method _parse_file Undocumented
Static Method _parse_legacy_object_header Parse a legacy object, creating it but not reading the file.
Static Method _parse_object_header Parse a new style object, creating it but not reading the file.
Method _check_has_member Check that the object has a given member variable.
Method _deserialize Undocumented
Method _header Undocumented
Method _parse_legacy_object Parse a legacy object, setting the raw string.
Method _parse_object Parse a new style object, setting self._text.
Method _serialize Undocumented
Instance Variable _chunked_text Undocumented
Instance Variable _needs_serialization Undocumented
Instance Variable _sha Undocumented
def from_file(cls, f: BufferedIOBase | IO[bytes] | _GitFile, sha: ObjectID | None = None, *, object_format: ObjectFormat | None = None) -> ShaFile:

Get the contents of a SHA file on disk.

def from_path(cls, path: str | bytes, sha: ObjectID | None = None, *, object_format: ObjectFormat | None = None) -> ShaFile:
def from_string(cls, string: bytes) -> Self:

Create a ShaFile from a string.

def from_raw_chunks(type_num: int, chunks: list[bytes], sha: ObjectID | RawObjectID | None = None) -> ShaFile:

Creates an object of the indicated type from the raw chunks given.

Parameters
type_num:intThe numeric type of the object.
chunks:list[bytes]An iterable of the raw uncompressed contents.
sha:ObjectID | RawObjectID | NoneOptional known sha for the object
Returns
ShaFileUndocumented
def from_raw_string(type_num: int, string: bytes, sha: ObjectID | RawObjectID | None = None, *, object_format: ObjectFormat | None = None) -> ShaFile:

Creates an object of the indicated type from the raw string given.

Parameters
type_num:intThe numeric type of the object.
string:bytesThe raw uncompressed contents.
sha:ObjectID | RawObjectID | NoneOptional known sha for the object
object_format:ObjectFormat | NoneOptional hash algorithm for the object
Returns
ShaFileUndocumented
def __bytes__(self) -> bytes:

Return raw string serialization of this object.

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

Return True if the SHAs of the two objects match.

def __hash__(self) -> int:

Return unique hash for this object.

def __init__(self):
def __le__(self, other: object) -> bool:

Check whether SHA of this object is less than or equal to the other.

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

Return whether SHA of this object is less than the other.

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

Check whether this object does not match the other.

def __repr__(self) -> str:

Return string representation of this object.

def as_legacy_object(self, compression_level: int = -1) -> bytes:

Return string representing the object in the experimental format.

def as_legacy_object_chunks(self, compression_level: int = -1) -> Iterator[bytes]:

Return chunks representing the object in the experimental format.

Returns: List of strings

def as_pretty_string(self) -> str:
overridden in dulwich.objects.Tree

Return a string representing this object, fit for display.

def as_raw_chunks(self) -> list[bytes]:

Return chunks with serialization of the object.

Returns: List of strings, not necessarily one per line

def as_raw_string(self) -> bytes:

Return raw string with serialization of the object.

Returns: String object

def check(self):

Check this object for internal consistency.

Raises
ObjectFormatExceptionif the object is malformed in some way
ChecksumMismatchif the object was created with a SHA that does not match its contents
def copy(self) -> ShaFile:

Create a new copy of this SHA1 object from its raw string.

def get_id(self, object_format: ObjectFormat | None = None) -> bytes:

Get the hex SHA of this object using the specified hash algorithm.

Example

>>> blob = Blob()
>>> blob.data = b"Hello, World!"
>>> blob.id  # Always returns SHA1 for backward compatibility
b'4ab299c8ad6ed14f31923dd94f8b5f5cb89dfb54'
>>> blob.get_id()  # Same as .id
b'4ab299c8ad6ed14f31923dd94f8b5f5cb89dfb54'
>>> from dulwich.object_format import SHA256
>>> blob.get_id(SHA256)  # Get SHA256 hash
b'03ba204e2f2e707...'  # 64-character SHA256
Parameters
object_format:ObjectFormat | NoneOptional HashAlgorithm to use. Defaults to SHA1.
Returns
bytesUndocumented
def raw_length(self) -> int:

Returns the length of the raw string of this object.

def set_raw_chunks(self, chunks: list[bytes], sha: ObjectID | RawObjectID | None = None, *, object_format: ObjectFormat | None = None):

Set the contents of this object from a list of chunks.

def set_raw_string(self, text: bytes, sha: ObjectID | RawObjectID | None = None):

Set the contents of this object from a serialized string.

def sha(self, object_format: ObjectFormat | None = None) -> FixedSha | HASH:

The SHA object that is the name of this object.

Parameters
object_format:ObjectFormat | NoneOptional HashAlgorithm to use. Defaults to SHA1.
Returns
FixedSha | HASHUndocumented
object_format: ObjectFormat =

Undocumented

The hex SHA1 of this object.

For SHA256 repositories, use get_id(object_format) instead. This property always returns SHA1 for backward compatibility.

def _is_legacy_object(cls, magic: bytes) -> bool:

Undocumented

def _parse_file(cls, f: BufferedIOBase | IO[bytes] | _GitFile, *, object_format: ObjectFormat | None = None) -> ShaFile:

Undocumented

def _parse_legacy_object_header(magic: bytes, f: BufferedIOBase | IO[bytes] | _GitFile) -> ShaFile:

Parse a legacy object, creating it but not reading the file.

def _parse_object_header(magic: bytes, f: BufferedIOBase | IO[bytes] | _GitFile) -> ShaFile:

Parse a new style object, creating it but not reading the file.

def _check_has_member(self, member: str, error_msg: str):

Check that the object has a given member variable.

Parameters
member:strthe member variable to check for
error_msg:strthe message for an error if the member is missing
Raises
ObjectFormatExceptionwith the given error_msg if member is missing or is None
def _deserialize(self, chunks: list[bytes]):
def _header(self) -> bytes:

Undocumented

def _parse_legacy_object(self, map: bytes):

Parse a legacy object, setting the raw string.

def _parse_object(self, map: bytes):

Parse a new style object, setting self._text.

_chunked_text: list[bytes] | None =
overridden in dulwich.objects.Blob

Undocumented

_sha: FixedSha | None | HASH =

Undocumented