
    64%e!                        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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 )!zBModule with functions which are supposed to be as fast as possible    )S_ISDIR)safe_decodedefenc)CallableListMutableSequenceSequenceTupleTYPE_CHECKINGUnionoverload)ReadableBuffer)GitCmdObjectDBN)tree_to_streamtree_entries_from_datatraverse_trees_recursivetraverse_tree_recursive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 give list of entries into a stream using its write method

    :param entries: **sorted** list of tuples with (binsha, mode, name)
    :param write: 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
             /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 )zReads the binary representation of a tree and returns tuples of 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   F   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   u   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          Cr   c                     d S rG   rH   rI   s     r/   rJ   rJ      rK   r   c                 >    | s| S | d         | d         || d         z   fS )z$Rebuild entry with given path prefixr   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 lostNc                     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   )rR   eis     r/   rT   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   )rR   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)rN   rO   rE   
trees_datanttree_shar0   r8   tir;   iirB   r   _shar*   r+   r<   tios     `               r/   r   r      s   " .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   rb   c           	      .   g }t          |                     |                                                    }|D ][\  }}}t          |          r+|                    t          | |||z   dz                        @|                    ||||z   f           \|S )a&  
    :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 pathsrW   )r   r\   r]   r   r^   r   r5   )rN   rb   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__statr   
git.compatr   r   typingr   r   r   r	   r
   r   r   r   	_typeshedr   gitr   r"   intr$   EntryTupEntryTupOrNone__all__r   r   boolrD   rJ   r   r   rH   r   r/   <module>rs      s   H H       + * * * * * * *	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  #((((((""""""S!x~&
EHX. ExAQ@RTYZ]_cZcTd@d7e Ejn E E E E@, ,4> , , , ,^_^< C QU ad iw    . 
 3 4    
 
 s x    
5 5S 5^ 5 5 5 5J	J&.uUD[/A&BJQTJ	%#
$%J J J JZ!1 U QT Y]^fYg      r   