
    6h_C                       S r SSKJ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
JrJr  SrS	rS
rSr\S\S\S0rS rS rS rS rS rS rS rS rS r\R6                   " S S5      5       rS rS rg)a>  supports walking the history as DAGs suitable for graphical output

The most basic format we use is that of::

  (id, type, data, [parentids])

The node and parent ids are arbitrary integers which identify a node in the
context of the graph returned. Type is a constant specifying the node type.
Data depends on type.
    )annotationsN   )nullrev)attr)dagopsmartsetutil   C   P   G   M   |   :c              #    ^
#    0 nU GH  nX   nUR                  5        Vs1 s H(  oUR                  5       U;   d  M  UR                  5       iM*     snm
UR                  5        Vs/ s HC  nUR                  5       [        :w  d  M  UR                  5       T
;  d  M3  UR                  5       PME     nn[        T
5       Vs/ s H  n[        U4PM     nnU H  nUR                  U5      n	U	cc  [        U[        R                  5      (       d  [        R                  " U5      n[        [        [        R                  " XU/5      5      5      =oU'   U	(       d*  UR                  [        U45        T
R                  U5        M  UR                  U
4S jU	 5       5        T
R!                  U	5        M     UR                  5       ["        XG4v   GM     gs  snf s  snf s  snf 7f)a  cset DAG generator yielding (id, CHANGESET, ctx, [parentinfo]) tuples

This generator function walks through revisions (which should be ordered
from bigger to lower). It returns a tuple for each node.

Each parentinfo entry is a tuple with (edgetype, parentid), where edgetype
is one of PARENT, GRANDPARENT or MISSINGPARENT. The node and parent ids
are arbitrary integers which identify a node in the context of the graph
returned.

Nc              3  B   >#    U  H  oT;  d  M
  [         U4v   M     g 7fN)GRANDPARENT).0gpsets     4/usr/lib/python3/dist-packages/mercurial/graphmod.py	<genexpr>dagwalker.<locals>.<genexpr>Z   s     MA}/Q/s   	)parentsrevr   sortedPARENTget
isinstancer   basesetsetr   reachablerootsappendMISSINGPARENTaddextendupdate	CHANGESET)reporevsgpcacher   ctxpmparsr   mpargpr   s             @r   	dagwalkerr1   1   s     Gi "%BA%%'T/B [[]
"uuw'! &'eegT&9 AEEG" 	 

 )/t51FA;5DT"Bz "$(8(899#++D1D%+,,T$@A& T] t45MMMB " wwy)S22= 
 C

 6s:   GGGG&GGG0G?GDGc              #    #    [        U5      nU Hs  nX   nUR                  5        Vs1 s H.  oUR                  5       U;   d  M  [        UR	                  5       4iM0     nnUR	                  5       [
        U[        U5      4v   Mu     gs  snf 7f)zcset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples

This generator function walks the given nodes. It only returns parents
that are in nodes, too.
N)r!   r   noder   r   r(   r   )r)   nodesincluder3   r,   r-   r   s          r   r4   r4   `   s|      %jGj'*{{}
'4!G8KVQUUW} 	 
 wwy)S&/:: 
s   'BBB/Bc              #    ^^#    / n0 nSn0 mTR                   R                  S5       H  u  pVSU;   d  M  UR                  SS5      u  pxUS:X  a5  UR                  5       (       a   [	        U5      TR                  U0 5      U'   M\  US:X  d  Md  UR                  5       (       d  M{  UTR                  U0 5      U'   M     T(       a  [        R                  " UU4S j5      n	OS n	U  GHy  u  ppX;  a  UR                  U
5        XCU
'   US-  nUR                  U
5      nUR                  U
5      nUSS nU VVs/ s H  u  nnUU;  d  M  UPM     nnnUUXS-   & [        U5       H  u  nnU(       d  XU'   M  XCU'   US-  nM     / n[        U5       H  u  nnUU;   aR  U	" U5      nUR                  UUR                  U5      UU   UR                  SS	5      UR                  SS
5      45        M^  UU
:X  d  Mf  U HS  u  nnU	" U5      nUR                  UUR                  U5      UUR                  SS	5      UR                  SS
5      45        MU     M     XXU4U4v   UnGM|     gs  snnf 7f)a\  annotates a DAG with colored edge information

For each DAG node this function emits tuples::

  (id, type, data, (col, color), [(col, nextcol, color)])

with the following new elements:

  - Tuple (col, color) with column and color index for the current node
  - A list of tuples indicating the edges between the current node and its
    parents.
r   s   graph   .s   widths   colorc                J   > TR                  TU    R                  5       0 5      $ r   )r   branch)r   configr)   s    r   <lambda>colored.<locals>.<lambda>   s    

49#3#3#5r:    c                    0 $ r    )r   s    r   r;   r<      s    br=   Nr=   )uiconfigitemsrsplitisdigitint
setdefaultisalnumr	   lrucachefuncr#   indexpop	enumerater   )dagr)   seencolorsnewcolorkeyvalr9   settinggetconfcurtypedatar   colcolornextptr-   
addparentsiedgesecoleidbconfptyper:   s    `                        @r   coloredrb   o   s\     DFHFGG''13;!jjq1OF("s{{}}9<S!!&"-g6H$9<!!&"-g6 2 ##:
 !$' 4?KK"3KMHjjo

3Aw &->WEBaW
>(S7 j)DAq!q	$q	A * "4ID#d{

3s		(B/		(C0  'HE1#AJELL  JJqM!!IIh3!IIh4 !( )4 $ee44i %( ?s2   -I)AI)I)#BI)6I#I#B$I)5A4I)c              #    #    UR                   nX5;  a  UR                  U5        UR                  U5      n/ n/ nU H^  u  pX:X  a  M  X;   a  UR                  U
5        M$  UR                  U
5        UR                  R	                  U	S5      UR
                  U
'   M`     [        U5      nSUS-  -   nUSS nXXfS-   & U Vs/ s H  oUR                  U5      4PM     nnXSS& [        U5      S:  aY  UR                  Xf45        UR                  XfS-   45        SnUS-  nXXXU44v   SnUS-  nUS-  n/ nUS	 [        U5      S:  a  MY  [        U5      S:  a  UR                  Xf45        [        U5      S:  a  UR                  XfS-   45        [        U5      U-
  nUS:  a  US-  nUR
                  R                  US5        XXXU44v   gs  snf 7f)z9adds edge info to changelog DAG walk suitable for ascii()r   r      N   \r   )rM   r#   rI   stylesr   r]   lenrJ   )rU   charstater   r   rM   nodeidxknownparents
newparentsra   parentncolswidthnextseenr-   r]   	nmorecolss                    r   
asciiedgesrr      s    ::D
CjjoGLJ =>'f%"',,"2"25$"?EKK ! IE	MEAwH&0W{#3?@<ax~~a()<E@G
j/A

 	g'(g{+,	
5E)"DEE1
qM j/A
  :g'(
:g{+,H%I1}
	KKOOCui@
AA9 As   B>G GA,G
B	Gc                P    [        U 5       H  u  nu  p#X2:  d  M  X#S-   4X'   M     g )Nr   )rK   )r]   r\   startends       r   _fixlongrightedgesrv      s*    $U+<E;Qw'EH ,r=   c                    U(       aS  XE:X  aN  US:w  aH  US:X  a6  [        US-   U5      nXS-  US-
  S-   nUR                  SS/X7-
  -  5        U$ SS/X1-
  S-
  -  $ X1-
  S-
  n	U	S:  a  X	S-  * S  $ / $ )Nr   r@   r   rd      /    re   )maxr&   )
echarsidxpidxrn   coldiffpdifffix_tailrt   tail	remainders
             r   _getnodelineedgestailr     s    G$Ab=a&E'UQY!O4DKKt67K4=EK!O44K!O	-6]vA&()BBr=   c                2   U H  u  pEXES-   :X  a  SUSU-  S-   '   M  XES-
  :X  a  SUSU-  S-   '   M/  XE:X  a  U SU-     USU-  '   MD  SU-  [        U5      :  a  MX  SUSU-  '   XE:  a  XTpT[        SU-  S-   SU-  5       H  nX&   S:w  d  M  SX&'   M     M     g )Nr   rx   rd   re      +   -)rg   range)r{   r]   nodeline	interlinert   ru   r\   s          r   
_drawedgesr     s    
!G%)Ia#gk"Ag',Ia%i!m$\#)!e)#4Ia%i 3w#h-' $HQW{ #1u9q=!c'2;$&"&HK 3 r=   c                    U S US-   nXS-
  4U;   d  X4U;   a  UR                  XS-  US-   S-   5        OUR                  SS/5        X!-
  S-
  nUS:  a  UR                  XS-  * S  5        U$ )Nrd   r   ry   r   )r&   )r{   r|   rn   r]   liner   s         r   _getpaddingliner   &  s    )C!GD1W~3*"5 	F7cAg]34T4L!aI1}F]+-./Kr=   c           	        SUR                  5       ;  a  gUSSS2   nU(       a%  US   c  UR                  5         U(       a  US   c  M  [        UR                  S5      S-  S-
  S5      nUR                  (       d  SOSn[        U 5      Xv-   :  a'  U R                  USS 5        [        U 5      Xv-   :  a  M'  U(       a  / n/ n	UR                  S5      n
[        XSS2   U
S-  5       H2  u  pUc  UR                  US-  5        M  U	R                  US-  5        M4     [        [        X[        U	5      S-  -   S5      5      nU	SS nX* S  H]  nS/[        U5      U
-
  -  XS& [        [        U5      5       H.  nX   S-
  n[        UX   5      X'   UX   :  a  SOXU      UU'   M0     M_     UR                  (       d  S	S
S.OSS
0n[        U 5       H;  u  pSU;  a  M  U Vs/ s H  o=(       d    UR                  US5      PM     snUSS& M=     UR                  5        VVs/ s H  u  nob  M
  UPM     nnnU H  nUU	 UR                  U5        M     gs  snf s  snnf )zDraw ending lines for missing parent edges

None indicates an edge that ends at between this node and the next
Replace with a short line ending in ~ and add / lines to any edges to
the right.

Nrd   r@   r   r      ry   rx   r      ~)r   rd   )valuesrJ   rz   countgraphshortenrg   r#   rI   rK   listr   r   itemsremove)linesextraedgemaprM   ri   	edgechars
shift_sizeminlinesemptiestoshiftfirst_emptyr\   ctargets	positionsr   posmapr-   r   rm   s                        r   _drawendinglinesr   ;  sO    7>>## cc
I
	"- 	"-iood+a/14a8J**qH
e*x,
,U1X e*x,
, kk$'eNN3[A5EFDAyq1u%q1u%	 G
 u[Gq8H*H!LMAJ	+,'D"&3t9{+B!CD3y>*lQ&"3
3	$''*$4D%
:KS	 + ( %*$6$6dt
QICU#t267$Q(4(($7Q $ $MMO9ODAqaOF9FOF 	 8 :s   #$I$	I1Ic                  X   \ rS rSrSr\R                  " S\R                  " \5      S9r	\R                  " S\R                  " \
5      S9r\R                  " SSS9r\R                  " SSS9r\R                  " S\R                  " \R                  5      S9r\R                  " SSS9rSrg)
asciistateio  z State of ascii() graph renderingF)initdefaultr   r?   N)__name__
__module____qualname____firstlineno____doc__r   ibFactoryr   rM   dictr]   lastcoldiff	lastindexEDGEScopyrf   r   __static_attributes__r?   r=   r   r   r   o  s    *77t||D'9:DGGT(:;E''ua0KUA.IWW%ejj)ABF77u5Lr=   r   c                b    U H)  u  p#U R                  X#-   R                  5       S-   5        M+     g)a<  outputs an ASCII graph of a DAG

this is a helper function for 'ascii' below.

takes the following arguments:

- ui to write to
- graph data: list of { graph nodes/edges, text }

this function can be monkey-patched by extensions to alter graph display
without needing to mimic all of the edge-fixup logic in ascii()
   
N)writerstrip)rA   graphlnlogstrs       r   outputgraphr   {  s,     

"+%%'%/0 r=   c                &   Uu  pgpSU	s=:  a  S:  d   e   eUR                   UR                  pU VVs/ s H  oR                  US5      S4  H  oPM     M!     nnnUR                  S[	        X-   [        U5      -
  S5      -  5        U	S:X  a  [        U5        [        U5      S:  =(       a/    U	S:H  =(       a#    U VVs/ s H  u  nnUS-   U:  d  M  UPM     snnn[        U5      S:*  =(       a    U(       + nUS	US-   nUR                  US/5        UR                  [        UUUR                  UU	UR                  U5      5        US	US-   n[        SU	-   5       H  nUR                  S5        M     X-
  S-
  nU	S:X  a&  [        U5       H  nUR                  S
S/5        M     OHU	S:X  a  UR                  XS-   S-  US-   5        O%[        U5       H  nUR                  SS/5        M     [        XUU5        U/nU(       a  UR                  [        XX5      5        UR                  (       a)  [        S U 5       5      (       a  UR                  U5        OUR                  U5        US	X-   S-   n[        U5      [        U5      :  aF  [        U5      [        U5      :  a.  UR                  US	S	 5        [        U5      [        U5      :  a  M.  [!        UUXU5        [        U5      [        U5      :  a+  UR                  S5        [        U5      [        U5      :  a  M+  [	        XU	-   5      nU Vs/ s H  nSSU-  SR#                  U5      4-  PM     nn[%        U ['        UU5      5        Xl	        Xal        g	s  snnf s  snnf s  snf )aY  prints an ASCII graph of the DAG

takes the following arguments (one call per node in the graph):

  - ui to write to
  - Somewhere to keep the needed state in (init to asciistate())
  - Column of the current node in the set of ongoing edges.
  - Type indicator of node data, usually 'C' for changesets.
  - Payload: (char, lines):
    - Character to use as node's symbol.
    - List of lines to display as the node's text.
  - Edges; a list of (col, next_col) indicating the edges between
    the current node and its parents.
  - Number of columns (ongoing edges) in the current revision.
  - The difference between the number of columns (ongoing edges)
    in the next revision and the number of columns (ongoing edges)
    in the current revision. That is: -1 means one column removed;
    0 means no columns added or removed; 1 means one column added.
rd   r   ry   )r   ry   r   r@   r   Nrx   re   c              3  <   #    U  H  o(       d  M  US ;   v   M     g7f)s   \/Nr?   )r   r   s     r   r   ascii.<locals>.<genexpr>  s     9Oqq{qF{Os   
r=   s   %-*s )r]   rM   r   r&   rz   rg   rv   r   r   r   r   r#   r   r   r   anyr   joinr   zip)rA   ri   rU   rh   textcoldatar|   r]   rn   r~   r   rM   r-   r   r{   xyadd_padding_linefix_nodeline_tailr   shift_interliner\   r   r   extra_interlineindentation_levelr   s                              r   asciir     s`   ( ")C!KKT DAAt(<d'C!a'CaFD
MM,U_s4y%@!!DDE"} 	5! 	D	AP'R-PU,PU6Aqa!eaiQU,P  D	Q?/?+? ia HOOT4L!OOOO	

 YsQw'O1w;t$  K!OE"}uA""D$<0 	AvQw!meai@AuA""E4=1  vh8 JE_V%?@ 9O999LL) 	_% 4145O
5zCI%j3t9$LL+, %j3t9$ UOWEB
d)c%j
 C d)c%j
  E7?3GLGLtA))388D>::u 
  Ct$%  OK E( -QTs   &N NN:#N)r   
__future__r   typingr3   r   
thirdpartyr   TYPE_CHECKING r   r   r	   r(   r   r   r$   r   r1   r4   rb   rr   rv   r   r   r   r   sr   r   r   r?   r=   r   <module>r      s   	 #    
  		
 
{D->,3^;Vr3Bl(C'&*1h 6 6 61"r=   