
    q&fB                         d Z ddlmZ ddlmZ ddlmZmZmZ dZ	dZ
dZdZe
d	ed
ediZd Zd Zd Zd Zd Zd Zd Zd Zd Zej.                   G d d             Zd Zd Zy)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.
   )nullrev)attr)dagopsmartsetutil   C   P   G   M   |   :Nc              #   ~  
K   i }|D ]  }| |   }|j                         D ch c]%  }|j                         |v s|j                         ' c}
|j                         D cg c];  }|j                         t        k7  r"|j                         
vr|j                         = }}t        
      D cg c]
  }t        |f }}|D ]  }|j                  |      }	|	^t        |t        j                        st        j                  |      }t        t        t        j                  | ||g                  x}	||<   |	s)|j                  t        |f       
j                  |       |j                  
fd|	D               
j!                  |	        |j                         t"        ||f  yc c}w c c}w c c}w w)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   8   K   | ]  }|vst         |f  y wN)GRANDPARENT).0gpsets     4/usr/lib/python3/dist-packages/mercurial/graphmod.py	<genexpr>zdagwalker.<locals>.<genexpr>Q   s     MAq}Q/Ms   	)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   	dagwalkerr.   (   s     G 33i "%BA!%%'T/B [[]
uuw'!aeegT&9 EEG
 

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

 6s/    F=F.F.F="A F3"F=1F8 C=F=c              #     K   t        |      }|D ]n  }| |   }|j                         D ch c]+  }|j                         |v st        |j	                         f- }}|j	                         t
        |t        |      f p yc c}w w)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includer0   r)   r*   r   s          r   r1   r1   W   s      %jG ;4j'*{{}
"#G8KVQUUW
 
 wwy)S&/::;
s   (BBB-Bc              #     K   g }i }d}i j                   j                  d      D ]  \  }}d|v s|j                  dd      \  }}|dk(  r/|j                         rt	        |      j                  |i       |<   T|dk(  sZ|j                         sk|j                  |i       |<    rt        j                  fd      }	nd }	| D ]h  \  }
}}}|
|vr|j                  |
       |||
<   |dz  }|j                  |
      }|j                  |
      }|dd }|D cg c]  \  }}||vs| }}}||||dz    t        |      D ]  \  }}|s|||<   |||<   |dz  } g }t        |      D ]  \  }}||v rQ |	|      }|j                  ||j                  |      ||   |j                  dd	      |j                  dd
      f       [||
k(  sa|D ]R  \  }} |	|      }|j                  ||j                  |      ||j                  dd	      |j                  dd
      f       T  |
||||f|f |}k yc c}}w w)ax  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    j                  |    j                         i       S r   )r   branch)r   configr&   s    r   <lambda>zcolored.<locals>.<lambda>   s    

49#3#3#5r:     c                     i S r    )r   s    r   r8   zcolored.<locals>.<lambda>   s    b r9   Nr9   )uiconfigitemsrsplitisdigitint
setdefaultisalnumr   lrucachefuncr    indexpop	enumerater   )dagr&   seencolorsnewcolorkeyvalr6   settinggetconfcurtypedatar   colcolornextptr*   
addparentsiedgesecoleidbconfptyper7   s    `                        @r   coloredr^   f   s     DFHFGG''1 =S3;!jjq1OFG("s{{}9<S!!&"-g6H$9<!!&"-g6= ##:
 !&) 5"dD' d?KK"F3KMHjjo

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

3s		(B/		(C0  ' 
HE1#AJELL  JJqM!!IIh3!IIh4
	4 D$ee44k5 ?s2   .H>AH>H>BH>H8,H80BH>A0H>c              #     K   |j                   }||vr|j                  |       |j                  |      }g }g }|D ][  \  }	}
|
|k(  r|
|v r|j                  |
       "|j                  |
       |j                  j	                  |	d      |j
                  |
<   ] t        |      }d|dz  z   }|dd }||||dz    |D cg c]  }||j                  |      f }}||dd t        |      dkD  r\|j                  ||f       |j                  ||dz   f       d}|dz  }| ||||||ff d}|dz  }|dz  }g }|d= t        |      dkD  r\t        |      dkD  r|j                  ||f       t        |      dkD  r|j                  ||dz   f       t        |      |z
  }|dkD  r|dz  }|j
                  j                  |d       | ||||||ff yc c}w w)z9adds edge info to changelog DAG walk suitable for ascii()r   r      N   \    )rI   r    rE   stylesr   rY   lenrF   )rQ   charstater   r   rI   nodeidxknownparents
newparentsr]   parentncolswidthnextseenr*   rY   	nmorecolss                    r   
asciiedgesro      s    ::D
$CjjoGLJ  @vS=T>'f%"',,"2"25$"?EKK@ IE	MEAwH&0HWw{#3?@agx~~a()@E@DG
j/A

 	gw'(gw{+,	
T57E5)"DEE1
qM j/A
  :gw'(
:gw{+,H%I1}
	KKOOCuwui@
AA9 As   B;G=GA0GBGc                 P    t        |       D ]  \  }\  }}||kD  s||dz   f| |<    y )Nr   )rG   )rY   rX   startends       r   _fixlongrightedgesrs      s8    &u- (LUC;sQw'E!H(r9   c                     |rT||k(  rO|dk7  rJ|dk(  r8t        |dz   |      }| |dz  |dz
  dz   }|j                  ddg||z
  z         |S ddg||z
  dz
  z  S ||z
  dz
  }	|	dkD  r	| |	dz   d  S g S )Nrb   r<   r   r`      /    ra   )maxr#   )
echarsidxpidxrk   coldiffpdifffix_tailrq   tail	remainders
             r   _getnodelineedgestailr      s    Gu$Ab=a&E#'UQY!O4DKKt67K4=ECK!O44CK!O	-6]v	A&()BBr9   c                 &   |D ]  \  }}||dz   k(  rd|d|z  dz   <   ||dz
  k(  rd|d|z  dz   <   .||k(  r| d|z     |d|z  <   Bd|z  t        |      k\  rTd|d|z  <   ||kD  r||}}t        d|z  dz   d|z        D ]  }||   dk7  sd||<     y )Nr   ru   r`   ra      +   -)rd   range)rx   rY   nodeline	interlinerq   rr   rX   s          r   
_drawedgesr     s     'C!G%)Ia#gk"cAg',Ia%i!m$c\#)!e)#4Ia%i 3w#h-' $HQWs{ #U1u9q=!c'2 'A;$&"&HQK''r9   c                     | d |dz   }||dz
  f|v s||f|v r|j                  | |dz  |dz   dz          n|j                  ddg       ||z
  dz
  }|dkD  r|j                  | |dz   d         |S )Nr`   r   rv   rb   )r#   )rx   ry   rk   rY   liner   s         r   _getpaddingliner     s    )C!GDS1W~3*"5 	F37cAg]34T4L!aI1}FY]+-./Kr9   c           	      h   d|j                         vry|ddd   }|r|d   |j                          |r|d   t        |j                  d      dz  dz
  d      }|j                  sdnd}t        |       ||z   k  r&| j                  |dd        t        |       ||z   k  r&|rg }g }	|j                  d      }
t        ||
dd   |
dz        D ]0  \  }}||j                  |dz         |	j                  |dz         2 t        t        |
|
t        |	      dz  z   d            }|	dd }| | d D ]_  }dgt        |      |
z
  z  ||
d t        t        |            D ]1  }||   dz
  }t        |||         ||<   |||   kD  rdn||	|      ||<   3 a |j                  sd	d
dndd
i}t        |       D ]1  \  }}d|vr|D cg c]  }|xs |j                  |d       c}|dd 3 |j                         D cg c]
  \  }}|	| }}}|D ]  }||= |j                  |        yc c}w c c}}w )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.

    Nr`   r<   r   rb      rv   ru   r      ~)r   r`   )valuesrF   rw   countgraphshortenrd   r    rE   rG   listr   r   itemsremove)linesextraedgemaprI   rf   	edgechars
shift_sizeminlinesemptiestoshiftfirst_emptyrX   ctargets	positionsr   posmapr*   r   rj   s                        r   _drawendinglinesr   3  s    7>>## cc
I
	"- 	"-iood+a/14a8J**qH
e*x*,
,U1X e*x*,
, kk$'eKNN3[A5EF 	&DAqyq1u%q1u%		&
 u[+Gq8H*H!LMAJ	:+,' 	LD"&3t9{+B!CD3y>* LlQ&"3
3	!$''!*$4D%
:KS	L	L %*$6$6dt
QICU# 84t267Q1(4((7Q8 $MMO9DAqqya9F9 FOF	 8 :s   H);
H.H.c                   t   e Zd ZdZ ej
                  d ej                  e            Z ej
                  d ej                  e	            Z
 ej
                  dd      Z ej
                  dd      Z ej
                  d ej                  ej                              Z ej
                  dd      Zy)
asciistatez State of ascii() graph renderingF)initdefaultrb   N)__name__
__module____qualname____doc__r   ibFactoryr   rI   dictrY   lastcoldiff	lastindexEDGEScopyrc   r   r;   r9   r   r   r   g  s    *477|t||D'9:DDGGT(:;E$''ua0KUA.ITWW%ejj)ABF477u5Lr9   r   c                 b    |D ]*  \  }}| j                  ||z   j                         dz          , y)aX  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)r=   graphlnlogstrs       r   outputgraphr   s  s5      1V
"v+%%'%/01r9   c                    |\  }}}}	d|	cxk  rdk  sJ  J |j                   |j                  }}
|D cg c]  }|
j                  |d      dfD ]  }|  }}}|j                  dt	        ||	z   t        |      z
  d      z         |	dk(  rt        |       t        |      dkD  xr% |	dk(  xr |D cg c]  \  }}|dz   |k  s| c}}}t        |      dk  xr | }|d	|dz   }|j                  |dg       |j                  t        |||j                  ||	|j                  |             |d	|dz   }t        d|	z         D ]  }|j                  d        ||z
  dz
  }|	dk(  r$t        |      D ]  }|j                  d
dg        nF|	dk(  r|j                  ||dz   dz  |dz          n#t        |      D ]  }|j                  ddg        t        ||||       |g}|r|j                  t        ||||             |j                  r$t        d |D              r#|j                  |       n|j                  |       |d	||	z   dz   }t        |      t        |      k  rCt        |      t        |      k  r,|j                  |d	d	        t        |      t        |      k  r,t!        |||
||       t        |      t        |      k  r)|j                  d       t        |      t        |      k  r)t	        |||	z         }|D cg c]  }dd|z  dj#                  |      fz   }}t%        | t'        ||             |	|_	        ||_        y	c c}}w c c}}w c c}w )a  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.
    r`   r   rv   )r   rv   rb   r<   r   Nru   ra   c              3   *   K   | ]  }|s|d v   yw)s   \/Nr;   )r   r   s     r   r   zascii.<locals>.<genexpr>  s     9qqqF{9s   	r9   s   %-*s )rY   rI   r   r#   rw   rd   rs   r   r   r   r   r    r   r   r   anyr   joinr   zip)r=   rf   rQ   re   textcoldatary   rY   rk   r{   r   rI   r*   r   rx   xyadd_padding_linefix_nodeline_tailr   shift_interlinerX   r   r   extra_interlineindentation_levelr   s                              r   asciir     s   ( ")Cw!KKTG DAAt(<d'CD!aDaDFD
MM,UW_s4y%@!!DDE"} 	5! 	D	AP'R-PU,P6Aqa!eaiQ,P  D	Q?/?+? ia HOOT4L!OOOO	

 YsQw'O1w; %t$%CK!OE"}u 	1A""D$<0	1	AvsQw!meai@Au 	2A""E4=1	2 vuh8 JE_VS%?@ 9O99LL) 	_% 4145O
5zCI%j3t9$LL+, %j3t9$ UOWdEB
d)c%j
 C d)c%j
  E57?3GL?CA))388D>::E  Ct$%  EEOK E( -QTs   "M3MM	 M)r   r0   r   
thirdpartyr    r   r   r   r%   r   r   r!   r   r.   r1   r^   ro   rs   r   r   r   r   sr   r   r   r;   r9   r   <module>r      s   	    		
 
{D->,3^;Wt3Bl(C'&*1h 6 6 61"r9   