§
    	^µcU<  ã                   óp   — d dl Z d dlZddlmZ ddlmZmZ ddlmZ d„ Z		 	 	 	 	 	 	 dd
„Z
	 	 	 	 	 	 	 dd„ZdS )é    Né   )Ú_)ÚerrorÚpycompat)Ú
stringutilc              #   ón  ‡‡‡‡‡‡‡‡‡K  — | sdS t          j        t          j        t          j        z   ¦  «        Ši ŠdŠdŠˆˆˆfd„Št          j        | ¦  «        Šˆfd„Šˆfd„Šˆfd„Šˆˆˆˆfd„} ‰¦   «         }|d	k    �r±|t          j        t          j        ¦  «        v r* ‰¦   «         }|t          j        t          j        ¦  «        v °*|d
k    rd‰‰gffV — ‰Š‰dz  Š ‰¦   «         }�n<|dk    rg ‰ ‰¦   «         t          j        t          j        ¦  «        ¦  «        \  }}t          |¦  «        }t          d|¦  «        D ]}d‰‰gffV — ‰Š‰dz  ŠŒ�nÏ|dv rw|dk    r
 ‰¦   «         } ||¦  «        \  }}|g}|dk    r1 | ‰¦   «         ¦  «        \  }}| 	                    |¦  «         |dk    °1ˆfd„|D ¦   «         }d‰|ffV — ‰Š‰dz  Š�nT|dk    r# | ‰¦   «         ¦  «        \  }}	 ‰|	¦  «        Š�n+|dk    r% | ‰¦   «         ¦  «        \  }}
‰‰|
<   d‰|
ffV — �n |dk    r | ‰¦   «         ¦  «        \  }}d|fV — nÝ|dk    rO ‰¦   «         }|dk    r*d} ‰¦   «         }|dvr||z  } ‰¦   «         }|dv°d|fV — n� ||¦  «        \  }}d|fV — nˆ|dk    r|dvr ‰¦   «         }|dv°no|dk    rdŠ ‰¦   «         }n\|d	k    rdS d}d}|d	k    r&|dk     r ||z  }|dz  } ‰¦   «         }|d	k    r|dk     ° t          j        t          d¦  «        |z  ¦  «        ‚|d	k    �°¯dS dS ) a#  parses a DAG from a concise textual description; generates events

    "+n" is a linear run of n nodes based on the current default parent
    "." is a single node based on the current default parent
    "$" resets the default parent to -1 (implied at the start);
        otherwise the default parent is always the last node created
    "<p" sets the default parent to the backref p
    "*p" is a fork at parent p, where p is a backref
    "*p1/p2/.../pn" is a merge of parents p1..pn, where the pi are backrefs
    "/p2/.../pn" is a merge of the preceding node and p2..pn
    ":name" defines a label for the preceding node; labels can be redefined
    "@text" emits an annotation event for text
    "!command" emits an action event for the current node
    "!!my command
" is like "!", but to the end of the line
    "#...
" is a comment up to the end of the line

    Whitespace between the above elements is ignored.

    A backref is either
     * a number n, which references the node curr-n, where curr is the current
       node, or
     * the name of a label you placed earlier using ":name", or
     * empty to denote the default parent.

    All string valued-elements are either strictly alphanumeric, or must
    be enclosed in double quotes ("..."), with "" as escape character.

    Generates sequence of

      ('n', (id, [parentids])) for node creation
      ('l', (id, labelname)) for labels on nodes
      ('a', text) for annotations
      ('c', command) for actions (!)
      ('C', command) for line actions (!!)

    Examples
    --------

    Example of a complex graph (output not shown for brevity):

        >>> len(list(parsedag(b"""
        ...
        ... +3         # 3 nodes in linear run
        ... :forkhere  # a label for the last of the 3 nodes from above
        ... +5         # 5 more nodes on one branch
        ... :mergethis # label again
        ... <forkhere  # set default parent to labeled fork node
        ... +10        # 10 more nodes on a parallel branch
        ... @stable    # following nodes will be annotated as "stable"
        ... +5         # 5 nodes in stable
        ... !addfile   # custom command; could trigger new file in next node
        ... +2         # two more nodes
        ... /mergethis # merge last node with labeled node
        ... +4         # 4 more nodes descending from merge node
        ...
        ... """)))
        34

    Empty list:

        >>> list(parsedag(b""))
        []

    A simple linear run:

        >>> list(parsedag(b"+3"))
        [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [1]))]

    Some non-standard ways to define such runs:

        >>> list(parsedag(b"+1+2"))
        [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [1]))]

        >>> list(parsedag(b"+1*1*"))
        [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [1]))]

        >>> list(parsedag(b"*"))
        [('n', (0, [-1]))]

        >>> list(parsedag(b"..."))
        [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [1]))]

    A fork and a join, using numeric back references:

        >>> list(parsedag(b"+2*2*/2"))
        [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [0])), ('n', (3, [2, 1]))]

        >>> list(parsedag(b"+2<2+1/2"))
        [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [0])), ('n', (3, [2, 1]))]

    Placing a label:

        >>> list(parsedag(b"+1 :mylabel +1"))
        [('n', (0, [-1])), ('l', (0, 'mylabel')), ('n', (1, [0]))]

    An empty label (silly, really):

        >>> list(parsedag(b"+1:+1"))
        [('n', (0, [-1])), ('l', (0, '')), ('n', (1, [0]))]

    Fork and join, but with labels instead of numeric back references:

        >>> list(parsedag(b"+1:f +1:p2 *f */p2"))
        [('n', (0, [-1])), ('l', (0, 'f')), ('n', (1, [0])), ('l', (1, 'p2')),
         ('n', (2, [0])), ('n', (3, [2, 1]))]

        >>> list(parsedag(b"+1:f +1:p2 <f +1 /p2"))
        [('n', (0, [-1])), ('l', (0, 'f')), ('n', (1, [0])), ('l', (1, 'p2')),
         ('n', (2, [0])), ('n', (3, [2, 1]))]

    Restarting from the root:

        >>> list(parsedag(b"+1 $ +1"))
        [('n', (0, [-1])), ('n', (1, [-1]))]

    Annotations, which are meant to introduce sticky state for subsequent nodes:

        >>> list(parsedag(b"+1 @ann +1"))
        [('n', (0, [-1])), ('a', 'ann'), ('n', (1, [0]))]

        >>> list(parsedag(b'+1 @"my annotation" +1'))
        [('n', (0, [-1])), ('a', 'my annotation'), ('n', (1, [0]))]

    Commands, which are meant to operate on the most recently created node:

        >>> list(parsedag(b"+1 !cmd +1"))
        [('n', (0, [-1])), ('c', 'cmd'), ('n', (1, [0]))]

        >>> list(parsedag(b'+1 !"my command" +1'))
        [('n', (0, [-1])), ('c', 'my command'), ('n', (1, [0]))]

        >>> list(parsedag(b'+1 !!my command line\n +1'))
        [('n', (0, [-1])), ('C', 'my command line'), ('n', (1, [0]))]

    Comments, which extend to the end of the line:

        >>> list(parsedag(b'+1 # comment\n+1'))
        [('n', (0, [-1])), ('n', (1, [0]))]

    Error:

        >>> try: list(parsedag(b'+1 bad'))
        ... except Exception as e: print(pycompat.sysstr(bytes(e)))
        invalid character in dag description: bad...

    Néÿÿÿÿr   c                 óŒ   •— | s‰S | d         t          j        t          j        ¦  «        v r‰t	          | ¦  «        z
  S ‰|          S )Nr   )r   ÚbytestrÚstringÚdigitsÚint)ÚrefÚlabelsÚp1Úrs    €€€ú5/usr/lib/python3/dist-packages/mercurial/dagparser.pyÚresolvezparsedag.<locals>.resolve²   sF   ø€ Øð 	ØˆIà�ŒV•xÔ'­¬Ñ6Ô6Ð6Ð6à•s˜3‘x”x‘<Ðà˜#”;Ðó    c                  ó$   •— t          ‰ d¦  «        S )Nó    )Únext)Úchiters   €r   Únextchzparsedag.<locals>.nextch¾   s   ø€ Ý�F˜EÑ"Ô"Ð"r   c                 ó>   •— d}| |v r|| z  } ‰¦   «         } | |v °| |fS ©Nr   © )ÚcÚallowÚsr   s      €r   Únextrunzparsedag.<locals>.nextrunÁ   s;   ø€ ØˆØ�5ˆjˆjØ�‰FˆAØ�‘”ˆAð �5ˆjˆjð �!ˆtˆr   c                 óv   •— d}| |k    r%| |k    r
 ‰¦   «         } || z  } ‰¦   «         } | |k    °% ‰¦   «         |fS r   r   )r   ÚlimitÚescaper    r   s       €r   Únextdelimitedzparsedag.<locals>.nextdelimitedÈ   sV   ø€ ØˆØ�5ŠjˆjØ�FŠ{ˆ{Ø�F‘H”H�Ø�‰FˆAØ�‘”ˆAð	 �5Šjˆjð
 ˆv‰xŒx˜ˆ{Ðr   c                 óR   •— | dk    r ‰ ‰¦   «         dd¦  «        S  ‰| ‰¦  «        S )Nó   "ó   \r   )r   r   r%   r!   Ú	wordcharss    €€€€r   Ú
nextstringzparsedag.<locals>.nextstringÑ   s8   ø€ Ø�Š9ˆ9Ø �=  ¡¤¨4°Ñ7Ô7Ð7à�7˜1˜iÑ(Ô(Ð(r   r   ó   .ó   nr   ó   +s   */ó   *ó   /c                 ó&   •— g | ]} ‰|¦  «        ‘ŒS r   r   )Ú.0r   r   s     €r   ú
<listcomp>zparsedag.<locals>.<listcomp>ó   s!   ø€ Ð0Ð0Ð0 3�'�'˜#‘,”,Ð0Ð0Ð0r   ó   <ó   :ó   ló   @ó   aó   !r   s   
 ó   Có   có   #ó   $é
   s+   invalid character in dag description: %s...)r   r   r   Úascii_lettersr   ÚiterbytestrÚ
whitespacer   ÚrangeÚappendr   ÚAbortr   )Údescr*   r   ÚdigsÚnÚiÚprefÚprefsÚpsr   ÚnameÚtextÚcmdr    r   r   r   r%   r!   r   r   r   r)   s                 @@@@@@@@@r   ÚparsedagrN      sÇ  øøøøøøøøøè è € ðf ð Øˆõ Ô ¥Ô!5½¼Ñ!EÑFÔF€Ið €FØ	€BØ	€Aðð ð ð ð ð ð õ Ô! $Ñ'Ô'€Fð#ð #ð #ð #ð #ðð ð ð ð ðð ð ð ð ð)ð )ð )ð )ð )ð )ð )ð )ð 	ˆ‰Œ€AØ
ˆuŠ*‰*à•8Ô#¥FÔ$5Ñ6Ô6Ð6Ð6à�‘”ˆAð •8Ô#¥FÔ$5Ñ6Ô6Ð6Ð6ð �Š9ˆ9Ø˜˜R˜D˜	�/Ð!Ð!Ð!ØˆBØ�‰FˆAØ�‘”ˆA‰AØ�$ŠYˆYà�g˜f˜f™hœh­Ô(8½¼Ñ(GÔ(GÑHÔH‰GˆAˆtå�D‘	”	ˆAÝ˜1˜a‘[”[ð ð �Ø˜Q  ˜I�oÐ%Ð%Ð%Ø�Ø�Q‘��ñð �%ˆZˆZØ�DŠyˆyØ�F‘H”H�Ø �j ‘m”m‰GˆAˆtØ�FˆEØ�t’)�)Ø$˜* V V¡X¤XÑ.Ô.‘��4Ø—’˜TÑ"Ô"Ð"ð �t’)�)ð 1Ð0Ð0Ð0¨%Ð0Ñ0Ô0ˆBØ˜˜B˜�-ÐÐÐØˆBØ�‰FˆA‰AØ�$ŠYˆYØ�Z  ¡¤Ñ)Ô)‰FˆAˆsØ�˜‘”ˆB‰BØ�$ŠYˆYØ �j  ¡¤Ñ*Ô*‰GˆAˆtØˆF�4‰LØ˜˜T˜
Ð"Ð"Ð"Ð"Ñ"Ø�$ŠYˆYØ �j  ¡¤Ñ*Ô*‰GˆAˆtØ˜�*ÐÐÐÐØ�$ŠYˆYØ�‘”ˆAØ�DŠyˆyØ�Ø�F‘H”H�Ø˜yÐ(Ð(Ø˜1‘H�CØ˜™œ�Að ˜yÐ(Ð(ð ˜C�i����à#˜ A™œ‘��3Ø˜C�i����Ø�$ŠYˆYØ˜9Ð$Ð$Ø�F‘H”H�ð ˜9Ð$Ð$øà�$ŠYˆYØˆBØ�‘”ˆAˆAØ�%ŠZˆZØˆFàˆAØˆAØ�u’*�*  R¢ Ø�Q‘�Ø�Q‘�Ø�F‘H”H�ð �u’*�*  R¢ õ ”+ÝÐ@ÑAÔAÀAÑEñô ð ðI ˆuŠ*‰*ˆ*ˆ*ˆ*ˆ*r   TFéF   c              #   óü   ‡ ‡‡‡‡‡‡K  — d„ Šˆ ˆˆˆˆˆˆfd„}d}	 |¦   «         D ]O}
|
dk    r	|	r|	V — d}	Œt          |	¦  «        t          |
¦  «        z   |k    r|	V — d}	n|r|	r|
dk    r|	dz  }	|	|
z  }	ŒP|	r|	V — dS dS )z$generates single lines for dagtext()c                 ó�   — t          j        d| ¦  «        r| S d|                      dd¦  «                             dd¦  «        z   dz   S )Ns   ^[0-9a-z]*$r'   r(   s   \\)ÚreÚmatchÚreplace)rL   s    r   Ú
wrapstringz dagtextlines.<locals>.wrapstring-  sI   € ÝŒ8�N DÑ)Ô)ð 	ØˆKØ�d—l’l 5¨'Ñ2Ô2×:Ò:¸4ÀÑGÔGÑGÈ$ÑNÐNr   c               3   óÄ  •K  — i } d}d}d}‰D �]E\  }}|dk    �rd|\  }}||k    r&t          j        t          d¦  «        ||fz  ¦  «        ‚|sdg}n1|D ].}||k    r&t          j        t          d¦  «        ||fz  ¦  «        ‚Œ/|dz  }|dz
  }	t          |¦  «        dk    r(|d         dk    r|r|r	d|z  V — d}‰rd	V — d
V — d}	nd}t          |¦  «        dk    r|d         |	k    r‰rdV — Œà|dz  }Œæ|r	d|z  V — d}‰rd	V — g }
|D ]Y}||	k    r|
                     d¦  «         Œ|| v r|
                     | |         ¦  «         Œ>|
                     d||z
  z  ¦  «         ŒZdd                     |
¦  «        z   V — �Œq|r	d|z  V — d}|dk    r|\  }}|| |<   d|z   V — ‰rd	V — �Œ›|dk    rd ‰|¦  «        z   V — ‰rd	V — �Œ¹|dk    rd|z   V — d	V — �ŒÌ|dk    r‰rd	V — d ‰|¦  «        z   V — �Œê|dk    rd|z   V — d	V — �Œýt          j        t          d¦  «        t          j        |¦  «        t          j        |¦  «        fz  ¦  «        ‚|r	d|z  V — d S d S )Nr   Fr,   s   expected id %i, got %ir	   s)   parent id %i is larger than current id %ir   s   +%dó   
r<   Tr+   r   s   %dr.   r/   r5   r4   r:   r8   r9   s   !!r7   r6   r;   s'   invalid event type in dag: ('%s', '%s'))r   rC   r   ÚlenrB   Újoinr   Ú	escapestr)r   ÚrunÚwantrÚneedrootÚkindÚdatar   rJ   Úpr   rI   ÚridrK   ÚeventsÚusedotsÚwrapannotationsÚwrapcommandsÚ
wraplabelsÚwrapnonlinearrU   s                €€€€€€€r   Úgenzdagtextlines.<locals>.gen2  sÅ  øè è € ØˆØˆØˆØˆØ ð U	ñ U	‰JˆD�$Ø�tŠ|‰|Ø‘��2ð ˜’:�:Ýœ+¥aÐ(AÑ&BÔ&BÀeÈQÀZÑ&OÑPÔPÐPØð Ø˜�B�Bàð ð ˜Ø š6˜6Ý"'¤+Ý !ð%5ñ!"ô !"ð $% a &ñ	!)ñ#ô #ð ð "ð ˜‘
�ð ˜‘U�Ý�r‘7”7˜a’<�< B q¤E¨R¢K KØð 	(Øð $Ø"(¨3¡,Ð.Ð.Ð.Ø"#˜CØ(ð (Ø"'˜K˜K˜KØ"˜
˜
˜
Ø˜˜à#'˜Ý�r‘7”7˜a’<�< B q¤E¨R¢K KØð !Ø"˜
˜
˜
˜
à˜q™˜˜àð  Ø$ s™lÐ*Ð*Ð*Ø˜Ø$ð $Ø#˜˜˜Ø�EØð :ð :˜Ø š7˜7Ø!ŸLšL¨Ñ-Ô-Ð-Ð-Ø &˜[˜[Ø!ŸLšL¨°¬Ñ3Ô3Ð3Ð3à!ŸLšL¨°!°a±%©Ñ9Ô9Ð9Ð9Ø §¢¨5Ñ!1Ô!1Ñ1Ð1Ð1Ð1Ñ1àð Ø  3™,Ð&Ð&Ð&Ø�CØ˜4’<�<Ø $‘I�C˜Ø"&�F˜3‘KØ ™+Ð%Ð%Ð%Ø!ð $Ø#˜˜˜ùØ˜T’\�\Ø  ¨DÑ!1Ô!1Ñ1Ð1Ð1Ð1Ø#ð $Ø#˜˜˜ùØ˜T’\�\Ø $™,Ð&Ð&Ð&Ø�K�K�K‘KØ˜T’\�\Ø&ð $Ø#˜˜˜Ø  ¨DÑ!1Ô!1Ñ1Ð1Ð1Ð1Ñ1Ø˜T’\�\Ø ™+Ð%Ð%Ð%Ø�K�K�K‘Kåœ+ÝÐDÑEÔEå&Ô0°Ñ6Ô6Ý&Ô0°Ñ6Ô6ðññô ð ð ð 	Ø˜3‘,ÐÐÐÐÐð	ð 	r   r   rW   r+   ó    N)rX   )rb   Ú	addspacesrf   rd   re   rg   rc   Úmaxlinewidthrh   ÚlineÚpartrU   s   ` `````    @r   Údagtextlinesrn   !  s  øøøøøøøè è € ðOð Oð Oð
\ð \ð \ð \ð \ð \ð \ð \ð \ð \ð \ð| €DØ�‘”ð ð ˆØ�5Š=ˆ=Øð Ø�
�
�
Ø�øå�4‰yŒy�3˜t™9œ9Ñ$¨Ò4Ð4Ø�
�
�
Ø��Øð ˜tð ¨°ª¨Ø˜‘�Ø�D‰LˆDˆDØð Øˆ
ˆ
ˆ
ˆ
ˆ
ðð r   c                 óT   — d                      t          | |||||||¦  «        ¦  «        S )aÒ  generates lines of a textual representation for a dag event stream

    events should generate what parsedag() does, so:

      ('n', (id, [parentids])) for node creation
      ('l', (id, labelname)) for labels on nodes
      ('a', text) for annotations
      ('c', text) for commands
      ('C', text) for line commands ('!!')
      ('#', text) for comment lines

    Parent nodes must come before child nodes.

    Examples
    --------

    Linear run:

        >>> dagtext([(b'n', (0, [-1])), (b'n', (1, [0]))])
        '+2'

    Two roots:

        >>> dagtext([(b'n', (0, [-1])), (b'n', (1, [-1]))])
        '+1 $ +1'

    Fork and join:

        >>> dagtext([(b'n', (0, [-1])), (b'n', (1, [0])), (b'n', (2, [0])),
        ...          (b'n', (3, [2, 1]))])
        '+2 *2 */2'

    Fork and join with labels:

        >>> dagtext([(b'n', (0, [-1])), (b'l', (0, b'f')), (b'n', (1, [0])),
        ...          (b'l', (1, b'p2')), (b'n', (2, [0])), (b'n', (3, [2, 1]))])
        '+1 :f +1 :p2 *f */p2'

    Annotations:

        >>> dagtext([(b'n', (0, [-1])), (b'a', b'ann'), (b'n', (1, [0]))])
        '+1 @ann +1'

        >>> dagtext([(b'n', (0, [-1])),
        ...          (b'a', b'my annotation'),
        ...          (b'n', (1, [0]))])
        '+1 @"my annotation" +1'

    Commands:

        >>> dagtext([(b'n', (0, [-1])), (b'c', b'cmd'), (b'n', (1, [0]))])
        '+1 !cmd +1'

        >>> dagtext([(b'n', (0, [-1])),
        ...          (b'c', b'my command'),
        ...          (b'n', (1, [0]))])
        '+1 !"my command" +1'

        >>> dagtext([(b'n', (0, [-1])),
        ...          (b'C', b'my command line'),
        ...          (b'n', (1, [0]))])
        '+1 !!my command line\n+1'

    Comments:

        >>> dagtext([(b'n', (0, [-1])), (b'#', b' comment'), (b'n', (1, [0]))])
        '+1 # comment\n+1'

        >>> dagtext([])
        ''

    Combining parsedag and dagtext:

        >>> dagtext(parsedag(b'+1 :f +1 :p2 *f */p2'))
        '+1 :f +1 :p2 *f */p2'

    rW   )rY   rn   )Údagrj   rf   rd   re   rg   rc   rk   s           r   Údagtextrq   ¡  s@   € ðn �:Š:ÝØØØØØØØØñ		
ô 		
ñô ð r   )TFFFFFrO   )rR   r   Úi18nr   Ú r   r   Úutilsr   rN   rn   rq   r   r   r   ú<module>ru      så   ðð 
€	€	€	Ø €€€à Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð Ð Ð Ð Ð Ð ðJð Jð Jð^ ØØØØØØð}ð }ð }ð }ðD ØØØØØØðbð bð bð bð bð br   