
    	^cB                         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dS )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 ]m}| |         }fd|                                 D             		fd|                                 D             }d t          	          D             }|D ]}|                    |          }|dt          t          j                  st	          j                  t          t          t          j        | |g                              x}||<   |s2|	                    t          |f           	                    |           |                    	fd|D                        	                    |           |                                t          ||fV  odS )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.

    c                 d    h | ],}|                                 v |                                 -S  rev).0prevss     4/usr/lib/python3/dist-packages/mercurial/graphmod.py	<setcomp>zdagwalker.<locals>.<setcomp>;   s.    BBBA!%%''T/////    c                     g | ]I}|                                 t          k    |                                 v5|                                 JS r   )r   r   )r   r   psets     r   
<listcomp>zdagwalker.<locals>.<listcomp><   sP     
 
 
uuww'!!aeeggT&9&9 EEGG&9&9&9r   c                      g | ]}t           |fS r   )PARENT)r   r   s     r   r   zdagwalker.<locals>.<listcomp>A   s    5551FA;555r   Nc              3   2   K   | ]}|vt           |fV  d S N)GRANDPARENT)r   gr   s     r   	<genexpr>zdagwalker.<locals>.<genexpr>Q   s,      MMAq}}Q/}}}}MMr   )parentssortedget
isinstancer   basesetsetr   reachablerootsappendMISSINGPARENTaddextendupdater   	CHANGESET)
repor   gpcacher   ctxmparsr#   mpargpr   s
    `       @r   	dagwalkerr6   (   s      G 3 33i CBBBBBB
 
 
 
[[]]
 
 

 65t555 	  	 DT""Bz "$(899 2#+D11D%+,T4$@@AA& & WT]   t4555MMMMMMMMMMBwwyy)S'22222=3 3r   c              #      K   t          |          |D ]V}| |         }fd|                                D             }|                                t          |t	          |          fV  WdS )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.
    c                 r    h | ]3}|                                 v t          |                                f4S r   )noder   r   )r   r   includes     r   r   znodes.<locals>.<setcomp>`   s?     
 
 
"#G8K8KVQUUWW8K8K8Kr   N)r(   r#   r   r/   r$   )r0   nodesr9   r2   r#   r:   s        @r   r;   r;   W   s       %jjG ; ;4j
 
 
 
'*{{}}
 
 
 wwyy)S&//:::::; ;r   c              #     K   g }i }d}i j                             d          D ]\  }}d|v r|                    dd          \  }}|dk    r;|                                r't	          |                              |i           |<   c|dk    r-|                                r|                    |i           |<   rt          j        fd          }	nd }	| D ]\  }
}}}|
|vr|	                    |
           |||
<   |dz  }|
                    |
          }|                    |
          }|dd         fd	|D             }|||dz   <   t          |          D ]\  }}|s|||<   |||<   |dz  }g }t          |          D ]\  }}|v rg |	|          }|	                    |
                    |          ||         |                    dd
          |                    dd          f           p||
k    rh|D ]e\  }} |	|          }|	                    |
                    |          ||                    dd
          |                    dd          f           f|
||||f|fV  }dS )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                 `                         |                                          i           S r   )r%   branch)r   configr0   s    r   <lambda>zcolored.<locals>.<lambda>   s%    

49#3#3#5#5r:: r   c                     i S r   r   r   s    r   rA   zcolored.<locals>.<lambda>   s    b r   Nc                 "    g | ]\  }}|v	|S r   r   )r   ptr   nexts      r   r   zcolored.<locals>.<listcomp>   s"    >>>EBar   r   )uiconfigitemsrsplitisdigitint
setdefaultisalnumr   lrucachefuncr*   indexpop	enumerater%   )dagr0   seencolorsnewcolorkeyvalr?   settinggetconfcurtypedatar#   colcolor
addparentsir   edgesecoleidbconfptyper@   rE   s    `                      @@r   coloredrf   f   s&      DFHFG''11 = =S3;;!jjq11OFG(""s{{}}"9<S!!&"--g66H$$$9<!!&"--g6 !#:::::
 
 !.&) 5 5"dD' d??KK"F3KMHjjoo

3AAAw ?>>>W>>>
(S37] j)) 	 	DAq !q		$q	A "4 	 	ID#d{{

3s		(B//		(C00     ' 
 
HE1#GAJJELL  JJqMM!!IIh33!IIh44    D$ee4444k5 5r   c              #     K   |j         }||vr|                    |           |                    |          g }g }|D ]^\  }}	|	|k    r|	|v r|                    |	           &|                    |	           |j                            |d          |j        |	<   _t          |          }
d|
dz  z   }|dd         |dz   <   fd|D             }|dd<   t          |          dk    rh|                    f           |                    dz   f           d}|dz  }| ||||
|ffV  d}dz  |
dz  }
g }|d= t          |          dk    ht          |          dk    r|                    f           t          |          dk    r|                    dz   f           t                    |
z
  }|dk    r|dz  }|j                            |d           | ||||
|ffV  dS )z9adds edge info to changelog DAG walk suitable for ascii()r   r      Nc                 >    g | ]}                     |          fS r   )rO   )r   r   nextseennodeidxs     r   r   zasciiedges.<locals>.<listcomp>   s*    @@@agx~~a(()@@@r      \    )rS   r*   rO   stylesr%   ra   lenrP   )r[   charstater   r#   rS   knownparents
newparentsre   parentncolswidthra   	nmorecolsrj   rk   s                 @@r   
asciiedgesrx      ss     :D
$CjjooGLJ  @ @vS==T>>''''f%%%"',"2"25$"?"?EKIIE	MEAAAwH&0HWw{"#@@@@@<@@@EDG
j//A


 	gw'(((gw{+,,,	
T57E5)"DEEEE1
qM j//A

  :gw'(((
:gw{+,,,H%I1}}
	KOOCuwui@
AAAAAAr   c                 V    t          |           D ]\  }\  }}||k    r
||dz   f| |<   d S )Nr   )rQ   )ra   r`   startends       r   _fixlongrightedgesr|      sH    &u-- ( (LUC;;sQw'E!H( (r   c                 
   |rd||k    r^|dk    rX|dk    rEt          |dz   |          }| |dz  |dz
  dz           }|                    ddg||z
  z             |S ddg||z
  dz
  z  S ||z
  dz
  }	|	dk    r| |	dz   d          ng S )Nrm   rF   r   rh      /    rl   )maxr-   )
echarsidxpidxru   coldiffpdifffix_tailrz   tail	remainders
             r   _getnodelineedgestailr      s     CGu$$Ab==a&&E#'UQY!O34DKKt6777K4=ECK!O44CK!O	-6]]v	A&(())Br   c                 F   |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  <   Gd|z  t          |          k    r^d|d|z  <   ||k    r||}}t          d|z  dz   d|z            D ]}||         dk    rd||<   d S )Nr   r~   rh   rl      +   -)ro   range)r   ra   nodeline	interlinerz   r{   r`   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2 ' 'A;$&&"&HQK'' 'r   c                    | d |dz           }||dz
  f|v s||f|v r'|                     | |dz  |dz   dz                      n|                     ddg           ||z
  dz
  }|dk    r!|                     | |dz   d                     |S )Nrh   r   r   rm   )r-   )r   r   ru   ra   liner   s         r   _getpaddingliner     s    )C!G)DS1W~3*"5"5 	F37cAg]234444T4L!!!aI1}}FY]+--.///Kr   c           	         d|                                 vrdS |ddd         }|r&|d         |                                 |r|d         t          |                    d          dz  dz
  d          }|j        sdnd}t          |           ||z   k     r3|                     |dd                    t          |           ||z   k     3|r4g }g }	|                    d          }
t          ||
dd         |
dz            D ]8\  }||                    dz              |	                    dz             9t          t          |
|
t          |	          dz  z   d                    }|	dd         }| | d         D ]}dgt          |          |
z
  z  ||
d<   t          t          |                    D ]E|         dz
  }t          ||                   |<   ||         k    rdn||	                  ||<   F|j        sd	d
dndd
it          |           D ]\  }d|vr
fd|D             |dd<   d |                                D             }|D ]}||= |                    |           dS )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.

    Nrh   rF   r   rm      r   r~   r      ~)r   rh   c                 @    g | ]}|p                     d           S )r   r%   )r   cr`   maps     r   r   z$_drawendinglines.<locals>.<listcomp>^  s,    777Q1(4((777r   c                     g | ]	\  }}||
S r   r   )r   r   r   s      r   r   z$_drawendinglines.<locals>.<listcomp>a  s    999DAqqyayyyr   )valuesrP   r   countgraphshortenro   r*   rO   rQ   listr   itemsremove)linesextraedgemaprS   rq   	edgechars
shift_sizeminlinesemptiestoshiftfirst_emptyr   targets	positionsr   posr   rt   r`   r   s                     @@r   _drawendinglinesr   3  s    7>>#### ccc
I
 	"-  	"-iood++a/14a88J*1qqH
e**x*,
,
,U111X e**x*,
,
,  Lkk$''eKNN3[A5EFF 	& 	&DAqyq1u%%%%q1u%%%%u[+Gq8H*H!LLMMAAAJ	:+,,' 	L 	LD"&3t99{+B!CD3y>>** L LlQ&"3
33	!$''!*$4$4DD%
:KS		L
 %*$6
Edt


QICU## 8 84t77777$777QQQ :9GMMOO999F  FOF r   c                   H   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dS )
asciistatez State of ascii() graph renderingF)initdefaultrm   N)__name__
__module____qualname____doc__r   ibFactoryr   rS   dictra   lastcoldiff	lastindexEDGEScopyrn   r   r   r   r   r   r   g  s        **47|t|D'9'9:::DDGT(:(:;;;E$'ua000KUA...ITW%ej)A)ABBBF47u555LLLr   r   c                 p    |D ]2\  }}|                      ||z                                   dz              3dS )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)rG   graphlnlogstrs       r   outputgraphr   s  sK      1 1V
"v+%%''%/00001 1r   c                 N   |\  }}}}	d|	cxk     rdk     sn J |j         |j        c}
fd|
D             }|                    dt          ||	z   t	          |
          z
  d          z             |	dk    rt          |           t	          |          dk    o|	dk    od |D             }t	          |          dk    o| }|d|dz           }|                    |d	g           |                    t          |||j        ||	|j        |                     |d|dz           }t          d|	z             D ]}|
                    d	           ||z
  d
z
  }|	dk    r*t          |          D ]}|                    dd	g           nV|	dk    r'|                    ||d
z   dz  |dz                      n)t          |          D ]}|                    dd	g           t          ||||           |g}|r%|
                    t          ||||                     |j        r/t          d |D                       r|
                    |           n|
                    |           |d||	z   dz           }t	          |          t	          |          k     r]t	          |          t	          |          k     r=|
                    |dd                    t	          |          t	          |          k     =t          |||
|           t	          |          t	          |          k     r5|
                    d           t	          |          t	          |          k     5t          |||	z             fd|D             }t!          | t#          ||                     |	|_        ||_        dS )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.
    rh   c                 J    g | ]}                     |d           dfD ]}| S r   r   r   )r   r   r   r   s      r   r   zascii.<locals>.<listcomp>  s9    DDDAAt(<(<d'CDD!aDDDDr   r   rm   rF   c                 *    g | ]\  }}|d z   |k     |S )r   r   )r   xys      r   r   zascii.<locals>.<listcomp>  s%    ,P,P,P6Aqa!eaiiQiiir   Nr   r   r~   rl   c              3   "   K   | ]
}||d v V  dS )s   \/Nr   )r   r   s     r   r"   zascii.<locals>.<genexpr>  s+      99qq9qF{999999r   r   c                 J    g | ]}d dz  d                     |          fz   S )s   %-*s rh   r   )join)r   r   indentation_levels     r   r   zascii.<locals>.<listcomp>  s@       ?CA))388D>>::  r   )ra   rS   r-   r   ro   r|   r   r   r   r   r*   r   r   r   anyr   r   zip)rG   rq   r[   rp   textcoldatar   ra   ru   r   rS   r   add_padding_linefix_nodeline_tailr   shift_interliner`   r   r   extra_interliner   r   s                       @@r   asciir     s8   ( ")Cw!KMGT EDDDDDDF
MM,UW_s4yy%@!!D!DDEEE"}} 	5!!! 	D		AP'R-P,P,PU,P,P,P  D		Q?/?+? iai HOOT4L!!!OOO	
 	

 
 
 YsQwY'O1w; % %t$$$$CK!OE"}}u 	1 	1A""D$<0000	1	AvsQw!meai&?@AAAAu 	2 	2A""E4=1111 vuh888 JE A_VS%??@@@  &99O99999 	*LL))) 	_%%% 41445O
5zzCII%jj3t99$$LL+,,, %jj3t99$$ UOWdEBBB
d))c%jj
 
 C d))c%jj
 
  E57?33   GL  E Ct$$%%%  EEOOOr   )r   r9   r   
thirdpartyr    r   r   r   r/   r   r    r+   r   r6   r;   rf   rx   r|   r   r   r   r   sr   r   r   r   r   r   <module>r      s  	 	                      		
 
{D->,3 ,3 ,3^; ; ;W W Wt3B 3B 3Bl( ( (C C C' ' '&  *1 1 1h 6 6 6 6 6 6 6 61 1 1"    r   