
    6h                       S SK Jr  S SKrS SKrS SKJr  SSKJr  \R                  (       a  S SKrSSKJ	r	  SSK
JrJrJrJrJrJr  \R"                  r\R$                  rSrS	 rS)S
 jrS)S jrS r S*S jrS rS rS rS+S jrS r " S S5      rS rS)S jr S r!S)S jr"S r#\RH                  " SSS9 " S S5      5       r%\RH                  " SSS9 " S S5      5       r&S  r'S! r(S" r)S+S,S# jjr*S-S$ jr+S% r,S& r-S+S' jr.S( r/g).    )annotationsN)List   )attr)nullrev)errormdiffpatchpycompatscmutilsmartsetl        c              #    #    Uc  SnUc  [         nUS:X  a  gUS:  a  [        R                  " S5      eU(       a  SnOSnUR                  U5        [	        U5      n/ n[        US5      nUb  [        R                  " XuU-  S45        Sn	U(       a  [        R                  " U5      u  pXZ-  n
X:X  a*  [        US5      nUb  [        R                  " XuU-  S45        X:g  nU(       a  X:  a  U
n	U
v   US-   nU(       a;  X:  a6  U " U
5       H*  nU[        :w  d  M  [        R                  " XuU-  U45        M,     U(       a  M  gg7f)a  Walk DAG using 'pfunc' from the given 'revs' nodes

'pfunc(rev)' should return the parent/child revisions of the given 'rev'
if 'reverse' is True/False respectively.

Scan ends at the stopdepth (exlusive) if specified. Revisions found
earlier than the startdepth are omitted.
Nr   s   negative stopdepthr   )
maxlogdepthr   ProgrammingErrorsortiternextheapqheappushheappopr   )pfuncrevs
startdepth	stopdepthreverseheapsignirevspendingheapinputrevlastrevcurrevcurdepthfoundnewpdepthprevs                  1/usr/lib/python3/dist-packages/mercurial/dagop.py_walkrevtreer(   (   s>     
	A~1}$$%:;; 	IIgJEKE4 H{%8!$<=G
 ==5"E4(H#{-@!,DE $.GLA*f7?NN;D&0IJ & +s   DE&EEc              #  B  ^^	#    0 m/ m	UU	4S jnU(       a  SnOSnU  H  nU" U5        M     T(       aa  [         R                  " T	5      * nTR                  U5      nXV4v   U H%  nUR                  5       SU  H  nU" U5        M     M'     T(       a  Ma  T	(       a   eg7f)zLike filectx.ancestors(), but can walk from multiple files/revisions,
and includes the given fctxs themselves

Yields (rev, {fctx, ...}) pairs in descending order.
c                   > [         R                  " U 5      nUT;  a%  [        5       TU'   [        R                  " TU* 5        TU   R                  U 5        g N)r   intrevsetr   r   add)fctxrevvisit	visitheaps     r'   addvisit"filectxancestors.<locals>.addvisitf   sD    nnT"eE#JNN9sd+c
t    r   N)r   r   popparents)
fctxsfollowfirstr3   cutcr"   curfctxsparentr1   r2   s
           @@r'   filectxancestorsr>   ]   s      EI  
==+,99V$A))+ds+  , 	 % =ys   BB
Bc                :    S [        X5       5       n[        USS9$ )zLike filectx.ancestors(), but can walk from multiple files/revisions,
and includes the given fctxs themselves

Returns a smartset.
c              3  *   #    U  H	  u  pUv   M     g 7fr+    ).0r0   _css      r'   	<genexpr>#filerevancestors.<locals>.<genexpr>   s     
DC833Cs   Fiterasc)r>   generatorset)r8   r9   gens      r'   filerevancestorsrJ   ~   s"     E/C
DCU++r5   c                   ^ ^^^^	 U(       a  SmOS mT R                   mUUU 4S jm	Tc  T	nOUU	4S jnUR                  U4S j5      n[        XaX4SS9$ )Nr   c                   >  TR                  U 5      S T $ ! [        R                   a     S TU    R                  5       S T  5       s $ f = f)Nc              3  @   #    U  H  oR                  5       v   M     g 7fr+   r0   rB   pctxs     r'   rD   7_genrevancestors.<locals>.plainpfunc.<locals>.<genexpr>   s     E+D4HHJJ+D   )
parentrevsr   WdirUnsupportedr7   )r0   clr:   repos    r'   
plainpfunc$_genrevancestors.<locals>.plainpfunc   sU    	F==%ds++$$ 	FE49+<+<+>t+DEE	Fs    1A
Ac                ^   > T" U 5       Vs/ s H  nT" U5      (       a  M  UPM     sn$ s  snf r+   rA   )r0   rcutfuncrW   s     r'   <lambda>"_genrevancestors.<locals>.<lambda>   s!    
3J1wqzQJJs   **c                   > T" U 5      (       + $ r+   rA   )r0   r[   s    r'   r\   r]      s    73<'7r5   Tr   )	changelogfilterr(   )
rV   r   r9   r   r   r[   r   rU   r:   rW   s
   `    ` @@@r'   _genrevancestorsrb      sN    	BF J{{78ZDIIr5   c                0    [        XX#XE5      n[        USS9$ )aT  Like revlog.ancestors(), but supports additional options, includes
the given revs themselves, and returns a smartset

Scan ends at the stopdepth (exlusive) if specified. Revisions found
earlier than the startdepth are omitted.

If cutfunc is provided, it will be used to cut the traversal of the DAG.
When cutfunc(X) returns True, the DAG traversal stops - revision X and
X's ancestors in the traversal path will be skipped. This could be an
optimization sometimes.

Note: if Y is an ancestor of X, cutfunc(X) returning True does not
necessarily mean Y will also be cut. Usually cutfunc(Y) also wants to
return True in this case. For example,

    D     # revancestors(repo, D, cutfunc=lambda rev: rev == B)
    |\    # will include "A", because the path D -> C -> A was not cut.
    B C   # If "B" gets cut, "A" might want to be cut too.
    |/
    A
FrF   )rb   rH   )rV   r   r9   r   r   r[   rI   s          r'   revancestorsrd      s$    0 KYC U++r5   c              #  x  #    U(       a  SnOS nU R                   nUR                  5       nU[        :X  a  Uv   U H  nUv   M	     g [        U5      nUR	                  U5       HR  nXg;   a  Uv   M  UR                  U5      S U  H,  nU[        :w  d  M  X;   d  M  UR                  U5        Uv     MP     MT     g 7f)Nr   )r`   minr   r-   r   rS   r.   )	rV   r   r9   r:   rU   firstiseenxs	            r'   _genrevdescendantsrk      s     	BHHJE AG  4yAy]]1%ds+<AIHHQKG	 ,	  s   BB:B:B:c                h   U R                   n[        U[        U5      5       Vs/ s H  n/ PM     nnUR                  US-   5       Hc  nUR	                  U5      u  pxXq:  a  XWU-
     R                  U5        U(       a  M:  U[        :w  d  MF  X:  d  MM  XXU-
     R                  U5        Me     U$ s  snf )z6Build map of 'rev -> child revs', offset from startrevr   )r`   rangelenr   rS   appendr   )	rV   startrevr9   rU   _revdescmapr"   p1revp2revs	            r'   _builddescendantsmapru      s    	B#Hc"g676dr6G7''(Q,'}}V,H$%,,V4{u/E4EH$%,,V4 ( N 8s   B/c                d   ^^ UR                  5       m[        U TU5      mUU4S jn[        XQX4SS9$ )Nc                   > TU T-
     $ r+   rA   )r0   rr   rp   s    r'   r   (_genrevdescendantsofdepth.<locals>.pfunc   s    sX~&&r5   Fr_   )rf   ru   r(   )rV   r   r9   r   r   r   rr   rp   s         @@r'   _genrevdescendantsofdepthry      s2    xxzH"4;?G' ZEJJr5   c                j    Uc  Ub
  U[         :  a  [        XU5      nO[        XX#U5      n[        USS9$ )zLike revlog.descendants() but supports additional options, includes
the given revs themselves, and returns a smartset

Scan ends at the stopdepth (exlusive) if specified. Revisions found
earlier than the startdepth are omitted.
TrF   )r   rk   ry   rH   )rV   r   r9   r   r   rI   s         r'   revdescendantsr{      sB     y0I4L [9'
 T**r5   c              #    #    [        U 5      nU[        :X  a  U" 5        H  nUv   M	     g[        U 5      nU" US-   S9 H;  nU" U5       H,  nU[        :w  d  M  Xe;   d  M  UR                  U5        Uv     M9     M=     g7f)a?  Generate revision number descendants in revision order.

Yields revision numbers starting with a child of some rev in
``revs``. Results are ordered by revision number and are
therefore topological. Each revision is not considered a descendant
of itself.

``revsfn`` is a callable that with no argument iterates over all
revision numbers and with a ``start`` argument iterates over revision
numbers beginning with that value.

``parentrevsfn`` is a callable that receives a revision number and
returns an iterable of parent revision numbers, whose values may include
nullrev.
Nr   start)rf   r   r-   r.   )r   revsfnparentrevsfnrg   r0   ri   r&   s          r'   descendantrevsr      su       IE8CI t9DEAI& %Dw4<		 & 's   AA?A? A?c                  @    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
rg)subsetparentswalkeri  a  Scan adjacent ancestors in the graph given by the subset

This computes parent-child relations in the sub graph filtered by
a revset. Primary use case is to draw a revisions graph.

In the following example, we consider that the node 'f' has edges to all
ancestor nodes, but redundant paths are eliminated. The edge 'f'->'b'
is eliminated because there is a path 'f'->'c'->'b' for example.

      - d - e -
     /         \
    a - b - c - f

If the node 'c' is filtered out, the edge 'f'->'b' is activated.

      - d - e -
     /         \
    a - b -(c)- f

Likewise, if 'd' and 'e' are filtered out, this edge is fully eliminated
since there is a path 'f'->'c'->'b'->'a' for 'f'->'a'.

       (d) (e)

    a - b - c - f

Implementation-wise, 'f' is passed down to 'a' as unresolved through the
'f'->'e'->'d'->'a' path, whereas we do also remember that 'f' has already
been resolved while walking down the 'f'->'c'->'b'->'a' path. When
processing the node 'a', the unresolved 'f'->'a' path is eliminated as
the 'f' end is marked as resolved.

Ancestors are searched from the tipmost revision in the subset so the
results can be cached. You should specify startrev to narrow the search
space to ':startrev'.
Nc                   Ub  UR                  SU5      U-  nUR                  nU(       a  U" 5       nOZUR                  5       (       d:  UR                  5       (       d%  [        R
                  " U5      nUR                  SS9  [        U5      nXl        UR                  U l
        X l        / U l        0 U l        0 U l        0 U l        [         U l        XPl        [         U l        U R)                  5         g )Ns   %d:nullTr_   )r   fastdescisdescendingistopor   basesetr   r   _repor`   
_changelog_subset_tovisit_pendingcnt	_pointers_parentsr   
_inputhead
_inputtail
_bottomrev_advanceinput)selfrV   subsetrp   r   desciters         r'   __init__subsetparentswalker.__init__C  s    YYz84v=F ??zH&&((!))&1D)F|H
.. !"!r5   c                L    [         R                  " U R                  U5      5      $ )zNLook up parents of the given revision in the subset, and returns
as a smartset)r   r   r7   )r   r0   s     r'   
parentssetsubsetparentswalker.parentsset`  s     S 122r5   c                    U R                  U5        [        U R                  R                  U/ 5      5       VVs/ s H  u  p#UPM	     snn$ s  snnf )zpLook up parents of the given revision in the subset

The returned revisions are sorted by parent index (p1/p2).
)_scanparentssortedr   get)r   r0   _crZ   s       r'   r7   subsetparentswalker.parentse  sD    
 	#%dmm&7&7R&@ABAebABBBs   Ac                     U R                   R                  U5      nUS   [        :X  a  US S $ U$ ! [        R                   a0    [        S U R                  S    R                  5        5       5      s $ f = f)Nr   c              3  @   #    U  H  oR                  5       v   M     g 7fr+   rN   rO   s     r'   rD   2subsetparentswalker._parentrevs.<locals>.<genexpr>t  s     K0J0JrR   )r   rS   r   r   rT   tupler   r7   )r   r0   r   s      r'   _parentrevssubsetparentswalker._parentrevsm  ss    	L??--c2DBx7"CRy K$$ 	LK

40@0H0H0JKKK	Ls   ,1 1 AA54A5c                    U R                   [        :  a  g [        U R                  5      U l         g! [         a"    U R                   U l        [        S-
  U l          gf = f)zBAdvance the input iterator and set the next revision to _inputheadNr   )r   r   r   r   StopIterationr   )r   s    r'   r   !subsetparentswalker._advanceinputv  sK    ??W$	*"4??3DO 	*"ooDO%kDO	*s   2 )AAc                  ^ U R                   mU R                  nU R                  nU R                  nU R                  nU(       d  U R
                  [        :  Ga  UR                  U5      S:X  a  gU(       d1  [        R                  " X R
                  * 5        U R                  5         U R
                  US   * :  aG  [        R                  " X R
                  * 5        U R                  5         U R
                  US   * :  a  MG  [        R                  " U5      * nX`R                  :  a  gXc;   a  Xd;  a  M  UT;   nUR                  US5        U(       a  Xe;  d   e/ XV'   UR                  U0 [        5       45      u  pU(       a  UR!                  5        HQ  u  pX:==   S-  ss'   X:   S:  d   eX;   a  M"  XZ   R#                  X45        X:   S:  d  M@  U	R%                  U
5        MS     UR'                  5         U	 V
s1 s H  oU
   S:  d  M  U
iM     n	n
U R)                  U5      n[+        U4S jU 5       5      nU(       a  U(       d  U	(       Ga#  [-        U5      S::  a  X4/nO^X4UR/                  5       U	R/                  5       4/nU H5  n
X:==   S-  ss'   US   S   U
==   S-  ss'   US   S   U
==   S-  ss'   M7     [1        U5       H  u  nnUU:  d   e[        R                  " UU* 5        UU;   ao  UU   u  nnX   u  pUR!                  5        H:  u  pU
U;   a*  X:==   S-  ss'   X:   S:  d   e[3        UUU
   5      UU
'   M5  UUU
'   M<     UR5                  U	5        M  X   UU'   M     [-        U5      S::  a  S/OSS/nU(       aA  U(       a:  [1        U5       H   u  nnUU   nXV   R#                  UU45        M"     X6   S:X  d   eOU(       az  [1        U5       HW  u  nnUU   u  pXh;  d   eUU   nUT;   a(  XV   R#                  UU45        U	R%                  U5        MG  X6==   S-  ss'   XU'   MY     SX6   s=:  a  S::  d   e   eU(       a  GM  U R
                  [        :  a  GM  ggs  sn
f )	zFScan ancestors until the parents of the specified stoprev are
resolvedr   Nr   c              3  ,   >#    U  H	  oT;   v   M     g 7fr+   rA   )rB   pr   s     r'   rD   3subsetparentswalker._scanparents.<locals>.<genexpr>  s     #DAKs      1   2r5      )r   r   r   r   r   r   r   r   r   r   r   r   r   
setdefaultr6   r-   itemsro   r.   clearr   allrn   copy	enumeraterf   update)r   stoprevtovisit
pendingcntpointersr7   r0   	curactive
unresolvedresolvedrZ   r;   rS   bothparentsactiveparentpointersrh   r   knownunresolvedknownresolved
chaincodesr   s                       @r'   r    subsetparentswalker._scanparents  sM   , --%%
>>--G3~~g&!+ w(89""$//gaj[0w(89""$ //gaj[0 ==))C__$ S%8vI!!#q))))!#+<<b#%[#A J&,,.DAMQ&M%=A---} J%%qh/ "}q( Q /   " (0Ex!a=13DAxE))#.J ##D#D D
 %
hz?a''1&<%=N $.#*HMMO<&N ("*&q)!,Q/47/&q)!,Q/47/ ( &j1DAqs7N7NN7QB/H} :B!6/=/@,
$.$4$4$6DA O3 * 2'1}q'8 8'858OA<N5O 256 2 %7 &,,X6&4&7+ 24 #&j/Q"6#T4LJ.%j1DAq"1AL''A/ 2
 "!+++%j1DAq+3A;(J000"1AF{++QF3 S)"1,*+3 2 :?/a/////_ gG33R Fs   =Q6Q6)
r   r   r   r   r   r   r   r   r   r   r+   )__name__
__module____qualname____firstlineno____doc__r   r   r7   r   r   r   __static_attributes__rA   r5   r'   r   r     s)    #J:3
CL*K0r5   r   c                   U(       d  / $ [        U5      n[        U5      n[        5       n0 nUR                  nUR                  n	UR                  n
U(       aQ  U
" 5       nX;   a  U" U5        U(       d  M$  U " U5      nXU'   U H  nX:  d  M
  X;  d  M  U	" U5        M     U(       a  MQ  U(       d
  [        5       $ U(       d  U$ [        U5       H  nX{    H  nX;   d  M
  U" U5        M     M     U$ zSee revlog.reachableroots)r-   listr.   ro   r6   r   r   )r   minrootrootsheadsincludepathr1   	reachableri   reacheddovisit	nextvisitr0   r7   r=   s                 r'   _reachablerootspurer     s    	JEKEIDmmGllG		I k<CL*S	F V%7  % yd|iF"    r5   c                    U(       d
  [        5       $ UR                  5       n[        U5      n[        U5      nU R                  R	                  XBX5      n[        U5      nUR                  5         U$ r   )r   rf   r   r`   reachablerootsr   )rV   r   r   r   r   r   s         r'   r   r   2  sW    yiikGKEKE>>((LD4=DIIKKr5   c                    [         R                  " U R                  5       UR                  5       U5      n[         R                  " XB5      u  pV[	        S U 5       5      nXv4$ )zReturn `(diffinrange, linerange1)` where `diffinrange` is True
if diff from fctx2 to fctx1 has changes in linerange2 and
`linerange1` is the new line range for fctx1.
c              3  0   #    U  H  u  pUS :H  v   M     g7f)   !NrA   )rB   _stypes      r'   rD    _changesrange.<locals>.<genexpr>F  s     CNetmNs   )r	   	allblocksdatablocksinrangeany)fctx1fctx2
linerange2diffoptsblocksfilteredblocks
linerange1diffinranges           r'   _changesranger   ?  sN    
 __UZZ\5::<BF!&!4!4V!HNCNCCK""r5   c              #  d  #    [         R                  " U R                  R                  5      nU R	                  5       n U R                  5       U R                  5       4XU440nU(       a  UR                  [        U5      5      u  pgUR                  5       nU(       a  USS nU(       d  Xg4v   MM  Sn	U Hb  n
[        XXt5      u  pU	=(       d    Un	US   US   :X  a  M*  UR                  5       U
l        X4XZR                  5       U
R                  5       4'   Md     U	(       a  Xg4v   U(       a  M  gg7f)z_Yield ancestors of `fctx` with respect to the block of lines within
`fromline`-`toline` range.
Nr   Fr   )r
   r   r   uiintrofilectxlinkrevfilenoder6   maxr7   r   r0   _descendantrev)r/   fromlinetoliner9   r   r1   r;   r   plinranger   inrangepr   s                r'   blockancestorsr   J  s     ~~djjmm,HDllndmmo.&7I0JKE
		#e*-YY[BQB-A#0z#L H)G!}
1-   !uuwA/0}E))+qzz|+,  -1 %s   D*D0.D0c              #    #     [        [        XU5      5      u  p4X0:X  a  X44v   [        R                  " U R
                  R                  5      nU R                  5       nU R                  5       XU440nUR                  U R                  5       /5       H  nU R                  U5      nSn	UR                  U5       Ha  n
 Xz   u  p[        X;X5      u  pU	=(       d    Un	X;   a4  Xx   S   U:w  a)  [        XGU   S   5      u  p[        U5      [!        U5      4nX44Xx'   Mc     U	(       d  M  UW4v   M     g! [         a     GNf = f! [         a     M  f = f7f)zaYield descendants of `fctx` with respect to the block of lines within
`fromline`-`toline` range.
Fr   N)r   r   r   r
   r   r   r   filelogfilerevdescendantsfilectxrS   KeyErrorr   ziprf   r   )r/   r   r   r;   r   r   flri   rh   r   rj   r   r   r   lbsubss                   r'   blockdescendantsr  l  sI     ^DFCD 9-~~djjmm,H	BLLNTf#567D^^T\\^,-LLOq!A $ $1z#L H)G
 yTWQZ:5z71:6 Xs3x/
mDG "  7Z-) .    sS   ED4 B#E?EA E)E4
E>EEE
EEEET)slotsfrozenc                      \ rS rSr\R
                  " 5       r\R
                  " 5       r\R
                  " SS9r\R
                  " SS9r	Sr
g)annotatelinei  F)defaultNrA   )r   r   r   r   r   ibr/   linenoskiptextr   rA   r5   r'   r  r    s4    779DWWYF775!D774 Dr5   r  c                      \ rS rSr\R
                  " 5       r\R
                  " 5       r\R
                  " 5       r\R
                  " 5       r	Sr
g)_annotatedfilei  rA   N)r   r   r   r   r   r
  r8   linenosskipsr  r   rA   r5   r'   r  r    s0     GGIEggiGGGIE779Dr5   r  c                    U R                  S5      (       a  U R                  S5      $ U R                  S5      [        [        U 5      5      -   $ )N   
)endswithcountintbool)r  s    r'   _countlinesr    s<    }}Uzz%  ::es4:..r5   c                x    [        U 5      n[        R                  " SUS-   5      n[        U/U-  US/U-  U 5      $ )Nr   F)r  r   	rangelistr  )r  r/   nr  s       r'   _decoratelinesr    s?    DA  AE*G4&1*gw{DAAr5   c           
         U  Vs/ s H/  nU[         R                  " UR                  UR                  US94PM1     nnU(       a!  U VVs/ s H  u  pxU[        U5      4PM     nnnU Hj  u  pXU H_  u  u  ppnUS:X  d  M  UR                  X UR                  X& UR
                  X UR
                  X& UR                  X UR                  X& Ma     Ml     U(       Ga  UR                  5         U VVs/ s H	  u  p^U/ 4PM     nnn[        U5       H  u  nu  pXU H  u  u  ppnX-
  X-
  :  a  [        X5       Ht  nUR                  U   U:X  d  M  [        U	UU-
  -   U
S-
  5      nUR                  U   UR                  U'   UR
                  U   UR
                  U'   SUR                  U'   Mv     M  UU   S   R                  XX45        M     M     U H  u  pXU H  u  pp[        X5       Ht  nUR                  U   U:X  d  M  [        U	UU-
  -   U
S-
  5      nUR                  U   UR                  U'   UR
                  U   UR
                  U'   SUR                  U'   Mv     M     M     U$ s  snf s  snnf s  snnf )aT  
Given parent and child fctxes and annotate data for parents, for all lines
in either parent that match the child, annotate the child with the parent's
data.

Additionally, if `skipchild` is True, replace all other lines with parent
annotate data as well such that child is never blamed for any lines.

See test-annotate.py for unit tests.
)opts   =r   T)r	   r   r  r   r8   r  r  r   r   rm   rf   ro   )r7   	childfctxchild	skipchildr   r=   pblocksr   r   a1a2b1b2t_blocks	remainingidx_tbkaks                       r'   _annotatepairr/    sj    F 
ejjxHI  
 8?@!AtF|$@ "#)RRa Dy%+\\"%8B"'-~~b'<b$%+\\"%8B" $* "  	 :AAoffb\	A%.w%7!C!&(.$ "7bg%#Bm ;;r?i7!$R27^R!V!<B.4ll2.>EKKO06r0BEMM"-.2EKKO , cN1%,,bb-=> )/ &8 (NF"(-B{{2)3 rBwa8*0,,r*:B,2NN2,>b)*.B ( #) ( Lq A4 Bs   6I/	I42I:c                   U /n0 nU S0nU(       ad  UR                  5       nXu;   a  M  U" U5      nXU'   U H2  n	UR                  U	S5      S-   Xi'   X;  d  M!  UR                  U	5        M4     U(       a  Md  U /USS& 0 n
U(       a  US   nXz;   a  UR                  5         M#  SnXW   nU H  n	X;  d  M
  SnUR                  U	5        M     U(       a  UR                  5         [        UR	                  5       U5      nSnUb  UR
                  U;   n[        U V	s/ s H  oU	   PM	     sn	X|X5      nU H  n	Xi   S:X  a  X	 Xi	 M  Xi==   S-  ss'   M     XU'   XW	 U(       a  M  X   n[        UR                  UR                  UR                  [        R                  " UR                  5      5       Vs/ s H  n[        U6 PM     sn$ s  sn	f s  snf )zjCore algorithm for filectx.annotate()

`parents(fctx)` is a function returning a list of parent filectxs.
r   r   Nr   TF)r6   r   ro   r  r   	_changeidr/  r   r8   r  r  r	   splitnewlinesr  r  )baser7   skiprevsr   r1   pcacheneededfr   r   histreadycurrr"  arZ   s                   r'   annotater<    s    FEFAYF
IIK;QZq	A

1a(1,FIQ  % vE!HD
"I9IIKYA}Q  IIK!!&&(A.DI#KK83	 "$%"Qa"%q	D 9>	INI  G	; %> 	
A QWWaii%2E2Eaff2MNNA 	aN  &s   G0G
c              #    #    U R                  SS9  [        U5      n/ U4/n/ n[        5       n[        R                  " U5        [        R                  n[        R
                  nU  GH  n	X;  a  U" XY* 5        UR                  U	5        Sn
X:w  d  M,  U" U5      * n
UR                  U
5        [        U5       VVs/ s H  u  pXS   ;   d  M  UPM     nnnU(       aV  UR                  S5      nXN   u  nnU H#  nXK   nUR                  US   5        UUS   -  nM%     [        U5       H  nXK	 M     O[        U5      nUR                  / U
145        XN   nX:X  a  US   R                  U
5        US   R                  U
5        U" U
5       Vs/ s H  nU[        :  d  M  UPM     nnUS   R                  U5        U H&  nUU;  d  M  UR                  U5        U" UU* 5        M(     U(       d  [        U5      S:  a  SnUS   nOUS   U-  (       d  SnUb'  UUS   -  nUS    Sh  vN   U(       a  XN	 O/ US   SS& X:w  a  GM  GM     U H  nUS    Sh  vN   M     gs  snnf s  snf  NE N7f)a  Yield revisions from heads to roots one (topo) branch at a time.

This function aims to be used by a graph generator that wishes to minimize
the number of parallel branches and their interleaving.

Example iteration order (numbers show the "true" order in a changelog):

  o  4
  |
  o  1
  |
  | o  3
  | |
  | o  2
  |/
  o  0

Note that the ancestors of merges are understood by the current
algorithm to be on the same branch. This means no reordering will
occur behind a merge.
Tr_   Nr   r   )r   r-   r   heapifyr   r   r.   remover   r6   extendreversedrn   ro   r   r   )r   parentsfuncfirstbranch	unblockedgroupsr   
pendingsetr   r   
currentrevr0   rh   gmatching	targetidxtrevstparentsgrr   r7   s                       r'   toposortrN  ;  s    f 	IIdI K I2 9oFKJ	MM+mmG~~H
'[+.NN:& ;''Cc" '0&7G&7da3A$;&7HG( %LLO	"("3x!ABLLA'1%H " "(+A	 ,  K	rC5k*"B  1S!qELL"-c"2B"2Qa'kq"2GBqELL!J&NN1%[1"-   v;? !IBUY&~ RU"	a5   )!BqE!Hu  J Q4 q Hb C< ! 	s\   BI0(I0:I!I!B:I0I'I'$I0AI0&I,'I0I0I.I0.I0c                    [        U 5      n[        1nUR                  nU  H  nU" U" U5      5        M     UR                  U5        U$ )a  Resolve the set of heads from a set of revisions.

Receives an iterable of revision numbers and a callbable that receives a
revision number and returns an iterable of parent revision numbers, possibly
including nullrev.

Returns a set of revision numbers that are DAG heads within the passed
subset.

``nullrev`` is never included in the returned set, even if it is provided in
the input set.
)r-   r   r   difference_update)r   	parentsfnheadrevsr7   upr0   s         r'   rR  rR     sF     4yHiG	B
9S> w'Or5   c                   [        5       n[        5       n[        5       n[        US-
  US-
  S5       HK  nXc;   a  UR                  U5        OUR                  U5        U " U5       H  nUR                  U5        M     MM     US-
  nU(       aU  Xc;   a"  UR                  U5        UR                  U5        U " U5       H  nUR	                  U5        M     US-
  nU(       a  MU  XT4$ )zOCompute how the set of heads changed between
revisions `start-1` and `stop-1`.
r   r   )r-   rm   r?  r.   discard)rQ  r~   stopr7   heads_addedheads_removedr0   r   s           r'   headrevsdiffrY    s     eG%KEMTAXuqy"->NN3OOC 3AKKN   . !)C
>c"NN33AOOA  Ag ' ''r5   c                    Uc  [         n[        U=(       d    / 5      nU1nU1nU " US-   S9 H]  nU" U5       HN  nXt;   a'  Xc;  a  UR                  U5        UR                  U5        Xu;   d  M6  Xs;  d  M=  UR                  U5        MP     M_     U$ )a}  Returns the set of all revs that have no children with control.

``revsfn`` is a callable that with no arguments returns an iterator over
all revision numbers in topological order. With a ``start`` argument, it
returns revision numbers starting at that number.

``parentrevsfn`` is a callable receiving a revision number and returns an
iterable of parent revision numbers, where values can include nullrev.

``startrev`` is a revision number at which to start the search.

``stoprevs`` is an iterable of revision numbers that, when encountered,
will stop DAG traversal beyond them. Parents of revisions in this
collection will be heads.
r   r}   )r   r-   r.   r?  )r   r   rp   stoprevsr   r   r0   r&   s           r'   headrevssubsetr\  6  s      8>r"H
IJEHqL) %D &MM#&		#}!5T" & * Lr5   c                   [        [        [        X5      SS95      n[        5       n/ nU(       a  UR	                  5       nUS:  a.  U* S-
  nXS;  a"  UR                  U5        UR                  U5        OKUR                  U* S-
  5        U" U5       H*  nU[        :X  d
  X`;  d  Xc;   a  M  UR                  U5        M,     U(       a  M  [        U5      [        U 5      :X  d   eU$ )a  Linearize and topologically sort a list of revisions.

The linearization process tries to create long runs of revs where a child
rev comes immediately after its first parent. This is done by visiting the
heads of the revs in inverse topological order, and for each visited rev,
visiting its second parent, then its first parent, then adding the rev
itself to the output list.

Returns a list of revision numbers.
Tr_   r   r   )	r   r   rR  r-   r6   ro   r.   r   rn   )r   rQ  r1   finishedresultr0   r&   s          r'   	linearizer`  [  s     14@AEuHF
iik7$(C"c"S! LL#"!#7?d&6$:JT"	 ' %$ v;#d)###Mr5   )F)FNNN)NN)returnzList[annotateline])rA   )0
__future__r   r   typingr   
thirdpartyr   TYPE_CHECKINGnoder    r   r	   r
   r   r   r   r   rH   r   r(   r>   rJ   rb   rd   rk   ru   ry   r{   r   r   r   r   r   r   r  sr  r  r  r  r/  r<  rN  rR  rY  r\  r`  rA   r5   r'   <module>ri     s8   #    
   

$$ 2KjB,J, MQ,<6
K+ @n0 n0b!H
# D% P d4 ! ! !! d4   !/BCL?DBJ.(>"J#r5   