
    d@                         d Z ddlZddlZddlmZ ddlmZmZmZm	Z	m
Z
 ddlmZmZmZmZ ddlmZ ddlmZmZmZ d	Zd
ZeefZdZ G d d          Z G d d          Z G d d          Zd fdZdS )z=General implementation of walking commits and their contents.    N)chain)DequeListOptionalSetTuple   )RENAME_CHANGE_TYPESRenameDetectortree_changestree_changes_for_merge)MissingCommitError)CommitObjectIDTagdatetopo   c                   &    e Zd ZdZd ZddZd ZdS )	WalkEntryz1Object encapsulating a single result from a walk.c                 j    || _         |j        | _        |j        | _        i | _        |j        | _        d S N)commitstore_storeget_parents_get_parents_changesrename_detector_rename_detector)selfwalkerr   s      P/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/dulwich/walk.py__init__zWalkEntry.__init__.   s5    l". & 6    Nc                      j                             |          }| j        }                     |          st          }d}nt                               |                    dk    ret          } j                             |          d                  j        }|r0|                     j        j	        |          \  }} j        |         }nt          } fd                     |          D             }|r^ fd|D             }g }|D ]K}		 |	                     j        j	        |          \  }}
|                    |
           <# t          $ r Y Hw xY w|j        }|r0 j        |         }|                     j        j	        |          \  }}t           | j        || j                            }| j         |<    j         |         S )a-  Get the tree changes for this entry.

        Args:
          path_prefix: Portion of the path in the repository to
            use to filter changes. Must be a directory name. Must be
            a full, valid, path reference (no partial names or wildcards).
        Returns: For commits with up to one parent, a list of TreeChange
            objects; if the commit has no parents, these will be relative to
            the empty tree. For merge commits, a list of lists of TreeChange
            objects; see dulwich.diff.tree_changes_for_merge.
        Nr	   r   c                 4    g | ]}j         |         j        S  )r   tree.0pr!   s     r#   
<listcomp>z%WalkEntry.changes.<locals>.<listcomp>R   s"    QQQ!$+a.-QQQr%   c                 *    g | ]}j         |         S r(   )r   r*   s     r#   r-   z%WalkEntry.changes.<locals>.<listcomp>T   s    #C#C#CqDKN#C#C#Cr%   )r   )r   getr   r   r   lenr   r)   lookup_path__getitem__r   appendKeyErrorlistr    )r!   path_prefixcachedr   changes_funcparentmodesubtree_shaparent_treesr,   stcommit_tree_shacommit_trees   `            r#   changeszWalkEntry.changes5   s     "";//>[F$$V,, .+T&&v..//144+T%6%6v%>%>q%ABG 6(.(:(:/#) )%D+ "[5F5QQQQt7H7H7P7PQQQ .#C#C#C#CF#C#C#CLF) 	. 	..'(}} $ 7 +( (HD" #MM"----  ( ! ! ! D! %kO "k/:(3(?(?K+) )%o K#$($9	   F *0DM+&}[))s   #E		
EEc                 f    d                     | j        j        |                                           S )Nz#<WalkEntry commit={}, changes={!r}>)formatr   idr@   r!   s    r#   __repr__zWalkEntry.__repr__r   s,    4;;KNLLNN
 
 	
r%   r   )__name__
__module____qualname____doc__r$   r@   rE   r(   r%   r#   r   r   +   sM        ;;7 7 7;* ;* ;* ;*z
 
 
 
 
r%   r   c                   6    e Zd ZdZd
dZdefdZd Zd ZeZ	d	S )_CommitTimeQueuez3Priority queue of WalkEntry objects by commit time.r"   Walkerc                    || _         |j        | _        |j        | _        |j        | _        g | _        t                      | _	        t                      | _
        t                      | _        |j        | _        d | _        t          | _        d| _        t%          |j        |j                  D ]}|                     |           d S )NF)_walkerr   r   r   r   excluded	_excluded_pqset_pq_set_seen_donesince	_min_time_last_MAX_EXTRA_COMMITS_extra_commits_left_is_finishedr   include_push)r!   r"   	commit_ids      r#   r$   z_CommitTimeQueue.__init__|   s    l".-/&)ee$'EE
$'EE

#5 !v~v?? 	" 	"IJJy!!!!	" 	"r%   	object_idc                    	 | j         |         }n"# t          $ r}t          |          |d }~ww xY wt          |t                    r"|                     |j        d                    d S |}|j        | j        vrp|j        | j	        vrdt          j        | j        |j         |f           | j                            |j                   | j                            |j                   d S d S d S Nr	   )r   r4   r   
isinstancer   r]   objectrC   rS   rU   heapqheappushrQ   commit_timeaddrT   )r!   r_   objexcr   s        r#   r]   z_CommitTimeQueue._push   s    	9+i(CC 	9 	9 	9$Y//S8	9c3 	JJsz!}%%%F9DL((VYdj-H-HN48v'9&96%BCCCLVY'''JNN69%%%%% )(-H-Hs    
/*/c                    | j         }| j        }|g}|rm|                                }|                     |          D ]?}||vr$||v r |                    | j        |                    |                    |           @|kd S d S r   )rP   rT   popr   r3   r   rg   )r!   r   rO   seentodor9   s         r#   _exclude_parentsz!_CommitTimeQueue._exclude_parents   s    >zx 		%XXZZF++F33 % %))fnn
 KKF 3444V$$$$  		% 		% 		% 		% 		%r%   c                      j         rd S  j        rnt          j         j                  \  }}|j        } j                            |           | j        v rO j                            |            	                    |          D ]} 
                    |           d}| j        v }|rm                     |            j        rQt           fd j        D                       r1 j        d         \  }} j        r|j         j        j        k    rd}nd} j        |j         j        k     rd}|rt"           _        n xj        dz  c_         j        sn&|s| _        t'           j        |          S  j        nd _         d S )NTc              3   :   K   | ]\  }}|j         j        v V  d S r   )rC   rP   )r+   _cr!   s      r#   	<genexpr>z(_CommitTimeQueue.next.<locals>.<genexpr>   s0      #P#Ptq!ADDN$:#P#P#P#P#P#Pr%   r   Fr	   )r[   rQ   rd   heappoprC   rS   removerU   rg   r   r]   rP   rn   allrX   rf   rW   rY   rZ   r   rN   )r!   rq   r   sha	parent_idreset_extra_commitsis_excludedns   `       r#   nextz_CommitTimeQueue.next   s    	4h ,	7dh//IAv)CL$$$dj  JNN3!..v66 & &	

9%%%%"&/K 4%%f---8 
4#P#P#P#Ptx#P#P#P P P 
48A;DAqz 4amtz7M&M&M /3++.3+~)f.@4>.Q.Q
 ',#" +=((((A-((/  7#
 v666Y h ,	7Z !tr%   N)r"   rL   )
rF   rG   rH   rI   r$   bytesr]   rn   r|   __next__r(   r%   r#   rK   rK   y   si        ==" " " ""&u & & & &% % %1 1 1f HHHr%   rK   c                       e Zd ZdZdddddddddd efdee         deee                  ded	e	d
ee
         deee                  dee         de	dee
         dee
         fdZd Zd Zd Zd Zd Zd ZdS )rL   zObject for performing a walk of commits in a store.

    Walker objects are initialized with a store and other options and can then
    be treated as iterators of Commit objects.
    Nr   Fc                     | j         S r   parentsr   s    r#   <lambda>zWalker.<lambda>   s    6> r%   r\   excludeorderreversemax_entriespathsr   followrV   untilc                    |t           vrt          d|z            || _        t          |t                    r|g}|| _        t          |pg           | _        || _        || _	        || _
        |rt          |          pd| _        |	r|st          |          }|| _        || _        |	| _        |
| _        || _        d| _         ||           | _        t)          j                    | _        dS )a  Constructor.

        Args:
          store: ObjectStore instance for looking up objects.
          include: Iterable of SHAs of commits to include along with their
            ancestors.
          exclude: Iterable of SHAs of commits to exclude along with their
            ancestors, overriding includes.
          order: ORDER_* constant specifying the order of results.
            Anything other than ORDER_DATE may result in O(n) memory usage.
          reverse: If True, reverse the order of output, requiring O(n)
            memory.
          max_entries: The maximum number of entries to yield, or None for
            no limit.
          paths: Iterable of file or subtree paths to show entries for.
          rename_detector: diff.RenameDetector object for detecting
            renames.
          follow: If True, follow path across renames/copies. Forces a
            default rename_detector.
          since: Timestamp to list commits after.
          until: Timestamp to list commits before.
          get_parents: Method to retrieve the parents of a commit
          queue_cls: A class to use for a queue of commits, supporting the
            iterator protocol. The constructor takes a single argument, the
            Walker.
        zUnknown walk order %sNr   )
ALL_ORDERS
ValueErrorr   rb   r}   r\   rR   rO   r   r   r   r   r   r   r   r   rV   r   _num_entries_queuecollectionsdeque
_out_queue)r!   r   r\   r   r   r   r   r   r   r   rV   r   r   	queue_clss                 r#   r$   zWalker.__init__   s    X 
""4u<===
gu%% 	  iGGMr**
&)s5zz1T
 	4/ 	4,U33O.&

ioo,7,=,?,?r%   c                     |dS | j         dS | j         D ]<}||k    r dS |                    |          r|t          |                   dk    r dS =dS )NFT/   )r   
startswithr0   )r!   changed_pathfollowed_paths      r#   _path_matcheszWalker._path_matches-  sx    5:4!Z 	 	M},,tt''66 ]!3!34??ttur%   c                 ,   |sdS |j         j        }|j        j        }|                     |          rK| j        rB|j        t          v r4| j                            |           | j        	                    |           dS |                     |          rdS dS )NFT)
oldpathnewr   r   typer
   r   rg   ru   )r!   changeold_pathnew_paths       r#   _change_matcheszWalker._change_matches<  s     	5:?:?h'' 	{ ,v{.AAA
x(((
!!(+++4)) 	4ur%   c                    |j         }| j        |j        | j        k     rdS | j        |j        | j        k    rdS |j        | j        v rdS | j        dS t          |                     |                    dk    r6|	                                D ] }|D ]}| 
                    |          r  dS !n/|	                                D ]}| 
                    |          r dS dS )a	  Determine if a walk entry should be returned..

        Args:
          entry: The WalkEntry to consider.
        Returns: True if the WalkEntry should be returned by this walk, or
            False otherwise (e.g. if it doesn't match any requested paths).
        NFTr	   )r   rV   rf   r   rC   rO   r   r0   r   r@   r   )r!   entryr   path_changesr   s        r#   _should_returnzWalker._should_returnK  s    :!f&84:&E&E5:!f&84:&E&E59%%5:4t''((1,, % $ $ + $ $F++F33 $#ttt$$	$  --//    ''//  44 tr%   c                 x   | j         }|| j        |k     rt          | j                  }|| j                            |           |t          | j                  t          k    rI| j        sd S | j                                        }| 	                    |          r| xj        dz  c_        |S || j        |k     d S ra   )
r   r   r|   r   r   r3   r0   rY   popleftr   )r!   r   r   s      r#   _nextzWalker._nextl  s    &!T%6%D%D%%E &&u---}DO 4 47I I I  4//11&&u-- !%%*%% L !T%6%D%D tr%   c                     | j         t          k    rt          || j                  }| j        rt          t          |                    }|S )a  Possibly reorder a results iterator.

        Args:
          results: An iterator of WalkEntry objects, in the order returned
            from the queue_cls.
        Returns: An iterator or list of WalkEntry objects, in the order
            required by the Walker.
        )r   
ORDER_TOPO_topo_reorderr   r   reversedr5   )r!   resultss     r#   _reorderzWalker._reorder{  sE     :###GT-=>>G< 	.tG}}--Gr%   c                 l    t          |                     t          | j        d                               S r   )iterr   r   rD   s    r#   __iter__zWalker.__iter__  s(    DMM$tz4"8"899:::r%   )rF   rG   rH   rI   rK   r   r}   r   strboolintr   r$   r   r   r   r   r   r   r(   r%   r#   rL   rL      sb         *.%)'+48##11"C@ C@ eC@ $u+&	C@
 C@ C@ c]C@ U$C@ ".1C@ C@ }C@ }C@ C@ C@ C@J      B    ; ; ; ; ;r%   rL   c                     | j         S r   r   r   s    r#   r   r     s    fn r%   c              #     K   t          j                    }i }t          j        t                    }| D ]:}|                    |            ||j                  D ]}||xx         dz  cc<   ;|r|                                }|j        }|j        }||         r|||<   2 ||          D ]G}	||	xx         dz  cc<   ||	         s-|                    |	d          }
|
r|	                    |
           H|V  |dS dS )a  Reorder an iterable of entries topologically.

    This works best assuming the entries are already in almost-topological
    order, e.g. in commit time order.

    Args:
      entries: An iterable of WalkEntry objects.
      get_parents: Optional function for getting the parents of a commit.
    Returns: iterator over WalkEntry objects from entries in FIFO order, except
        where a parent would be yielded before any of its children.
    r	   N)
r   r   defaultdictr   r3   r   r   rC   rk   
appendleft)entriesr   rm   pendingnum_childrenr   r,   r   r^   rx   parent_entrys              r#   r   r     sZ      DG*3//L ! !EU\** 	! 	!AOOOq OOOO	!  I		" 	!&GI$V,, 	2 	2I###q(###	* 2&{{9d;; 2OOL111      r%   )rI   r   rd   	itertoolsr   typingr   r   r   r   r   	diff_treer
   r   r   r   errorsr   objectsr   r   r   
ORDER_DATEr   r   rY   r   rK   rL   r   r(   r%   r#   <module>r      s  * D C            4 4 4 4 4 4 4 4 4 4 4 4 4 40 0 0 0 0 0 0 0 0 0 0 0 & & & & & & * * * * * * * * * *

*%
  K
 K
 K
 K
 K
 K
 K
 K
\e e e e e e e ePj; j; j; j; j; j; j; j;Z (E'D ! ! ! ! ! !r%   