a
    &0_+Y                    @   s  d dl mZ d dlZddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddl m!Z!m"Z" ej#Z#ej$Z$ej%Z%ej&Z&ej'Z'ej(Z(ej)Z)ej*Z*ej+Z+ej,Z,ej-Z-ej.Z.ej/ej0fZ1dZ2d	Z3d
Z4e3fddZ5dd Z6dd Z7dd Z8dd Z9dd Z:dd Z;dd Z<dd Z=dd Z>dd  Z?d!d" Z@d#d$ ZAd%d& ZBd'd( ZCd)d* ZDd+d, ZEd-d. ZFd/d0 ZGd1d2 ZHd3d4 ZId5d6 ZJd7d8 ZKd9d: ZLd;d< ZMd=d> ZNejOZOeP ZQeR ZSeSd?d@dA ZTeSdBdCdD ZUeSdEdFdGdHdIdJ ZVeSdKdFdLdHdMdN ZWddPdQZXeSdRdFdSdTdU ZYeSdVdFdSdWdX ZZdYdZ Z[d[d\ Z\eSd]dFd^dHd_d` Z]eSdadFdSdbdc Z^eSdddFdSdedf Z_eSdgdFdSdhdi Z`eSdjdFd^dHdkdl ZaeSdmdFdSdndo ZbeSdpdFdSdqdr Zcdsdt Zddudv ZeeSdwdFdSdxdy ZfeSdzdFd^dHd{d| ZgeSd}dFdSd~d ZheSddFdSdd ZieSddFdSdd ZjeSddFdSdd ZkeSddddd ZleSddFdSdd ZmeSddFd^dHdd ZneSddFd^dHdd ZodddZpeSddFdSdd ZqeSddFdSdd ZreSddFd^dHdd ZseSddddd ZteSddFdSdd ZueSddFdFddd ZveSddOddHdd ZweSddFdSdd ZxeSddFdSdd ZyeSddFdSdd ZzeSddFdFd ddd Z{dddZ|eSddFdSdd Z}eSddFdSddĄ Z~eSddFdSddǄ ZeSddFdSddʄ ZeSdd^ddd̈́ ZeSddFdSddЄ ZeSddFd^dHddӄ ZeSddFdSddք ZeSddFdFdddل ZeSddFdSdd܄ ZeSddFd^dHdd߄ ZeSddFdFd ddd ZeSddFdFddd ZeSddFdSdd ZeSddFdSdd ZeSddFdSdd ZeSddFdSdd ZeSddFdGdHdd ZeSddd ZeSddFdSdd ZeSddFdSdd ZeSddFdSdd  ZeSddFdSdd ZeSddFdSdd ZeSddOd^dHdd	 ZeSd
dFdSdd ZeSddFdSdd Zdd ZeSddFdSdd Zdd ZeSddFdSdd ZeSddFdSdd ZeSddFdSdd ZeSd dFdSd!d" Zd#d$ ZeSd%dFdFdd&d' ZeSd(dFdSd)d* ZeSd+dFdSd,d- ZeSd.dFdSd/d0 ZeSd1dOdSd2d3 ZeSd4dFdGdHd5d6 ZeSd7dFdSd8d9 ZeSd:dFdSd;d< ZeSd=dFdFdd>d? ZReSd@dFdSdAdB ZeSdCdFdFd ddDdE ZeSdFdFdSdGdH ZejdIdJ dKdJ dLdJ dMdJ dNdJ ejdOZdPdQ ZeSdRdFdFd^ddSdT ZeSdUdVdW ZdXdY ZeSdZdFdSd[d\ Zdd]d^ZeSd_dFdSd`da ZeSdbdFdSdcdd ZeSdedFdSdfdg ZeSdhdFdSdidj ZeSdkdFd^dHdldm ZeSdndFd dHdodp Zdqdr ZeSdsdFdFddtdu Zdvdw ZeSdxdFdFd ddydz Zd{d| ZeSd}dFdFdd~d Ze:e;e<e=e?e8e8e@eAeDeEeBeFeJeKeLeMeNe\eee9dZeHeHdZeIeIdZdd ZdddZdddZdd Zdd ZeddeS eOġ ZdS (      )absolute_importN   )_getattr)dagopdestutildiffutilencodingerrorgrephbisectmatchnodeobsoleteobsutilpathutilphasespycompat	registrarrepoview
revsetlangscmutilsmartsetstackutil)dateutil
stringutils   anys   define   followc                 C   s:   |st tdt|d  | |g|dd  R d|iS )Ns   missing argumentr   r   order)r   
ParseErrorr   methodsreposubsetxr    r&   2/usr/lib/python3/dist-packages/mercurial/revset.pygetseti   s    r(   c              	   C   sN   | |   }dD ]8}||v rz| ||   W   S  tjyF   Y q0 qd S )N)   sources   transplant_sources   rebase_source)extrarevr   RepoLookupError)r#   rr*   labelr&   r&   r'   _getrevsourceo   s    r/   c                 C   s   t ttj| S N)sortedr   ZrapplyZmaybebytestr)xsr&   r&   r'   _sortedbz   s    r3   c                 C   sN   |st tdtt| |}||v s>|tv rHt|trHt	|gS t	 S )Ns$   empty string is not a valid revision)
r   r    r   r   intrevZ	revsymbol_virtualrevs
isinstancefullreposetbasesetr"   r&   r&   r'   	stringset   s    
r9   c                 C   s   |t kr||@ S ||@ S dS )z1argument is already a smartset, use that directlyN)followorderr"   r&   r&   r'   rawsmartset   s    r;   c                 C   sF   t | t| |}t | t| |}|r(|s.t S t| || | |S r0   )r(   r7   r8   _makerangesetfirstlast)r#   r$   r%   yr   mnr&   r&   r'   rangeset   s
    rB   c                 C   s"   |d u sJ t | |d| j |S Nr   )r<   	changelogtiprevr"   r&   r&   r'   rangeall   s    rF   c                 C   s.   t | t| |}|st S t| |d| |S rC   )r(   r7   r8   r<   r>   )r#   r$   r?   r   rA   r&   r&   r'   rangepre   s    rG   c                 C   s4   t | t| |}|st S t| || | j |S r0   )r(   r7   r8   r<   r=   rD   rE   )r#   r$   r%   r   r@   r&   r&   r'   	rangepost   s    rH   c                 C   s   ||krt |g}n||tjkr:t| |t| t |g }nV|tjkrft |gt| | j |d  }n*||k rt| ||d }nt| ||d }|tkr||@ S ||@ S d S Nr   )r8   r   wdirrevspansetlenrD   rE   defineorder)r#   r$   r@   rA   r   r-   r&   r&   r'   r<      s    

"r<   c                 C   s2   t | }tj| t| ||t| ||dd}||@ S )NT)Zincludepath)r7   r   Zreachablerootsr(   )r#   r$   r%   r?   r   r-   r2   r&   r&   r'   dagrange   s
    rN   c                 C   s*   |t krt }nt}t| t| |||||S r0   anyorderr:   r(   r#   r$   r%   r?   r   Zyorderr&   r&   r'   andset   s    rR   c                 C   s*   |t krt }nt}t| t| |||||S r0   rO   rQ   r&   r&   r'   andsmallyset   s    rS   c                 C   s   t | |||t | ||t S r0   r(   rP   r#   r$   r%   r?   r   r&   r&   r'   differenceset   s    rV   c                 C   sf   |sJ t |dkr&t| ||d |S t |d }t| ||d | |}t| |||d  |}|| S )Nr   r      )rL   r(   
_orsetlist)r#   r$   r2   r   pabr&   r&   r'   rX      s    rX   c                 C   sB   t |}|st S |tkr0|t| t| |t@ S t| |||S d S r0   )getlistr8   r:   rX   r7   rP   )r#   r$   r%   r   r2   r&   r&   r'   orset   s    r]   c                 C   s   |t | ||t S r0   rT   r"   r&   r&   r'   notset   s    r^   c                 C   sF   t |}|tv r$t| | ||||S dd t D }t||d S )Nc                 S   s   g | ]}t |d kr|qS r   rL   .0r-   r&   r&   r'   
<listcomp>      zrelationset.<locals>.<listcomp>)	getsymbol	relationskeysr   UnknownIdentifier)r#   r$   r%   r?   r   relrelnamesr&   r&   r'   relationset   s
    rk   c                 C   sd   d}d}| |  krdkr$n nd}| dk rBt |d |  d f}|dkr\t| d|d f}||fS )a  Split range with bounds a and b into two ranges at 0 and return two
    tuples of numbers for use as startdepth and stopdepth arguments of
    revancestors and revdescendants.

    >>> _splitrange(-10, -5)     # [-10:-5]
    ((5, 11), (None, None))
    >>> _splitrange(5, 10)       # [5:10]
    ((None, None), (5, 11))
    >>> _splitrange(-10, 10)     # [-10:10]
    ((0, 11), (0, 11))
    >>> _splitrange(-10, 0)      # [-10:0]
    ((0, 11), (None, None))
    >>> _splitrange(0, 10)       # [0:10]
    ((None, None), (0, 11))
    >>> _splitrange(0, 0)        # [0:0]
    ((0, 1), (None, None))
    >>> _splitrange(1, -1)       # [1:-1]
    ((None, None), (None, None))
    NNr   )r   r   r   )minmax)rZ   r[   Z	ancdepthsZ
descdepthsr&   r&   r'   _splitrange  s    ro   c                 C   s   d}t | |||||S )N)   rangeallN)generationssubrel)r#   r$   r%   ri   r   zr&   r&   r'   generationsrel%  s    rs   c                 C   s   t |tdtdtjd  tjd 
 d\}}t||\\}}	\}
}|d u rZ|
d u rZt S t| t| |}|stt S |d ur|
d urt| |d||	}|t	| |d|
|7 }n6|d urt| |d||	}n|
d urt	| |d|
|}||@ S )Ns0   relation subscript must be an integer or a ranges*   relation subscript bounds must be integersr   )ZdeffirstZdeflastF)
getintranger   r   Zmaxlogdepthro   r8   r(   r7   revancestorsrevdescendants)r#   r$   r%   ri   rr   r   rZ   r[   ZancstartZancstopZ	descstartZdescstoprevssr&   r&   r'   rq   *  s*    


rq   c                 C   sH   t |}|tv r&t| | |||||S dd t D }t||d S )Nc                 S   s   g | ]}t |d kr|qS r_   r`   ra   r&   r&   r'   rc   P  rd   z#relsubscriptset.<locals>.<listcomp>)re   subscriptrelationsrg   r   rh   )r#   r$   r%   r?   rr   r   ri   rj   r&   r&   r'   relsubscriptsetH  s
    rz   c                 C   s   t tdd S )Ns%   can't use a subscript in this contextr   r    r   rU   r&   r&   r'   subscriptsetT  s    r|   c                 O   s   t jtdtddd S )Ns    can't use a list in this contexts   see 'hg help "revsets.x or y"'hintr{   )r#   r$   r2   optsr&   r&   r'   listsetX  s    r   c                 C   s   t tdd S )Ns*   can't use a key-value pair in this contextr{   )r#   r$   kvr   r&   r&   r'   keyvaluepair_  s    r   c                    sl   t |}|tv r>t| }t|ddr2|| |||S || ||S dd   fddt D }t||d S )NZ
_takeorderFc                 S   s   t | dd d uS )N__doc__r   )fnr&   r&   r'   <lambda>k  rd   zfunc.<locals>.<lambda>c                    s   g | ]\}} |r|qS r&   r&   )rb   rx   r   Zkeepr&   r'   rc   m  rd   zfunc.<locals>.<listcomp>)re   symbolsr   itemsr   rh   )r#   r$   rZ   r[   r   ffuncZsymsr&   r   r'   r   c  s    r   s   _destupdatec                 C   s2   t |dd}|ttj| fi t|d g@ S )N   limits   cleanr   )getargsdictr8   r   Z
destupdater   Z	strkwargs)r#   r$   r%   argsr&   r&   r'   _destupdate  s    r   s
   _destmergec                 C   s4   d }|d urt | t| |}|ttj| |dg@ S )N)	sourceset)r(   r7   r8   r   Z	destmerge)r#   r$   r%   r   r&   r&   r'   
_destmerge  s    r   s   adds(pattern)T   )safeweightc                 C   s   t |td}t| ||dS )zChangesets that add a file matching pattern.

    The pattern without explicit kind like ``glob:`` is expected to be
    relative to the current directory and match against a file or a
    directory.
    s   adds requires a patternadded	getstringr   checkstatusr#   r$   r%   patr&   r&   r'   adds  s    	r   s   ancestor(*changeset)g      ?c                 C   s|   t t| t| |td}z| t| }W n ty@   t  Y S 0 |D ]}|| | }qFt	|}||v rvt|gS t S )zA greatest common ancestor of the changesets.

    Accepts 0 or more changesets.
    Will return empty list when passed no args.
    Greatest common ancestor of a single changeset is that changeset.
    r   )
iterr]   r7   rP   nextStopIterationr8   ancestorr   r4   )r#   r$   r%   ZreviterZancr-   r&   r&   r'   r     s    

r   Fc                 C   s4   t | t| |}|st S t| ||||}||@ S r0   )r(   r7   r8   r   ru   )r#   r$   r%   followfirst
startdepth	stopdepthheadsrx   r&   r&   r'   
_ancestors  s
    r   s   ancestors(set[, depth]))r   c                 C   s   t |dd}d|vr"ttdd }}d|v rVt|d d}|dk rRtd	|}d
|v rt|d
 td}|dk rttd|d }t| ||d ||dS )zChangesets that are ancestors of changesets in set, including the
    given changesets themselves.

    If depth is specified, the result only includes changesets up to
    the specified generation.
    s	   ancestors   set depth startdepth   sets#   ancestors takes at least 1 argumentN
   startdepths'   ancestors expects an integer startdepthr      negative startdepth   depths"   ancestors expects an integer depth   negative depthr   r   r   )r   r   r    r   
getintegerr   r#   r$   r%   r   r   r   rA   r&   r&   r'   	ancestors  s&    	
r   s   _firstancestorsc                 C   s   t | ||ddS NTr   )r   r#   r$   r%   r&   r&   r'   _firstancestors  s    r   c           	      C   s~   t  }t| t| |D ]^}t|D ]F}| |  }t|dkrB qt|dkr\ttd|d 	 }q"|
| q||@ S )zAChangesets that are the Nth child of a changeset
    in set.
    r   r   s'   revision in set has more than one child)setr(   r7   rangechildrenrL   r   r,   r   r+   add)	r#   r$   r%   rA   r   csr-   icr&   r&   r'   _childrenspec  s    r   c           	   
   C   s   t |td}|dk r(t| ||| |S t }| j}t| t| |D ]T}t|D ]<}z||d }W qP t	j
y   | |   }Y qP0 qP|| qD||@ S )zg``set~n``
    Changesets that are the Nth ancestor (first parents only) of a changeset
    in set.
    s   ~ expects a numberr   )r   r   r   r   rD   r(   r7   r   
parentrevsr   WdirUnsupportedp1r+   r   )	r#   r$   r%   rA   r   psclr-   r   r&   r&   r'   ancestorspec  s    r   s   author(string)
   c                    s<   t |td}t|dd\}} |j fddd|fdS )z Alias for ``user(string)``.
    s   author requires a stringFcasesensitivec                    s    |    S r0   userr%   matcherr#   r&   r'   r     rd   zauthor.<locals>.<lambda>s	   <user %r>Zcondreprr   r   _substringmatcherfilter)r#   r$   r%   rA   kindpatternr&   r   r'   author  s
    r   s   bisect(string)c                 C   s*   t |td }tt| |}||@ S )a	  Changesets marked in the specified bisect status:

    - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip
    - ``goods``, ``bads``      : csets topologically good/bad
    - ``range``              : csets taking part in the bisection
    - ``pruned``             : csets that are goods, bads or skipped
    - ``untested``           : csets whose fate is yet unknown
    - ``ignored``            : csets ignored due to DAG topology
    - ``current``            : the cset currently being bisected
    s   bisect requires a string)r   r   lowerr   r   get)r#   r$   r%   statusstater&   r&   r'   bisect  s    r   s   bisectedc                 C   s   t | ||S r0   )r   r   r&   r&   r'   bisected2  s    r   s   bookmark([name])c                    s
  t |ddtd}|rt|d td}t|\}}}t }|dkr||krZ j|} j|d}	|	s~t	
td| | |	   qt }
t jD ]\}}	||r|
|	 q|
D ]}	| |	   qn fdd	 j D }|tjh8 }||@ S )
z{The named bookmark or all bookmarks.

    Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
    r   r   s"   bookmark takes one or no argumentss)   the argument to bookmark must be a string   literalNs   bookmark '%s' does not existc                    s   h | ]} |   qS r&   r+   ra   r#   r&   r'   	<setcomp>X  rd   zbookmark.<locals>.<setcomp>)getargsr   r   r   stringmatcherr   Z
_bookmarksZ
expandnamer   r   r,   r   r+   r   	iteritemsvaluesr   nullrev)r#   r$   r%   r   Zbmr   r   r   ZbmsZbmrevZ	matchrevsnamer&   r   r'   bookmark7  s4    
r   s   branch(string or set)c                    s    jfddzt|d W n tjy:   Y n~0 t \}}|dkr |r~|j	fddd fdS  
d	rttd
| n|j	fddd fdS tt|}t  |D ]} | q|j|j	 fdd fdddS )z
    All changesets belonging to the given branch or the branches of the given
    changesets.

    Pattern matching is supported for `string`. See
    :hg:`help revisions.patterns`.
    c                    s4   z | d W S  t jy.   |    Y S 0 d S rC   )r   r   branchr-   )getbir#   r&   r'   	getbranchh  s    zbranch.<locals>.getbranchrd   r   c                    s    | S r0   r&   r   r   r   r&   r'   r   z  rd   zbranch.<locals>.<lambda>   <branch %r>r   s   literal:s   branch '%s' does not existc                    s    | S r0   r&   r   r   r&   r'   r     rd   c                    s   | p|  v S r0   r&   r   )r[   r   r   r&   r'   r     rd   c                      s   dt   S )Nr   r3   r&   )r[   r&   r'   r     rd   )ZrevbranchcacheZ
branchinfor   r   r    r   r   	branchmapZ	hasbranchr   
startswithr,   r   r(   r7   r   r   __contains__)r#   r$   r%   r   r   rx   r-   r&   )r[   r   r   r   r   r#   r'   r   ]  s:    	



r   s   phasedivergent()c                 C   s&   t |ddtd t| d}||@ S )zMutable changesets marked as successors of public changesets.

    Only non-public and non-obsolete changesets can be `phasedivergent`.
    (EXPERIMENTAL)
    r   s!   phasedivergent takes no arguments   phasedivergentr   r   obsmodgetrevs)r#   r$   r%   phasedivergentr&   r&   r'   r     s    r   s   bundle()c                 C   s6   z| j j}W n  ty,   ttdY n0 ||@ S )zIChangesets in the bundle.

    Bundle must be specified by the -R option.s$   no bundle provided - specify with -R)rD   
bundlerevsAttributeErrorr   Abortr   )r#   r$   r%   r   r&   r&   r'   bundle  s
    r   c                    sB   t dkdg fdd}|j|dt fdS )zuHelper for status-related revsets (adds, removes, modifies).
    The field parameter says which kind is desired.
    r   Nc                    s   |  }d rr2t jj g|dd< d  d } d usJJ   snt  dkrn  d }|d ur|| vrdS nt fdd| D sdS t	|
  | }|d ur||v rdS nt fdd|D rdS d S )	Nr   ctxr   Fc                 3   s   | ]} |V  qd S r0   r&   rb   r   r@   r&   r'   	<genexpr>  rd   z/checkstatus.<locals>.matches.<locals>.<genexpr>Tc                 3   s   | ]} |V  qd S r0   r&   r   r   r&   r'   r     rd   )matchmodr   rootgetcwdZanypatsrL   filesanyr   r   r   r   )r%   r   fnamer   fieldhassetmcacher   r#   r   r'   matches  s&    zcheckstatus.<locals>.matchess   <status.%s %r>r   )r   patkindr   r   Zsysbytes)r#   r$   r   r  r  r&   r   r'   r     s    r   c           
      C   sz   |s
t  S t }| jj}| }tj}|D ]F}||kr8q*||\}}	||v rV|| |	|kr*|	|v r*|| q*t |S r0   )r8   r   rD   r   rm   r   r   r   )
r#   r$   Z	parentsetr   Zprminrevr   r-   r   p2r&   r&   r'   	_children  s    
r  s   children(set)c                 C   s$   t | t| |}t| ||}||@ S )z+Child changesets of changesets in set.
    )r(   r7   r  )r#   r$   r%   rx   r   r&   r&   r'   r     s    r   s   closed()c                    s(   t |ddtd |j fddddS )zChangeset is closed.
    r   s   closed takes no argumentsc                    s    |    S r0   )Zclosesbranchr   r   r&   r'   r     rd   zclosed.<locals>.<lambda>s   <branch closed>r   )r   r   r   r   r&   r   r'   closed  s    r	  s   _commonancestorheads(set)c                 C   s0   t | t| |td}| jjt| }|t|@ S )Nr   )r(   r7   rP   rD   Z_commonancestorsheadslistr8   )r#   r$   r%   	startrevsZancsr&   r&   r'   _commonancestorheads  s    r  s   commonancestors(set)c                 C   sB   t | t| |td}|st S |D ]}|t| t|gM }q"|S )z=Changesets that are ancestors of every changeset in set.
    r   )r(   r7   rP   r8   r   ru   )r#   r$   r%   r  r-   r&   r&   r'   commonancestors  s    r  s   conflictlocal()c                 C   sZ   t |ddtd ddlm} |j| }| rT| j|jrT|| j	|jh@ S t
 S )zThe local side of the merge, if currently in an unresolved merge.

    "merge" here includes merge conflicts from e.g. 'hg rebase' or 'hg graft'.
    r   s    conflictlocal takes no argumentsr   
mergestate)r   r    r  readactiverD   hasnodeZlocalr+   r8   r#   r$   r%   Zmergestatemodr  r&   r&   r'   conflictlocal  s    r  s   conflictother()c                 C   sZ   t |ddtd ddlm} |j| }| rT| j|jrT|| j	|jh@ S t
 S )zThe other side of the merge, if currently in an unresolved merge.

    "merge" here includes merge conflicts from e.g. 'hg rebase' or 'hg graft'.
    r   s    conflictother takes no argumentsr   r  )r   r   r  r  r  r  rD   r  otherr+   r8   r  r&   r&   r'   conflictother   s    r  s   contains(pattern)d   )r   c                    s.   t |td  fdd}|j|d fdS )a<  The revision's manifest contains a file matching pattern (but might not
    modify it). See :hg:`help patterns` for information about file patterns.

    The pattern without explicit kind like ``glob:`` is expected to be
    relative to the current directory and match against a file exactly
    for efficiency.
    s   contains requires a patternc                    sr   t  s0tj  }||  v rndS n>|  }t jj  g|d}| D ]}||rZ dS qZdS )NTr   F)r   r  r   	canonpathr   r   r   manifest)r%   patsr   r@   r   r   r#   r&   r'   r  <  s    
zcontains.<locals>.matchess   <contains %r>r   )r   r   r   r#   r$   r%   r  r&   r  r'   contains0  s    
r  s   converted([id])c                    sT   dt |ddtd}|r,t|d tdfdd |j fdd	d
fdS )zChangesets converted from the given identifier in the old repository if
    present, or all converted changesets if no identifier is specified.
    Nr   r   s#   converted takes one or no argumentss   converted requires a revisionc                    s.    |    dd }|d uo,d u p,|S )Ns   convert_revision)r*   r   r   )r-   source)r#   r+   r&   r'   _matchvalue\  s    zconverted.<locals>._matchvaluec                    s    | S r0   r&   r   r   r&   r'   r   a  rd   zconverted.<locals>.<lambda>s   <converted %r>r   )r   r   r   r   r#   r$   r%   lr&   )r   r#   r+   r'   	convertedL  s    	r$  s   date(interval)c                    s4   t |td}t| |j fddd|fdS )z:Changesets within the interval, see :hg:`help dates`.
    s   date requires a stringc                    s    |    d S rC   dater   Zdmr#   r&   r'   r   m  rd   zdate.<locals>.<lambda>s	   <date %r>r   )r   r   r   Z	matchdater   )r#   r$   r%   dsr&   r'  r'   r&  e  s
    
r&  s   desc(string)c                    s<   t |td}t|dd\}} |j fddd|fdS )zSearch commit message for string. The match is case-insensitive.

    Pattern matching is supported for `string`. See
    :hg:`help revisions.patterns`.
    s   desc requires a stringFr   c                    s    |    S r0   descriptionr   r   r&   r'   r   ~  rd   zdesc.<locals>.<lambda>s	   <desc %r>r   r   )r#   r$   r%   r(  r   r   r&   r   r'   descq  s
    r+  c                 C   s4   t | t| |}|st S t| ||||}||@ S r0   )r(   r7   r8   r   rv   )r#   r$   r%   r   r   r   rootsrx   r&   r&   r'   _descendants  s
    r-  s   descendants(set[, depth])c                 C   s   t |dd}d|vr"ttdd }}d|v rVt|d d}|dk rRtd	|}d
|v rt|d
 td}|dk rttd|d }t| ||d ||dS )zChangesets which are descendants of changesets in set, including the
    given changesets themselves.

    If depth is specified, the result only includes changesets up to
    the specified generation.
    s   descendantsr   r   s%   descendants takes at least 1 argumentNr   s)   descendants expects an integer startdepthr   r   r   s$   descendants expects an integer depthr   r   r   )r   r   r    r   r   r-  r   r&   r&   r'   descendants  s*    	
r.  s   _firstdescendantsc                 C   s   t | ||ddS r   )r-  r   r&   r&   r'   _firstdescendants  s    r/  s   destination([set])c                    s   |durt | t| |}nt| }t  |D ]^}t| |}d}|dur,|du rTt }|| ||v sn| v rz | q,|}t| |}q>q,|j j fdddS )zChangesets that were created by a graft, transplant or rebase operation,
    with the given revisions specified as the source.  Omitting the optional set
    is the same as passing all().
    Nc                      s   dt   S )Ns   <destination %r>r   r&   destsr&   r'   r     rd   zdestination.<locals>.<lambda>r   )	r(   r7   r   r/   r
  appendupdater   r   )r#   r$   r%   Zsourcesr-   srcZlineager&   r0  r'   destination  s(    



r5  s   diffcontains(pattern)n   c                    s   t |dd}d|vr"ttdt|d td}t|tj}t	
   fddtj| j| |ddfd	d
}|j|d|fdS )zSearch revision differences for when the pattern was added or removed.

    The pattern may be a substring literal or a regular expression. See
    :hg:`help revisions.patterns`.
    s   diffcontainss   patterns&   diffcontains takes at least 1 arguments&   diffcontains requires a string patternc                    s    S r0   r&   r   )fmatchr&   r'   makefilematcher  s    z%diffcontains.<locals>.makefilematcherT)diffc                    s>   d} t| g D ]"\}}}}tt||d rd}q|S )NFT)Zsearchfilesr8   r   grepmodZdifflinestates)r+   foundr   r   ZpstatesZstates)r8  searcherr&   r'   testdiff  s    
zdiffcontains.<locals>.testdiffs   <diffcontains %r>r   )r   r   r    r   r   r   ZsubstringregexpreMr   alwaysr:  Zgrepsearcheruir   )r#   r$   r%   r   r   Zregexpr=  r&   )r7  r8  r<  r'   diffcontains  s    
rB  s   contentdivergent()c                 C   s&   t |ddtd t| d}||@ S )zh
    Final successors of changesets with an alternative set of final
    successors. (EXPERIMENTAL)
    r   s#   contentdivergent takes no arguments   contentdivergentr   )r#   r$   r%   contentdivergentr&   r&   r'   rD    s    rD  s   expectsize(set[, size]))r   	takeorderc           	      C   s"  t |dd}d}t| d }d}d|vs0d|vr>ttdt|d td	td
||\}}|dk sn|dk r|ttdt| t| |d |d}||krt||k st||krtd||t|f }n(||krt||krtd|t|f }|rt||t	kr||@ S ||@ S dS )a  Return the given revset if size matches the revset size.
    Abort if the revset doesn't expect given size.
    size can either be an integer range or an integer.

    For example, ``expectsize(0:1, 3:5)`` will abort as revset size is 2 and
    2 is not between 3 and 5 inclusive.s
   expectsizes   set sizer   r   rd   s   sizer   s   invalid set of argumentss6   expectsize requires a size range or a positive integers"   size range bounds must be integerss   negative sizer   s8   revset size mismatch. expected between %d and %d, got %ds)   revset size mismatch. expected %d, got %dN)
r   rL   r   r    r   rt   r(   r7   r,   r:   )	r#   r$   r%   r   r   Zminsizemaxsizeerrr+   r&   r&   r'   
expectsize  s@    	 

rH  s   extdata(source)c                 C   s8   t |dd}t|dtd}t| |}|t|@ S )z:Changesets in the specified extdata source. (EXPERIMENTAL)s   extdatar)   s(   extdata takes at least 1 string argument)r   r   r   r   r   Zextdatasourcer8   )r#   r$   r%   r   r  datar&   r&   r'   extdataG  s    rJ  s	   extinct()c                 C   s&   t |ddtd t| d}||@ S )zGObsolete changesets with obsolete descendants only. (EXPERIMENTAL)
    r   s   extinct takes no argumentss   extinctr   )r#   r$   r%   Zextinctsr&   r&   r'   extinctU  s    rK  s   extra(label, [value])c                    s   t |dd}d|vr"ttdt|d tddd|v rbt|d tdt\}fd	d
 |j fdddfdS )zChangesets with the given label in the extra metadata, with the given
    optional value.

    Pattern matching is supported for `value`. See
    :hg:`help revisions.patterns`.
    s   extras   label values   labels   extra takes at least 1 arguments(   first argument to extra must be a stringNs   values)   second argument to extra must be a stringc                    s(   |    } |v o&d u p&|  S r0   )r*   )r-   r*   )r.   r   r#   valuer&   r'   r   x  s    zextra.<locals>._matchvaluec                    s    | S r0   r&   r   r!  r&   r'   r   }  rd   zextra.<locals>.<lambda>s   <extra[%r] %r>r   )r   r   r    r   r   r   r   r   )r#   r$   r%   r   r   r&   )r   r.   r   r#   rL  r'   r*   _  s     r*   s   filelog(pattern)c                    s  t |td}t }| j}t|s@t| j| 	 |}|g}n4tj
| j| 	 |g| d d  fdd| d D }|D ]}| |}i }	d}
t|D ]}||}||	v r||	|  q||}||v r|| q|
durt||
d }d}
||D ]}|||v r |||v r zD| | |}||	vrf||kr^|| |}
W  qn||	|< W n tjy   Y q Y n0 q qqx||@ S )a  Changesets connected to the specified filelog.

    For performance reasons, visits only revisions mentioned in the file-level
    filelog, rather than filtering through all changesets (much faster, but
    doesn't include deletes or duplicate changes). For a slower, more accurate
    result, use ``file()``.

    The pattern without explicit kind like ``glob:`` is expected to be
    relative to the current directory and match against a file exactly
    for efficiency.
    s   filelog requires a patternNr   c                 3   s   | ]} |r|V  qd S r0   r&   r   r   r&   r'   r     rd   zfilelog.<locals>.<genexpr>r   r   )r   r   r   rD   r   r  r   r  r   r   r   filer
  r   r   Zlinkrevrn   rw   revision	readfilesZfilenoder   ZManifestLookupError)r#   r$   r%   r   rx   r   r   r   ZflZknownZscanposfrr   Zlrstartr-   rA   r&   r   r'   filelog  sH    




 


rR  s   first(set, [n]))r   rE  r   c                 C   s   t | |||S )zAn alias for limit().
    )limitr"   r&   r&   r'   r=     s    r=   c                    s   t ||d}d }d|v r,t| t| |d }d|v rt|d td| }|d u rXd g}g }|D ]^}| |   }	|d u r| d  tj| j|  |g|	dd}
|	 fdd	 
 |
D  q`t||}n(|d u rt| d  g}t| ||}||@ S )
Ns   file startrev   startrev   files   %s expected a pattern   .s   path)r   defaultc                 3   s   | ]} |   V  qd S r0   )Zintrofilectxr   r   r&   r'   r     rd   z_follow.<locals>.<genexpr>)r   r(   r7   r   r   r   r   r   r   extendr  walkr   Zfilerevancestorsr8   r+   ru   )r#   r$   r%   r   r   r   rw   Zfctxsr-   Zmctxr@   rx   r&   r   r'   _follow  s,    $rZ  s   follow([file[, startrev]])c                 C   s   t | ||dS )z
    An alias for ``::.`` (ancestors of the working directory's first parent).
    If file pattern is specified, the histories of files matching given
    pattern in the revision given by startrev are followed, including copies.
    r   rZ  r   r&   r&   r'   follow  s    r\     _followfirstc                 C   s   t | ||dddS )Nr]  Tr   r[  r   r&   r&   r'   _followfirst  s    r^  s?   followlines(file, fromline:toline[, startrev=., descend=False])c                 C   s8  t |dd}t|d dkr*ttdd}d|v rlt| t| |d }t|dkrdttd| }t|d	 td
}td}t	
| |||}tjt|d d tdtd \}	}
| | |}d}d|v rt|d td}|rtdd t||	|
D dd}n tdd t||	|
D dd}||@ S )a  Changesets modifying `file` in line range ('fromline', 'toline').

    Line range corresponds to 'file' content at 'startrev' and should hence be
    consistent with file size. If startrev is not specified, working directory's
    parent is used.

    By default, ancestors of 'startrev' are returned. If 'descend' is True,
    descendants of 'startrev' are returned though renames are (currently) not
    followed in this direction.
    s   followliness   file *lines startrev descends   linesr   s!   followlines requires a line rangerV  rT  s(   followlines expects exactly one revisionrU  s   followlines requires a patterns$   followlines expects exactly one filer   s,   followlines expects a line number or a ranges"   line range bounds must be integersFs   descends"   descend argument must be a booleanc                 s   s   | ]\}}|  V  qd S r0   r   rb   r   Z
_lineranger&   r&   r'   r   )  s   zfollowlines.<locals>.<genexpr>T)Ziterascc                 s   s   | ]\}}|  V  qd S r0   r   r_  r&   r&   r'   r   3  s   )r   rL   r   r    r   r(   r7   r>   r   r   Zparsefollowlinespatternr   Zprocesslinerangert   Zfilectx
getbooleangeneratorsetr   ZblockdescendantsZblockancestors)r#   r$   r%   r   r+   rw   r   msgr   ZfromlineZtolineZfctxZdescendZrsr&   r&   r'   followlines  s\    
	
	rc  s   all()c                 C   s   t |ddtd |t| @ S )z+All changesets, the same as ``0:tip``.
    r   s   all takes no arguments)r   r   rK   r   r&   r&   r'   getall>  s    rd  s   grep(regex)c              
      sz   zt t|td W n> t jyV } z$ttdt| W Y d}~n
d}~0 0  fdd}|j|d j	fdS )zLike ``keyword(string)`` but accepts a regex. Use ``grep(r'...')``
    to ensure special escape characters are handled correctly. Unlike
    ``keyword(string)``, the match is case-sensitive.
    s   grep requires a strings   invalid match pattern: %sNc                    s:   |  }|  | | g D ]} |r  dS q dS NTF)r   r   r*  search)r%   r   eZgrr#   r&   r'   r  U  s
    
zgrep.<locals>.matchess	   <grep %r>r   )
r>  compiler   r   r   r    r   Zforcebytestrr   r   )r#   r$   r%   rg  r  r&   rh  r'   r   G  s    r   s   _matchfilesc           	   
      s\  t |ddd}g g g   d\ |D ]}t|d}|d d |dd   }}|dkrf| q*|dkrz| q*|d	kr| q*|d
krd urtd|dkrtjq|q*|dkrވ d urtd| q*td| q* sd tdd   D d gjj	tj	 	f
dd}|j
|d fdS )Nr   s*   _matchfiles requires at least one argumentrl   s%   _matchfiles requires string argumentsrW      p:s   i:s   x:s   r:s)   _matchfiles expected at most one revisionrd   s   d:s-   _matchfiles expected at most one default modes   invalid _matchfiles prefix: %ss   globc                 s   s   | ]}t |d kV  qdS )r   N)r   r  rb   rY   r&   r&   r'   r     rd   z_matchfiles.<locals>.<genexpr>c              	      s   | 	kr|    }n| }d r2rhd u rhd u r>| n}tjj |  dd< d }|D ]}||rt dS qtdS )Nr   )includeexcluder   rW  TF)r   r   r   r   r   )r%   r   r-   r@   r   
rW  excZgetfilesr  Zincr  r  r#   r+   rJ   r&   r'   r    s&    
	z_matchfiles.<locals>.matchessC   <matchfiles patterns=%r, include=%r exclude=%r, default=%r, rev=%r>r   )r   r   r2  r   r    r   rJ   r   rD   rO  r   )	r#   r$   r%   r#  argrx   prefixrL  r  r&   ro  r'   _matchfiles_  sX    
rs  s   file(pattern)c                 C   s"   t |td}t| |dd| fS )zChangesets affecting files matched by pattern.

    For a faster but less accurate result, consider using ``filelog()``
    instead.

    This predicate uses ``glob:`` as the default kind of pattern.
    s   file requires a pattern   stringrk  )r   r   rs  r   r&   r&   r'   hasfile  s    
ru  s   head()c                    sT   t |ddtd t }| j |   D ]}| fdd|D  q*|t|@ S )z&Changeset is a named branch head.
    r   s   head takes no argumentsc                 3   s   | ]}  |V  qd S r0   r   )rb   hr   r&   r'   r     rd   zhead.<locals>.<genexpr>)r   r   r   rD   r   Z	iterheadsr3  r8   )r#   r$   r%   Zhslsr&   rw  r'   head  s    ry  s
   heads(set)c                 C   s   |t krt}t| t| ||d}d}tj|v rXdd | d  D }t|}|tj | j	
|}|dur|| |tj t|}||@ S )z,Members of set with no children in set.
    r   Nc                 S   s   g | ]}|  qS r&   r   rl  r&   r&   r'   rc     rd   zheads.<locals>.<listcomp>)rM   r:   r(   r7   r   rJ   parentsr   discardrD   headrevsdifference_updater   r8   )r#   r$   r%   r   ZinputsetZwdirparentsr   r&   r&   r'   r     s    

r   s   hidden()c                 C   s&   t |ddtd t| d}||@ S )zHidden changesets.
    r   s   hidden takes no argumentss   visible)r   r   r   Z
filterrevs)r#   r$   r%   Z
hiddenrevsr&   r&   r'   hidden  s    r~  s   keyword(string)c                    s4   t t|td  fdd}|j|d fdS )zSearch commit message, user name, and names of changed files for
    string. The match is case-insensitive.

    For a regular expression or case sensitive search of these fields, use
    ``grep(regex)``.
    s   keyword requires a stringc                    s2   |  }t  fdd| | | g D S )Nc                 3   s   | ]} t |v V  qd S r0   r
   r   )rb   t)kwr&   r'   r     s   z+keyword.<locals>.matches.<locals>.<genexpr>)r   r   r   r*  )r-   r   r  r#   r&   r'   r    s    zkeyword.<locals>.matchess   <keyword %r>r   )r
   r   r   r   r   r  r&   r  r'   keyword  s    	r  s   limit(set[, n[, offset]])c           	      C   s   t |dd}d|vr"ttdt|dtddd}|d	k rPttd
t|dtdd	d}|d	k r~ttdt| t| |d }|||| }|t	kr|dkr||@ S ||@ S )zCFirst n members of set, defaulting to 1, starting from offset.
    r   s   set n offsetr   s%   limit requires one to three arguments   ns   limit expects a numberr   rW  r      negative number to selects   offsets   negative offset)
r   r   r    r   r   r   r(   r7   slicer:   )	r#   r$   r%   r   r   limZofsosrx  r&   r&   r'   rS    s     rS  s   last(set, [n])c                 C   s   t |ddtd}d}t|dkr4t|d td}|dk rJttdt| t| |d }|  |	d|}|t
kr|dkr||@ S |  ||@ S )z,Last n members of set, defaulting to 1.
    r   rW   s"   last requires one or two argumentss   last expects a numberr   r  )r   r   rL   r   r   r    r(   r7   reverser  r:   )r#   r$   r%   r   r#  r  r  rx  r&   r&   r'   r>   $  s    r>   s   max(set)c                 C   s^   t | t| |}z*| }||v r8t|gd||fdW S W n tyL   Y n0 td||fdS )z3Changeset with highest revision number in set.
    s   <max %r, %r>Zdatarepr)r(   r7   rn   r8   
ValueErrorr#   r$   r%   r  r@   r&   r&   r'   maxrev9  s    r  s   merge()c                    s<   t |ddtd j tj fdd}|j|ddS )z$Changeset is a merge changeset.
    r   s   merge takes no argumentsc                    s>   z  | d kW S  tjy8   t|    Y S 0 d S rI   )r   r   r   boolr  r   r   r   r#   r&   r'   ismergeR  s    zmerge.<locals>.ismerges   <merge>r   )r   r   rD   r   r   r   )r#   r$   r%   r  r&   r  r'   mergeI  s
    r  s   branchpoint()c                    s   t |ddtd | j}|s"t S t| dgt|    |j d dD ]0}||D ] }| krZ|    d7  < qZqL|j fddddS )	z)Changesets with more than one child.
    r   s   branchpoint takes no argumentsr   )rQ  c                    s   |    dkS rI   r&   r   ZbaserevZparentscountr&   r'   r   m  rd   zbranchpoint.<locals>.<lambda>s   <branchpoint>r   )	r   r   rD   r8   rm   rL   rw   r   r   )r#   r$   r%   r   r-   rY   r&   r  r'   branchpoint[  s    r  s   min(set)c                 C   s^   t | t| |}z*| }||v r8t|gd||fdW S W n tyL   Y n0 td||fdS )z2Changeset with lowest revision number in set.
    s   <min %r, %r>r  )r(   r7   rm   r8   r  r  r&   r&   r'   r  q  s    r  s   modifies(pattern)c                 C   s   t |td}t| ||dS )zChangesets modifying files matched by pattern.

    The pattern without explicit kind like ``glob:`` is expected to be
    relative to the current directory and match against a file or a
    directory.
    s   modifies requires a patternmodifiedr   r   r&   r&   r'   modifies  s    	r  s   named(namespace)c              	      s   t |ddtd}t|d td}t|\}}}t }|dkrp| jvr^ttd| |	 j|  n(t
 jD ]\}	}||	r||	| q|t }
|D ]>}| D ].}	|	|jvr|
 fdd| |	D  qq|
tjh8 }
||
@ S )	zThe changesets in a given namespace.

    Pattern matching is supported for `namespace`. See
    :hg:`help revisions.patterns`.
    r   s#   named requires a namespace argumentr   s&   the argument to named must be a stringr   s   namespace '%s' does not existc                 3   s   | ]} |   V  qd S r0   r   rb   rA   r   r&   r'   r     rd   znamed.<locals>.<genexpr>)r   r   r   r   r   r   namesr   r,   r   r   r   Z	listnamesZ
deprecatedr3  nodesr   r   )r#   r$   r%   r   nsr   r   r   Z
namespacesr   r  r&   r   r'   named  s.    


$r  s
   id(string)c              	   C   s   t |ddtd}t|d td}t|dkr|z| jt|}W q tj	y`   tj
}Y q ttfyx   d}Y q0 nTd}z$t| |}|dur| j|}W n* ty   Y n tj	y   tj
}Y n0 |du rt S t|g}||@ S )zGRevision non-ambiguously specified by the given hex string prefix.
    r   s   id requires one argumentr   s   id requires a string(   N)r   r   r   rL   rD   r+   r   binr   r   rJ   LookupError	TypeErrorr   Zresolvehexnodeidprefixr8   )r#   r$   r%   r#  rA   ZrnZpmresultr&   r&   r'   node_  s,    

r  s   none()c                 C   s   t |ddtd t S )zNo changesets.
    r   s   none takes no arguments)r   r   r8   r   r&   r&   r'   none  s    r  s
   obsolete()c                 C   s&   t |ddtd t| d}||@ S )z6Mutable changeset with a newer version. (EXPERIMENTAL)r   s   obsolete takes no argumentss   obsoleter   )r#   r$   r%   Z	obsoletesr&   r&   r'   r     s    r   s   only(set, [set])c                    s   | j }t|ddtd}t| t| |d t|dkrnsBt S tt	| d  fdd|
 D }nt| t| |d }t|j|d}||@ S )	a  Changesets that are ancestors of the first set that are not ancestors
    of any other head in the repo. If a second set is specified, the result
    is ancestors of the first set that are not ancestors of the second set
    (i.e. ::<set1> - ::<set2>).
    r   rW   s   only takes one or two argumentsr   Fc                    s    g | ]}| vr|vr|qS r&   r&   rb   r+   r.  rm  r&   r'   rc     s   zonly.<locals>.<listcomp>)commonr   )rD   r   r   r(   r7   rL   r8   r   r   rv   r|  Zfindmissingrevs)r#   r$   r%   r   r   rn  Zresultsr&   r  r'   only  s    r  s   origin([set])c                    sR   |durt t|}nt}fdd  fdd|D }|dh8 }||@ S )an  
    Changesets that were specified as a source for the grafts, transplants or
    rebases that created the given revisions.  Omitting the optional set is the
    same as passing all().  If a changeset created by these operations is itself
    specified as a source for one of these operations, only the source changeset
    for the first operation is selected.
    Nc                    s6   t  | }|d u rd S t  |}|d u r,|S |}qd S r0   )r/   )r+   r4  prevr   r&   r'   	_firstsrc  s    

zorigin.<locals>._firstsrcc                    s   h | ]} |qS r&   r&   ra   )r  r&   r'   r     rd   zorigin.<locals>.<setcomp>)r(   r7   )r#   r$   r%   r1  or&   )r  r#   r'   origin  s    	
r  s   outgoing([path])c                    s  ddl m}m} t|ddtd}|r8t|d tdp:d}|sDd}jjj|dd	}|spt	j
td
tdd|jpz|j}|jg f}||g \}	}
|	rfdd|	D }	|i |}j  |j||	d}j  j  fdd|jD }||@ S )zdChangesets not found in the specified destination repository, or the
    default push location.
    r   )	discoveryhgr   s"   outgoing takes one or no argumentss#   outgoing requires a repository pathrd   N)s   default-push   defaultr  s"   default repository not configured!s   see 'hg help config.paths'r}   c                    s   g | ]}  |qS r&   lookupr  r   r&   r'   rc   D  rd   zoutgoing.<locals>.<listcomp>)Z	onlyheadsc                    s   h | ]}  |qS r&   r   ra   rw  r&   r'   r   J  rd   zoutgoing.<locals>.<setcomp>)r  r  r  r   r   r   rA  pathsZgetpathr   r   ZpushlocZlocr   ZaddbranchrevspeerZ
pushbufferZfindcommonoutgoingZ	popbufferrD   Zmissing)r#   r$   r%   r  r  r#  destpathbranchesrw   Zcheckoutr  outgoingr  r&   )r   r#   r'   r  %  s0    


r  s	   p1([set])c              	   C   s   |du r4| |    }|dkr.|t|g@ S t S t }| j}t| t| |D ]H}z|||d  W qP t	j
y   || |     Y qP0 qP|tjh8 }||@ S )zAFirst parent of changesets in set, or the working directory.
    Nr   )r   r+   r8   r   rD   r(   r7   r   r   r   r   r   r   )r#   r$   r%   rY   r   r   r-   r&   r&   r'   r   N  s    r   s	   p2([set])c              	   C   s   |du rZ| |   }z,|d  }|dkr:|t|g@ W S t W S  tyX   t  Y S 0 t }| j}t| t| |D ]X}z||	|d  W qv t
jy   | |   }t|dkr||d  Y qv0 qv|tjh8 }||@ S )zBSecond parent of changesets in set, or the working directory.
    Nr   r   rW   )rz  r+   r8   
IndexErrorr   rD   r(   r7   r   r   r   r   rL   r   r   )r#   r$   r%   r   rY   r   r-   rz  r&   r&   r'   r  e  s(    r  c                 C   s   t | ||S r0   )r   r"   r&   r&   r'   
parentpost  s    r  s   parents([set])c              	   C   s   |du r dd | |   D }nnt }| j}|j}|j}t| t| |D ]D}z||| W qH tjy   |dd | |   D  Y qH0 qH|t	j
h8 }||@ S )zU
    The set of all parents for all changesets in set, or the working directory.
    Nc                 S   s   h | ]}|  qS r&   r   rl  r&   r&   r'   r     rd   zparents.<locals>.<setcomp>c                 s   s   | ]}|  V  qd S r0   r   rl  r&   r&   r'   r     rd   zparents.<locals>.<genexpr>)rz  r   rD   r3  r   r(   r7   r   r   r   r   )r#   r$   r%   r   r   Zupr   r-   r&   r&   r'   rz    s    "rz  c                 G   s   | j | ||S )z,helper to select all rev in <targets> phases)_phasecacheZ	getrevset)r#   r$   targetsr&   r&   r'   _phase  s    r  s   _phase(idx)c                 C   s(   t |ddd}t|d d}t| ||S )Nr   s   _phase requires one argumentr   s   _phase expects a number)r   r   r  )r#   r$   r%   r#  targetr&   r&   r'   phase  s    r  s   draft()c                 C   s$   t |ddtd tj}t| ||S )zChangeset in draft phase.r   s   draft takes no arguments)r   r   r   draftr  r#   r$   r%   r  r&   r&   r'   r    s    r  s   secret()c                 C   s$   t |ddtd tj}t| ||S )zChangeset in secret phase.r   s   secret takes no arguments)r   r   r   secretr  r  r&   r&   r'   r    s    r  s   stack([revs])c                 C   sP   |du rt | }n4tg }t| t| |D ]}t | |}|| }q.||@ S )zdExperimental revset for the stack of changesets or working directory
    parent. (EXPERIMENTAL)
    N)stackmodZgetstackr   r8   r(   r7   )r#   r$   r%   ZstacksrN  Zcurrentstackr&   r&   r'   r     s    

r   c           	   	   C   s<  zt |d }|dvrtW n$ ttfy@   ttdY n0 t }| j}t| t	| |D ]}|dkrv|
| q^|dkrz|
||d  W n* tjy   |
| |    Y n0 q^z*||}|d tjkr|
|d  W q^ tjy0   | |  }t|dkr,|
|d   Y q^0 q^||@ S )z``set^0``
    The set.
    ``set^1`` (or ``set^``), ``set^2``
    First or second parent, respectively, of all changesets in set.
    r   )r   r   rW   s   ^ expects a number 0, 1, or 2r   rW   )intr  r  r   r    r   r   rD   r(   r7   r   r   r   r   r+   r   r   rz  rL   )	r#   r$   r%   rA   r   r   r   r-   rz  r&   r&   r'   
parentspec  s2    
r  s   present(set)c                 C   s0   zt | |||W S  tjy*   t  Y S 0 dS )a  An empty set, if any revision in set isn't found; otherwise,
    all revisions in set.

    If any of specified revisions is not present in the local repository,
    the query is normally aborted. But this predicate allows the query
    to continue even in such cases.
    N)r(   r   r,   r8   r"   r&   r&   r'   present  s    	r  
   _notpublicc                 C   s    t |ddd t| |tjtjS )Nr   s   _notpublic takes no arguments)r   r  r   r  r  r   r&   r&   r'   
_notpublic  s    r  s"   _phaseandancestors(phasename, set)c           
         s   t |ddd}t|d }tt|d }tj tj}  |d}||vr\td| || j	j
fdd}tj||d	}	|d
kr|	 fdd}	||	@ S )NrW   s)   _phaseandancestors requires two argumentsr   r   )r     drafts   secrets   %r is not a valid phasenamec                    s    | k S r0   r&   r   )getphaseminimalphaser#   r&   r'   cutfunc  s    z#_phaseandancestors.<locals>.cutfunc)r  r  c                    s   |  kS r0   r&   r   )r  r  r#   r&   r'   r     rd   z$_phaseandancestors.<locals>.<lambda>)r   re   r(   r7   r   r  r  r   r    r  r  r   ru   r   )
r#   r$   r%   r   Z	phasenamerx   r  Zphasenamemapr  rw   r&   )r  r  r  r#   r'   _phaseandancestors  s$    r  s   public()c                 C   s    t |ddtd t| |tjS )zChangeset in public phase.r   s   public takes no arguments)r   r   r  r   publicr   r&   r&   r'   r  !  s    r  s   remote([id [,path]])c                 C   s   ddl m} t|ddtd}d}t|dkr@t|d td}|dkrT| d  }d}t|dkrvt|d td	}| j|pd
}|	|\}}|
| i |}||}	|	| v r| |	  }
|
|v rt|
gS t S )zLocal revision that corresponds to the given identifier in a
    remote repository, if present. Here, the '.' identifier is a
    synonym for the current local branch.
    r   )r  r   rW   s(   remote takes zero, one, or two argumentsrV  s   remote requires a string idrd   s!   remote requires a repository pathr  )r  r  r   r   rL   r   r   rA  Z
expandpathZparseurlr  r  r+   r8   )r#   r$   r%   r  r#  qr  r  r  rA   r-   r&   r&   r'   remote)  s&    

r  s   removes(pattern)c                 C   s   t |td}t| ||dS )zChangesets which remove files matching pattern.

    The pattern without explicit kind like ``glob:`` is expected to be
    relative to the current directory and match against a file or a
    directory.
    s   removes requires a patternremovedr   r   r&   r&   r'   removesL  s    	r  s   rev(number)c                 C   s.   zt | ||W S  tjy(   t  Y S 0 dS )z+Revision with the given numeric identifier.N)_revr   r,   r8   r   r&   r&   r'   r+   Y  s    r+   s   _rev(number)c              	   C   s   t |ddtd}ztt|d td}W n$ ttfyP   ttdY n0 |tvrz| j	
| W n$ ty   ttd| Y n0 |t|g@ S )Nr   s   rev requires one argumentr   s   rev requires a numbers   rev expects a numbers   unknown revision '%d')r   r   r  r   r  r  r   r    r5   rD   r   r  r,   r8   r"  r&   r&   r'   r  b  s    r  s   revset(set)c                 C   s   t | |||S )a  Strictly interpret the content as a revset.

    The content of this special predicate will be strictly interpreted as a
    revset. For example, ``revset(id(0))`` will be interpreted as "id(0)"
    without possible ambiguity with a "id(0)" bookmark or tag.
    )r(   r"   r&   r&   r'   revsetpredicateu  s    r  s   matching(revision [, field])c                    s  t |ddtd}tt|d dg}t|dkrNt|d td }g }|D ]F}|dkrp|g d7 }qV|dkr|d	dg7 }qV|d
krd}|| qVt|}d|v rd|v r|	d g d  fdd}t
|}|j|d g fddfddfddfddfddfddfddfddfddfddd
}|D ]8}	||	d}
|
du rttd|	 |
 qZfd dfd!d"}|j|d#|fd$S )%a  Changesets in which a given set of fields match the set of fields in the
    selected revision or set.

    To match more than one field pass the list of fields to match separated
    by spaces (e.g. ``author description``).

    Valid fields are most regular revision fields and some special fields.

    Regular revision fields are ``description``, ``author``, ``branch``,
    ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user``
    and ``diff``.
    Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the
    contents of the revision. Two revisions matching their ``diff`` will
    also match their ``files``.

    Special fields are ``summary`` and ``metadata``:
    ``summary`` matches the first line of the description.
    ``metadata`` is equivalent to matching ``description user date``
    (i.e. it matches the main metadata fields).

    ``metadata`` is the default field which is used when no fields are
    specified. You can match more than one field at a time.
    r   rW   s   matching takes 1 or 2 argumentsr   s   metadatas1   matching requires a string as its second argument)   user   description   date   diff   files   authorr     summaryr  )
   phase   parentsr  r     branchr  r  r     substater  c                    s,   z  | W S  ty&   t  Y S 0 d S r0   )indexr  rL   )r   )
fieldorderr&   r'   fieldkeyfunc  s    zmatching.<locals>.fieldkeyfunc)keyc                    s    |    S r0   r   r   r   r&   r'   r     rd   zmatching.<locals>.<lambda>c                    s    |    S r0   r   r   r   r&   r'   r     rd   c                    s    |    S r0   r%  r   r   r&   r'   r     rd   c                    s    |    S r0   r)  r   r   r&   r'   r     rd   c                    s    |    S r0   )r   r   r   r&   r'   r     rd   c                    s    |    S r0   )rz  r   r   r&   r'   r     rd   c                    s    |    S r0   )r  r   r   r&   r'   r     rd   c                    s
    |  j S r0   )substater   r   r&   r'   r     rd   c                    s    |     d S rC   )r*  
splitlinesr   r   r&   r'   r     rd   c                    s"   t  |  jt jddidS )Ns   gitT)r   )r
  r9  r	   ZdiffalloptsrA  r   r   r&   r'   r     s   )
r  r  r  r  r  r  r  r  r  r  Ns,   unexpected field name passed to matching: %sc                    s    fddD S )Nc                    s   g | ]}| qS r&   r&   r   r   r&   r'   rc     rd   z.matching.<locals>.<lambda>.<locals>.<listcomp>r&   r   )getfieldfuncsr   r'   r     rd   c                    sJ   D ]@}|}d}t  D ]\}}|| || krd}q|r dS qdS re  )	enumerate)r%   r+   r  r   rA   r   )r  getinforw   r&   r'   r    s    zmatching.<locals>.matchess   <matching%r %r>r   )r   r   r(   r7   rL   r   splitr2  r   r{  r
  sortr   r   r    r   )r#   r$   r%   r#  Z	fieldlistfieldsr  r  Z_funcsinfoZgetfieldr  r&   )r  r  r  r#   rw   r'   matching  s`    	











r  s   reverse(set)c                 C   s"   t | |||}|tkr|  |S )zReverse order of set.
    )r(   rM   r  )r#   r$   r%   r   r#  r&   r&   r'   r  	  s    r  s
   roots(set)c                    s8   t | t| || jj  fdd}|j|dd@ S )z7Changesets in set with no parent changeset in set.
    c                    s(    | D ]}d|kr|v r dS qdS )Nr   FTr&   )r-   rY   rz  rx   r&   r'   r   	  s    zroots.<locals>.filters   <roots>r   )r(   r7   rD   r   r   )r#   r$   r%   r   r&   r  r'   r,  	  s    r,  c                 C   s   |   S r0   r  r   r&   r&   r'   r   	  rd   r   c                 C   s   |   S r0   r)  r  r&   r&   r'   r   	  rd   c                 C   s   |   S r0   r   r  r&   r&   r'   r    	  rd   c                 C   s   |   S r0   r   r  r&   r&   r'   r   !	  rd   c                 C   s   |   d S rC   r%  r  r&   r&   r'   r   "	  rd   )   revr  s   descr  r  r  s   nodec                 C   s  t | dd}d|vr"ttdd}d|v r@t|d td}g }| D ]X}|}|d}|rn|d	d
 }|tvr|dkrttdt	| |
||f qLt|d	krtdd |D rttdi }d|v rtdd |D r|d |d< nttd|d ||fS )z5Parse sort options into (set, [(key, reverse)], opts)s   sorts   set keys topo.firstbranchr   s"   sort requires one or two argumentsr  s   keyss   sort spec must be a string   -r   N   topos   unknown sort key %rc                 s   s   | ]\}}|d kV  qdS r  Nr&   rb   r   r  r&   r&   r'   r   >	  rd   z_getsortargs.<locals>.<genexpr>s7   topo sort order cannot be combined with other sort keys   topo.firstbranchc                 s   s   | ]\}}|d kV  qdS r  r&   r  r&   r&   r'   r   F	  rd   s>   topo.firstbranch can only be used when using the topo sort key)r   r   r    r   r   r  r   _sortkeyfuncsr   Zbytestrr2  rL   r   )r%   r   rg   keyflagsr   Zfkr  r   r&   r&   r'   _getsortargs'	  s>    

r  s   sort(set[, [-]key... [, ...]])c                    s  t |\}}}t |||}|r(|tkr,|S t|dkr`|d d dkr`|j|d d d |S |d d dkrd}d|v rt ||d }tt| jj	|dd	}|d d r|
  |S  fd
d|D }	t|D ]\}
}|	jt|
 |d qtdd |	D S )a  Sort set by keys. The default sort order is ascending, specify a key
    as ``-key`` to sort in descending order.

    The keys can be:

    - ``rev`` for the revision number,
    - ``branch`` for the branch name,
    - ``desc`` for the commit message (description),
    - ``user`` for user name (``author`` can be used as an alias),
    - ``date`` for the commit date
    - ``topo`` for a reverse topographical sort
    - ``node`` the nodeid of the revision

    The ``topo`` sort order cannot be combined with other sort keys. This sort
    takes one optional argument, ``topo.firstbranch``, which takes a revset that
    specifies what topographical branches to prioritize in the sort.

    r   r   r  )r  r  r&   r  T)Zistopoc                    s   g | ]} | qS r&   r&   ra   r   r&   r'   rc   	  rd   zsort.<locals>.<listcomp>)r  r  c                 S   s   g | ]}|  qS r&   r   )rb   r   r&   r&   r'   rc   	  rd   )r  r(   rM   rL   r  r8   r   ZtoposortrD   r   r  reversedr  )r#   r$   r%   r   rx   r  r   rw   ZfirstbranchZctxsr   r  r&   r   r'   r  T	  s,    r  s   subrepo([pattern])c                    sp   t |ddtd}dt|dkr4t|d tdtdg fdd fd	d
}|j|dfdS )zChangesets that add, modify or remove the given subrepo.  If no subrepo
    pattern is named, any subrepo changes are returned.
    r   r   s"   subrepo takes at most one argumentNs   subrepo requires a patterns   .hgsubstatec                 3   s,   t  \}}}| D ]}||r|V  qd S r0   )r   r   )r  r   rY   r@   r   )r   r&   r'   
submatches	  s    zsubrepo.<locals>.submatchesc                    s   |  }j |  |  d}d u r>|jp<|jp<|jS |jrVt|j S |jrt	| j }|
|j  |D ]&}| j||j|kr dS q|jrt| j S dS )N)r   TF)r   r   r   r   r  r  r   r  rg   r   r3  r   )r%   r   rx   Zsubsr  r@   r   r#   r  r&   r'   r  	  s    zsubrepo.<locals>.matchess   <subrepo %r>r   )r   r   rL   r   r   exactr   )r#   r$   r%   r   r  r&   r  r'   subrepo	  s    r  c                    sX   |   j}|jj|j fdd| fdd|D D }|d t|| jj S )z(repo, smartset, [node] -> [node]) -> smartset

    Helper method to map a smartset to another smartset given a function only
    talking about nodes. Handles converting between rev numbers and nodes, and
    filtering.
    c                    s   h | ]} |qS r&   r&   r  )torevr&   r'   r   	  rd   z!_mapbynodefunc.<locals>.<setcomp>c                 3   s   | ]} |V  qd S r0   r&   ra   )tonoder&   r'   r   	  rd   z!_mapbynodefunc.<locals>.<genexpr>N)	Z
unfilteredrD   r  Zget_revr   r{  r   r8   Zfilteredrevs)r#   rx   r   r   r  r&   )r  r  r'   _mapbynodefunc	  s    
$
r  s   successors(set)c                    s0   t  t |} fdd}t ||}||@ S )zNAll successors for set, including the given set themselves.
    (EXPERIMENTAL)c                    s   t  j| S r0   )r   ZallsuccessorsZobsstore)r  r   r&   r'   r   	  rd   zsuccessors.<locals>.<lambda>)r(   r7   r  )r#   r$   r%   rx   r   dr&   r   r'   
successors	  s    r   c                    sN   t j |d\} }|dkrD|s8t   fdd}n fdd}| |fS )Nr   r   c                    s    t | v S r0   r  rx   r   r&   r'   r   	  rd   z#_substringmatcher.<locals>.<lambda>c                    s    | v S r0   r&   r  r  r&   r'   r   	  rd   )r   r   r
   r   )r   r   r   r   r&   r  r'   r   	  s    
r   s   tag([name])c                    s   t |ddtd}| j |rt|d td}t|\}}|dkr| jj|d}|du rpt	
td| | |  h}q fdd	|  D }n fd
d	|  D }||@ S )zThe specified tag by name, or all tagged revisions if no name is given.

    Pattern matching is supported for `name`. See
    :hg:`help revisions.patterns`.
    r   r   s   tag takes one or no argumentss$   the argument to tag must be a stringr   Ns   tag '%s' does not existc                    s"   h | ]\}}|r  |qS r&   r   rb   r  rA   r   r   r&   r'   r   	  rd   ztag.<locals>.<setcomp>c                    s"   h | ]\}}|d kr  |qS )s   tipr   r  rw  r&   r'   r   	  rd   )r   r   rD   r   r   r   Z
_tagscacheZtagsr   r   r,   r+   Ztagslist)r#   r$   r%   r   r   r   Ztnrx   r&   r  r'   tag	  s$    
r  s   taggedc                 C   s   t | ||S r0   )r  r   r&   r&   r'   tagged	  s    r  s   orphan()c                 C   s&   t |ddtd t| d}||@ S )zDNon-obsolete changesets with obsolete ancestors. (EXPERIMENTAL)
    r   s   orphan takes no arguments   orphanr   )r#   r$   r%   orphanr&   r&   r'   r  	  s    r  s
   unstable()c                 C   sV   t |ddd t }|t| d |t| d |t| d |t|@ S )z2Changesets with instabilities. (EXPERIMENTAL)
    r   s   unstable takes no argumentsr  r   rC  )r   r   r3  r   r   r8   )r#   r$   r%   Z	_unstabler&   r&   r'   unstable
  s    r	  s   user(string)c                 C   s   t | ||S )zUser name contains string. The match is case-insensitive.

    Pattern matching is supported for `string`. See
    :hg:`help revisions.patterns`.
    )r   r   r&   r&   r'   r   
  s    r   s   wdir()c                 C   s8   t |ddtd tj|v s&t|tr2ttjgS t S )z!Working directory. (EXPERIMENTAL)r   s   wdir takes no arguments)r   r   r   rJ   r6   r7   r8   r   r&   r&   r'   wdir
  s    r
  c           
   	   C   s   t |d}|st S | j}g }t }|dD ]}z*t|}d| |ksP||vrTt|g}	W n  ty|   t| ||t}	Y n0 |	D ]<}||v rq||v s|t	v rt
|tr|| || qq.t|S )N   internal error    s   %d)r   r8   rD   r   r  r  r  r9   rM   r5   r6   r7   r2  r   )
r#   r$   r%   rx   r   rx  seenr  r-   rw   r&   r&   r'   _orderedlist(
  s4    


r  s   _listc                 C   s,   |t kr|t| t| |@ S t| ||S d S r0   )r:   r  r7   r"   r&   r&   r'   _listI
  s    r  c                    sB   t |d  st S dd  dD }| t fdd|D S )Nr  c                 S   s   g | ]}t |qS r&   )r  ra   r&   r&   r'   rc   V
  rd   z#_orderedintlist.<locals>.<listcomp>r  c                    s   g | ]}| v r|qS r&   r&   ra   r  r&   r'   rc   X
  rd   )r   r8   r  r#   r$   r%   rx  r&   r  r'   _orderedintlistR
  s    
r  s   _intlistc                 C   s,   |t kr|t| t| |@ S t| ||S d S r0   )r:   r  r7   r"   r&   r&   r'   _intlist\
  s    r  c                    sL   t |dst S | j  fdddD }|tfdd|D S )Nr  c                    s   g | ]}  t|qS r&   )r+   r   r  ra   rw  r&   r'   rc   j
  rd   z#_orderedhexlist.<locals>.<listcomp>r  c                    s   g | ]}| v r|qS r&   r&   ra   r  r&   r'   rc   l
  rd   )r   r8   rD   r  r  r&   )r   rx   r'   _orderedhexliste
  s    
r  s   _hexlistc                 C   s,   |t kr|t| t| |@ S t| ||S d S r0   )r:   r  r7   r"   r&   r&   r'   _hexlistp
  s    r  )s   rangerp   s   rangepres	   rangeposts   dagrangert  s   symbols   ands	   andsmally   ors   nots
   differences   relations   relsubscripts	   subscript   lists   keyvalues   funcs   ancestors   parents
   parentposts   smartset)   gs   generationsc                    s    fddS )Nc                    s   t  | S r0   )r   Zisrevsymbol)Zsymbolr   r&   r'   r   
  rd   zlookupfn.<locals>.<lambda>r&   r   r&   r   r'   lookupfn
  s    r  c                 C   s   t | |g|dS )z+Create a matcher for a single revision specr  )matchany)rA  specr  r&   r&   r'   r   
  s    r   c                    s   |sddd}|S t |s(ttdt|dkrFt|d  }nddt fd	d
|D  f}g }d}| r|| 	d | j
}|r||  |rtj|||d}t|}t|}t|}t|S )ae  Create a matcher that will include any revisions matching one of the
    given specs

    If lookup function is not None, the parser will first attempt to handle
    old-style ranges, which may contain operator characters.

    If localalias is not None, it is a dict {name: definitionstring}. It takes
    precedence over [revsetalias] config section.
    Nc                 S   s   t  S r0   )r8   )r#   r$   r&   r&   r'   mfunc
  s    zmatchany.<locals>.mfuncs   empty queryr   r   r  )r  c                 3   s   | ]}t | V  qd S r0   )r   parse)rb   rx   r  r&   r'   r   
  rd   zmatchany.<locals>.<genexpr>s   revsetalias)warn)N)allr   r    r   rL   r   r  tuplerX  Zconfigitemsr  r   ZexpandaliasesZ
foldconcatZanalyzeoptimizemakematcher)rA  Zspecsr  Z
localaliasr  treealiasesr  r&   r  r'   r  
  s.    




r  c                    s   d fdd	}|S )z)Create a matcher from an evaluatable treeNc                    s8   |d u r|d u rt }nt}|d u r*t| }t| | |S r0   )rM   r:   r7   r(   )r#   r$   r   r"  r&   r'   r  
  s    zmakematcher.<locals>.mfunc)NNr&   )r"  r  r&   r$  r'   r!  
  s    
r!  c                 C   s2   t |jD ] \}}|t|< |jrt| qdS )z7Load revset predicates from specified registrarobj
    N)r   r   Z_tabler   Z_safesafesymbolsr   )rA  ZextnameZregistrarobjr   r   r&   r&   r'   loadpredicate
  s    r&  )FNN)FNN)F)T)N)NN)Z
__future__r   r>  Zi18nr   r   r   r  r   r   r	   r
   r   r   r:  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   Zutilsr   r   re   r   r   r`  r\   rt   r   r   r8   ra  rK   r7   r   rJ   r5   rP   rM   r:   r(   r/   r3   r9   r;   rB   rF   rG   rH   r<   rN   rR   rS   rV   rX   r]   r^   rk   ro   rs   rq   rz   r|   r   r   r   r   r   r%  r  Z	predicater   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r	  r  r  r  r  r  r$  r&  r+  r-  r.  r/  r5  rB  rD  rH  rJ  rK  r*   rR  r=   rZ  r\  r^  rc  rd  rs  ru  ry  r   r~  r  rS  r>   r  r  r  r  r  r  r  r  r  r  r  r   r  r  rz  r  r  r  r  r  r  r  r  r  r  r  r+   r  r  r  r,  r4   Zbinnoder  r  r  r  r  r   r   r  r  r  r	  r   r
  r  r  r  r  r  r  r!   rf   ry   r  r  r!  r&  r   Zi18nfunctionsr&   r&   r&   r'   <module>   sT  \(				

















%
3



%




















!


/

)


+


	

!

?


	


E





[





	












%




 (""
 	




-
.,				!
	)
