
    6h1                        S SK Jr  S SKrSSKJr  SSKJrJr  \R                  " S5      r	S r
S r " S	 S
5      rS r " S S5      rg)    )annotationsN   )nullrev)dagoppolicyparsersc                   [        U[        5      (       d  [        U5      n[        U;   a
  [        5       $ [        U5      S::  a  U$ S[        U5      -  S-
  nS/[	        U5      S-   -  n[        U5       H  u  pESU-  X5'   M     SWS-   -  n[        5       n[        U5      n[        U5      S-
  n	U	S:  a  U(       a  U	n
U	S-  n	X:   (       d  M  X:   nX:  a'  US-  nX:X  a  UR                  U
5        X-  nX;   a  U
1$ X:  aD  U " U
5       H7  nX<   nU[        :X  a  M  US:X  a  XU'   US-  nM$  X:w  d  M+  X<==   U-  ss'   M9     O4U " U
5       H(  nU[        :X  a  M  X<   nU(       a
  X:  a  US-  nXU'   M*     U	S:  a	  U(       a  M  U$ )zReturns a set with the heads of all common ancestors of all nodes,
heads(::nodes[0] and ::nodes[1] and ...) .

pfunc must return a list of parent vertices for a given vertex.
r   r   )
isinstancesetr   lenmax	enumerateadd)pfuncnodesallseenseeninpoisongcainterestingnvvsvpsps                 4/usr/lib/python3/dist-packages/mercurial/ancestor.pycommonancestorsheadsr      s    eS!!E
%u
5zQCJ!#G3#e*q.!D% q& !1q5\F
%Ce*K	TQB
'k
awW;1K}
:3J;1XW<7 G1$KXGrMG  1X<W"+1$KQ 3 'kk@ J    c                Z   ^  U 4S jn[        T /UQ76 n[        U5      S::  a  U$ U" U5      $ )z
Returns the common ancestors of a and b that are furthest from a
root (as measured by longest path).

pfunc must return a list of parent vertices for a given vertex.
c                  > 0 n[        U 5      S-   nS/U-  nS/U-  n/ n[        [        U 5      5       H(  u  pgSX7'   SU-  nXU'   SX'   UR                  X45        M*     US-
  n	U	S:  Ga  [	        U5      S:  a  U	n
U	S-  n	X:   nUS:X  a  M)  XJ   nT" U
5       H  nU[
        :X  a  M  X=   nXM   nX::  aA  US-   X='   X:w  a3  X==   S-  ss'   XU'   U(       a  X==   S-  ss'   X   S:X  a  X	 MW  MY  M[  M]  XS-
  :X  d  Mg  X-  nUU:X  a  Ms  UXM'   UR                  US5        UU==   S-  ss'   X==   S-  ss'   X   S:X  d  M  X	 M     X==   S-  ss'   X   S:X  a  X	 U	S:  a  [	        U5      S:  a  M  [	        U5      S:w  a  / $ SnU H  nUU-  nM
     U VVs1 s H  u  pgUU-  (       d  M  UiM     snn$ s  snnf )Nr   r   )r   r   sortedappendr   r   
setdefault)r   r   countdepthr   mappingr   r   br   r   dvr   r   dpr   nspkr   s                     r   deepestancestors.<locals>.deepestV   s   E
QesU{fUm,DAEHQAGKNNNA6" - QYAg#k*Q.A!GBBQwB1X<XW8!AvEHx#1,"$Q'Oq0O*!3$/O  4    6\'Cby !DG**32$)$Oq(O"!+'O/ 0 Oq O!#OC Ag#k*Q.F {q IAFA  '1fq1q5111s   F=3F=r   )r   r   )r   	orignodesr.   r   s   `   r   	ancestorsr1   N   s4    62p u
1y
1C
3x1}
3<r    c                  <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)incrementalmissingancestors   a  persistent state used to calculate missing ancestors incrementally

Although similar in spirit to lazyancestors below, this is a separate class
because trying to support contains and missingancestors operations with the
same internal data structures adds needless complexity.c                    [        U5      U l        U R                  (       d  U R                  R                  [        5        Xl        g N)r   basesr   r   r   )selfr   r7   s      r   __init__$incrementalmissingancestors.__init__   s)    Z
zzJJNN7#
r    c                P    U R                   =(       a    U R                   [        1:g  $ )z0whether the common set has any non-trivial bases)r7   r   r8   s    r   hasbases$incrementalmissingancestors.hasbases   s    zz5djjWI55r    c                :    U R                   R                  U5        g)z)grow the ancestor set by adding new basesN)r7   update)r8   newbasess     r   addbases$incrementalmissingancestors.addbases   s    

(#r    c                X    [         R                  " U R                  U R                  5      $ r6   )r   headrevsr7   r   r<   s    r   
basesheads&incrementalmissingancestors.basesheads   s    ~~djj$**55r    c                  ^ U R                   nU R                  nUR                  U5        UR                  [        5        U(       d  g[        U5      m[        U4S jU 5       5      n[        U5      U:X  a  g[        T[        U5      S-
  S5       HC  nXR;  a  M
  UR                  U5        UR                  U" U5      5        [        U5      U:X  d  MC    g   g)z:remove all ancestors of bases from the set revs (in place)Nc              3  6   >#    U  H  oT:  d  M
  S v   M     g7f)r   N ).0rstarts     r   	<genexpr>Bincrementalmissingancestors.removeancestorsfrom.<locals>.<genexpr>   s     54au94s   		r   )r7   r   difference_updatediscardr   r   sumr   rangeminr@   )r8   revsr7   r   	keepcountcurrrM   s         @r   removeancestorsfrom/incrementalmissingancestors.removeancestorsfrom   s    



u%W E
5455	t9	!%TQ3D LLLLt%4yI% 4r    c                D   [        U5      nU R                  nU R                  nUR                  U5      nUR	                  U5        U(       d  / $ [        [        U5      [        U5      5      n/ n[        U[        S5       GH  nU(       d    GOX;   aU  UR                  U5        U" U5       H6  n	UR                  U	5        UR                  U	5        UR                  U	5        M8     Mh  X;   a'  UR                  U5        UR                  U5        Un
UnOX;   a  Un
UnOM  U" U5       H_  n	U	[        :X  a  M  X;   d  X;   a5  UR                  U	5        UR                  U	5        UR                  U	5        MN  U
R                  U	5        Ma     GM     UR                  5         U$ )zreturn all the ancestors of revs that are not ancestors of self.bases

This may include elements from revs.

Equivalent to the revset (::revs - ::self.bases). Revs are returned in
revision number order, which is a topological order.rP   )r   r7   r   intersectionrQ   r   rT   r   removerR   r   r$   reverse)r8   rV   	revsvisit
basesvisitr   	bothvisitrM   missingrX   r   	thisvisit
othervisits               r   missingancestors,incrementalmissingancestors.missingancestors   sp    I	ZZ


**:6	##I.IC	NC
O4  %"-D   & tA%%a(NN1%MM!$ %  t$  &%	'
#&	&
 4[<_ %%a(NN1%MM!$ MM!$ !5 .N 	r    )r7   r   N)__name__
__module____qualname____firstlineno____doc__r9   r=   rB   rF   rY   re   __static_attributes__rJ   r    r   r3   r3      s&    ?6$64Hr    r3   c              #    #    [         1n[        R                  n[        R                  n[        R                  nUR
                  nU(       a:  U V	s/ s H  o* PM     n
n	UR                  U5        [        R                  " U
5        OY/ n
[        R                  " U
5        U H;  n	U " U	5      u  pX;  a  U" X* 5        U" U5        X;  d  M*  U" X* 5        U" U5        M=     U
(       ah  U
S   * nX:  a  g Uv   U " U5      u  pX;  a!  X-
  S:X  a  U* U
S'   O	U" X* 5        U" U5        OU" U
5        X;  a  U" X* 5        U" U5        U
(       a  Mg  g g s  sn	f 7f)Nr   r   )r   heapqheappushheappopheapreplacer   r@   heapify)
parentrevsinitrevsstoprev	inclusiver   ro   rp   rq   seerL   visitp1p2currents                 r   _lazyancestorsiterr|     s3    9D~~HmmG##K
((C%&XX&HeeA]FB~$B~$B  8) G$>|q 3aE3'GEN>UC G% % 's    AEEA*EBEEc                  4    \ rS rSrSS jrS r\rS rS rSr	g)	lazyancestorsi?  c                   Xl         U Vs/ s H  oUU:  d  M
  UPM     snU l        X0l        X@l        [	        5       U l        [        U R                   U R                  U R                  U R                  5      U l        gs  snf )a  Create a new object generating ancestors for the given revs. Does
not generate revs lower than stoprev.

This is computed lazily starting from revs. The object supports
iteration and membership.

cl should be a changelog and revs should be an iterable. inclusive is
a boolean that indicates whether revs should be included. Revs lower
than stoprev will not be generated.

Result does not include the null revision.N)_parentrevs	_initrevs_stoprev
_inclusiver   _containsseenr|   _containsiter)r8   r   rV   ru   rv   rL   s         r   r9   lazyancestors.__init__@  se     !%):T'\!T:# U/dnndmmT__
 ;s
   	A=A=c                N     [        [        U 5      5        g! [         a     gf = f)z*False if the set is empty, True otherwise.TF)nextiterStopIterationr<   s    r   __nonzero__lazyancestors.__nonzero__V  s(    	d 		s    
$$c                n    [        U R                  U R                  U R                  U R                  5      $ )a  Generate the ancestors of _initrevs in reverse topological order.

If inclusive is False, yield a sequence of revision numbers starting
with the parents of each revision in revs, i.e., each revision is
*not* considered an ancestor of itself. Results are emitted in reverse
revision number order. That order is also topological: a child is
always emitted before its parent.

If inclusive is True, the source revisions are also yielded. The
reverse revision number order is still enforced.)r|   r   r   r   r   r<   s    r   __iter__lazyancestors.__iter__`  s,     "dnndmmT__
 	
r    c                    U R                   nX;   a  gU R                  nUc  gUc  gUR                  n  [        U5      nU" U5        XQ:X  a  gXQ:  a  gM!  ! [         a
    SU l         gf = f)z5Test whether target is an ancestor of self._initrevs.TNF)r   r   r   r   r   )r8   targetr   r   rw   revs         r   __contains__lazyancestors.__contains__o  s    !!>!!< >hh	4jC=<    	 "&D		s   A A A A*)A*)r   r   r   r   r   r   N)r   F)
rg   rh   ri   rj   r9   r   __bool__r   r   rl   rJ   r    r   r~   r~   ?  s    
, H
r    r~   )
__future__r   rn   noder    r   r   	importmodr   r   r1   r3   r|   r~   rJ   r    r   <module>r      sS    #  
 

9
%6rDNz z|)XK Kr    