class documentation

A Git tree object.

Class Method from_path Read a tree from a file on disk.
Method __contains__ Check if name exists in tree.
Method __delitem__ Delete tree entry by name.
Method __getitem__ Get tree entry by name.
Method __init__ Initialize an empty Tree.
Method __iter__ Iterate over tree entry names.
Method __len__ Return number of entries in tree.
Method __setitem__ Set a tree entry by name.
Method add Add an entry to the tree.
Method as_pretty_string Return a human-readable string representation of this tree.
Method check Check this object for internal consistency.
Method items Return the sorted entries in this tree.
Method iteritems Iterate over entries.
Method lookup_path Look up an object in a Git tree.
Class Variable __slots__ Undocumented
Class Variable type_name Undocumented
Class Variable type_num Undocumented
Method _deserialize Grab the entries in the tree.
Method _serialize Undocumented
Instance Variable _entries Undocumented
Instance Variable _needs_serialization Undocumented

Inherited from ShaFile:

Class Method from_file Get the contents of a SHA file on 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 __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_raw_chunks Return chunks with serialization of the object.
Method as_raw_string Return raw string with serialization of the object.
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.
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 _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.
Instance Variable _chunked_text Undocumented
Instance Variable _sha Undocumented
def from_path(cls, filename: str | bytes, sha: ObjectID | None = None, *, object_format: ObjectFormat | None = None) -> Tree:

Read a tree from a file on disk.

Parameters
filename:str | bytesPath to the tree file
sha:ObjectID | NoneOptional known SHA for the object
object_format:ObjectFormat | NoneOptional object format to use
Returns
TreeA Tree object
Raises
NotTreeErrorIf the file is not a tree
def __contains__(self, name: bytes) -> bool:

Check if name exists in tree.

def __delitem__(self, name: bytes):

Delete tree entry by name.

def __getitem__(self, name: bytes) -> tuple[int, ObjectID]:

Get tree entry by name.

def __init__(self):

Initialize an empty Tree.

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

Iterate over tree entry names.

def __len__(self) -> int:

Return number of entries in tree.

def __setitem__(self, name: bytes, value: tuple[int, ObjectID]):

Set a tree entry by name.

Parameters
name:bytesThe name of the entry, as a string.
value:tuple[int, ObjectID]A tuple of (mode, hexsha), where mode is the mode of the entry as an integral type and hexsha is the hex SHA of the entry as a string.
def add(self, name: bytes, mode: int, hexsha: ObjectID):

Add an entry to the tree.

Parameters
name:bytesThe name of the entry, as a string.
mode:intThe mode of the entry as an integral type. Not all possible modes are supported by git; see check() for details.
hexsha:ObjectIDThe hex SHA of the entry as a string.
def as_pretty_string(self) -> str:

Return a human-readable string representation of this tree.

Returns
strPretty-printed tree entries
def check(self):

Check this object for internal consistency.

Raises
ObjectFormatExceptionif the object is malformed in some way
def items(self) -> list[TreeEntry]:

Return the sorted entries in this tree.

Returns: List with (name, mode, sha) tuples

def iteritems(self, name_order: bool = False) -> Iterator[TreeEntry]:

Iterate over entries.

Returns: Iterator over (name, mode, sha) tuples

Parameters
name_order:boolIf True, iterate in name order instead of tree order.
Returns
Iterator[TreeEntry]Undocumented
def lookup_path(self, lookup_obj: Callable[[ObjectID], ShaFile], path: bytes) -> tuple[int, ObjectID]:

Look up an object in a Git tree.

Returns: A tuple of (mode, SHA) of the resulting path.

Parameters
lookup_obj:Callable[[ObjectID], ShaFile]Callback for retrieving object by SHA1
path:bytesPath to lookup
Returns
tuple[int, ObjectID]Undocumented
__slots__: str =

Undocumented

type_name: bytes =

Undocumented

type_num: int =

Undocumented

def _deserialize(self, chunks: list[bytes]):

Grab the entries in the tree.

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

Undocumented

_entries: dict[bytes, tuple[int, ObjectID]] =

Undocumented

_needs_serialization: bool =