o
    ﯪg6                     @   st  U d dgZ ddlZddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZmZmZmZmZmZmZmZmZmZm Z  ej!dkraddlm"Z" nddl#m"Z" ddl$m%Z% er{ddl&m'Z' ddl(m)Z) ee*e+e,f Z-eeed eed f  Z.dd Z/ee,e,ge+f e0d< G dd  d Z1G dd deej2e
j3e
j4Z5e5e5j6e5j7< dS )TreeModifierTree    N)IterableList	join_path
to_bin_sha   )util)IndexObjUnionIndexObject)Blob)tree_entries_from_datatree_to_stream)	Submodule)AnyCallableDictIterableIteratorListTupleTYPE_CHECKINGTypeUnioncast)      )Literal)PathLike)BytesIO)Repo)r   N)r   r   c                 C   s   | |k| |k  S N )abr!   r!   L/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/git/objects/tree.py<lambda>5   s    r%   cmpc                   @   s   e Zd ZdZdZdee ddfddZdede	fd	d
Z
dddZddede	dededd f
ddZdede	deddfddZdeddfddZdS )r   a  A utility class providing methods to alter the underlying cache in a list-like
    fashion.

    Once all adjustments are complete, the :attr:`_cache`, which really is a reference
    to the cache of a tree, will be sorted. This ensures it will be in a serializable
    state.
    _cachecachereturnNc                 C   s
   || _ d S r    r'   )selfr)   r!   r!   r$   __init__C      
zTreeModifier.__init__namec                 C   s,   t | jD ]\}}|d |kr|  S qdS )z7:return: index of an item with name, or -1 if not found   )	enumerater(   )r+   r.   itr!   r!   r$   _index_by_nameF   s
   zTreeModifier._index_by_namec                 C   s   | j jdd d | S )zCall this method once you are done modifying the tree information.

        This may be called several times, but be aware that each call will cause a sort
        operation.

        :return:
            self
        c                 S   s&   | d t jd> kr| d d S | d S )Nr      r/   /)r   tree_id)xr!   r!   r$   r%   Y   s   & z'TreeModifier.set_done.<locals>.<lambda>)key)r(   sortr+   r!   r!   r$   set_doneP   s   	zTreeModifier.set_doneFshamodeforcec                 C   s   d|v rt d|d? tjvrt d| t|}| |}|||f}|dkr/| j| | S |r8|| j|< | S | j| }|d |ksI|d |krOt d| | S )	a  Add the given item to the tree.

        If an item with the given name already exists, nothing will be done, but a
        :exc:`ValueError` will be raised if the sha and mode of the existing item do not
        match the one you add, unless `force` is ``True``.

        :param sha:
            The 20 or 40 byte sha of the item to add.

        :param mode:
            :class:`int` representing the stat-compatible mode of the item.

        :param force:
            If ``True``, an item with your name and information will overwrite any
            existing item with the same name, no matter which information it has.

        :return:
            self
        r6   z$Name must not contain '/' charactersr5   z(Invalid object type according to mode %or0   r   r   z)Item %r existed with different properties)
ValueErrorr   _map_id_to_typer   r4   r(   append)r+   r=   r>   r.   r?   indexitemex_itemr!   r!   r$   add_   s"   



zTreeModifier.addbinshac                 C   s<   t |trt |trt |tsJ |||f}| j| dS )a  Add the given item to the tree. Its correctness is assumed, so it is the
        caller's responsibility to ensure that the input is correct.

        For more information on the parameters, see :meth:`add`.

        :param binsha:
            20 byte binary sha.
        N)
isinstancebytesintstrr(   rB   )r+   rG   r>   r.   
tree_cacher!   r!   r$   add_unchecked   s   "	
zTreeModifier.add_uncheckedc                 C   s"   |  |}|dkr| j|= dS dS )z0Delete an item with the given name if it exists.r0   N)r4   r(   )r+   r.   rC   r!   r!   r$   __delitem__   s   
zTreeModifier.__delitem__)r*   r   )F)__name__
__module____qualname____doc__	__slots__r   TreeCacheTupr,   rK   rJ   r4   r<   rI   boolrF   rM   rN   r!   r!   r!   r$   r   8   s    

 ,c                       sx  e Zd ZU dZdZed ed< dZdZdZ	dZ
dZeee	ee
eiZeeee f ed	< ed
> dfdddededeedf f fddZededeed ed f fddZdeddf fddZdee dee fddZdedefd d!Z dedefd"d#Z!e"de#d  fd$d%Z$e"de#e fd&d'Z%e"de&fd(d)Z'd*d+ d,d+ d-d.d/d0d/fd1e(eee)f ege*f d2e(eee)f ege*f d3ed4e*d5e*d6ed7e*deee ee) f f fd8d9Z+d:e,d;e,de-e f fd<d=Z.d>ed?ede#e fd@dAZ/dee fdBdCZ0defdDdEZ1dFeeee2f defdGdHZ3dFeeef de*fdIdJZ4dee fdKdLZ5dSdOdPZ6dSdQdRZ7  Z8S )Tr   a  Tree objects represent an ordered list of :class:`~git.objects.blob.Blob`\s and
    other :class:`Tree`\s.

    See :manpage:`gitglossary(7)` on "tree object":
    https://git-scm.com/docs/gitglossary#def_tree_object

    Subscripting is supported, as with a list or dict:

    * Access a specific blob using the ``tree["filename"]`` notation.
    * You may likewise access by index, like ``blob = tree[0]``.
    treetyper'      r   
      rA   r5   Nrepor   rG   r>   pathc                    s   t  |||| d S r    )superr,   )r+   r[   rG   r>   r\   	__class__r!   r$   r,      s   zTree.__init__index_objectr*   )r   .r!   c                 C   s   |j dkrt||jS dS )NrV   r!   )rW   tuple_iter_convert_to_objectr(   )clsr`   r!   r!   r$   _get_intermediate_items   s   
zTree._get_intermediate_itemsattrc                    s:   |dkr| j j| j}t| | _d S t | d S )Nr(   )	r[   odbstreamrG   r   readr(   r]   _set_cache_)r+   re   ostreamr^   r!   r$   ri      s   zTree._set_cache_iterablec                 c   sl    |D ]0\}}}t | j|}z| j|d?  | j|||V  W q ty3 } z	td||f |d}~ww dS )zIterable yields tuples of (binsha, mode, name), which will be converted to
        the respective object representation.
        r5   z0Unknown mode %o found in tree data for path '%s'N)r   r\   rA   r[   KeyError	TypeError)r+   rk   rG   r>   r.   r\   er!   r!   r$   rb      s    zTree._iter_convert_to_objectfilec           	   	   C   s   d}d|v rA| }| }| d}t|D ]!\}}|| }|jdkr#|}q|t|d kr1t|| |  S || kr?t|| |S | jD ]#}|d |krg| j|d d?  | j|d |d t| j	|d   S qDt|| )a   Find the named object in this tree's contents.

        :return:
            :class:`~git.objects.blob.Blob`, :class:`Tree`, or
            :class:`~git.objects.submodule.base.Submodule`

        :raise KeyError:
            If the given file or tree does not exist in this tree.
        zBlob or Tree named %r not foundr6   rV   r   r/   r5   r   )
splitr1   rW   lenrl   r(   rA   r[   r   r\   )	r+   ro   msgrV   rD   tokensr2   tokeninfor!   r!   r$   join   s,   



z	Tree.joinc                 C   s
   |  |S )zaThe ``/`` operator is another syntax for joining.

        See :meth:`join` for details.
        )rv   )r+   ro   r!   r!   r$   __truediv__  s   
zTree.__truediv__c                 C      dd | D S )z?:return: list(Tree, ...) List of trees directly below this treec                 S      g | ]	}|j d kr|qS )rV   rW   .0r2   r!   r!   r$   
<listcomp>      zTree.trees.<locals>.<listcomp>r!   r;   r!   r!   r$   trees     z
Tree.treesc                 C   rx   )z?:return: list(Blob, ...) List of blobs directly below this treec                 S   ry   )blobrz   r{   r!   r!   r$   r}     r~   zTree.blobs.<locals>.<listcomp>r!   r;   r!   r!   r$   blobs  r   z
Tree.blobsc                 C   
   t | jS )a  
        :return:
            An object allowing modification of the internal cache. This can be used to
            change the tree's contents. When done, make sure you call
            :meth:`~TreeModifier.set_done` on the tree modifier, or serialization
            behaviour will be incorrect.

        :note:
            See :class:`TreeModifier` for more information on how to alter the cache.
        )r   r(   r;   r!   r!   r$   r)     s   
z
Tree.cachec                 C      dS )NTr!   r2   dr!   r!   r$   r%   /      zTree.<lambda>c                 C   r   )NFr!   r   r!   r!   r$   r%   0  r   r0   TFr   	predicateprunedepthbranch_first
visit_onceignore_selfas_edgec              
      s,   t ttt tt f t ||||||S )zFor documentation, see
        `Traversable._traverse() <git.objects.util.Traversable._traverse>`.

        Trees are set to ``visit_once = False`` to gain more performance in the
        traversal.
        )r   r   r   r	   TraversedTreeTupr]   	_traverse)r+   r   r   r   r   r   r   r   r^   r!   r$   traverse-  s   zTree.traverseargskwargsc                    s   t  j|i |S )z
        :return:
            :class:`~git.util.IterableList` with the results of the traversal as
            produced by :meth:`traverse`

            Tree -> IterableList[Union[Submodule, Tree, Blob]]
        )r]   _list_traverse)r+   r   r   r^   r!   r$   list_traverseT  s   zTree.list_traverser2   jc                 C   s   t | | j|| S r    )listrb   r(   )r+   r2   r   r!   r!   r$   __getslice__`  s   zTree.__getslice__c                 C   s   |  | jS r    )rb   r(   r;   r!   r!   r$   __iter__c  s   zTree.__iter__c                 C   r   r    )rq   r(   r;   r!   r!   r$   __len__f  r-   zTree.__len__rD   c                 C   sf   t |tr#| j| }| j|d d?  | j|d |d t| j|d S t |tr-| |S t	d| )Nr   r5   r   r/   zInvalid index type: %r)
rH   rJ   r(   rA   r[   r   r\   rK   rv   rm   )r+   rD   ru   r!   r!   r$   __getitem__i  s   

2

zTree.__getitem__c                 C   s\   t |tr| jD ]}|j|d kr dS qdS | j}| jD ]}|t||d kr+ dS qdS )Nr   Tr/   F)rH   r
   r(   rG   r\   r   )r+   rD   ru   r\   r!   r!   r$   __contains__u  s   


zTree.__contains__c                 C   s   t | | jS r    )reversedrb   r(   r;   r!   r!   r$   __reversed__  s   zTree.__reversed__rg   r   c                 C   s   t | j|j | S )a9  Serialize this tree into the stream. Assumes sorted tree data.

        :note:
            We will assume our tree data to be in a sorted state. If this is not the
            case, serialization will not generate a correct tree representation as these
            are assumed to be sorted by algorithms.
        )r   r(   writer+   rg   r!   r!   r$   
_serialize  s   zTree._serializec                 C   s   t | | _| S r    )r   rh   r(   r   r!   r!   r$   _deserialize  s   zTree._deserialize)rg   r   r*   r   )9rO   rP   rQ   rR   rW   r   __annotations__rS   	commit_idblob_id
symlink_idr7   r   r   rA   r   rJ   r   r	   rI   r   r   r,   classmethodr   rd   rK   ri   r   rT   r   rb   rv   rw   propertyr   r   r   r   r)   r   r   rU   r   r   r   r   r   r   r   slicer   r   r   r   r   __classcell__r!   r!   r^   r$   r      s   
 
		'	'
)8__all__sysgit.diffdiffgit_diffgit.utilr   r   r    r   baser	   r
   r   r   funr   r   submodule.baser   typingr   r   r   r   r   r   r   r   r   r   r   version_infor   typing_extensions	git.typesr   ior   git.repor   rI   rJ   rK   rT   r   r&   r   r   DiffableTraversableSerializabler   rA   r7   r!   r!   r!   r$   <module>   s0   
4
j }