
    .Ph@                         d Z ddlZddlZddlmZ ddlmZ ddlmZ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)Optional   )RENAME_CHANGE_TYPESRenameDetector
TreeChangetree_changestree_changes_for_merge)MissingCommitError)CommitObjectIDTagdatetopo   c                   .    e Zd ZdZddZddZdefdZdS )		WalkEntryz1Object encapsulating a single result from a walk.returnNc                 j    || _         |j        | _        |j        | _        i | _        |j        | _        d S N)commitstore_storeget_parents_get_parents_changesrename_detector_rename_detector)selfwalkerr   s      L/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/dulwich/walk.py__init__zWalkEntry.__init__3   s5    l".57 & 6    c                      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>W   s"    QQQ!$+a.-QQQr#   c                 *    g | ]}j         |         S r&   )r   r(   s     r!   r+   z%WalkEntry.changes.<locals>.<listcomp>Y   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.changes:   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                 L    d| j         j         d|                                 dS )Nz<WalkEntry commit=z
, changes=>)r   idr>   r   s    r!   __repr__zWalkEntry.__repr__w   s'    QDKNQQdllnnQQQQr#   r   Nr   )__name__
__module____qualname____doc__r"   r>   strrC   r&   r#   r!   r   r   0   se        ;;7 7 7 7;* ;* ;* ;*zR# R R R R R Rr#   r   c                   <    e Zd ZdZddZdeddfdZdd	Zd
 ZeZ	dS )_CommitTimeQueuez3Priority queue of WalkEntry objects by commit time.r    Walkerr   Nc                    || _         |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   r2   r   
isinstancer   r]   objectrA   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   r1   r   rg   )r   r   rO   seentodor7   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   )rA   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   heappoprA   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#   )r    rL   r   NrD   )
rE   rF   rG   rH   r"   bytesr]   rn   r|   __next__r&   r#   r!   rK   rK   {   su        ==" " " ""&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
         ddfdZde	fdZde	fdZdee	         f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   untilr   c                    |t           vrt          d|           || _        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 Nr   )
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 
"":5::;;;
gu%% 	  iGGMr**
&*E

3t
 	4/ 	4,U33O.&

ioo8C8I8K8Kr#   c                     |dS | j         dS | j         D ]<}||k    r dS |                    |          r|t          |                   dk    r dS =dS )NFT/   )r   
startswithr.   )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                 >   | j         sJ |sdS |j        j        }|j        j        }|                     |          rK| j        rB|j        t          v r4| j                             |           | j         	                    |           dS |                     |          rdS dS )NFT)
r   oldpathnewr   r   typer   rg   ru   )r   changeold_pathnew_paths       r!   _change_matcheszWalker._change_matches>  s    z 	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   rA   rO   r   r.   r   r>   r   )r   entryr   path_changesr   s        r!   _should_returnzWalker._should_returnN  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   r1   r.   rY   popleftr   )r   r   r   s      r!   _nextzWalker._nexto  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   reversedr3   )r   resultss     r!   _reorderzWalker._reorder~  sE     :###GT-=>>G< 	.tG}}--Gr#   c                 l    t          |                     t          | j        d                               S r   )iterr   r   rB   s    r!   __iter__zWalker.__iter__  s(    DMM$tz4"8"899:::r#   )rE   rF   rG   rH   rK   r3   r}   r   rI   boolintr   r"   r   r   r   r   r   r   r&   r#   r!   rL   rL      s         *.%)'+48##11"CL CL eCL $u+&	CL
 CL CL c]CL U$CL ".1CL CL }CL }CL 
CL CL CL CLJT         x~    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   r1   r   r   rA   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#   )rH   r   rd   	itertoolsr   typingr   	diff_treer   r   r   r	   r
   errorsr   objectsr   r   r   
ORDER_DATEr   r   rY   r   rK   rL   r   r&   r#   r!   <module>r      s  , D C                               ' & & & & & * * * * * * * * * *

*%
  HR HR HR HR HR HR HR HRVe e e e e e e ePk; k; k; k; k; k; k; k;\ (E'D ! ! ! ! ! !r#   