
    >                         S r SSKrSSKrSSKJr  SSKJrJrJrJ	r	  SSK
Jr  SSKJr  SrSr\\4rS	r " S
 S\5      r " S S\5      r " S S\5      rS 4S jrg)z=General implementation of walking commits and their contents.    N)chain)RENAME_CHANGE_TYPEStree_changestree_changes_for_mergeRenameDetector)MissingCommitError)Tagdatetopo   c                   .    \ rS rSrSrS rSS jrS rSrg)		WalkEntry2   z1Object encapsulating a single result from a walk.c                     X l         UR                  U l        UR                  U l        0 U l        UR                  U l        g N)commitstore_storeget_parents_get_parents_changesrename_detector_rename_detector)selfwalkerr   s      lib/third_party/dulwich/walk.py__init__WalkEntry.__init__5   s5    ll".. & 6 6    Nc           	      R   U R                   R                  U5      nUGc  U R                  nU R                  U5      (       d
  [        nSnGO5[        U R                  U5      5      S:X  ap  [        nU R                  U R                  U5      S      R                  nU(       a7  UR                  U R                  R                  U5      u  pgU R                  U   nO[        nU R                  U5       Vs/ s H  oR                  U   R                  PM     nnU(       ac  U Vs/ s H  oR                  U   PM     n	n/ nU	 H=  n UR                  U R                  R                  U5      u  pjUR                  U
5        M?     UR                  nU(       a7  U R                  U   nUR                  U R                  R                  U5      u  pk[        U" U R                  UUU R                  S95      nX R                   U'   U R                   U   $ s  snf s  snf ! [         a     M  f = f)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.
N   r   )r   )r   getr   r   r   lenr   treelookup_path__getitem__r   appendKeyErrorlistr   )r   path_prefixcachedr   changes_funcparentmodesubtree_shapparent_treesstcommit_tree_shacommit_trees                r   changesWalkEntry.changes<   s    "";/>[[F$$V,,+T&&v./14+T%6%6v%>q%ABGG(.(:(://#)%D "[[5F57;7H7H7PQ7P!++a.--7PQ<B#CFqKKNFL#CF).'(}} $ 7 7 +(HD #MM"- * %kkO"kk/:(3(?(?KK++)% KK#$($9$9	F *0MM+&}}[))= R#C  ( ! !s   3"H"H(H
H&%H&c                 \    SU R                   R                  < SU R                  5       < S3$ )Nz<WalkEntry commit=z
, changes=>)r   idr5   r   s    r   __repr__WalkEntry.__repr__y   s     KKNNLLN
 	
r   )r   r   r   r   r   r   )	__name__
__module____qualname____firstlineno____doc__r   r5   r;   __static_attributes__ r   r   r   r   2   s    ;7;*z
r   r   c                   4    \ rS rSrSrS rS rS rS r\r	Sr
g)	_CommitTimeQueue   z3Priority queue of WalkEntry objects by commit time.c                    Xl         UR                  U l        UR                  U l        UR
                  U l        / U l        [        5       U l	        [        5       U l
        [        5       U l        UR                  U l        S U l        [        U l        SU l        [%        UR&                  UR
                  5       H  nU R)                  U5        M     g )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   _CommitTimeQueue.__init__   s    ll"..uU
U

#5 !v~~v?IJJy! @r   c                     U R                   U   n[        U[        5      (       a  U R                  UR                  S   5        g UnUR                  U R                  ;  a  UR                  U R                  ;  ay  [        R                  " U R                  UR                  * U45        U R                  R                  UR                  5        U R                  R                  UR                  5        g g g ! [         a    [        U5      ef = fNr!   )r   r(   r   
isinstancer	   rW   objectr9   rM   rO   heapqheappushrK   commit_timeaddrN   )r   	object_idobjr   s       r   rW   _CommitTimeQueue._push   s    	0++i(C c3JJszz!}%99DLL(VYYdjj-HNN488v'9'9&96%BCLLVYY'JJNN699% .I(  	0$Y//	0s   C6 6Dc                    U R                   nU R                  nU/nU(       ak  UR                  5       nU R                  U5       H<  nXR;  a#  XS;   a  UR	                  U R
                  U   5        UR                  U5        M>     U(       a  Mj  g g r   )rJ   rN   popr   r'   r   ra   )r   r   rI   seentodor-   s         r   _exclude_parents!_CommitTimeQueue._exclude_parents   sr    >>zzxXXZF++F3)fn
 KKF 34V$ 4 dr   c                 "  ^  T R                   (       a  g T R                  (       Ga  [        R                  " T R                  5      u  pUR                  nT R
                  R                  U5        UT R                  ;   a  Mm  T R                  R                  U5        T R                  U5       H  nT R                  U5        M     SnUT R                  ;   nU(       a  T R                  U5        T R                  (       ao  [        U 4S jT R                   5       5      (       aK  T R                  S   u  pT R                  (       a'  UR                  T R                  R                  :  a  SnOSnT R                   b  UR                  T R                   :  a  SnU(       a  ["        T l        O'T =R$                  S-  sl        T R$                  (       d  O8U(       d  UT l        ['        T R(                  U5      $ T R                  (       a  GM  ST l         g )NTc              3   Z   >#    U  H   u  pUR                   TR                  ;   v   M"     g 7fr   )r9   rJ   ).0_cr   s      r   	<genexpr>(_CommitTimeQueue.next.<locals>.<genexpr>   s      #PxtqADDDNN$:xs   (+r   Fr!   )rU   rK   r^   heappopr9   rM   removerO   ra   r   rW   rJ   ri   allrR   r`   rQ   rS   rT   r   rH   )r   rn   r   sha	parent_idreset_extra_commitsis_excludedns   `       r   next_CommitTimeQueue.next   s   hhhdhh/IA))CLL$djj JJNN3!..v6	

9% 7 #'/K%%f-88#Ptxx#P P P88A;DAzzammtzz7M7M&M /3+.3+~~)f.@.@4>>.Q
 ',#"+=(((A-(//#
 v66Y hhhZ !r   )rO   rJ   rT   r   rU   rR   rQ   rK   rM   rN   r   rH   N)r=   r>   r?   r@   rA   r   rW   ri   rz   __next__rB   rC   r   r   rE   rE      s!    =""&%1f Hr   rE   c                   ^    \ rS rSrSrS\SSSSSSSS \4S jrS rS r	S	 r
S
 rS rS rSrg)Walker   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.
NFc                     U R                   $ r   parentsr   s    r   <lambda>Walker.<lambda>   s    6>>r   c                    U[         ;  a  [        SU-  5      eXl        [        U[        5      (       a  U/nX l        [        U=(       d    / 5      U l        X@l        XPl	        X`l
        U=(       a    [        U5      =(       d    SU l        U	(       a  U(       d  [        U5      nXl        Xl        Xl        Xl        Xl        SU l        U" U 5      U l        [(        R*                  " 5       U l        g)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   r\   bytesrV   rL   rI   orderreversemax_entriespathsr   r   r   followrP   until_num_entries_queuecollectionsdeque
_out_queue)r   r   rV   excluder   r   r   r   r   r   rP   r   r   	queue_clss                 r   r   Walker.__init__   s    X 
"4u<==
gu%% iGGMr*
&)s5z1T
/,U3O.&

o%++-r   c                     Uc  gU R                    H6  nX:X  a    gUR                  U5      (       d  M"  U[        U5         S:X  d  M6    g   g)NFT/   )r   
startswithr#   )r   changed_pathfollowed_paths      r   _path_matchesWalker._path_matches4  sM    !ZZM,''66 ]!34? ( r   c                 ~   U(       d  gUR                   R                  nUR                  R                  nU R                  U5      (       a\  U R                  (       aJ  UR
                  [        ;   a6  U R                  R                  U5        U R                  R                  U5        gU R                  U5      (       a  gg)NFT)
oldpathnewr   r   typer   r   ra   rs   )r   changeold_pathnew_paths       r   _change_matchesWalker._change_matchesA  s    ::??::??h''{{v{{.AA

x(

!!(+))r   c                    UR                   nU R                  b  UR                  U R                  :  a  gU R                  b  UR                  U R                  :  a  gUR                  U R
                  ;   a  gU R                  c  g[        U R                  U5      5      S:  a:  UR                  5        H%  nU H  nU R                  U5      (       d  M      g   M'     gUR                  5        H  nU R                  U5      (       d  M    g   g)zDetermine 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   rP   r`   r   r9   rI   r   r#   r   r5   r   )r   entryr   path_changesr   s        r   _should_returnWalker._should_returnP  s     ::!f&8&84::&E::!f&8&84::&E99%::t'(1, % +F++F33# +	 !0   --/''// * r   c                    U R                   nUb  U R                  U:  a  [        U R                  5      nUb  U R                  R                  U5        Ub  [        U R                  5      [        :  aY  U R                  (       d  g U R                  R                  5       nU R                  U5      (       a  U =R                  S-  sl        U$ Uc  M  U R                  U:  a  M  g r[   )
r   r   rz   r   r   r'   r#   rS   popleftr   )r   r   r   s      r   _nextWalker._nextq  s    &&!T%6%6%D%E &&u-}DOO 47I I//1&&u--%%*% L !T%6%6%D r   c                     U R                   [        :X  a  [        XR                  5      nU R                  (       a  [        [        U5      5      nU$ )zPossibly 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   reversedr)   )r   resultss     r   _reorderWalker._reorder  s:     ::##G-=-=>G<<tG}-Gr   c                 ^    [        U R                  [        U R                  S 5      5      5      $ r   )iterr   r   r:   s    r   __iter__Walker.__iter__  s!    DMM$tzz4"89::r   )r   r   r   rI   r   r   rV   r   r   r   r   r   rP   r   r   )r=   r>   r?   r@   rA   
ORDER_DATErE   r   r   r   r   r   r   r   rB   rC   r   r   r~   r~      sP     1"C.JB;r   r~   c                     U R                   $ r   r   r   s    r   r   r     s    fnnr   c              #   (  #    [         R                  " 5       n0 n[         R                  " [        5      nU  H9  nUR	                  U5        U" UR
                  5       H  nXF==   S-  ss'   M     M;     U(       a  UR                  5       nUR
                  nUR                  nXH   (       a  XSU'   M>  U" U5       HF  n	XI==   S-  ss'   XI   (       a  M  UR                  U	S5      n
U
(       d  M5  UR                  U
5        MH     Uv   U(       a  M  gg7f)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   defaultdictintr'   r   r   r9   rf   
appendleft)entriesr   rh   pendingnum_childrenr   r0   r   rX   rv   parent_entrys              r   r   r     s      DG**3/LEU\\*AOq O + 
 II	"!&I$V,I#q(#**&{{9d;<OOL1 -  $s   CDD. DD)rA   r   r^   	itertoolsr   dulwich.diff_treer   r   r   r   dulwich.errorsr   dulwich.objectsr	   r   r   r   rS   r]   r   rE   r~   r   rC   r   r   <module>r      s   * D     

*%
  K
 K
\ev ePh;V h;V (E !r   