
    .Ph"                        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dS )!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           
      v   t          d          }d}| D ]\  }}}d}t          d          D ]!}t          ||dz  z	  |z  |z   g          |z   }"|d         |k    r
|dd         }t          |t                    r|                    t                    }	n|}	 |d                    |d	|	d
|f                     dS )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
             O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/git/objects/fun.pyr   r   )   s     3xxHH% E Edq 	U 	UAQ8;xGHIIHTHH A;(""|H dC   	V,,JJJchh$
E6BCCDDDD)E Er   datac                    t          d          }t          d          }t          |           }d}g }||k     rd}| |         |k    r"|dz  | |         |z
  z   }|dz  }| |         |k    "|dz  }|}| |         dk    r|dz  }| |         dk    | ||         }t          |          }	|dz  }| ||dz            }
|dz   }|                    |
||	f           ||k     |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'    3xxHCI4yyH	A
C
h,,
 1g"" AI$q'H"45DFA	 1g"" 	
Q 1gllFA 1gll "Q$Z
:&& 	
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 n# t          $ r Y nw xY wt          |           D ]5\  }}|r.|d         |k    r"t          |d                   |k    r	d| |<   |c S 6dS )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GtOOQ(8(8F(B(B"&IhK    !++  t 	DGtOOQ(8(8F(B(B#IeKKK 4s   59 
AArB   path_prefixc                     d S N rB   rE   s     r/   _to_full_pathrJ      s    9<r   c                     d S rG   rH   rI   s     r/   rJ   rJ      s    ADr   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 ]]}|g }nAt          t          |                     |                                                              }|                    |           ^g }t          |          D ]\  }}	t          |	          D ]\  }
}|sd t          |          D             }|||<   |\  }}}t          |          }t          |dz   ||z             D ]"}||z  }t          ||         |||
          ||<   #|r5|
                    t          | d |D             |z   dz                        n.|                    t          fd|D                                  d|	|
<   |	dd= |S )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.
    Nc                     g | ]}d S rG   rH   ).0_s     r/   
<listcomp>z,traverse_trees_recursive.<locals>.<listcomp>   s    ///t///r   r   c                 &    g | ]}|r|d          pdS )r   NrH   )rQ   eis     r/   rS   z,traverse_trees_recursive.<locals>.<listcomp>   s%    DDDb2<"Q%0DDDDr   /c              3   8   K   | ]}t          |          V  d S rG   )rJ   )rQ   erE   s     r/   	<genexpr>z+traverse_trees_recursive.<locals>.<genexpr>   s-       P P1q+!>!> P P P P P Pr   )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<   tios     `               r/   r   r      s   8 .0J	YB    )+DD .szz(/C/C/H/H/J/JKKLLD$ -/C
 #:.. % %I!),,  	!  	!HB  0/U2YY///GGBK#D$T]]F
 R!VR"W-- P PBh,Z_dFBOO  	R

,DDGDDD#d*S0     

5 P P P P P P PPPQQQ !IbMM aaaLLJr   ra   c           	      .   g }t          |                     |                                                    }|D ][\  }}}t          |          r+|                    t          | |||z   dz                        @|                    ||||z   f           \|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.
    rV   )r   r[   r\   r   r]   r   r5   )rM   ra   rE   r   r0   r:   r*   r+   s           r/   r   r      s     G!#**X"6"6";";"="=>>D   < <T44== 	<NN23[4=ORU=UVVWWW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>rr      s   = <         * * * * * * * *	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  #((((((""""""S!x~&
 EHX.  ExAQ@RTYZ]_cZcTd@d7e  Ejn  E  E  E  EH1 14> 1 1 1 1h_^< C QU ad iw    0 
 < <3 <4 < < < 
 < 
 D Ds Dx D D D 
 D5 5S 5^ 5 5 5 5U	U&.uUD[/A&BUQTU	%#
$%U U U Up!1 U QT Y]^fYg      r   