
    g"                        d Z g dZddlmZ ddlmZmZ ddlmZm	Z	m
Z
mZmZmZmZmZ erddlmZ ddlmZ eeeef   Zeedf   Zd	ee   d
edgeedf   f   ddfdZdede	e   fdZde
e   dedededef
dZedddeddfd       Zedededefd       ZdededefdZdddeeedf      dede	eedf      fdZdddedede	e   fd Zy)!z6Functions that are supposed to be as fast as possible.)tree_to_streamtree_entries_from_datatraverse_trees_recursivetraverse_tree_recursive    )S_ISDIR)safe_decodedefenc)CallableListMutableSequenceSequenceTupleTYPE_CHECKINGUnionoverload)ReadableBuffer)GitCmdObjectDBNentrieswriter   returnc           
      0   t        d      }d}| D ]  \  }}}d}t        d      D ]  }t        ||dz  z	  |z  |z   g      |z   } |d   |k(  r|dd }t        |t              r|j                  t              }	n|}	 |dj                  |d	|	d
|f              y)zWrite the given list of entries into a stream using its ``write`` method.

    :param entries:
        **Sorted** list of tuples with (binsha, mode, name).

    :param write:
        A ``write`` method which takes a data string.
    0             r      N        )ordrangebytes
isinstancestrencoder	   join)
r   r   ord_zerobit_maskbinshamodenamemode_stri
name_bytess
             D/var/www/openai/venv/lib/python3.12/site-packages/git/objects/fun.pyr   r   )   s     3xHH%dqAQ8;xGHIHTH 
 A;("|H dC V,JJchh$
E6BCD) &r   datac                 X   t        d      }t        d      }t        |       }d}g }||k  rd}| |   |k7  r|dz  | |   |z
  z   }|dz  }| |   |k7  r|dz  }|}| |   dk7  r|dz  }| |   dk7  r| || }t        |      }	|dz  }| ||dz    }
|dz   }|j                  |
||	f       ||k  r|S )zRead the binary representation of a tree and returns tuples of
    :class:`~git.objects.tree.Tree` items.

    :param data:
        Data block with tree data (as bytes).

    :return:
        list(tuple(binsha, mode, tree_relative_path), ...)
    r    r   r   r      )r    lenr   append)r0   r'   	space_ordlen_datar-   outr*   nsr.   r+   shas              r/   r   r   M   s    3xHCI4yH	A
C
h,
 1g" AI$q'H"45DFA	 1g" 	
Q 1glFA 1gl "QZ
:& 	
Q1q2vF

Ct$%A h,D Jr   	tree_datar+   is_dirstart_atc                     	 | |   }|r |d   |k(  rt        |d         |k(  rd| |<   |S t        |       D ]+  \  }}|s	|d   |k(  st        |d         |k(  s$d| |<   |c S  y# t        $ r Y Ew xY w)zReturn data entry matching the given name and tree mode or ``None``.

    Before the item is returned, the respective data item is set None in the `tree_data`
    list to mark it done.
       r   N)r   
IndexError	enumerate)r;   r+   r<   r=   itemindexs         r/   _find_by_namerD      s    "DGtOQ(8F(B"&IhK !+tDGtOQ(8F(B#IeK ,   s   &A# #	A/.A/rB   path_prefixc                      y N rB   rE   s     r/   _to_full_pathrJ      s    9<r   c                      y rG   rH   rI   s     r/   rJ   rJ      s    ADr   c                 ,    | s| S | d   | d   || d   z   fS )z%Rebuild entry with given path prefix.r   r   r?   rH   rI   s     r/   rJ   rJ      s(    GT!WkDG344r   odbr   	tree_shas.c                    g }t        |      }|D ]I  }|g }n1t        t        | j                  |      j	                                     }|j                  |       K g }t        |      D ]  \  }}	t        |	      D ]  \  }
}|s	t        |      D cg c]  }d }}|||<   |\  }}}t        |      }t        |dz   ||z         D ]  }||z  }t        ||   |||
      ||<    |r<|j                  t        | |D cg c]  }|xr |d   xs d c}|z   dz                n#|j                  t        fd|D                     d|	|
<    |	dd=  |S c c}w c c}w )a%  
    :return:
        List of list with entries according to the given binary tree-shas.

        The result is encoded in a list
        of n tuple|None per blob/commit, (n == len(tree_shas)), where:

        * [0] == 20 byte sha
        * [1] == mode as int
        * [2] == path relative to working tree root

        The entry tuple is ``None`` if the respective blob/commit did not exist in the
        given tree.

    :param tree_shas:
        Iterable of shas pointing to trees. All trees must be on the same level.
        A tree-sha may be ``None``, in which case ``None``.

    :param path_prefix:
        A prefix to be added to the returned paths on this level.
        Set it ``""`` for the first iteration.

    :note:
        The ordering of the returned items will be partially lost.
    Nr   r   /c              3   6   K   | ]  }t        |        y wrG   )rJ   ).0erE   s     r/   	<genexpr>z+traverse_trees_recursive.<locals>.<genexpr>   s      P1q+!>s   )r4   listr   streamreadr5   rA   r!   r   rD   extendr   tuple)rM   rN   rE   
trees_datanttree_shar0   r8   tir;   iirB   _r   _shar*   r+   r<   tioeis     `                 r/   r   r      s   8 .0J	YB)+D .szz(/C/H/H/JKLD$  -/C
 #:.I!),HB &+2Y/YtYG/GBK#D$T]F
 R!VR"W-Bh,Z_dFBO . 

,<CDGb2<"Q%0D0GD#d*S0 

5 P PPQ !IbMA -H aLK /N JC 0$ Es   	E9Er\   c           	          g }t        | j                  |      j                               }|D ]K  \  }}}t        |      r#|j	                  t        | |||z   dz                5|j                  ||||z   f       M |S )aA  
    :return:
        List of entries of the tree pointed to by the binary `tree_sha`.

        An entry has the following format:

        * [0] 20 byte sha
        * [1] mode as int
        * [2] path relative to the repository

    :param path_prefix:
        Prefix to prepend to the front of all returned paths.
    rP   )r   rV   rW   r   rX   r   r5   )rM   r\   rE   r   r0   r:   r*   r+   s           r/   r   r      s~     G!#**X"6";";"=>D  T44=NN23[4=ORU=UVWNNC{T'9:;	   Nr   ) __doc____all__statr   
git.compatr   r	   typingr
   r   r   r   r   r   r   r   	_typeshedr   gitr   r"   intr$   EntryTupEntryTupOrNoner   r   boolrD   rJ   r   r   rH   r   r/   <module>ro      s   =  *	 	 	 ("S!x~&
 EHX.  ExAQ@RTYZ]_cZcTd@d7e  Ejn  EH1 14> 1h_^< C QU ad iw 0 
 < <3 <4 < 
 < 
 D Ds Dx D 
 D5 5S 5^ 5U	U&.uUD[/A&BUQTU	%#
$%Up!1 U QT Y]^fYg r   