
    	^c;                       d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	m
Z
mZ ddlmZmZ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+m,Z, ej-        Z-dd	d ed
          fgZ.i Z/ e j0        e/          Z0dZ1i Z2 e j3        e2          Z3 e3ddd            e3ddd            e3ddd            e3ddd           	  ej4        d           n2# e5$ r*  G d d          Z6 ej7         e6            dd           Y nw xY we$j$        Z$ddZ8e&j9        Z: G d d          Z;g dZ<ddddZ=d Z>d  Z? G d! d"          Z@d# ZA G d$ d%ejB                  ZC G d& d'          ZDd( ZE e0d)d*d+d ed,          fd-d.g  ed/           ed0          fg ed1          e0jF        2          d3             ZG e0d4d5d6d ed7          fge.z    ed8          e0jF        2          dd9            ZH e0d:d5d;d ed<          fge.z    ed=          e0jF        2          dd>            ZI e0d?d@dAd edB          fdCdDd edE           edF          fdGdHd edI          fd-d.g  edJ           ed0          fdKdd edL          fdMdNd edO          fg edP          e0jJ        2          dQ             ZKdR ZL e0dSdTdUd edV          fg edW          e0jM        dXY          dZ             ZN e0d[dd\d ed]          fd^d_d ed`          fddad edb          fdcddd ede           edf          fgejO        z    edg          e0jM        dXh          ddi            ZP e0djejQ        dk         d          edl          e0jR        dXm          dn             ZS e0dodpdqd edr          fge.z    eds          e0jF        2          dt             ZT e0due. edv          e0jF        2          dw             ZU e0dxe. edy          e0jF        2          dz             ZV e0d{e. ed|          e0jF        2          d}             ZWd~ ZX e0dd@dd ed          fdGdHd ed          fdKdd edL          fd^dd ed          fddd ed           ed          fddd ed          fddd ed           ed          fgejY        z   ejZ        z    ed          e0jR        dXdX          d             Z[ e0dd@dd ed          fdKdd edL          fddd ed          fd^dd ed          fddd ed           ed          fddd ed          fddd ed           ed          fgejY        z   ejZ        z    ed          e0jR        dXdX          d             Z\ e0dej]        ej^        z   ejY        z    ed          e0j_        dXdX          d             Z` e0dd@dd ed          fd*d+d ed          fgejZ        z    ed          e0ja        2          d             Zb e0dddd ed          fdGdHd ed          fddd ed          fg ed          e0jF        2          d             Zc e0dddd ed          fdCdd ed          fg ed          e0jF        2          d             Zd e0dg  ed          e0jF        2          dd            Zed Zfd Zg e0dddd ed          fdGdHd ed          fd@dd ed          fddd ed          fddd ed          fdpdd ed          fdCdDd ed¦           edF          fddd edĦ          fddd ed          fg	 edŦ          e0jF        dXY          ddƄ            Zh e0dddd edȦ          fdCdDd edɦ           edF          fddd ed          fdGdHd edʦ          fddd ed          fg ed˦          e0jF        dXY          dd̄            Zi e0dg  edΦ          e0jF        2          ddτ            Zj e0dddd edҦ          fddd edԦ          fg edզ          e0jF        2          dք             Zk e0ddTdd ed٦          fdCdDd edڦ           edF          fd@dd edܦ          fdGdHd edݦ          fgejZ        z    edަ          e0jF        2          d߄             Zl e0ddCdd ed          fddd ed          fddd ed          fddd ed          fg ed          e0jF        2          d             Zm e0dddd ed          fg ed          e0jF        2          d             Zn e0dddd ed          fddd ed          fdTdd ed          fddd ed          fddd ed          fddd ed          fg ed          e0jF        2          dd            Zod Zpd Zqd Zrd Zsd  Ztd Zu e jv                    Zv evd          d             ZwewgZxd Zyddddd	d
d	dZzdS (  a  manage a stack of patches

This extension lets you work with a stack of patches in a Mercurial
repository. It manages two stacks of patches - all known patches, and
applied patches (subset of known patches).

Known patches are represented as patch files in the .hg/patches
directory. Applied patches are both patch files and changesets.

Common tasks (use :hg:`help COMMAND` for more details)::

  create new patch                          qnew
  import existing patch                     qimport

  print patch series                        qseries
  print applied patches                     qapplied

  add known patch to applied stack          qpush
  remove patch from applied stack           qpop
  refresh contents of top applied patch     qrefresh

By default, mq will automatically use git patches when required to
avoid losing file mode changes, copy records, binary files or empty
files creations or deletions. This behavior can be configured with::

  [mq]
  git = auto/keep/yes/no

If set to 'keep', mq will obey the [diff] section configuration while
preserving existing git patches upon qrefresh. If set to 'yes' or
'no', mq will override the [diff] section and always generate git or
regular patches, possibly losing data in the second case.

It may be desirable for mq changesets to be kept in the secret phase (see
:hg:`help phases`), which can be enabled with the following setting::

  [mq]
  secret = True

You will by default be managing a patch queue named "patches". You can
create other, independent patch queues with the :hg:`qqueue` command.

If the working directory contains uncommitted files, qpush, qpop and
qgoto abort immediately. If -f/--force is used, the changes are
discarded. Setting::

  [mq]
  keepchanges = True

make them behave as if --keep-changes were passed, and non-conflicting
local changes will be tolerated and preserved. If incompatible options
such as -f/--force or --exact are passed, this setting is ignored.

This extension used to provide a strip command. This command now lives
in the strip extension.
    N_)binhexnullrevshort)delattrgetattropen)cmdutilcommandsdirstateguardencodingerror
extensionshg	localrepolock
logcmdutilpatchphasespycompat	registrar
revsetlangscmutilsmartsetstripsubrepoutilutilvfs)dateutil
stringutilurlutil   s   summarys    print first line of patch headers   ships-with-hg-core   mq   git   auto)default   keepchangesF   plain   secrets   stripc                       e Zd Zd Zd ZdS )dummyuic                     d S N )selfmsgs     */usr/lib/python3/dist-packages/hgext/mq.pydebugzdummyui.debug       D    c                     d S r0   r1   )r2   eventmsgfmtmsgargsoptss        r4   logzdummyui.log   r6   r7   N)__name__
__module____qualname__r5   r=   r1   r7   r4   r.   r.      s2        	 	 		 	 	 	 	r7   r.   r7   c                 `   g }| d         }|r	| |         }n|                                 }t          |j                  D ]o}|                    |                              d           ||j        vs'|                    |                                          r|                    |           p|S )zrreturn list of subrepos at a different revision than substate.
    Abort if any subrepos have uncommitted changes.NT)p1sortedsubstatesubbailifchangeddirtyappend)repobaserevinclsubswctxbctxss         r4   checksubstaterO      s     H:D G}wwyyDM""  !!$'''DM!!TXXa[[%6%6%8%8!OOAOr7   c                   Z    e Zd Zd Zd Z ej        e          Z ej        e          ZdS )statusentryc                 $    ||c| _         | _        d S r0   nodename)r2   rT   rU   s      r4   __init__zstatusentry.__init__   s    #T	4999r7   c                 @    t          | j                  dz   | j        z   S )N   :)r   rT   rU   r2   s    r4   	__bytes__zstatusentry.__bytes__   s    49~~$ty00r7   N)	r>   r?   r@   rV   rZ   r   	strmethod__str____repr__r1   r7   r4   rQ   rQ      sR        * * *1 1 1 !h ++G!x!),,HHHr7   rQ   )   # User    # Date s   #      	   # Branch 
   # Node ID 
   # Parent        )s   from   dates   subjectc                    |                      d          dz   }t                               |          }t          |           }t          |t          |                     D ]}| |         }|                    d          st          ||          } n\t          t                    D ]F\  }}	|                    |	          r,||k    r||z   | |<   | c c S ||k    rt          ||          } nG|                     |||z              | S )a  Assuming lines contains a HG patch header, add a header line with value.
    >>> try: inserthgheader([], b'# Date ', b'z')
    ... except ValueError as inst: print("oops")
    oops
    >>> inserthgheader([b'# HG changeset patch'], b'# Date ', b'z')
    ['# HG changeset patch', '# Date z']
    >>> inserthgheader([b'# HG changeset patch', b''], b'# Date ', b'z')
    ['# HG changeset patch', '# Date z', '']
    >>> inserthgheader([b'# HG changeset patch', b'# User y'], b'# Date ', b'z')
    ['# HG changeset patch', '# User y', '# Date z']
    >>> inserthgheader([b'# HG changeset patch', b'# Date x', b'# User y'],
    ...                b'# User ', b'z')
    ['# HG changeset patch', '# Date x', '# User z']
    >>> inserthgheader([b'# HG changeset patch', b'# Date y'], b'# Date ', b'z')
    ['# HG changeset patch', '# Date z']
    >>> inserthgheader([b'# HG changeset patch', b'', b'# Date y'],
    ...                b'# Date ', b'z')
    ['# HG changeset patch', '# Date z', '', '# Date y']
    >>> inserthgheader([b'# HG changeset patch', b'# Parent  y'],
    ...                b'# Date ', b'z')
    ['# HG changeset patch', '# Date z', '# Parent  y']
       # HG changeset patchrc      # )index	HGHEADERSlenrange
startswithmin	enumerateinsert)
linesheadervaluestartnewindexbestposiline	lineindexhs
             r4   inserthgheaderr{      s   . KK/0014Ev&&H%jjG5#e**%%  Qxu%% 	'1ooGE%i00 	 	LIqq!! ((%~E!H LLLLLx''!'1ooG 
LL&5.)))Lr7   c                    t           |                                         }t          |           }t          |           D ]\  }}d|v r|                    dd          d                                                                         }t                               ||dz             }||k    rd||fz  | |<   | c S ||k    r||k     r|}|r|                     |d           ||k     r|} |                     |d||fz             | S )a  For lines containing a plain patch header, add a header line with value.
    >>> insertplainheader([], b'Date', b'z')
    ['Date: z']
    >>> insertplainheader([b''], b'Date', b'z')
    ['Date: z', '']
    >>> insertplainheader([b'x'], b'Date', b'z')
    ['Date: z', '', 'x']
    >>> insertplainheader([b'From: y', b'x'], b'Date', b'z')
    ['From: y', 'Date: z', '', 'x']
    >>> insertplainheader([b' date : x', b' from : y', b''], b'From', b'z')
    [' date : x', 'From: z', '']
    >>> insertplainheader([b'', b'Date: y'], b'Date', b'z')
    ['Date: z', '', 'Date: y']
    >>> insertplainheader([b'foo: bar', b'DATE: z', b'x'], b'From', b'y')
    ['From: y', 'foo: bar', 'DATE: z', '', 'x']
    rX   rc   r      %s: %sr7   )PLAINHEADERSlowerrk   ro   splitr   getrp   )	rq   rr   rs   newpriorv   rw   rx   lheaderlprios	            r4   insertplainheaderr     s   " 6<<>>*G%jjGU##  44<<jjq))!,2244::<<G $$Wgk::E$6aw1w;; %Q$$$7{{	LL)vuo5666Lr7   c                   Z    e Zd Zd
dZd Zd Zd Zd Zd Z e	j
        e          Zd Zd	S )patchheaderFc                    d }d }g }g }d }d }d }	d }
d }d }d }d}t          |d          D ]M}|                                }|                    d          s|r|                    d          rd} nd}|                    d          rd	}b|
d
k    r|                    d          r|dd          }n|                    d          r|dd          }n|                    d          r|dd                                          }	n[|                    d          r|dd          }n:|                    d          r|dd          }n|                    d          s|r|                    |           d }
n|dk    rg }d
}
n|
dk    r7|                    d          s|                    d          r|dd          }d}
n|
dk    r7|                    d          s|                    d          r|dd          }d}
ne|
dk    r7|                    d          s|                    d          r|dd          }d}
n(|
dk    r	|dk    rd}
n|s|r|                    |           |                    |           O ||            ||           t          |          | _         ||            ||           |
r-|
                    d          r|r|                    d|           || _        || _	        || _
        || _        |	| _        || _        || _        |d	k    | _        |p&d| j	        vot!          d | j	        D                       | _        d S ) Nc                     | rQ| d         }|                     d          s*|                     d          s|                     d          r| d= nd S | Od S d S )Ns   diff -s   Index:s   ===========rm   )rq   ls     r4   eatdiffz%patchheader.__init__.<locals>.eatdiff)  s     	"ILL++||I.. ||N33
 b		E  	 	 	 	 	r7   c                 R    | r$| d                                          s| d= nd S | "d S d S )Nr   r   )rq   s    r4   eatemptyz&patchheader.__init__.<locals>.eatempty5  sL     Ry(( b		E	      r7   r   s   rb
   diff --gits   +++ rd   s   --- rc   s   hgpatchr^      r_   s	   # Parent 	   r`   ra   
   rh   rg   s   tagdones	   Subject: 	   subject: s   tag   From: s   from:       Date: s   date: r7   c              3   j   K   | ].}|                     d           p|                     d          V  /dS )r   r   Nr   ).0cs     r4   	<genexpr>z'patchheader.__init__.<locals>.<genexpr>  sS         Y''B1<<	+B+B     r7   )r   rstriprm   lstriprH   rk   diffstartlinerp   messagecommentsuserdateparentnodeidbranchhaspatchany	plainmode)r2   pfr   r   r   r   r   r   r   r   formatsubjectr   r   	diffstartrx   s                   r4   rV   zpatchheader.__init__(  s$   
	 
	 
		 	 	 	UOO 2	" 2	"D;;==D}-- "oog66 	Iw'' )%	:%%??:.. "8DD__Z00 
"8DD__\22 "!!""X__..FF__\22 "!!""XFF__]33 "!"##YFF// "D "NN4(((!F000#:%%-- &151N1N & qrr(:%%	** &.2ooi.H.H & ABBx:%%	** &.2ooi.H.H & ABBx6!!dckk $ %D %t$$$OOD!!!! !]]  	'f''// 	'G 	'NN1g&&& 		!A &dm;        	r7   c                     	 t          | j        d|           nD# t          $ r7 | j        rt	          | j        d|           ndd|z   g}|| j        z   | _        Y nw xY w|| _        d S )Nr^   s   Fromrg   )r{   r   
ValueErrorr   r   r   )r2   r   tmps      r4   setuserzpatchheader.setuser      	44=*d;;;; 	4 	4 	4~ 4!$-$????.
T0AB #dm 3	4 			    >AAc                     	 t          | j        d|           nD# t          $ r7 | j        rt	          | j        d|           ndd|z   g}|| j        z   | _        Y nw xY w|| _        d S )Nr_   s   Daterg   )r{   r   r   r   r   r   )r2   r   r   s      r4   setdatezpatchheader.setdate  r   r   c                     	 t          | j        d|           n-# t          $ r  | j        sdd|z   g}|| j        z   | _        Y nw xY w|| _        d S )Nrb   rg   )r{   r   r   r   r   )r2   r   r   s      r4   	setparentzpatchheader.setparent  so    	44=-@@@@ 	4 	4 	4> 4.0FG #dm 3	4 s    'AAc                     | j         r|                                  |g| _        |rQ| j        r.| j         r'| j         d         r| j                             d           | j                             |           d S d S )Nr   r7   )r   _delmsgr   r   rH   )r2   r   s     r4   
setmessagezpatchheader.setmessage  s    = 	LLNNNy 	*~ *$- *DM"4E *$$S)))M  )))))	* 	*r7   c                 l    d                     | j                                                  }|sdS |dz   S )N   
r7   s   

)joinr   r   )r2   rN   s     r4   rZ   zpatchheader.__bytes__  s8    JJt}%%,,.. 	37{r7   c                    | j         rd| j         d                                         z   }t          t          | j                            D ]C}|| j        |                                         k    r| j        |= | j         dd         | _          nDd}| j         D ]1}|| j        |         k    r|dz  }|| j        |         k    | j        |= 2dS )zRemove existing message, keeping the rest of the comments fields.
        If comments contains 'subject: ', message will prepend
        the field and a blank line.r   r   rd   Nrc   )r   r   rl   rk   r   )r2   subjrw   cimis        r4   r   zpatchheader._delmsg  s     < 	$,q/"7"7"9"99D3t}--..  4=+113333a(#'<#3DLE 4 , 	" 	"Bb)))a b)))b!!	" 	"r7   NF)r>   r?   r@   rV   r   r   r   r   rZ   r   r[   r\   r   r1   r7   r4   r   r   '  s        o
 o
 o
 o
b	 	 		 	 	  * * *   !h ++G" " " " "r7   r   c                 N   |                                  } |'| j                            dd          rt          j        }ddi}|||d<   | j                            |d          5  | j                            ddd            | j        |i |cddd           S # 1 swxY w Y   dS )	zhelper dedicated to ensure a commit respect mq.secret setting

    It should be used instead of repo.commit inside the mq source for operation
    creating new changeset.
    Nr&   r,   )   ui   allowemptycommitT)s   phasess
   new-commitr   r   )
unfilteredui
configboolr   secretconfigoverride	setconfigcommit)rI   phaseargskwargs	overridess        r4   	newcommitr     s     ??D}7eY// 	"ME-t4I05	,-				5	1	1 , ,%!4d;;;t{D+F++, , , , , , , , , , , , , , , , , ,s   $)BB!Bc                       e Zd ZdS )AbortNoCleanupN)r>   r?   r@   r1   r7   r4   r   r     s        Dr7   r   c                   t   e Zd Zd?dZej        d             Zej        d             Zej        d             Zej        d             Z	d Z
d@d	Zd
 Zd Zd Z ej        d          Zd Zd Zd Zd Zd Zd ZdAdZd Zd ZdAdZ	 	 	 	 	 dBdZd Zd?dZd Zd Z 	 	 	 	 	 	 	 	 dCdZ!	 	 	 	 	 	 	 	 dCdZ"dAd Z#d! Z$d" Z%d# Z&d$ Z'd% Z(dDd&Z)d'Z*d( Z+dAd)Z,d* Z-d+ Z.d, Z/d- Z0dAd.Z1	 	 	 	 	 	 	 	 	 dEd/Z2	 	 	 	 	 	 dFd0Z3d1 Z4d?d2Z5dAd3Z6d?d4Z7	 	 	 	 	 dGd6Z8d7 Z9dAd8Z:dHd9Z;d?d:Z<d; Z=dAd<Z>d= Z?	 	 	 	 	 dId>Z@dS )JqueueNc                    || _         	 t          t          j                            |d          d          5 }|                                                                }d d d            n# 1 swxY w Y   |s!t          j                            |d          }n#t          j                            |d|z             }n0# t          $ r# t          j                            |d          }Y nw xY w|p|| _        t          j	        | j                  | _
        || _        || _        d| _        d| _        g | _        d| _        d| _        d| _        d | _        d| _        |                    d	d
                                          }t/          j        |          }	|	|	rd}nd}|| _        |                    d	d          | _        d| _        d S )N   patches.queuerb   patches   patches-F   series   status   guardsr&   r'      yes   nor+   T)basepathr   ospathr   readr   IOErrorvfsmodr    openerr   baseuiapplieddirtyseriesdirtyadded
seriespath
statuspath
guardspathactiveguardsguardsdirtyconfigr   r"   	parseboolgitmoder   r   checkapplied)
r2   r   r   r   patchdirfhcurcurpathr   boolmodes
             r4   rV   zqueue.__init__  s   		5bgll4)9::DAA )Rggii&&(() ) ) ) ) ) ) ) ) ) ) ) ) ) )  @',,tZ88',,t[3->?? 	5 	5 	5gll444GGG	5'	j++! 
###  ))E6**0022'00   uh77 s5   .B< 'A*B< *A..B< 1A.2A	B< <*C)(C)c                       fd}	  j                              j                                                  }t	           ||                    S # t
          $ r g cY S w xY w)Nc              3   R  K   | D ]}|                     dd          }t          |          dk    r%|\  }}t          t          |          |          V  P|                                r<j                            t          d          t          j	        |          z             d S )NrX   rc   s   malformated mq status line: %s
)
r   rk   rQ   r   r   r   warnr   r"   pprint)rq   r   entrynrU   r2   s        r4   
parselinesz!queue.applied.<locals>.parselines  s       	 	a((u::>>#GAt%c!ffd333333WWYY GLL=>>$+E223  	 	r7   )r   r   r   
splitlineslistFileNotFoundError)r2   r   rq   s   `  r4   appliedzqueue.applied  s    
	 
	 
	 
	 
		K$$T_55@@BBE

5))***  	 	 	III	s   AA A A c                     	 | j                             | j                                                  S # t          $ r g cY S w xY wr0   )r   r   r   r   r  rY   s    r4   
fullserieszqueue.fullseries,  sO    	;##DO44??AAA  	 	 	III	s   03 AAc                 8    |                                   | j        S r0   )parseseriesseriesrY   s    r4   r  zqueue.series3  s    {r7   c                 8    |                                   | j        S r0   )r  seriesguardsrY   s    r4   r
  zqueue.seriesguards8  s      r7   c                     d                                 D ]}|| j        v rt          | |           d| _        d| _        d| _        d | _        d S )Nz&applied fullseries series seriesguardsF)r   __dict__r	   r   r   r   r   )r2   as     r4   
invalidatezqueue.invalidate=  sa    9??AA 	! 	!ADM!!a   !   r7   Fc                 :   t          j        | j        |d| |           }| j        dk    rd|_        nO| j        dk    rnC| j        dv r| j        dk    |_        n)t          j        t          d          | j        z            |r| 	                    ||          }|S )zReturn diff options tweaked for this mq use, possibly upgrading to
        git format, and possibly plain and without lossy options.T)git
whitespaceformatchangingr(      keep)r   r   r   s,   mq.git option can be auto/keep/yes/no got %s)
patchmoddifffeatureoptsr   r   upgrader  r   Abortr   	patchopts)r2   r<   patchfnplaindiffoptss        r4   r  zqueue.diffoptsF  s     +G y$9
 
 
 <7""#H\W$$\_,,<61HLL+ABB,    	9~~h88Hr7   c                     |                                 }|j        sX| j        dk    rM|D ]J}|                     |d          }t	          d |D                       |_        |                                 K|S )zReturn a copy of input diff options with git set to true if
        referenced patch is a git patch and should be preserved as such.
        r     rc              3   @   K   | ]}|                     d           V  dS )r   Nr   )r   rx   s     r4   r   z"queue.patchopts.<locals>.<genexpr>h  s?       # #7;DOOM22# # # # # #r7   )copyr  r   r   r   close)r2   r  patchesr  patchfs        r4   r  zqueue.patchopts_  s     ==??| 	 7 7"  Wd33" # #?E# # #     r7   c                 :    t          j        j        | j        g|R  S r0   )r   r   r   )r2   ps     r4   r   z
queue.joinn  s    w|DI*****r7   c                 d    fd}t          | j                  D ]\  }} ||          r|c S d S )Nc                 l    |                      dd          d         } |                                 k    S )N   #rc   r   )r   r   )r   r   s    r4   
matchpatchz$queue.findseries.<locals>.matchpatchr  s.    a  #A7799%%r7   )ro   r  )r2   r   r(  ri   r   s    `   r4   
findserieszqueue.findseriesq  s^    	& 	& 	& 	& 	& "$/22 	 	HE1z!}} tr7   s'   \s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)c                    g | _         g | _        | j        D ]}|                    d          }|dk    r|}d}n|dk    r)|d |         }||d          }|                                }|r|| j         v r>t          j        t          d          ||                     | j	                  fz            | j         
                    |           | j        
                    | j                            |                     d S )Nr'  r   r7   r   s   %s appears more than once in %s)r  r
  r  findr   r   r  r   r   r   rH   guard_refindall)r2   r   rz   r   comments        r4   r  zqueue.parseseries}  s    	I 	IAtABwwa"1"ABB%KKMME IDK''+<== $))DO"<"<=>   ""5)))!(()>)>w)G)GHHH%	I 	Ir7   c                     |st          d          S d}|d         }|dv rt          d          ||fz  S |D ]}||v rt          d          ||fz  c S d S )Ns   guard cannot be an empty strings   # 	
r      -+s*   guard %r starts with invalid character: %rs!   invalid character in guard %r: %rr   )r2   guard	bad_charsfirstr   s        r4   
checkguardzqueue.checkguard  s     	97888!	aE>>BCCG    	L 	LAEzz=>>%KKKK 	L 	Lr7   c                    |D ]-}|                      |          }|rt          j        |          .t          t	          |                    }| j                            dd                    |          z             || _        d| _	        d S )Ns   active guards: %s
    T)
r4  r   r  rC   setr   r5   r   r   r   )r2   guardsr1  bads       r4   	setactivezqueue.setactive  s     	' 	'E//%((C 'k#&&&'F$$,tyy/@/@@AAA"r7   c                    | j         g | _         	 | j                            | j                                                  }n# t
          $ r g }Y nw xY wt          |          D ]r\  }}|                     |          }|r<| j        	                    d| 
                    | j                  |dz   |fz             X| j                             |           s| j         S )Ns
   %s:%d: %s
rc   )r   r   r   r   r   r  ro   r4  r   r   r   rH   )r2   r8  rw   r1  r9  s        r4   activezqueue.active  s    $ "D))$/::@@BB$   %f-- 4 45ooe,, 4GLL&99T_55q1ucBC   
 %,,U3333  s   1A AAc                    |D ]}t          |          dk     r$t          j        t          d          |z            |d         dvr$t          j        t          d          |z            |                     |dd                    }|rt          j        |          | j                            d| j        |                   }|d                    d |D                       z   | j        |<   | 	                                 d	| _
        d S )
Nrd   s   guard %r too shortr   r0  s!   guard %r starts with invalid charrc   r7   c                     g | ]}d |z   S s    #r1   r   gs     r4   
<listcomp>z#queue.setguards.<locals>.<listcomp>  s    /J/J/Ja	/J/J/Jr7   T)rk   r   r  r   r4  r,  rE   r  r   r  r   )r2   idxr8  rA  r9  drops         r4   	setguardszqueue.setguards  s    	' 	'A1vvzzk!$9":":Q">???t5  k!$H"I"IA"MNNN//!ABB%((C 'k#&&&'}  doc&:;;#chh/J/J6/J/J/J&K&KKr7   c                    t          |t                    r| j                            |          }| j        |         }|sdS |                                 fd|D             }|rdt          j        |d                   fS d |D             }fd|D             }|r?|rdt          j        |d                   fS dd                    d	 |D                       fS d
S )N)TNc                 V    g | ]%}|                     d           r|dd         v #|&S )   -rc   Nr   r   rA  r8  s     r4   rB  z"queue.pushable.<locals>.<listcomp>  sA     
 
 
all4&8&8
=>qrrUf__A___r7   Fr   c                 <    g | ]}|                     d           |S )   +r   r@  s     r4   rB  z"queue.pushable.<locals>.<listcomp>  s)    <<<Qd););<q<<<r7   c                 ,    g | ]}|d d         v |S rc   Nr1   rI  s     r4   rB  z"queue.pushable.<locals>.<listcomp>  s&    666!aevooAooor7   Tr6  c                 6    g | ]}t          j        |          S r1   )r"   r   r   r$  s     r4   rB  z"queue.pushable.<locals>.<listcomp>  s#    $G$G$GaZ%6q%9%9$G$G$Gr7   )Tr7   )	
isinstancebytesr  ri   r
  r<  r"   r   r   )r2   rC  patchguardsexactnegposexactposr8  s         @r4   pushablezqueue.pushable  s   c5!! 	)+##C((C', 	:
 
 
 
"
 
 
  	9*+HQK8888<<+<<<6666s666 	I <Z.x{;;;;$))$G$G3$G$G$GHHHHyr7   c                    |r| j         j        }n| j         j        }|s| j         j        rt	          |t
                    r| j                            |          }|                     |          \  }}|r||rz|' |t          d          | j        |         z             nQ|s' |t          d          | j        |         z             n( |t          d          | j        |         |fz             |sV|r* |t          d          | j        |         |fz             d S  |t          d          | j        |         z             d S d S d S )Ns"   allowing %s - no guards in effect
s*   allowing %s - no matching negative guards
s   allowing %s - guarded by %s
s   skipping %s - guarded by %s
s!   skipping %s - no matching guards
)
r   writer   verboserP  rQ  r  ri   rV  r   )r2   rC  all_patchesrX  rV  whys         r4   explainpushablezqueue.explainpushable  s    	!GMEEGLE 	$'/ 	#u%% -k'',, MM#..MHc x ;E@AA+c*+   
  	LMM"k#./   
 >??#{3/56    
 	E:;;;s+S12    
 E?@@+c*+    9	 	*
 
r7   c                      fd} j         r0 |t          t           j                   j                   d _          j        r | j         j                   d _         j        r | j	         j
                   d _         j        rK                                 r,d                              fd j        D                        g  _        d S d S )Nc                                          |d          }| D ]}|                    d|z             |                                 d S )Ns   wb   %s
)r   rX  r   )itemsr   fprw   r2   s       r4   	writelistz"queue.savedirty.<locals>.writelist  sO    T5))B & &1%%%%HHJJJJJr7   Fc              3   0   K   | ]}|d          v|V  d S r0   r1   )r   fqrepos     r4   r   z"queue.savedirty.<locals>.<genexpr>  s1      NNa%+9M9M9M9M9M9MNNr7   )r   maprQ  r  r   r   r  r   r   r   r   r   re  add)r2   rb  re  s   ` @r4   	savedirtyzqueue.savedirty  s   	 	 	 	 	  	&Ic%..@@@ %D 	%Idot777$D 	%Id'999$D: 	JJLLE OdNNNN4:NNNNNNDJJJ		 	r7   c                 D   |                     d          }t          j                            |          sd S 	 t          j        |           d S # t
          $ rG}| j                            t          d          t          j
        |          z             Y d }~d S d }~ww xY w)Ns   undos   error removing undo: %s
)sjoinr   r   existsunlinkOSErrorr   r   r   r"   forcebytestr)r2   rI   undoinsts       r4   
removeundozqueue.removeundo  s    zz'""w~~d## 	F	IdOOOOO 	 	 	GLL.//*2I$2O2OO        	s   A 
B<BBc                    t          |          D ]}|                    |          }t          j                            |          rt          j        | j        ||          }| j                            t          d          |t          j        
                    |          fz             |rt          j        ||           t          j        ||           d S )Ns#   saving current version of %s as %s
)rC   wjoinr   r   lexistsr   
backuppathr   noter   relpathr   copyfilerename)r2   rI   filesr  rd  absfabsorigs          r4   backupzqueue.backup(  s     	/ 	/A::a==Dwt$$ 
/!,TWdA>>=>>"'//'2234  
  /M$0000Kg...	/ 	/r7   c	                     |i }|                     d          }	t          j        ||         ||          }
t          j        | j        ||||         ||         |
||	|	  	         d S )Ns   stat)r   r   matchr   diffordiffstatr   )r2   rI   r  node1node2rz  ra  changesr<   statms              r4   	printdiffzqueue.printdiff8  sz     <Dxx  M$u+ud33!GKK
	
 
	
 
	
 
	
 
	
r7   c                 x   |                      ||gdd|          \  }}|dk    r||fS |$t          j        t          d          |z            | j                            t          d          |z             t          j        ||           t          | j        ||gdd           ||         }	t          j	        |	d          }
|
r$t          j        t          d	          |
z            t          |d |	                                |	                                d
          }|!t          j        t          d                    	 t          |                    |          | j                  }n2# t           $ r% t          j        t          d          |z            w xY w|                     ||          }|                     |d          }t'          |          }|r|                    |           |                     |||||           |                                 |                     |           d|fS )NFT)update_statusstrictmerger   s   apply failed for patch %ss"   patch didn't work out, merging %s
updater}  )reminds   update returned %dforce   repo commit faileds   unable to read %s   w)ra  )applyr   r  r   r   r   r   cleanr   r  r   descriptionr   r   r   r   	Exceptionr  r   rQ  rX  r  r   rq  )r2   rI   mergeqheadr   revr  errr   ctxretphr"  r   s                 r4   mergeonezqueue.mergeoneS  s.   ::5't3  
 
a !888O9+a <==EFFFQ=>>FGGG 	tdgtaSu====3ihs5))) 	>+a 566<===dD#//"3"3SXXZZtLLL9+a 566777	?V[[//@@BB 	? 	? 	?+a 455=>>>	? >>(E22UD))99 	#LL"""tXtQ6:::1vs   (E1 1/F c                    |D|j                                         \  }}||j        k    r|S | j        sdS | j        d         j        S |j                            |          \  }}||j        k    r|d | j        D             v r|S |S )a  return the mq handled parent or p1

        In some case where mq get himself in being the parent of a merge the
        appropriate parent may be p2.
        (eg: an in progress merge started with mq disabled)

        If no parent are managed by mq, p1 is returned.
        Nr   c                     g | ]	}|j         
S r1   rT   r   xs     r4   rB  z"queue.qparents.<locals>.<listcomp>  s    'E'E'E1'E'E'Er7   )dirstateparentsnullidr  rT   	changelog)r2   rI   r  rB   p2s        r4   qparentszqueue.qparents{  s     ;},,..HRT[  	< t<#(('',,B'E'E'E'E'E!E!EI	r7   c           	      ^   | j         sYd}t          |d dd          }|                     |           | j                             t	          ||                     d| _        |                     |          }|D ]}|                    |d          }|s-| j        	                    t          d          |z              dS |                     |          \  }	}
|	s|                     |d           {|                    |          }|s-| j        	                    t          d	          |z              dS |d
         }|                     ||||||          \  }}|r/| j                             t	          ||                     d| _        |r||fc S |                                  d|fS )Ns   .hg.patches.merge.markers   [mq]: merge markerTr  r  s   patch %s does not exist
rM  rZ  s   patch %s is not applied
rc   r   )r  r   rq  rH   rQ   r   r  lookupr   r   r   rV  r\  	isappliedr  rh  )r2   rI   r  r  r  pnamer   r  r   rV  reasoninfor  r  s                 r4   
mergepatchzqueue.mergepatch  s   | 	% 0E$&;4HHHAOOD!!!LAu 5 5666 $D}}T"" 	# 	#EMM%M55E !Q;<<uDEEE yy#}}U33Hf $$U$===##E**D !Q;<<uDEEE yyq'CdFD%hOOIC )##Ke$<$<===$(! #T{"""#4yr7   c                    t                      }	 t          j        | j        ||d|d          }dt	          |          |fS # t
          $ r}| j                            t          j        |          dz              | j        j	        s'| j        
                    t          d                     | j                                         dt	          |          dfcY d}~S d}~ww xY w)zPApply patchfile  to the working directory.
        patchfile: name of patch filerc   N)r   rz  eolmodeTr   s*   patch failed, unable to continue (try -v)
F)r7  r  r   r   r  r  rv  r"   rn  rY  r   r   	traceback)r2   rI   	patchfilerz  fuzzrp  s         r4   r   zqueue.patch  s     
	/>y  D $u++t,, 	/ 	/ 	/GLL066>???7? PQMNNOOOG4;;.......	/s   0A 
C"BCC"C"Tc                    d x}x}}	 |                                 }|                                }|                    d          }	 |                     |||||||||	|

  
        }|                                 |                                  |t          |||           |                     |           S # t          $ r* |                                 |                                    	 |	                                 | 
                                 n# | 
                                 w xY w xY w# t          |||           |                     |           w xY w)N   qpush	all_filestobackupkeepchanges)wlockr   transaction_applyr   rh  releaserq  r   abortr  )r2   rI   r  r  r  r  r   r  r  r  r  r  r   trr  s                  r4   r  zqueue.apply  sq    !  r 	"JJLLE99;;D!!(++Bkk!'% + "   


    Be$$$OOD!!!! "   


   &HHJJJOO%%%%DOO%%%%Be$$$OOD!!!!s6   =D0 AB5 54D-*D>D-D))D--D0 0(Ec           
      J   |s| j         }d}d}|D ]}|                     |          \  }}|s|                     |d           5| j                            t          d          |z             t          j                             ||          }	 t          |                     |          | j	                  }n># t          $ r1 | j                            t          d          |z             d}Y  n.w xY w|j        }|sd|z  }n/|r|                    d	|z             d
                    |          }|j        r|	ryt          j        | j        ||          }t#          |          |	z  }|r-|
r+t%          t          d          t          d                    |                     ||d           |	|z
  }	|                     ||          \  }}}||                    |           | }n0| j                            t          d          |z             dg d}}}|r|r|j                                        5  |D ]}|j                            |d           |j                                        }|                    ||           ddd           n# 1 swxY w Y   |rEd|v rA|d         }|d         }d}t7          j        |||||          }||                                z  }t=          j        ||pg           }|j         !                                }tE          |d||j#        |j$        |d          }|j         !                                |k    r!tK          j&        t          d                    |!tK          j&        t          d                    |r(| j'                            tQ          ||                     |r+| j                            t          d                     d} n1|r-|r+| j                            t          d                     d} n||fS )zreturns (error, hash)

        error = 1 for unable to read, 2 for patch failed, 3 for patch
        fuzz. tobackup is None or a set of files to backup before they
        are modified by a patch.
        r   NTr  s   applying %s
s   unable to read %s
rc   s   imported patch %s
s   
imported patch %sr   s   conflicting local changes founds   did you forget to qrefresh?hint)r  s   patch %s is empty

p1_tracked   .hgsubstate   .F)r  r  s(   qpush exactly duplicates child changesets   repository commit faileds0   patch failed, rejects left in working directory
rd   s)   fuzz found when applying patch, stopping
   ))r   rV  r\  r   statusr   r   r   r   r   r   r   r   rH   r   r  changedfilesr7  r   r}  r   r  r  parentchangeupdate_file_p1rB   
setparentsr   submergekeysr   
matchfilesr  tipr   r   r   r   r  r  rQ   )r2   rI   r  r  r  r  r   r  r  r  r  r  r   	patchnamerV  r  r   r  r   touchedpatcherrrz  r  rd  rB   rL   pctx	overwritemergedsubstater  oldtips                                  r4   r  zqueue._apply  s   (  	!yH V	 V	I#}}Y77Hf $$YD$AAAGNN1-..:;;;h	22B 9!5!5t~FF   Q566BCCC
 jG .09< GNN#9I#EFFF**W--{ 1 	2&3DGT2FFG!'llX5G ; ,@AA!"#A!B!B    KKgDK999''1H*.**T2*>*>'5$($$U+++'<Q566BCCC()2q% / /]//11 / /" I I44Q44HHHH))++BOOB...	/ / / / / / / / / / / / / / /  /^y88DzDz!	!,!5$dI" " ,,...&tU[b99E^''))FdGRWbgU$  A ~!!##v--kABB   yk!$?"@"@AAA ?##K9$=$=>>> JKK     QLMMNNNQxs%   (B996C43C49AJJ	J	c                    |sn|                                  }|r|d                              |           |D ]:}	 t          j        |                     |                     +# t
          $ r Y 7w xY wg }|r | j        d |         }| j        d |= d| _        g }g }|D ]H}|                     |          }	|	|	                    d|f           1|	                    |	|f           I|
                    d           |D ])\  }
}|
dk    r	| j        |
= |	                    |           *|r|rSd |D             }|D ]C}t          d          | j                            t          ||                   |fz             DnBt          d          t!          j        d                    fd|D                                 |                                  d| _        d	 |D             S )
NTr   reversec                 (    i | ]}|j         |j        S r1   )rU   rT   r   r   s     r4   
<dictcomp>z"queue._cleanup.<locals>.<dictcomp>  s    EEE%uz5:EEEr7   s*   revision %s refers to unknown patches: %s
s   unknown patches: %s
r7   c              3   "   K   | ]	}|z  V  
d S r0   r1   )r   r$  r3   s     r4   r   z!queue._cleanup.<locals>.<genexpr>  s'      *D*Dq37*D*D*D*D*D*Dr7   c                     g | ]	}|j         
S r1   r  r  s     r4   rB  z"queue._cleanup.<locals>.<listcomp>  s    222u
222r7   )re  forgetr   rl  r   r  r  r   r)  rH   sortr  r   r   r   r   r   r  r  r   )r2   r!  numrevskeeprr$  	qfinishedunknownsortedseriesrC  rw   r  r3   s               @r4   _cleanupzqueue._cleanuph  sW    	

A ($w'''  Idiill++++(   D 	 	%XgX.IXgX& $D 	. 	.A//!$$C{##RG,,,,##S!H----$'''" 	" 	"FQBwwOA&&q!!!! 	F FEE9EEE  ; ;AJKKCGLLc!fq'9!9::::; 011k#((*D*D*D*DG*D*D*D"D"DEEE22	2222s   'A""
A/.A/c                 v   || j         d         j                                                 }g }t          |          D ]\  }}||k     r$t	          j        t          d          |z            ||         }| j         |         j        }|                                |k    r&t          d          }	t	          j        |	|z            | j         |         j        }
dD ]K}|                                ||
z  k    r.t          d          }	|j	        
                    |	|
z              nL|                    |
           |S )Nr   s   revision %d is not manageds/   cannot delete revision %d above applied patches)   [mq]: %ss   imported patch %ss-   patch %s finalized without changeset message
)r  rT   r  ro   r   r  r   rU   r  r   r  rH   )r2   rI   revsfirstrevr!  rw   r  r  baser3   r   fmts               r4   _revpatcheszqueue._revpatches  s4   Q,-1133oo 	" 	"FAsX~~k!$A"B"BS"HIIIs)C<?'DxxzzT!!JKKk#),,,LO(E:  ??$$e33MNNCGNN3;///E 4
 NN5!!!!r7   c                 F   |j          |                     |t          |                    }|                     |t	          |                    }|r|j                            dd          r||d                  }t          j        |j                  }|	                                |k    ru|
                                	                                |k    rM|                    d          5 }t          j        ||||           d d d            d S # 1 swxY w Y   d S d S d S d S d S )Nr&   r,   r      qfinish)_phasecacher  rC   r  rk   r   r   r   newcommitphaser   rB   r  advanceboundary)r2   rI   r  r!  r  oldqbasetphaser  s           r4   finishzqueue.finish  s|    	""466MM'3w<<88	 	H++E9== 	HIaL)H*4733F~~&((X[[]]-@-@-B-Bf-L-L%%j11 HR*4VYGGGH H H H H H H H H H H H H H H H H H	H 	H 	H 	H )(-L-Ls   )DDDc                 R   |s6|                     d          s!t          j        t          d                    g }|D ]}|                     |d          }|                     |          }|r$t          j        t          d          |z            || j        vr$t          j        t          d          |z            ||vr|                    |           d}|                     d          r| j        s!t          j        t          d                    t          j
        ||                     d                    }|                                 |                     ||          }	||	z  }t          |	          }|                     |||                     d	                     d S )
N   revs4   qdelete requires at least one revision or patch nameTr  s   cannot delete applied patch %ss   patch %s not in series filer      no patches appliedr  )r   r   r  r   r  r  r  rH   r  r   revranger  r  rk   r  )
r2   rI   r!  r<   realpatchesr   r  r  r  
revpatchess
             r4   deletezqueue.delete  s    	txx// 	+IJJ    	* 	*EKKdK33E>>%((D Pk!$E"F"F"NOOODK''k!$B"C"Ce"KLLLK''""5)))88F 	&< <k!$9":":;;;&tTXXf-=-=>>DIIKKK))$55J:%K*ooGk7DHHW,=,=>>>>>r7   c                     | j         rf| j         d         j        }| j         d         j        }|j                                        |k    r!t          j        t          d                    ||fS dS )z'check that working directory is at qtipr   s&   working directory revision is not qtipNN)r  rT   rU   r  rB   r   r  r   )r2   rI   topr   s       r4   checktoppatchzqueue.checktoppatch  sk    < 	,r"'CL$)E}!!S((k!$M"N"NOOO:zr7   c                 x   t          |t                    r|d d         }n|j        |j        |j        f}t          d |D                       rd S |j        s|j        s|d                             d           d S |j        r|d                             d           d S |d                             d           d S )Nr  c              3      K   | ]}d |v V  	dS )r  Nr1   )r   rz  s     r4   r   z,queue.putsubstate2changes.<locals>.<genexpr>  s'      99E%'999999r7   rc   r  rd   r   )rP  r  modifiedr   removedr   any_trackedrH   )r2   substatestater  mars       r4   putsubstate2changeszqueue.putsubstate2changes  s    gt$$ 	E"1"+CC#W]GODC99S999:: 	F 	*m&? 	*FMM.)))))" 	*FMM.)))))FMM.)))))r7   c                    d}|r d}t          d           t          d           |                                }|st          j        |           |j        s|j        s|j        s|j        r3t          d           t          j	        t          d|z                       t          |          r3t          d           t          j	        t          d|z                       nt          j        |d           |S )	Nr7   s   , qrefresh first#   local changes found, qrefresh firsts,   local changed subrepos found, qrefresh firsts   local changes founds   local changed subrepos foundT)	skipmerge)r   r  r   checkunfinishedr  r   r	  deletedr   r  rO   )r2   rI   r  refresh	excsuffixrN   s         r4   checklocalchangeszqueue.checklocalchanges  s   	 	?+I4555=>>>KKMM 	:#D)))z IQW I	 IQY I()))k!$:Y$F"G"GHHHT"" 1222k5	ABB   #DD9999r7   )r   r   r   r  s   ..c                    || j         v r$t          j        t          d          |z            ||                                k    r!t          j        t          d                    dD ];}|                    |          r$t          j        t          d          |z            <dD ]<}||v r6t          j        t          d          t          j        |          z            =d S )Ns*   "%s" cannot be used as the name of a patchs.   patch name cannot begin or end with whitespace)   .hgs   .mqs!   patch name cannot begin with "%s")r'  rX      r   s(   %r cannot be used in the name of a patch)	_reservedr   r  r   r   rm   r   bytestr)r2   rU   prefixr   s       r4   checkreservednamezqueue.checkreservedname  s   4>!!+?@@4G   4::<<+CDD   ' 	 	Fv&& k:;;fD   , 	 	ADyykABB&q))*   	 	r7   c                    |                      |           |st          j                            |                     |                    r|t          j                            |                     |                    r$t          j        t          d          |z            t          j        t          d          |z            d S d S )Ns"   "%s" already exists as a directorys   patch "%s" already exists)	r  r   r   rk  r   isdirr   r  r   )r2   rU   r  s      r4   checkpatchnamezqueue.checkpatchname#  s    t$$$ 	J		$88 	Jw}}TYYt__-- Jk;<<tC   k!$@"A"AD"HIII	J 	J 	J 	Jr7   c                    t          j        dd|                                                              d          }|dd         }|r.	 |                     |           n# t
          j        $ r |}Y nw xY w|}|}d}	 || j        vr,	 |                     |           n"# t
          j        $ r Y nw xY w|dz  }d||fz  }B|S )	zdReturn a suitable filename for title, adding a suffix to make
        it unique in the existing lists   [\s\W_]+   _NK   r   Trc   s   %s__%d)	rerE   r   r   r  r   r  r  r  )r2   titlefallbacknamenamebaserU   rw   s         r4   makepatchnamezqueue.makepatchname-  s    6,ekkmm<<BB4HHCRC= 	$(&&x0000; ( ( ('( $H	-4?**''---{   DFA!},D	- s$   	A A32A3B B/.B/c                 T    |r#|r#t          j        t          d                    d S d S )Ns*   cannot use both --force and --keep-changes)r   r  r   )r2   r  r  s      r4   checkkeepchangeszqueue.checkkeepchangesF  sD     	P[ 	P+a MNNOOO	P 	P 	P 	Pr7   c                     t          j        |          }|                    d          }|                    d          }|                    dd          }|                    d          }|                    d          }	|	rt          j        |	          }	|                     d|                    d          id	          }
|                    d
d          r|                     |           t          |          }|r|j        	                    d          }|                    d          s|                    d          s|r8d }t          j        |d         |||          }|                    |          }n|                     |d          }t          |          }|                    |j                   |                    |j                   |                    |j                   t          j        ||          }t)          |d                                                   dk    r!t-          j        t1          d                    |                     |           |                                 }|                                5  	 |                     |d          }nO# t:          $ rB}t-          j        t1          d          |t=          j        |j                   fz            d}~ww xY w	 d|z   tC          j"        |          }|r. fd}t1          d          }tC          j"        |||          }|}n|p }tG          |d|||	|d|          }|!t-          j        t1          d                    	 |g| j$        ||<   | j%        &                    tO          ||                     | (                                 d| _)        d| _*        ||         }tW          | ,                    |          | j-                  }|r|.                    |           |	r|/                    d|	z             |0                    tc          |2                                3                                                     |4                                5                                }| 5                                k    rd}|6                    |           |7                    tq          |                     |ra| 9                    ||          }|r| :                    ||           tw          j<        |||||
           }|D ]}|7                    |           |=                                 | >                                }|r|d         ?                    |g           n#  |@                                  xY wnt# t          $ rg | ,                    |          }	 t          jC        |           n:# t          $ r- | jE        F                    t1          d!          |z             Y nw xY w w xY w| G                    |           ddd           dS # 1 swxY w Y   dS )"zToptions:
        msg: a string or a no-argument function returning a string
           msg   edit   editforms   mq.qnew   userre   r'   Tr  s	   checknamer  s   includes   excludec                 D    | dk    rt          j        d| |fz            d S )Nr  r}   )r   r  )rd  r3   s     r4   badfnzqueue.new.<locals>.badfn^  s.    &&+i1c(&:;;; '&r7   N)r1  r  r  rc   s   cannot manage merge changesetsr  s   cannot write patch "%s": %sr  editformc                 4    |                                  r| S S r0   )r   )desc
defaultmsgs    r4   
finishdesczqueue.new.<locals>.finishdesc}  s    ;;== .#'K#--r7   +   Leave message empty to use default message.r8  extramsgr4  r  r  editorr     %d %dr7   )r  r  r  r<   s   error unlinking %s
)Hr   byteskwargsr   r!   	parsedater  r  rO   r  	get_entryr   r  r  r  r  extendr  r   r	  r  rk   r  r   r  r   r  fullseriesendr  r   r   r   
strtolocalstrerrorr   getcommiteditorr   r  r  rH   rQ   r  r   r   r   r   r   r   r   r   r   rB   rT   r  r   r   rX  rQ  r  r  r  diffr   re  rg  rollbackr  r   rl  rm  r   r   rq  )!r2   rI   r  patsr<   r3   editr4  r   r   r  rK   r  r1  r  r  commitfilesrp   r$  er=  r8  r;  	commitmsgr   nctxr  r   chunkschunkr  	patchpathr7  s!                                   @r4   newz	queue.newJ  s    #D))hhvxx  88K44xx  xx   	,%d++D==&$((6*:*:!;4=HH88L$'' 	)((( && 	D M33NCCM88J 		?488J#7#7 		?4 		?< < < M$t*dDFFFEkkk..GG,,T,>>G8nn7+,,,7=)))7?+++"455tDz!!##$$q((+a ABBCCC4   ##%%ZZ\\ X	" X	"KK..   k455 3AJ ? ?@A  
N(72
 0(CCC 2. . . . .  !!OPPH$4#-!)!)  F
 !$II # 1zI!	 	 	 9+a(=&>&>???%6=YDOF6M2L''Aw(?(?@@@$$&&&'+D$(,D%7D$TYYw%7%7HHB )

4((( 4

8d?333LLTWWYY^^%5%5!6!6777**,,2244Cj..0000!MM#&&&GGE"II&&&" +!%tQ!7!7# M 44]GLLL!) "("#$+!)" " " &, + +EGGENNNNGGIII

A /$WI...MMOOO    IIg..	IIi(((( I I IGLL#:!;!;i!GHHHHHI OOD!!!qX	" X	" X	" X	" X	" X	" X	" X	" X	" X	" X	" X	" X	" X	" X	" X	" X	" X	"s   YJ'&Y'
K31=K..K33Y7BV: HVV:V66V:9Y:X+W/.X+/4X&#X+%X&&X++YYYc                 r    t          | j                  D ]!\  }}|j        |k    r||j        |j        fc S "dS )zreturns (index, rev, patch)N)ro   r  rU   rT   )r2   r   rw   r  s       r4   r  zqueue.isapplied  sK    dl++ 	+ 	+DAqv1616**** tr7   c                 N     fd}| j         v r|S t          j                                                 |                    s	 t          |          }t           j                    |cxk    rt           j                   k     rn n% j         |         S n# t          t          f$ r Y nw xY w|sQ ||          }|r|S |	                    d          }|dk    r} ||d |                   }|rh j         
                    |          }	 t          ||dz   d          pd          }||z
  dk    r j         ||z
           S n# t          t          f$ r Y nw xY w|	                    d          }	|	dk    r ||d |	                   }|rz j         
                    |          }	 t          ||	dz   d          pd          }||z   t           j                   k     r j         ||z            S n# t          t          f$ r Y nw xY wt          j        t          d          |z            )Nc                      j         v r S  fdj         D             }t          |          dk    rNj                            t	          d           z             |D ]}j                            d|z              d S |r|d         S j         rCj        r< dk    r#j                             d          dz
           S  dk    rj         d         S d S )	Nc                     g | ]}|v |	S r1   r1   )r   r  rN   s     r4   rB  z5queue.lookup.<locals>.partialname.<locals>.<listcomp>  s    888Qaqr7   rc   s   patch name "%s" is ambiguous:
s     %s
r      qtipT   qbase)r  rk   r   r   r   r  	seriesend)rN   matchesr  r2   s   `  r4   partialnamez!queue.lookup.<locals>.partialname  s    DK8888$+888G7||aQABBQFGGG  0 0AGLLQ////t "qz!{ *t| *<<;t~~d';';a'?@@==;q>)4r7   rH  r   rc   rK  s   patch %s not in series)r  r   r   isfiler   intrk   r   OverflowErrorrfindri   r   r  r   )
r2   r   r  r[  snoresminusrw   offpluss
   `         r4   r  zqueue.lookup  s   	 	 	 	 	$ DKLw~~dii..// $	<,%jj $$$>>>>c$+.>.>>>>>>;s++ ? .     <!k%(( JD))A::%+eFUFm44C < K--c22<"%eEAIKK&8&=A">">C  !3w!||'+{1s7'; ;  , !+M: ! ! ! D!
 {{4((199%+eETEl33C < K--c22<"%eD1HJJ&7&<1"="=C  !3wT[)9)999'+{1s7'; ;  : !+M: ! ! ! D!
 k!566>???s6   B B,+B,E EE$G, ,H ?H c           	         |                      |
|           |                                 }|                                5  g }|                                                                D ]}|                    |           |s|j        g}|j                                        |vr)|s'| j	        
                    t          d                     | j        s5| j	                            t          d                     	 d d d            dS |rR|                     |          }|                     |          }|rY|d         t!          | j                  dz
  k    r8| j	                            t          d          |z             	 d d d            dS |                     |          \  }}|rU| j                            |          |                                 k     r$t+          j        t          d          |z            n|rt          d          |z  }nt          d          }| j	                            t          d	          ||fz             	 d d d            dS |rW| j        d
         }|                     |          r5| j	                            t          d                     	 d d d            dS |                                 }|t!          | j                  k    r5| j	                            t          d                     	 d d d            dS |s|
s|                     || j                   |r|
r!t+          j        t          d                    |r!t+          j        t          d                    | j        r!t+          j        t          d                    | j        |         }t1          |                     |          | j                  j        }|s$t+          j        t          d          |z            ||         |d         k    st9          j        ||           |r"|s!t+          j        t          d                    t=          | j                  D ]7\  }}| j         !                    |d          d         | j        |         k    r n8t=          | j        |d                    D ],\  }}| j         !                    |d          d         |k    r n-||z   }|t!          | j                  k     sJ | j        |         }| j        |= | j        "                    ||           | #                                 d| _$        d| _%        |dk    r| &                    |           |s| j        |         }|dz   }n| j                            ||          dz   }tO                      }|	s|s|
rn|                     |d          }|
r3|                    |j(        |j)        z   |j*        z   |j+        z              n"|                    |j(        |j)        z              | j        ||         }tO                      }	 |r| ,                    ||||          }n| -                    ||||||
          }n# t\          $ r   | j	                            t          d                     t_          j0        | j	        ||d         d           |D ]'}||j        vr|j1        2                    |d           (| j	                            t          d                      xY w| j        s|d         cd d d            S | j        d
         j3        } |d         r9|d         dk    r-t          d          }!| j	        4                    |!| z             n*| j	        4                    t          d          | z             |d         cd d d            S # 1 swxY w Y   d S )Ns"   (working directory not at a head)
s   no patches in series
r   rc   s    qpush: %s is already at the top
s#   cannot push to a previous patch: %ss   guarded by %ss   no matching guardss   cannot push '%s' - %s
r   s"   all patches are currently applied
s#   patch series already fully applied
)r  s.   cannot use --exact and --keep-changes togethers&   cannot use --exact and --move togethers(   cannot push --exact with applied patchess"   %s does not have a parent recordedr  s    please specify the patch to moveTr  r  s!   cleaning up working directory...
)	no_backupignoremissings   done
s0   errors during apply, please fix and qrefresh %s
   now at: %s
)5r)  r  r  	branchmap	iterheadsrB  r  r  rB   r   r  r   r  r   r  r  rk   r  rV  ri   rY  r   r  r  r   r   r   r   r   r  ro   r  r,  r   rp   r  r   r   r  r7  r  r   r	  r  r  r  r   r   revertwvfs
unlinkpathrU   rX  )"r2   rI   r   r  r  r  allmoveexactnobackupr  r  headshsr  rV  r  rt   roottarget	fullstartrpnrw   ri   	fullpatchendr  r  rN   r  r  rd  r  r3   s"                                     r4   pushz
queue.push  s	    	k5111==??ZZ\\ b	 b	Enn&&0022 ! !R     &}!!..u.q!GHHIII; Q899:::b	 b	 b	 b	 b	 b	 b	 b	"  E**~~e,, DGs4<'8'81'<<<GLL>??%G   1b	 b	 b	 b	 b	 b	 b	 b	4 $(==#7#7 & {((//$..2B2BBB#kDEEM   C
  :!"#3!4!4v!=!"#8!9!9GLL455G   Qb	 b	 b	 b	 b	 b	 b	 b	R  B>>%(( GLL#I!J!JKKK[b	 b	 b	 b	 b	 b	 b	 b	h NN$$EDK((((QFGGHHHob	 b	 b	 b	 b	 b	 b	 b	p  C C&&tT\&BBB , +KLL    +CDD   < +EFF   {5)$TYYt__dnEEL +?@@4G   F|tDz11IdF+++ ( N+a(K&L&LMMM&/&@&@  NIs}**32215U9KKK L'	

(CDD  FAs}**32215>> ?!As4?333333 OE2	OE*&&y)<<<  """#'  $Dqyy""4((( :E*aik''u559uuH 
D 
D; 
D//D/AA DOO ,' .) !.)    OOFOfl$BCCCE#I&AI 
//$8DDCC**"+!)$/ %  C "   QDEEFFFGJ"	    # D DA--	,,Qd,CCCQy\\***< 1vwb	 b	 b	 b	 b	 b	 b	 b	x ,r"'C1v 8#a&1**LMMcCi((((a0036777q6Eb	 b	 b	 b	 b	 b	 b	 b	 b	 b	 b	 b	 b	 b	 b	 b	 b	 b	sU   B>_
A;_C _A_8A_L0_
6Z _B(\))_B___c           	      F   |                      ||           |                                5  |rg|                     |          }|s|                     |          }|                     |          }|s$t	          j        t          d          |z            | j        s6| j        	                    t          d                     | cd d d            S |rd}	n%|r|d         dz   }	nt          | j                  dz
  }	|	t          | j                  k    r8| j        	                    t          d          |z             	 d d d            d S |s]|j                                        d | j        D             }
D ]/}||
v r)| j        	                    t          d                     d}0nLd	 |d                                          D             t          fd
| j        |	d          D                       }t                      }|rt|                     ||p|          }|r%|s"|                    |j        |j        z              n4|r2|                    |j        |j        z   |j        z   |j        z              d| _        t          | j                  }| j        |	         j        }	 |j                            |          }nF# t          j        $ r4 t5          |          }t	          j        t          d          |z            w xY w|| j        d         j        gk    r!t	          j        t          d                    || j        d         j                                                 s0t	          j        t          d          t          d                    |r|                     ||          }||         }|                    |d          }|j        |j        |j        |j        f\  }}}}|r!t	          j        t          d                    t          ||z   |z             |z  }|r#|r!t	          j        t          d                    |                     ||           |j                                        5  |D ];}|j         !                    |d           |j        "                    |dd           <||z   D ]b}||         }|#                    ||$                                |%                                           |j        "                    |dd           c|&                    ||j'                   d d d            n# 1 swxY w Y   tQ          | j        |	|                   D ]1}| j                            t          d          |j)        z             2| j        |	|= tU          | j        ||gdd           |d         j+        ,                                D ]3\  }}|d         -                    |          .                    |           4| j        r;| j        /                    t          d          | j        d         j)        z             n'| j        /                    t          d                     d d d            d S # 1 swxY w Y   d S )Ns   patch %s is not applied   no patches applied
r   rc   s   qpop: %s is already at the top
c                     g | ]	}|j         
S r1   r  r  s     r4   rB  zqueue.pop.<locals>.<listcomp>  s    333af333r7   s   qpop: forcing dirstate update
Tc                 6    g | ]}|                                 S r1   r  rO  s     r4   rB  zqueue.pop.<locals>.<listcomp>  s     BBB16688BBBr7   c              3   *   K   | ]}|j         v V  d S r0   r  )r   r   r  s     r4   r   zqueue.pop.<locals>.<genexpr>  s;        .3EJ')     r7   r  s   trying to pop unknown node %sr   s?   popping would remove a revision not managed by this patch queues&   popping would remove a public revision    see 'hg help phases' for detailsr  r  s!   deletions found between repo revsr  rg  Fr  
wc_trackeds   popping %s
r  ri  s   patch queue now empty
)0r)  r  r  r  r   r  r   r  r   r   rk   r  r  r   r7  r  r  r  r   r	  r  r   rT   r  rs  LookupErrorr   mutabler  r  r}  r  rm  rn  update_filewwritedataflagsr  r  reversedrU   r   rD   r`  rE   r   rX  )r2   rI   r   r  r  ro  rr  r  r  rt   rrr$  r  rN   rz  r  rs  rT   qpr  str  r  r  drd  fctxstater  s                               @r4   popz	queue.pop  s    	k5111ZZ\\ n	= n	= M~~e,, / KK..E~~e,, M+a(B&C&Ce&KLLL<  Q677888wn	= n	= n	= n	= n	= n	= n	= n	=   . .Q!DL))A-DL))))QBCCeKLLL3n	= n	= n	= n	= n	= n	= n	= n	=6  -//1133dl333  & &ABwwQ'I%J%JKKK!%&
 CBT$Z-?-?-A-ABBB    7;|EFF7K     uuH **4u7K*LL # > 
QW(<===  OO
QW,qy819D   !%Ddl##C,u%*CN,,S11$ N N NSzzk!$D"E"E"LMMMN b).///k7    R(-.6688 k?@@>??     5]]4--2h[[T**["(BJ
J
1a O+a(L&M&MNNNq1uqy>>H4 Q8 Q+a(N&O&OPPPD(+++]//11 5 5  	,,Qd,CCC11%E 2     U  "1vAtyy{{DJJLLAAA11$4 2     OOB4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 "$,uSy"9:: @ @q11EJ>????U3Y'$'4#uUCCCC J/5577 - -5T
q!!%%e,,,,| =a004<3C3HHIIIIa :;;<<<]n	= n	= n	= n	= n	= n	= n	= n	= n	= n	= n	= n	= n	= n	= n	= n	= n	= n	=s`   BZA-ZEZ*KZALE:ZCUZU	ZU	D1ZZZc                 V   |                      |          \  }}|s)| j                            t          d                     d S |                     ||          }|                    d          rd |}}n|d }}|                     ||          }	|                     ||	||||           d S )Nr}  s   reverse)rz  r<   )r  r   rX  r   r  r   r  r  )
r2   rI   rI  r<   r  r   r  r  r  r  s
             r4   rG  z
queue.diffA  s    ''--
U 	GMM!344555F]]4%%88J 	$5EEt5E==u--tXue4dKKKKKr7   c           
      L  <=>? t          j        |          }| j        s)| j                            t          d                     dS |                    dd                                          }|                    d          }|                    dd          }|                    d          }|                    d	          }|rd
t          j	        |          z  }|
                                }		 |                     |           | j        d         j        | j        d         j        }}
|j                            |
          |
gk    r!t!          j        t          d                    ||
                                         s0t!          j        t          d          t          d                    |j                            |
          }|                     ||
          }t+          ||          }|r|j                            d          }t1          |                     |          | j                  ?|                     d|                    d          i|d          }|r?                    |           |r?                    |           ?                    t?          |                     |                      |dd          }|!                    ||
          }|j"        |j#        |j$        }}}||
         }|d d          }tK          j&        |d          ||          }|                    d          rMtK          j'        |||z   |z   |(                                z             }tK          j&        |d          |          }ntK          j)        |          }|!                    |          }|j"        |j#        |j$        |j*        f\  }}}}tW          |          }tW          |          }tW          |          }|D ]}||vr|,                    |           |D ]F}||v r+|-                    |           |,                    |           1|,                    |           Gg } ||z   D ][}||v r+|-                    |           | .                    |           1|/                    |           |,                    |           \ta          |          }ta          |          }ta          |          }|!                    ||          }|j"        |j#        |j$        |j*        f\  }!}"}#}$tW          |!|"z   |#z   |$z             <<fd|||fD             }%tW          |          }&|%D ]}|&1                    |           tK          j'        ||&          }||
         2                                }'|j        3                                5  d }(	 ti          j4        |d          }(|j5        s|j6        r1i })|D ]m}*|j        7                    |*          }+|+2|+|j        v r)|)8                    |+g           .                    |*           |j        9                    |*dd           n|D ]}*||*         :                                }+|+r\|)8                    |+g           ;                    |)                    |*g                      |*|v r|)|+         .                    |*           |*|)v r|)|*= |)<                                D ]%\  }+},|,D ]}*|j        =                    |+|*           &nf|D ]}*|j        9                    |*dd            ta          |j        >                                          D ]}-|j        =                    d |-           |D ]}-|j        ?                    |-d           g }t          t          |          dz
  dd          D ]1}. |||.                   s|.                    ||.                    ||.= 2|D ]}-|j        ?                    |-d           |D ]}-|j        ?                    |-d           | D ]}-|j        ?                    |-d           ?jB        p|B                                }/||
         C                                }0 |jD        |  | j        E                                 d| _F        t          | j        ||
gdd           |(H                                 t          |(           n# t          |(           w xY w	 d d d            n# 1 swxY w Y   	 d|z  =t          jK        |           }1|rI=?fd!}2t          d"          }3t          jK        |2|3|#          }1|pd$                    ?jL                  }4n>|s%?jL        s=}4n2d$                    ?jL                  }4n|}4?M                    |           d x}5}6	 |N                                }5|O                    d%          }6t          ||0|4|/?jQ        |d|1&          >d' |%D             }7|r| R                    ||7           t          jT        |||7|(          }8t          ?          }9|9r|                    |9           |8D ]}:|                    |:           |H                                 |jV        };|;W                    ||6>fd)|'D                        |6H                                 | j        .                    t          >|                     t          jI        |6|5           n# t          jI        |6|5           w xY wn#  ||d*                  }|j        Z                    |                                |[                                           | \                                 | j        ]                    t          d+                      xY w	 |	I                                 | ^                    |           d S # |	I                                 | ^                    |           w xY w),Nr}  rc   r+  r7   r,  r-  s   mq.qrefreshr.  re   r>  r   s(   cannot qrefresh a revision with childrens   cannot qrefresh public revisionr  r  r  r'   Tr/  r  )
atomictemp   shortr<   r2  c                 :    g | ]}|                               S r1   )intersection)r   r  
allmatchess     r4   rB  z!queue.refresh.<locals>.<listcomp>  s%    OOOQannZ88OOOr7   s
   mq.refreshFr  r  r  r  r3  c                 ^    |                                  r                    |            | S S r0   )r   r   )r6  r7  r  s    r4   r8  z!queue.refresh.<locals>.finishdesc  s0    ;;== (MM$///#'K))r7   r9  r:  r   r&   r<  c                 ,    g | ]}t          |          S r1   )r  r  s     r4   rB  z!queue.refresh.<locals>.<listcomp>:  s    999Qa999r7   )r  r<   c                     g | ]}|fS r1   r1   )r   bmr   s     r4   rB  z!queue.refresh.<locals>.<listcomp>H  s    1K1K1Kb2q'1K1K1Kr7   r   sN   qrefresh interrupted while patch was popped! (revert --all, qpush to recover)
)_r   r?  r  r   rX  r   r   r   r!   r@  r  r  rT   rU   r  rs  r   r  r  r  r  rO   r  rA  r   r   r   r  r   r   r   r   r   r  r  r   r	  r   r  r  rz  matchallr  r7  rg  removerH   discardr  r  	bookmarksr  r   r  r  copied
setdefaultr  
copysourcerB  r`  r  copiesr  rl   rk   r   r   r  r  r   r   r   r  r   rF  r   r   r   r  r   r   r  r  rG  rQ  
_bookmarksapplychangesrQ   lockmodrebuildmanifestrh  r   rq  )@r2   rI   rI  r<   r3   rJ  r4  newusernewdater  r  r  cparentspatchparentrK   r  r  r"  r  mmaaddr  aaamatch1r  stbr  r  r  r  r  r  cmcacrcdrefreshchangesrz  bmlistdsguardr  dstsrcdstsrd  rw   r   oldphaser=  r8  r;  r   r   r  r   rO  r   rP  marksr  r7  r   r  s@                                                               @@@@r4   r  zqueue.refreshN  s   #D))| 	GMM!3445551hhvs##**,,xx  88K88((7##((7## 	=!3G!<!<<G

	"t$$$"l2.3T\"5E5J'S~##C((SE11kABB   9$$&& k899>??   
 ~--c22H--c22K$T;77H H $ 7 7 G GTYYw//@@B}}&))*G4 %  H  $

7### $

7###LL[))*** [[$4[@@F [#..Bbh
BBs)CQQQ%C]4:tT::F xx!! /  *4b21NOO tDz===(..++E+**Csy#+s{JJAq!QRBRBRB   B;;FF1III   77IIaLLLFF1IIIIFF1IIII FU  77IIaLLLMM!$$$JJqMMMq				RARARA [77B["(BJ
JNBBR"Wr\B.//JOOOO2r2,OOONMME#    Q&tU33E#Y((**F++-- B% B%?%+9$NNG| !8x'7 !8!##$  C"&-"6"6s";";C  #3$-3G3G & 1 1#r : : A A# F F F M55 #$ 6     $' 
0 
0C"%c("5"5"7"7C" < & 1 1#r : : A A$*JJsB$7$7!" !" !" $'!88$*3K$6$6s$;$;$;"f}}$*3K)/ = =IC'+ = = $ 2 23 < < < <== $%  C M55 #$ 6     "&dm&:&:&<&<!=!= 8 8A M..tQ7777 I I44Q44HHHH B"3q66A:r266 % %%vad|| %IIadOOO !! I I44Q44HHHH I I44Q44HHHH# J J44Q54IIII70chhjjD#Cy00H $DOX..L$$&&&(,D%$'4#uUKKKKMMOOOG$$$$GG$$$$$EB% B% B% B% B% B% B% B% B% B% B% B% B% B% B%HM )72
 0(CCC '* * * * * *  !!OPPH$4#-!)!)  F
 ";UZZ
%;%;GG ': 9","'**RZ"8"8!GMM#&&& ! r!.99;;D))%00B! #"%	 	 	A :9.999A C00BBB%]k18  F  %RyyH /X...!' , ,U++++LLNNN OE&&tR1K1K1K1KF1K1K1KLLLHHJJJL''Aw(?(?@@@OB----GOB-----
8A;'%%chhjj#,,..AAA   >     . MMOOOOOD!!!!! MMOOOOOD!!!!s}   4So8 dL!c=-d=ddo8 d""o8 %d"&o8 *B'l> D;l# l> #l::l> =o8 >Bo		o8 8+p#c                     |sEt           j                            | j                  r!t          j        t          d                    	 t          j        | j                   n# t          $ r |s Y nw xY w|r|                     d          S d S )Ns$   patch queue directory already existsTcreate)	r   r   r  r   r  r   mkdirFileExistsErrorre  )r2   rI   r  s      r4   initz
queue.init]  s     	J"'--	22 	J+a GHHIII	HTY 	 	 	  	  	+::T:***	+ 	+s   	A# #A32A3c                    |r-|| j         vr$t          j        t          d          |z            |s|                                 }n| j                             |          dz   }g }t          |t          | j                             D ]S}|                     |          \  }}|r"|	                    || j         |         f           | 
                    |           T|S )N   patch %s is not in series filerc   )r  r   r  r   rY  ri   rl   rk   rV  rH   r\  )r2   rI   r   rt   	unappliedrw   rV  r  s           r4   r  zqueue.unappliedh  s     	LU$+--+a ABBUJKKK 	1NN$$EEK%%e,,q0E	uc$+..// 	$ 	$A#}}Q//Hf 6  !T[^!4555  ####r7   r   c                 v     fd}d  j         D             }|t           j                  |z
  }|s j        j        rt          d||z   dz
  z            }	t          |||z             D ]l}
 j        |
         }||v rd\  }}n&                     |
          d         rd\  }}nd\  }}d	} j        j        r	d
|	|
|fz  }n	|r||k    r_ ||||           md S g }t          j         j	                  D ]\  }}}|t           j	                  dz   d          }|D ]k}t          j	        
                    ||          }| j        vr@| j         j         j        fvr*|                    d          s|                    |           lt!          |          D ]} j        j        rdpd	} |||d            d S )Nc                    | rj                             |            rt                              |          j                  }|j        r|j        d         }nd}j                                         rZj                                         t          |           z
  t          |          z
  dz
  }|dk    rt          j
        ||          }nd}j                             |d|z              j                             d           j                             |d|z              nj                             |d|z              j                             d           d S )	Nr   r7   rd   s   qseries.labels   : s   qseries.message.r   )r   rX  r   r   r   r   	formatted	termwidthrk   r"   ellipsis)pfxr  r  r  r3   widthr2   summarys         r4   displaynamez"queue.qseries.<locals>.displayname  sP    #c""" D 9!5!5t~FF: *Q-CCC7$$&& " G--//#c((:S^^KaOEqyy(1#u==!i{U/BCCCe$$$c)<u)DEEEEi{U/BCCCGMM%     r7   c                     h | ]	}|j         
S r1   rU   rO  s     r4   	<setcomp>z queue.qseries.<locals>.<setcomp>  s    000a16000r7      %drc   )   A   appliedr   )   U	   unapplied)   G   guardedr7   s   %*d %s r  s   D    missing)r  rk   r  r   rY  rl   rV  r   walkr   r   r   r   r   rm   rH   rC   )r2   rI   missingrt   lengthr  r  r  r  idxwidthrw   r   charr  r  	msng_listru  dirsrz  r  rd  flr  s   `     `                r4   qserieszqueue.qseriesw  s[   	! 	! 	! 	! 	! 	!. 104<000>%%-F $	0w =u(:;<<5%&.11 / /AG##"2KD%%]]1%%a( 3"4KD%%"2KD%7? $!T'::CC $C..../ / I%'WTY%7%7 - -!dETY!+--. - -Aa++B$+-- O O O   !#d 3 3 "((,,,- I&& 0 0go/%63CJ////0 0r7   c                      |j         dk    rdS d S )N   .hg.patches.save.lineTr  )r2   r   s     r4   
issavelinezqueue.issaveline  s    6---4 .-r7   c                    | j                                         }| j        j        rz|j        ss| j        j        |_        |                    dd| j                            dd          d           |                    dd| j                            dd          d           |s2t          j                            | 	                    d                    rt          j        || j        |          S d S )Nr   s	   formatteds   mqpagers   interactiver  )r   r  )r   r  r   pageractiver   r   r   r   r  r   r   
repository)r2   r  r   s      r4   re  zqueue.qrepo  s    [7 	r~ 	!W0BNLLul33	   LLun55	    	DRW]]499V#4#455 	D=$)FCCCC	D 	Dr7   c                    ||                                                                          }|                                }d }g }g }	d }
t          |          D ]\  }}|dk    r|dz   }|                    d          r>|                                }|dd                              d          }d |D             }
d|u|                                }|                    dd          \  }}|r1|	                    t          t          |          |                     |                    |           |)| j
                            t          d                     dS | j
                            t          d	          |d
         z             || _        |	| _        |                                  d| _        d| _        |j                                        }|r||vr(| j
                            t          d                     ns| j
                            t          d          t)          |          z             |j                                        }||v rd}nd}t          | j
        ||g|d           |
r| j
                            t          d          t)          |
d
                   t)          |
d                   fz             |r| j
                            t          d                     |                                 }|s)| j
                            t          d                     dS t3          j        ||
d
                    d S d S d S )Ns   Patch Data:rc   s	   Dirstate:r   r6  c                 ,    g | ]}t          |          S r1   )r   r  s     r4   rB  z!queue.restore.<locals>.<listcomp>  s    )))!s1vv)))r7   rX   s   no saved patch data found
s   restoring status: %s
r   Ts*   save entry has children, leaving it alone
s   removing save entry %s
Fr  s&   saved queue repository parents: %s %s
s   updating queue directory
s    unable to load queue repository
)r  r   r   ro   rm   r   r   rH   rQ   r   r   r   r   r  r  r  r   r   r  rs  r   r  r  r  re  r   r  )r2   rI   r  r  qupdater6  rq   	datastartr  r  qpprw   rx   r   r   rU   rs  ppr  r  s                       r4   restorezqueue.restore  s=   Cy$$&&,,..!!	 '' 	% 	%GAt~%%E		.. 
%KKMMbccFLL&&))q)))&KKMM''$**4 %NN;s1vvt#<#<====MM!$$$GLL9::;;;1Q011E!H<===  $$&& 
	I%QMNNOOOOQ:;;eCjjHIII]**,,"99!FF"FdgtcU6%HHHH 	$GLL<==Q==%A--01    $q!>??@@@JJLL GLL#G!H!HIII1CF#####	$ 	$
$ $r7   c                    | j         s)| j                            t          d                     dS |                     | j         d                   r)| j                            t          d                     dS |st          d          }nd|                    d          z   }|                                 }|rI|j                                        }|dt          |d	                   t          |d                   fz  z  }|d
z  }|d
                    d | j         D                       z  }|d
                    d | j        D                       z  }|                    |d          }|s)| j                            t          d                     dS | j                             t          |d                     d| _        |                     |           d S )Ns"   save: no patches applied, exiting
rc   r   s   status is already saved
s   hg patches saved states   hg patches: s   
s   
Dirstate: %s %sr   s   

Patch Data:
r7   c              3       K   | ]	}d |z  V  
dS )r_  Nr1   r  s     r4   r   zqueue.save.<locals>.<genexpr>!	  s&      ::!::::::r7   c              3       K   | ]	}d |z  V  
dS )s   :%s
Nr1   r  s     r4   r   zqueue.save.<locals>.<genexpr>"	  s&      >>1>>>>>>r7   Tr  s   repo commit failed
r  )r  r   r   r   r  r   re  r  r  r   r   r  r   rH   rQ   r   rq  )r2   rI   r3   r  r  r   s         r4   savez
queue.save	  s   | 	GLLABBCCC1??4<+,, 	GLL7889991 	8-..CC!CJJw$7$77CJJLL 	C##%%B'3r!u::s2a5zz*BBBC##sxx::T\::::::sxx>>do>>>>>>KK4K(( 	GLL2334441K+CDDEEE r7   c                     | j         rB| j         d         j        }|                     |          }|t          | j                  S |dz   S dS )Nr   rc   r   )r  rU   r)  rk   r  )r2   r$  rz  s      r4   rC  zqueue.fullseriesend+	  sO    < 	R %A//!$$C{4?+++7Nqr7   c                      d} fd} j         rM j         d         j        }	  j                            |          }n# t          $ r Y dS w xY w ||dz             S  ||          S )zIf all_patches is False, return the index of the next pushable patch
        in the series, or the series length. If all_patches is True, return the
        index of the first patch past the last applied one.
        r   c                    s| t          j                  k    r| S t          | t          j                            D ]5}                    |          \  }}|r|c S                     |           6t          j                  S r0   )rk   r  rl   rV  r\  )rt   rw   r$  r  rZ  r2   s       r4   	nextpatchz"queue.seriesend.<locals>.nextpatch;	  s     es4;'7'7775#dk"2"233 ( ( MM!,,	6 HHH$$Q''''t{###r7   r   rc   )r  rU   r  ri   r   )r2   rZ  rz  r  r$  s   ``   r4   rY  zqueue.seriesend4	  s    
 	$ 	$ 	$ 	$ 	$ 	$ < 	&R %Ak''**   qq9S1W%%%y~~s   A   
AAc                     | j         |         j        }| j        j        s|}n#d| j                            |          z  dz   |z   }|S )Nr  r6  )r  rU   r   rY  r  ri   )r2   ri   r  r$  s       r4   appliednamezqueue.appliednameN	  sN    U#(w 	BAA**5111T9EAAr7   c           	           fd}|rO|r!t          j        t          d                    t          j        ||          }|                    d           n#|s!t          j        t          d                    t          |          dk    st          |          dk    r#|r!t          j        t          d                    g }	|r|j                            |j        	                    |
                                                    }
t          |
          dk    r6t          j        t          d          |                                z             j        r|j        	                    |
                                          }|d	  j        D             v r6t          j        t          d
          |
                                z            |
 j        d         j	        gk    r6t          j        t          d          |
                                z            |j                             j        d         j	                  }|j                            |          d         }ni|
|j        	                    |
                                          gk    r6t          j        t          d          |
                                z            d }                     d|i          }|                    d          5 }|D ]s}||                                         s3t          j        t          d          |z  t          d                    |j                            |          \  }}|j        	                    |          }|t$          k    r$t          j        t          d          |z            |r,||k    r&t          j        t          d          ||fz            |}|sK                     ||                                                             dd          d         d|z            } ||                                ||            j                            d|                                |d          5 }t5          j        ||g||           d d d            n# 1 swxY w Y   t9          ||          } j                            d|            j                            |           |	                    |           d }|r=|j                             dd          r"tC          j"        ||tB          j#        |g            $                                 d _%        d _&        u	 d d d            n# 1 swxY w Y   tO          |          D ]U\  }}|r;|dk    r!t          j        t          d                    tQ          |          } )                    |           tU          j+        |          ,                                rX -                    |          }t\          j/        0                    |          s$t          j        t          d          |z            |rl                     ||            j        1                    t          d          ||fz             te          j3        | -                    |                     ne|}na|dk    r#|s!t          j        t          d                     |s?tQ          t\          j/        4                    |5                    d!                              }                     ||           	 |dk    r j        j6        7                                }nBtq          j9         j        |          }|7                                }|:                                 n9# tv          tx          f$ r% t          j        t          d"          |z            w xY w                     |d          }|1                    |           |:                                 |s ||           | j=        vr$ >                                |z   }|g j        ||<    $                                 d _&         j        ?                    t          d#          |z              j                            |           |	                    |           d }W @                    |           |	S )$Nc                 b    | j         v r$t          j        t          d          | z            d S )Ns&   patch %s is already in the series file)r  r   r  r   )r  r2   s    r4   checkseriesz"queue.qimport.<locals>.checkseries`	  s=    DK''k?@@9L   ('r7   s*   option "-r" not valid when importing filesTr  s   no files or revisions specifiedrc   s5   option "-n" not valid when importing multiple patchess/   revision %d is the root of more than one branchc                     g | ]	}|j         
S r1   r  )r   r   s     r4   rB  z!queue.qimport.<locals>.<listcomp>	  s    999qAF999r7   s   revision %d is already managedr   s*   revision %d is not the parent of the queuer   s"   revision %d has unmanaged childrenr'      qimports   revision %d is not mutabler  r  s   cannot import merge revision %ds#   revision %d is not the parent of %dr   s   %d.diffr  r  r&   r,   rH  s%   -e is incompatible with import from -s   patch %s does not exist   renaming %s to %s
s$   need --name to import a patch from -   /s   unable to read file %ss   adding %s to series file
)Ar   r  r   r   r  r  rk   r  rs  rT   r3  lastr  r  
parentrevsr  r  r  r   r'  r  r   r  r  rp   r   r   
exportfilerQ   r   rH   r   r   r   retractboundaryr   r  r   r   ro   normnamer  r#   urlislocalr   r   r   r\  rX  r   ry  basenamer   finr   r   openpathr   rm  r   r  rC  r   rq  )r2   rI   rz  r  r  existingr  r  r  importedrs  r  
lastparentr  r  r  rB   r  r   ra  serw   filename
originpathtextr"  ri   s   `                          r4   qimportzqueue.qimportV	  st	   	 	 	 	 	  	E kCDD   %dC00CHHTH"""" 	E+a BCCDDDJJNNc#hhll	l+JKK    J	, N(()<)<SYY[[)I)IJJE5zzA~~kHIIhhjj!   | "~**399;;7799DL99999+;<<syy{{J   T\"-2333+GHH))++&   ~))$,q/*>??!^66t<<Q?

T^00==>>>+?@@399;;N   "
}}fc]33H!!*-- +, *, *,A7??,, #k;<<q@!"#J!K!K    "^66q99FB++A..AW}}#k@AAAE   " jAoo#kDEE *o.   "$J$ $($6$6 G//1177qAA!D&N% %	  K	***''	5999O**1i888Y55 I*4!bxHHHHI I I I I I I I I I I I I I I %Q	22BL''2...J%%i000OOI... $I Mtw11%CC M.tRLLL$$&&&(,D%'+D$$U*,+, +, +, +, +, +, +, +, +, +, +, +, +, +, +,Z %U++ 9	 9	KAx -t##+BCC   $H--&&x000;x((0022 !%8!4!4J7>>*55 #k899HD    )''	5999GMM011Xy4II   K
DIIi,@,@AAAA (II t##I#+ABB   #  ((()>)>??! !I ##Iu555O4''#w{//11[(;;!wwyy


) O O O+a(A&B&BX&MNNNOY55T""" 'I&&&++**,,q009{e,#DGLL899IEFFFJi(((OOI&&&IIsE    FVR."V.R22V5R26CVV	V	$A'_6`r0   )NNFr   )NNNNN)FTFNNNNF)FT)	NFFNFFFFF)NFTFFF)Nr   NNFr  )NNNNF)Ar>   r?   r@   rV   r   propertycacher  r  r  r
  r  r  r  r   r)  r#  compiler,  r  r4  r:  r<  rE  rV  r\  rh  rq  r}  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r'  r)  rR  r  r  r{  r  rG  r  r  r  r  r  re  r  r  rC  rY  r  r  r1   r7   r4   r   r     s       #! #! #! #!J 
  ( 
   
   
! ! !! ! !   2  + + +   rzEFFHI I I.L L L     ! ! !$       (% % % %N  ,	 	 	/ / / /* 
 
 
 
6& & &P   *% % %N/ / /( ." ." ." ."h o o o ob.3 .3 .3 .3`  0H H H? ? ?:  * * *   . ?I  ,J J J J  2P P P}" }" }"~  ;@ ;@ ;@ ;@@ q q q ql y= y= y= y=vL L LM" M" M" M"^	+ 	+ 	+ 	+   $ G0 G0 G0 G0R  D D D D*5$ 5$ 5$ 5$n   6     4   f f f f f fr7   r   c                     |                      dd          r*|                    d          s|                    d          r|S t          |          }d|d<   |S )Nr&   r*      force   exactT   keep_changes)r   r   dictr   r<   s     r4   fixkeepchangesoptsr!  	  sc    MM%0088H 88H
 ::D DKr7   s   qdelete|qremove|qrm   kr  s   keep patch filer  r  s%   stop managing a revision (DEPRECATED)s   REVs   hg qdelete [-k] [PATCH]...)helpcategoryc                     |j         }|                    ||t          j        |                     |                                 dS )a=  remove patches from queue

    The patches must not be applied, and at least one patch is required. Exact
    patch identifiers must be given. With -k/--keep, the patch files are
    preserved in the patch directory.

    To stop managing a patch and move it into permanent history,
    use the :hg:`qfinish` command.r   )mqr  r   r?  rh  )r   rI   r!  r<   qs        r4   r  r  
  s>    0 	AHHT7H066777KKMMM1r7   s   qapplied   1   lasts%   show only the preceding applied patchs   hg qapplied [-1] [-s] [PATCH]c           	         |j         }t          j        |          }|rK||j        vr$t	          j        t          d          |z            |j                            |          dz   }n|                    d          }|	                    d          r&|s$| 
                    t          d                     dS |	                    d          r*|dk    r$| 
                    t          d                     dS |	                    d          r|dz
  }d}nd}|                    |||d	|	                    d
                     dS )z<print the patches already applied

    Returns 0 on success.r  rc   Tr(  r}     only one patch applied
rd   r   r  r%   )r  rt   r  r  N)r%  r   r?  r  r   r  r   ri   rY  r   rX  r  )r   rI   r   r<   r&  rz  rt   s          r4   r  r  )
  sU    	A%%D    +a ABBUJKKKhnnU##a'kk$xx 
 

*++,,,q	'		 saxx
.//000q	'		 aIISdDHHZ<P<P      r7   s
   qunapplied   firsts   show only the first patchs   hg qunapplied [-1] [-s] [PATCH]c           	      0   |j         }t          j        |          }|rK||j        vr$t	          j        t          d          |z            |j                            |          dz   }n|                    d          }|t          |j                  k    r9|
                    d          r$|                     t          d                     dS |
                    d          rd}nd}|                    |||d|
                    d          	           dS )
z<print the patches not yet applied

    Returns 0 on success.r  rc   Tr+     all patches applied
Nr  r%   rt   r  r  r  )r%  r   r?  r  r   r  r   ri   rY  rk   r   rX  r  )r   rI   r   r<   r&  rt   r  s          r4   r  r  P
  s    	A%%D "  +a ABBUJKKKu%%)D!!AH$((8"4"4
+,,---qxx II$$      r7   r     e   existings   import file in patch directory   n   names   name of patch files   NAME   fr  s   overwrite existing filess)   place existing revisions under mq control   gs   use git extended diff format   P   pushs   qpush after importings>   hg qimport [-e] [-n NAME] [-f] [-g] [-P] [-r REV]... [FILE]...c                 z   t          j        |          }|                                5  |j        }	 |                    |||                    d          |                    d          |                    d          |                    d          |                    d                    }|                                 n# |                                 w xY w	 ddd           n# 1 swxY w Y   |rF|                    d          r1|                    d          s|                    ||d	                   S d
S )a  import a patch or existing changeset

    The patch is inserted into the series after the last applied
    patch. If no patches have been applied, qimport prepends the patch
    to the series.

    The patch will have the same name as its source file unless you
    give it a new one with -n/--name.

    You can register an existing patch inside the patch directory with
    the -e/--existing flag.

    With -f/--force, an existing patch of the same name will be
    overwritten.

    An existing changeset may be placed under mq control with -r/--rev
    (e.g. qimport --rev . -n patch will place the current revision
    under mq control). With -g/--git, patches imported with --rev will
    use the git diff format. See the diffs help topic for information
    on why this is important for preserving rename/copy information
    and permission changes. Use :hg:`qfinish` to remove changesets
    from mq control.

    To import a patch from standard input, pass - as the patch file.
    When importing from standard input, a patch name must be specified
    using the --name flag.

    To import an existing patch while renaming it::

      hg qimport -e existing-patch -n new-name

    Returns 0 if import succeeded.
    r2  r0  r  r  r'   )r  r  r  r  r  Nr6  r   r   )r   r?  r   r%  r  r   rh  r{  )r   rI   r  r<   r&  r  s         r4   r  r  u
  s_   j %%D	  G	yy((7+++..hhx((HHV$$HHV$$ !  H KKMMMMAKKMMMMM                *DHHW%% *dhhv.>.> *vvdHRL)))1s)   C(A;C-C(CC((C,/C,c                    |j         }|                    ||          }|                                 |rQt          j                            |                    d                    s|                    dd          }|                    d           |                    d           |                    d           |                    d           |                    d           |	                                 t          j                            |                    d                    s(|                    dd          	                                 |d	         
                    ddg           t          j
        | |           d
S )a"  initialize a new queue repository

    This command also creates a series file for ordering patches, and
    an mq-specific .hgignore file in the queue repository, to exclude
    the status and guards files (these contain mostly transient state).

    Returns 0 if initialization succeeded.s	   .hgignorer  s   ^\.hg
s   ^\.mq
s   syntax: glob
s   status
s   guards
r   Nr   )r%  r  rh  r   r   rk  rs  rm  rX  r   rg  r   )r   rI   r  r&  r  ra  s         r4   qinitr9  
  sD    	A	tVAKKMMM w~~aggl3344 	d++BHH[!!!HH[!!!HH&'''HH[!!!HH[!!!HHJJJw~~aggi0011 	,FF9d##))+++	$\9-...R1r7   s   qinit   cs   create-repos   create queue repositorys   hg qinit [-c]T)r#  	helpbasicc                 L    t          | ||                    d                    S )a  init a new queue repository (DEPRECATED)

    The queue repository is unversioned by default. If
    -c/--create-repo is specified, qinit will create a separate nested
    repository for patches (qinit -c may also be run later to convert
    an unversioned patch repository into a versioned one). You can use
    qcommit to commit changes to this queue repository.

    This command is deprecated. Without -c, it's implied by other relevant
    commands. With -c, use :hg:`init --mq` instead.create_repor  )r9  r   r   rI   r<   s      r4   r  r  
  s%    $ T$((="9"9::::r7   s   qclone   pulls"   use pull protocol to copy metadatar     noupdates)   do not update the new working directories   uncompresseds)   use uncompressed transfer (fast over LAN)   pr   s#   location of source patch repositorys   REPOs#   hg qclone [OPTION]... SOURCE [DEST])r#  norepoc                 \   t          j        |          }d }|t          j        |          }t	          j        | |          \  }}}t          j        | ||          }|                    d          r-t	          j        | |                    d                    \  }}}n ||          }	 t          j        | ||           n4# t          j	        $ r" t          j
        t          d                    w xY wd\  }	}
|                                r|                                }|j        j        r||	                                         t           j        k    r|j        j        d         j        }	t          j        |          st)          |                                          }t-          |                    |                    |	                              }
|
                    |j                            |	          d                    nA|                    d          r,	 |                    d          }	n# t          j	        $ r Y nw xY w|                     t          d	                     t          j        | ||                                ||                    d
          |
d|                    d                    \  }}|                     t          d                     t          j        | ||                    d          p
 ||           ||          |                    d
          |                    d           |                    d                     |                                r|                                }|	r7|                     t          d                     tA          | ||	gdd           |                    d          sR|                     t          d                     t          j!        ||j        "                                           dS dS dS )aT  clone main and patch repository at same time

    If source is local, destination will have no patches applied. If
    source is remote, this command can not check if patches are
    applied in source, so cannot guarantee that patches are not
    applied in destination. If you clone remote repository, be sure
    before that it has no patches applied.

    Source patch repository is looked for in <src>/.hg/patches by
    default. Use -p <url> to change.

    The patch directory must be a nested Mercurial repository, as
    would be created by :hg:`init --mq`.

    Return 0 on success.
    c                 r    |                                  }|                    d          r
|dd         }|dz   S )z+compute a patch repo url from a repo objectr  Nr   s   /.hg/patches)r  endswith)rI   r  s     r4   r   zclone.<locals>.patchdir  s;    hhjj<< 	crc(C_$$r7   Nr   s4   versioned patch repository not found (see init --mq)r  r   s   lookuprX  s   cloning main repository
r?  FrA  )pullr  r  streams   cloning patch repository
r@  )rG  r  rH  s6   stripping applied patches from destination repository
r  s    updating destination repository
)#r   r?  r   defaultdestr#   get_clone_pathpeerr   r   	RepoErrorr  r   localr%  r  r   r   r   rT   r  r7  rs  r  
differencerH   r  r  capabler  rv  cloner  r   r  r  )r   sourcedestr<   r   __source_pathsrpatchespathqbasedestrevrI   rs  drs                 r4   rP  rP  
  s   \ %%D% % % |~f%%!0V<<BR	T;	'	'B xx
 #%4R*9M9MNNKhrll

D+&&&&? 
 
 
kEFF
 
 	

  NE7	xxzz xxzz7? 	AtE{0022fmCCGOA&+E:d## ADJJLL))u//

50A0ABBCCt~55e<<Q?@@@	I		 	IIh''EE 	 	 	D	 GGA*++,,,X

XXgxx((	 	 	FB GGA+,,---H
,XXg88K(((xx((    
xxzz 2xxzz 	@GG$    "dUGE$????xx$$ 	2GGA:;;<<<IdDN..00111112 2	2 	2s   +C 1C3"H8 8I
	I
s   qcommit|qcis	   commit|cis    hg qcommit [OPTION]... [FILE]...)r#  	inferrepoc                     |j         }|                                }|st          j        d          t	          j        |j        |g|R i | dS )zscommit changes in the queue repository (DEPRECATED)

    This command is deprecated; use :hg:`commit --mq` instead.   no queue repositoryN)r%  re  r   r  r   r   r   )r   rI   rI  r<   r&  r  s         r4   r   r   l  s[     	A			A 2k0111OAD!+d+++d+++++r7   s   qseries   mr  s   print patches not in seriess   hg qseries [-ms]c                     |j                             ||                    d          |                    d                     dS )z7print the entire series file

    Returns 0 on success.r  r  )r  r  r   )r%  r  r   r>  s      r4   r  r  ~  sG     	GOOdhhy))488I3F3F     1r7   s   qtops   hg qtop [-s]c           	          |j         }|j        r|                    d          }nd}|r2|                    ||dz
  dd|                    d                     dS |                     t          d                     dS )	z>print the name of the current patch

    Returns 0 on success.Tr   rc   r  r  r.  r}  N)r%  r  rY  r  r   rX  r   )r   rI   r<   r&  ts        r4   r  r    s     	Ay KK 
			a%HHY'' 	 	
 	
 	
 	
 	
 	*++,,,qr7   s   qnexts   hg qnext [-s]c                    |j         }|                                }|t          |j                  k    r$|                     t          d                     dS |                    ||d|                    d                     dS )zDprint the name of the next pushable patch

    Returns 0 on success.r-  rc   r  )rt   r  r  N)r%  rY  rk   r  rX  r   r  r   )r   rI   r<   r&  rz  s        r4   nextrb    sw     	A
++--C
c!(mm
+,,---qIId#a)1D1DIEEEEEr7   s   qprevs   hg qprev [-s]c           	         |j         }t          |j                  }|dk    r$|                     t	          d                     dS |s$|                     t	          d                     dS |j                            |j        d         j                  }|                    ||dd|	                    d                     dS )	zHprint the name of the preceding applied patch

    Returns 0 on success.rc   r*  r}  r  r  r.  N)
r%  rk   r  rX  r   r  ri   rU   r  r   )r   rI   r<   r&  r   rC  s         r4   prevre    s     	AAIAAvv
.//000q 
*++,,,q
(..2+
,
,CIIC$8K8K      r7   c                    |                     d          s,|                     d          r|                                 |d<   |                     d          s0|                     d          rdt          j                    z  |d<   d S d S d S )Nr.     currentuserre      currentdater>  )r   usernamer!   makedater   s     r4   setupheaderoptsrk    s    88G &.!9!9 &W88G 7.!9!9 7 8#4#6#66W7 7 7 7r7   s   qnewr,  s    invoke editor on commit messagess'   import uncommitted changes (DEPRECATED)rg  s#   add "From: <current user>" to patch   ur.  s   add "From: <USER>" to patchs   USER   Drh  s#   add "Date: <current date>" to patch   dre   s   add "Date: <DATE>" to patchs   DATEs0   hg qnew [-e] [-m TEXT] [-l FILE] PATCH [FILE]...)r#  r;  rZ  c                     t          j        |          }t          j        | |          }|j        }||d<   t          | |            |j        ||g|R i t          j        |           |                                 dS )a  create a new patch

    qnew creates a new patch on top of the currently-applied patch (if
    any). The patch will be initialized with any outstanding changes
    in the working directory. You may also use -I/--include,
    -X/--exclude, and/or a list of files after the patch name to add
    only changes to matching files to the new patch, leaving the rest
    as uncommitted modifications.

    -u/--user and -d/--date can be used to set the (given) user and
    date, respectively. -U/--currentuser and -D/--currentdate set user
    to current user and date to current date.

    -e/--edit, -m/--message or -l/--logfile set the patch header as
    well as the commit message. If none is specified, the header is
    empty and the commit message is '[mq]: PATCH'.

    Use the -g/--git option to keep the patch in the git extended diff
    format. Read the diffs help topic for more information on why this
    is important for preserving permission changes and copy/rename
    information.

    Returns 0 on successful creation of a new patch.
    r+  r   )	r   r?  r   
logmessager%  rk  rR  	strkwargsrh  )r   rI   r   r   r<   r3   r&  s          r4   rR  rR    s    V %%D

R
&
&CADLB	AE$9999 24 8 8999KKMMM1r7   s   qrefreshr  s;   refresh only files already in the patch and specified filess2   add/update author field in patch with current users0   add/update author field in patch with given users0   add/update date field in patch with current dates.   add/update date field in patch with given dates=   hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] [FILE]...c                 P   t          j        |          }|j        }t          j        | |          }t          | |           |                                5   |j        ||fd|it          j        |          }|	                                 |cddd           S # 1 swxY w Y   dS )a>  update the current patch

    If any file patterns are provided, the refreshed patch will
    contain only the modifications that match those patterns; the
    remaining modifications will remain in the working directory.

    If -s/--short is specified, files currently included in the patch
    will be refreshed just like matched files and remain in the patch.

    If -e/--edit is specified, Mercurial will start your configured editor for
    you to enter a message. In case qrefresh fails, you will find a backup of
    your message in ``.hg/last-message.txt``.

    hg add/remove/copy/rename work as usual, though you might want to
    use git-style patches (-g/--git or [diff] git=1) to track copies
    and renames. See the diffs help topic for more information on the
    git diff format.

    Returns 0 on success.
    r3   N)
r   r?  r%  r   rp  rk  r  r  rq  rh  )r   rI   rI  r<   r&  r   r  s          r4   r  r    s    D %%DA T**GB	  aidLLL83Ed3K3KLL	                 s   9BB"B   qdiffs   hg qdiff [OPTION]... [FILE]...c                     |                      d           |j                            ||t          j        |                     dS )a  diff of the current patch and subsequent modifications

    Shows a diff which includes the current patch as well as any
    changes which have been made in the working directory since the
    last refresh (thus showing what the current patch would become
    after a qrefresh).

    Use :hg:`diff` if you only want to see the changes made since the
    last qrefresh, or :hg:`export qtip` if you want to see changes
    made by the current patch without including changes made since the
    qrefresh.

    Returns 0 on success.
    rs  r   )pagerr%  rG  r   r?  )r   rI   rI  r<   s       r4   rG  rG  `  s>    . HHXGLLtX1$778881r7   s   qfolds   keep folded patch filess/   hg qfold [-e] [-k] [-m TEXT] [-l FILE] PATCH...c           	      >   t          j        |          }|j        }|s!t          j        t          d                    |                    |          d         s!t          j        t          d                    |                    |           t          j	        | |          }|
                    d          }g }g }|D ]}	|
                    |	          }
|
|v s|
|k    r%|                     t          d          |
z             |                    |
          r$t          j        t          d          |
z            |                    |
           |D ]}
|sIt          |                    |
          |j                  }|j        r|                    |j                   |                    |
          }|                    ||          \  }}}|s$t          j        t          d          |
z            |swt          |                    |          |j                  }|j        }|D ]0}|r,|r|                    d           |                    |           1d	                    |          } |j        |                                g|R  }|                                5  |                    |||j        |                    d
          d           |                    |||           |                                 ddd           dS # 1 swxY w Y   dS )a,  fold the named patches into the current patch

    Patches must not yet be applied. Each patch will be successively
    applied to the current patch in the order given. If all the
    patches apply successfully, the current patch will be refreshed
    with the new cumulative patch, and the folded patches will be
    deleted. With -k/--keep, the folded patch files will not be
    removed afterwards.

    The header for each folded patch will be concatenated with the
    current patch header, separated by a line of ``* * *``.

    Returns 0 on success.s&   qfold requires at least one patch namer   r  rW  s!   skipping already folded patch %s
s*   qfold cannot fold already applied patch %ss   error folding patch %ss   * * *r   r,  s   mq.qfold)r3   r  rJ  r4  N)r   r?  r%  r   r  r   r  r  r   rp  r  r   r  rH   r   r   r   r   r   rB  r  r  r  r  r  r   r  rh  )r   rI   rz  r<   r&  r   r   r!  messagesrd  r$  r  r   patchsuccessr  r3   r  s                    r4   foldry  |  sf   0 %%DA Hk!EFFGGG??4  # 4k!122333 T**GXXgFGH  HHQKK<<1;;GGA;<<q@AAA;;q>> 	+?@@1D   	q @ @ 	,QVVAYY44Bz ,
+++VVAYY&'ggdB&7&7#ud 	@+a 9::Q>???	@  &55* 	$ 	$C $ -NN8,,,s###**W%%q{1::<<2'222H	 	 				'""  	 	
 	
 	
 	
w%%%		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   'ALLLs   qgotos   keep-changess&   tolerate non-conflicting local changess   overwrite any local changess	   no-backups"   do not save backup copies of filess   hg qgoto [OPTION]... PATCHc                    t          j        |          }t          | |          }|j        }|                    |          }|                    d          }|                    d          }|                    |          r.|                    |||                    d          ||          }n-|                    |||                    d          ||          }|	                                 |S )zSpush or pop patches until named patch is at top of stack

    Returns 0 on success.	   no_backupr  r  )r  rr  r  )
r   r?  r!  r%  r  r   r  r  r{  rh  )r   rI   r   r<   r&  rr  r  r  s           r4   gotor|    s    & %%Db$''DAHHUOOExx%%H((?++K{{5 
ee((8$$#  
 
 ff((8$$#  
 
 KKMMMJr7   s   qguard   l   lists   list all patches and guards   nones   drop all guardss8   hg qguard [-l] [-n] [PATCH] [-- [+GUARD]... [-GUARD]...]c                    	 	 fd}|j         	d 	j        D             d}t          |          }|                    d          ri|s|                    d          r!t	          j        t          d                    t          t          	j	                            D ]} ||           dS |r|d         dd         d	v r:	j        s!t	          j        t          d
                    	j        d         j
        }|'|d         dd         d	vr|                    d          }|!t	          j        t          d                    |s|                    d          rg	                    |          }|$t	          j        t          d          |z            	                    ||           	                                 dS  |	j	                            	                    |                               dS )a  set or print guards for a patch

    Guards control whether a patch can be pushed. A patch with no
    guards is always pushed. A patch with a positive guard ("+foo") is
    pushed only if the :hg:`qselect` command has activated it. A patch with
    a negative guard ("-foo") is never pushed if the :hg:`qselect` command
    has activated it.

    With no arguments, print the currently active guards.
    With arguments, set guards for the named patch.

    .. note::

       Specifying negative guards now requires '--'.

    To set guards on another patch::

      hg qguard other.patch -- +2.6.17 -stable

    Returns 0 on success.
    c                    j         |          pdg}j        |          v rd}n                     |           d         rd}nd}d||fz  }                    d                    j        |          |          z             t          |          D ]\  }}|                    d          r                    |d	
           nD|                    d          r                    |d
           n                    |d
           |t          |          dz
  k    r                    d                               d           d S )Ns	   unguardedr  r   r  r  s!   qguard.patch qguard.%s qseries.%ss   %s: rK     qguard.positiver  rH     qguard.negative   qguard.unguardedrc   r6  r   )r
  r  rV  rX  r  ro   rm   rk   )	rC  r8  r  r  rw   r1  r  r&  r   s	         r4   r  zguard.<locals>.status  sT   $68C=G##EEZZ__Q 	 EEE4u~E
288AHSM5999:::!&)) 	 	HAu%% ;&89999!!$'' ;&89999&9:::CKK!O##
r7   c                     h | ]	}|j         
S r1   r  rO  s     r4   r  zguard.<locals>.<setcomp>0  s    )))!qv)))r7   Nr  nones.   cannot mix -l/--list with options or argumentsr   rc   r0  r  r   s   no patch to work withs   no patch named %s)r%  r  r  r   r   r  r   rl   rk   r  rU   r  r)  rE  rh  ri   r  )
r   rI   r   r<   r  r   rw   rC  r  r&  s
   `       @@r4   r1  r1    s   @      , 	A))qy)))GE::Dxx  	488F## 	+CDD   s18}}%% 	 	AF1IIII #471Q3<5((y 	8+a 566777	""}a1U22}k!455666 0txx 0ll5!!;+a 455=>>>	C	qx~~ahhuoo../////r7   s   qheaders   hg qheader [PATCH]c                 t   |j         }|r|                    |          }n@|j        s$|                     t	          d                     dS |                    d          }t          |                    |          |j                  }|                     d                    |j                  dz              dS )zMprint the header of the topmost or specified patch

    Returns 0 on success.r}  rc   rW  r   N)	r%  r  r  rX  r   r   r   r   r   )r   rI   r   r&  r  s        r4   rr   rr   M  s     	A "y 	HHQ.//0001!!	QVVE]]AK	0	0BHHUZZ
##e+,,,,,r7   c                    t           j                            |           \  }}t          j        |          }t	          j        d|z            }d }d }|D ]G}|                    |          }|r.t          |                    d                    }	||	|k    r|	}|}H|r"t           j        	                    ||          |fS dS )Ns   %s.([0-9]+)rc   r  )
r   r   r   listdirr#  r  r  r]  groupr   )
r   	directoryr  namesnameremaxindexmaxnamerd  r  ri   s
             r4   lastsavenamer  e  s    d++YJy!!EZ-..FHG  LLOO 	

OOE58#3#3  <Y00(;;<r7   c                 H    t          |           \  }}|d}| d|dz   z  z   }|S )Nr   s   .%drc   )r  )r   r  ri   newpaths       r4   savenamer  w  s5     &&MT5|Vuqy))GNr7   r  s   apply on top of local changesr  s-   apply the target patch to its recorded parents   list patch name in commit text   a   alls   apply all patches   merges%   merge from another queue (DEPRECATED)s   merge queue name (DEPRECATED)   moves-   reorder patch series and apply only the patchs0   hg qpush [-f] [-l] [-a] [--move] [PATCH | INDEX]c                 ^   |j         }d}t          j        |          }t          | |          }|                    d          r|                    d          r.|j                            |                    d                    }nt          |j                  \  }}|s$| 	                    t          d                     dS t          | |j        |j        |          }| 	                    t          d          |j        z             |                    |||                    d          |                    d          ||                    d	          |                    d
          |                    d          |                    d          |                    d          
  
        }|S )a,  push the next patch onto the stack

    By default, abort if the working directory contains uncommitted
    changes. With --keep-changes, abort only if the uncommitted files
    overlap with patched files. With -f/--force, backup and patch over
    uncommitted changes.

    Return 0 on success.
    Nr  r2  s%   no saved queues found, please use -n
rc   s   merging with queue at: %s
r  r~  r  r  r  r{  r  )r  r  r  ro  rp  rq  rr  r  )r%  r   r?  r!  r   r    r   r  r   r   r   r   r   r{  )	r   rI   r   r<   r&  r  r  rw   r  s	            r4   r{  r{    s   T 	AF%%Db$''Dxx 	A88G 	.hmmDHHW$5$566GG%af--JGQ 	GGA?@@AAA1r4;	7;;
011FK?@@@
&&hhx  XXgHHVXXghhx  ,''HH_--   C Jr7   s   qpops   pop all patchess   queue name to pop (DEPRECATED)s)   forget any local changes to patched filess!   hg qpop [-a] [-f] [PATCH | INDEX]c                 j   t          j        |          }t          | |          }d}|                    d          rtt	          | |j        |j        |j                            |                    d                              }| 	                    t          d          |j        z             d}n|j        }|                    |||                    d          ||                    d          |                    d          |                    d          	          }|                                 |S )
a  pop the current patch off the stack

    Without argument, pops off the top of the patch stack. If given a
    patch name, keeps popping off patches until the named patch is at
    the top of the stack.

    By default, abort if the working directory contains uncommitted
    changes. With --keep-changes, abort only if the uncommitted files
    overlap with patched files. With -f/--force, backup and discard
    changes made to such files.

    Return 0 on success.
    Tr2  s   using patch queue: %s
Fr  r  r{  r  )r  r  ro  rr  r  )r   r?  r!  r   r   r   r   r    r   r   r   r%  r  rh  )r   rI   r   r<   localupdater&  r  s          r4   r  r    s   @ %%Db$''DKxx "dk49dhmmDHHW<M<M.N.NOO
,--6777G
%%hhx  HHV,''HH_--   C KKMMMJr7   s   qrename|qmvs   hg qrename PATCH1 [PATCH2]c                    |j         }|s|}d}|r|                    |          }n@|j        s$|                     t	          d                     dS |                    d          }|                    |          }t          j                            |          r_t          t          j                            |t          j        
                    |                              }|                    |          }|                    |           |                     t	          d          ||fz             |                    |          }|j                            |j        |                   }|d                    d |D                       z   |j        |<   |                                 d|_        |                    |          }	|	r$t)          |	d         |          |j        |	d	         <   d|_        t          j                            |          }
t          j                            |
          st          j        |
           t1          j        |                    |          |           |                                }|r||j        v r|d         }|                                5  |j                            |          j        r5|j                            |           |j                             |           n,|!                    ||           |"                    |g           ddd           n# 1 swxY w Y   |#                                 dS )
zrename a patch

    With one argument, renames the current patch to PATCH1.
    With two arguments, renames PATCH1 to PATCH2.

    Returns 0 on success.Nr}  rW  r  r7   c                     g | ]}d |z   S r?  r1   r@  s     r4   rB  zrename.<locals>.<listcomp>  s    &A&A&AQuqy&A&A&Ar7   Trc   r   )$r%  r  r  rX  r   r   r   r   r  r  r  r  rv  r)  r,  r-  r  r  r   r  rQ   r   dirnamemakedirsr   ry  re  r  r  rA  r   set_untrackedset_trackedr  r  rh  )r   rI   r   rU   r<   r&  absdestrw   r8  r  destdirr  rL   s                r4   ry  ry    s    	A  "y 	HHQ.//000F!!ffTllG	w}}W T27+;+;E+B+BCCDD&&,,TGGA$%%5666	UAZQ00FSXX&A&A&&A&A&ABBBALOMMOOOAM;;uD 8(a$77	$q'ANgoog&&G7==!! 
GKuw'''			A %Uaj  wWWYY 	% 	%z##E**0 %
((///
&&t,,,,		%&&&UG$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% KKMMMMMs   +BL88L<?L<s   qrestore   deletes   delete save entrys   updates   update queue working directorys   hg qrestore [-d] [-u] REVc                     |                     |          }|j        }|                    |||                    d          |                    d                     |                                 dS )zsrestore the queue state saved by a revision (DEPRECATED)

    This command is deprecated, use :hg:`rebase` instead.r  r  )r  r  r   )r  r%  r  r   rh  )r   rI   r  r<   r&  s        r4   r  r  :  s`     ++c

CAIIdC 2 2DHHX<N<NIOOOKKMMM1r7   s   qsave   copys   copy patch directorys   copy directory name   emptys   clear queue status files
   force copys5   hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]c                    |j         }t          j        |          }t          j        | |          }|                    ||          }|r|S |                                 |                    d          r;|j        }|                    d          rt          j        
                    |j        |                    d                    }t          j                            |          r|t          j                            |          s$t          j        t!          d          |z            |                    d          s$t          j        t!          d          |z            nt#          |          }|                     t!          d          ||fz             t'          j        ||           |                    d          r%|j        d	d	= d
|_        |                                 dS )z`save current queue state (DEPRECATED)

    This command is deprecated, use :hg:`rebase` instead.)r3   r  r2  s,   destination %s exists and is not a directoryr  s&   destination %s exists, use -f to forces   copy %s to %s
r  NTr   )r%  r   r?  r   rp  r  rh  r   r   r   r   r   rk  r  r   r  r   r  r   r   	copyfilesr  r   )r   rI   r<   r&  r   r  r   r  s           r4   r  r  N  s     	A%%D T**G
&&7&
#
#C
 
KKMMMxx &v88G 	%gll1:txx/@/@AAGw~~g&& 	w}}W-- +IJJ!"   xx)) +CDDwN   tnnG
$%%w7888tW%%%xx IaaaL	1r7   s   qselects   disable all guardsr   s   list all guards in series file   pops)   pop to before first guarded applied patch   reapplys   pop, then reapply patchess!   hg qselect [OPTION]... [GUARD]...c                 	   |j         t          j        |          }                                }fd|s|                    d          r                    |          }fdt          t          j                            D             }	                    |           
                                 |s"|                     t          d                     |                    d          s|                    d          s                    |          }fdt          t          j                            D             }t          |          t          |          k    rA|                     t          d          t          |          t          |          fz             t          |          t          |          k    rA|                     t          d	          t          |          t          |          fz             nz|                    d
          ri }d}	j        D ]4}
|
s|	dz  }	|
D ](}|                    |d           ||xx         dz  cc<   )5| j        r|	|d<   t!          |                                          }|                    d            |rY|                     t          d                     |D ]3\  }}|                     d|z             |                     |d           4n|                     t          d                     nb|r>|                     t          d                     |D ]}|                     |d           n"|                     t          d                     |                    d          oj        oj        d         j        }d}|                    d          s|                    d          rt          t          j                            D ]z} |          sm|                     t          d                     d}|dk    r                    |d           n)                    |j        |dz
           j                    n{|rj	 |r8|                     t          d                                         ||           
                                 dS # 
                                 w xY wdS )au  set or print guarded patches to push

    Use the :hg:`qguard` command to set or print guards on patch, then use
    qselect to tell mq which guards to use. A patch will be pushed if
    it has no guards or any positive guards match the currently
    selected guard, but will not be pushed if any negative guards
    match the current guard. For example::

        qguard foo.patch -- -stable    (negative guard)
        qguard bar.patch    +stable    (positive guard)
        qselect stable

    This activates the "stable" guard. mq will skip foo.patch (because
    it has a negative match) but push bar.patch (because it has a
    positive match).

    With no arguments, prints the currently active guards.
    With one argument, sets the active guard.

    Use -n/--none to deactivate guards (no other arguments needed).
    When no guards are active, patches with positive guards are
    skipped and patches with negative guards are pushed.

    qselect can change the guards on applied patches. It does not pop
    guarded patches by default. Use --pop to pop back to the last
    applied patch that is not guarded. Use --reapply (which implies
    --pop) to push back to the current patch afterwards, but skip
    guarded patches.

    Use -s/--series to print a list of all guards in the series file
    (no other arguments needed). Use -v for more information.

    Returns 0 on success.c                 Z                         j        |          j                  d         S )Nr   )rV  r  rU   )rw   r&  s    r4   <lambda>zselect.<locals>.<lambda>  s!    AIaL$566q9 r7   r  c                 *    g | ]} |          |S r1   r1   r   rw   rV  s     r4   rB  zselect.<locals>.<listcomp>  &    KKKQxx{{KqKKKr7   s   guards deactivated
r  r  c                 *    g | ]} |          |S r1   r1   r  s     r4   rB  zselect.<locals>.<listcomp>  r  r7   sA   number of unguarded, unapplied patches has changed from %d to %d
s=   number of guarded, applied patches has changed from %d to %d
r   r   rc   s   NONEc                 "    | d         dd          S Nr   rc   r1   )r  s    r4   r  zselect.<locals>.<lambda>  s    !A$qrr( r7   )keys   guards in series file:
s   %2d  r   s   no guards in series file
s   active guards:
s   no active guards
r   Fs   popping guarded patches
T)ro  s   reapplying unguarded patches
N)r%  r   r?  r<  r   r  rl   rk   r  r:  rh  r  r   r
  r  rY  r  r`  r  rv  rX  rU   r  r{  )r   rI   r   r<   r8  old_unappliedold_guardedr  guardednoguardsgsrA  r1  countreapplypoppedrw   rV  r&  s                    @@r4   selectr  ~  s   \ 	A%%DXXZZF9999H 4/txx   4/D))KKKK%AI"7"7KKK	D	 	2IIa/00111xx 	(<(< 	D))IKKKK%AI"7"7KKKG9~~]!3!333		3  =))3y>>:	;   7||s;////		+  ;''W6	7   
)		 /. 	 	B A  !!!Q'''q			Q				 : 	'&F7Ofllnn%%**+++ 	6GGA122333 & ' 'u5()))&&&&' GGA3445555 	/GGA)**+++ # #E""""# HHQ,--...hhz""GqyGQYr]5GGFxx 	488J// 	s19~~&& 	 	A8A;; 		!899:::66EE$DE))))EE$	!a% 0 5666  	 &		!=>>???tW%%%KKMMMMMAKKMMMM s   :S S)r  r  s   finish all applied changesetss   hg qfinish [-a] [REV]...c                    |                     d          s#|s!t          j        t          d                    |                     d          rd|z   }|j        }|j        s$|                     t          d                     dS t          j        ||          }|d         	                                |v r<|d         
                                r"|                     t          d                     |                                5  |                    ||           |                                 ddd           n# 1 swxY w Y   dS )	ah  move applied patches into repository history

    Finishes the specified revisions (corresponding to applied
    patches) by moving them out of mq control into regular repository
    history.

    Accepts a revision range or the -a/--applied option. If --applied
    is specified, all applied mq revisions are removed from mq
    control. Otherwise, the given revisions must be at the base of the
    stack of applied patches.

    This can be especially useful if your changes have been applied to
    an upstream repository, or if you are about to push your changes
    to upstream.

    Returns 0 on success.
    r  s   no revisions specified)s   qbase::qtipr}  r   r  Ns6   warning: uncommitted changes in the working directory
)r   r   r  r   r%  r  r  r   r  r  rz  r   r   r  rh  )r   rI   r  r<   r&  r  s         r4   r  r    so   0 88I 0x 0k!566777	)		 0$x/A9 
		!+,,---qtX..DDz~~4DJ$4$4$6$6
LMMNNN 
  	t	               1s   +D==EEs   qqueues   list all available queues   actives   print name of active queue   creates   create new queue   renames   rename active queues   delete reference to queue   purges"   delete queue, and remove patch dirs   [OPTION] [QUEUE]c                    j         dddfdfd}fd}fd}fdfd	}fd
}d }	fd}
t          j        |          }|r*|                    d          s|                    d          r             }|                    d          r|                     d|fz             dS  |            D ]`}|                     d|fz             ||k    r*| j        s#|                     t          d                     K|                     d           adS  |	|          s!t          j        t          d                    	                                5   |            |                    d          rU|v r$t          j        t          d          |z             |            r |            ||            ||           nB|                    d          rx             }||k    r$t          j        t          d          |z            |v r$t          j        t          d          |z             ||          } ||          }t          j                            |          r$t          j        t          d          |z                                dd          }D ]o}||k    rN|                    d|fz             t          j                            |          rt          j        ||           V|                    d|fz             p|                                 j                            d            |           n|                    d          r |
|           n|                    d          rN|v r |
|            ||          }t          j                            |          rt#          j        |           n0|vr!t          j        t          d                     ||           ddd           dS # 1 swxY w Y   dS )a6  manage multiple patch queues

    Supports switching between different patch queues, as well as creating
    new patch queues and deleting existing ones.

    Omitting a queue name or specifying -l/--list will show you the registered
    queues - by default the "normal" patches queue is registered. The currently
    active queue will be marked with "(active)". Specifying --active will print
    only the name of the active queue.

    To create a new queue, use -c/--create. The queue is automatically made
    active, except in the case where there are applied patches from the
    currently active queue in the repository. Then the queue will only be
    created and switching will fail.

    To delete an existing queue, use --delete. You cannot delete the currently
    active queue.

    Returns 0 on success.
    r   s   patches.queuesr   c                      t           j                            j                  } |                     d          r
| dd          } | S )Nr      )r   r   r  rm   )r   r&  s    r4   _getcurrentzqqueue.<locals>._getcurrentO  s@    gqv&&>>+&& 	abb'C
r7   c                      	                      d          } |                                  n# t          $ r Y dS w xY wdS )Nr  TF)r    r   r   )r   
_allqueuesrI   s    r4   	_noqueueszqqueue.<locals>._noqueuesU  sS    	*d++BHHJJJJ 	 	 	44	 us   *. 
<<c                                   } 	                      d          }d |D             }|                                 | |vr|                    |            n# t          $ r g}Y nw xY wt	          |          S )Nr  c                 ^    g | ]*}|                                 |                                 +S r1   r   )r   r   s     r4   rB  z.qqueue.<locals>._getqueues.<locals>.<listcomp>c  s-    EEEu{{}}EekkmmEEEr7   )r    r   rH   r   rC   )currentr   queuesr  _defaultqueuer  rI   s      r4   
_getqueueszqqueue.<locals>._getqueues^  s    +--	%*d++BEEEEEFHHJJJf$$g&&& 	% 	% 	%#_FFF	% f~~s   AA A-,A-c                 n    j         r!t          j        t          d                     |            d S )Ns@   new queue created, but cannot make active as patches are applied)r  r   r  r   )rU   _setactivenocheckr&  s    r4   
_setactivezqqueue.<locals>._setactivel  sL    9 	+.    	$r7   c                                          d          }| dk    r|                    |            |                                 d S )Nr  r   r    rX  r   )rU   r   _activequeuerI   s     r4   r  z!qqueue.<locals>._setactivenocheckv  sA    XXlD)):HHTNNN





r7   c                                          d          }|                    d| fz             |                                 d S )Nr  r_  r  )rU   r   r  rI   s     r4   	_addqueuezqqueue.<locals>._addqueue|  s@    XXj$''
D7"###





r7   c                 ~    | dk    rj                             d          S j                             d| z             S )Nr   r   )r    r   )rU   rI   s    r4   	_queuedirzqqueue.<locals>._queuedir  s;    :8==,,,8==t!3444r7   c                     | D ]	}|dv r dS 
dS )Ns   :\/.FTr1   )rU   r   s     r4   
_validnamezqqueue.<locals>._validname  s+     	 	AH}}uu tr7   c                    | vr!t          j        t          d                                 }| |k    r!t          j        t          d                                        dd          }D ]"}|| k    r	|                    d|fz             #|                                 j                            d           d S )Ns'   cannot delete queue that does not exists$   cannot delete currently active queue   patches.queues.newr  r_  )r   r  r   r    rX  r   ry  )rU   r  r   r   r  r  r  rI   s       r4   _deletezqqueue.<locals>._delete  s    x+a JKKLLL+--7??+a GHHIIIXX+T22 	) 	)E}}HHWx'((((



-z:::::r7   r~  r  r_  Ns   %ss
    (active)
r   s9   invalid queue name, may not contain the characters ":\/."r  s   queue "%s" already existsr  s%   can't rename "%s" to its current names'   non-queue directory "%s" already existsr  r  r  r  s"   use --create to create a new queue)r%  r   r?  r   rX  quietr   r   r  r  r   r   rk  r    r   ry  r   shutilrmtree)r   rI   rU   r<   r  r  r  r  r  r  r  r  r   olddirnewdirr   qdirr  r  r  r  r  r  r&  s    `               @@@@@@@r4   qqueuer  (  s   D 	AM"J#L                                     
5 5 5 5 5  ; ; ; ; ; ; ; ;" %%D 488G$$ (;(; +--88I 	HHWz)***FZ\\ 	  	 EHHUeX%&&&>**++++:d 
kKLL
 
 	
 
 1 1:<<88I .	xk!$@"A"AD"HIIIy{{ )	-(((IdOOOJtXXi   '	!kmmGwk?@@4G   xk!$@"A"AD"HIIIYw''FYt__Fw~~f%% k@AAFJ   /66B! 1 1G##HHWw.///w~~f-- 4FF333HHWx/0000HHJJJHOO1:>>>d####XXi   	GDMMMMXXh 		x9T??Dw~~d## $d###8##k!$I"J"JKKKJtc1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1s   2J7P66P:=P:c                    | j         j        r~| j                            dd          rt          j        }nt          j        }| | j         j        d         j                 }||                             |                                           |S )zEcallback used to set mq changeset as secret when no phase data existsr&   r,   r   )	r%  r  r   r   r   r   draftrT   rg  )rI   rootsmqphaserW  s       r4   mqphasedefaultsr    ss    w )7eY// 	#mGGlGTW_Q',-g5::<<(((Lr7   c                      G fdd|j                   |                                r(|_         |j                            t                     d S d S )Nc                   ~     e Zd Zej        d             Z fdZd
dZ	 	 	 	 	 	 	 d fd	Z fdZ	 fd	Z
 xZS )reposetup.<locals>.mqrepoc                 B    t          | j        | j        | j                  S r0   )r   r   r   r   rY   s    r4   r%  zreposetup.<locals>.mqrepo.mq  s    $+ty999r7   c                     t          |                                            t          j        | d          r$t	          |                                 d           d S d S )Nr%  )superinvalidateallr   hasunfilteredcacher	   r   )r2   	__class__mqrepos    r4   r  z'reposetup.<locals>.mqrepo.invalidateall  s^    &$--///+D$77 1))4000001 1r7   Fc                    | j         j        rl| j         j        rb|sb| j                                        }d | j         j        D             t          fd|D                       rt          j        |          d S d S d S d S )Nc                     g | ]	}|j         
S r1   r  )r   rN   s     r4   rB  z@reposetup.<locals>.mqrepo.abortifwdirpatched.<locals>.<listcomp>   s    ;;;a16;;;r7   c              3       K   | ]}|v V  	d S r0   r1   )r   r$  r!  s     r4   r   z?reposetup.<locals>.mqrepo.abortifwdirpatched.<locals>.<genexpr>  s'      55qG|555555r7   )r%  r  r   r  r  r   r   r  )r2   errmsgr  r  r!  s       @r4   abortifwdirpatchedz,reposetup.<locals>.mqrepo.abortifwdirpatched  s    w .47#7 . .-//11;;47?;;;5555W55555 .+f---	. . . . . .. .r7   r7   Nc           	          |i }|                      t          d          |           t          	|                               |||||||          S )Ns&   cannot commit over an applied mq patch)r  r   r  r   )
r2   r  r   r   r  r  r=  extrar  r  s
           r4   r   z reposetup.<locals>.mqrepo.commit  sh     }##;<<e   &&--dD%  r7   c                    | j         j        r| j         j        r|j        sd | j         j        D             }|j        r@t          |j                  }t          |          D ]}||v r n|                                 |D ]K}| |                                         t          j
        k     r!t          j        t          d                    Lt          |                               |           d S )Nc                     g | ]	}|j         
S r1   r  )r   rL  s     r4   rB  z7reposetup.<locals>.mqrepo.checkpush.<locals>.<listcomp>  s    >>>af>>>r7   s   source has mq patches applied)r%  r  r   r  r  r7  r  r  r   r   r   r   r  r   r  	checkpush)r2   pushop
outappliedrs  rT   r  r  s        r4   r  z#reposetup.<locals>.mqrepo.checkpush  s   w O47#7 O O>>dgo>>>
; 	-  ,,E ( 4 4 - -5==!E&NN,,,,& O ODDz''))FM99#k!,L*M*MNNN : &$))&11111r7   c                    t          |                                           }| j        }|j        s|S d |j        D             }	 |                                 j                            |d         d                    nZ# t          j        $ rH | j	        
                    t          d          t          |d         d                   z             |cY S w xY w| j        j        fd|D             }|s|S |                    |d         d         df           |                    |d         d         df           |                    | j                            |d         d                   d         df           |d         }|D ]N}|d	         |v r1| j	        
                    t          d
          |d	         z             =|d         ||d	         <   O|S )z,augment tags from base class with patch tagsc                 *    g | ]}|j         |j        fS r1   rS   )r   r   s     r4   rB  z7reposetup.<locals>.mqrepo._findtags.<locals>.<listcomp>4  s!    FFF5uz5:.FFFr7   r   r   s)   mq status file refers to unknown node %s
c                 6    g | ]} |d                    |S )r   r1   )r   mqtincludeds     r4   rB  z7reposetup.<locals>.mqrepo._findtags.<locals>.<listcomp>B  s,    @@@cxxA/?/?@c@@@r7   rW  rX  s   qparentrc   s+   tag %s overrides mq patch of the same name
)r  	_findtagsr%  r  r   r  r  r   r  r   r   r   r   hasnoderH   r  )	r2   resultr&  mqtagstagsr   r  r  r  s	         @r4   r  z#reposetup.<locals>.mqrepo._findtags,  s   64((2244FA9 FFAIFFFF!!+//r
1>>>>$   CDDF2JqM**+    ~-H@@@@V@@@F MM6":a='2333MM6!9Q<2333MM4>11&)A,??BJOPPP!9D . .8t##GLLIJJ(#   
 &+1XDqNNMs   8B   ACCr   )r7   NNNFFN)r>   r?   r@   r   unfilteredpropertycacher%  r  r  r   r  r  __classcell__)r  r  s   @r4   r  r    s        		*	: 	: 
+	*	:	1 	1 	1 	1 	1 	1	. 	. 	. 	. 	 	 	 	 	 	 	(	2 	2 	2 	2 	2 	2('	 '	 '	 '	 '	 '	 '	 '	 '	 '	r7   r  )r  rM  _phasedefaultsrH   r  )r   rI   r  s     @r4   	reposetupr    s    a a a a a a a a a aF zz|| 4""?333334 4r7   c                     t          j        |d          rL|                    dd          s6|                    t	          d          |                    d                      | ||g|R i |S )Ns   abortifwdirpatched	no_commitFs#   cannot import over an applied patchr  )r   safehasattrr   r  r   )origr   rI   r   r   s        r4   mqimportr  [  s    344 
VZZU> > 
 	455vzz'7J7J	
 	
 	
 4D*4***6***r7   c                    |                     dd           }|s | |g|R i |S |r>|d         }t          j        |          s!t          j        t          d                    nHt          j        t          j	                              }|s!t          j        t          d                    t          j
        ||          }t          ||d          S )Nr%  r   s0   only a local queue repository may be initializeds5   there is no Mercurial repository here (.hg not found)T)r  r   r  r   r  r   r   findrepor   getcwdr  r9  )r  r   r   r   r%  repopathrI   s          r4   mqinitr  e  s    	D$		B )tB((((((( 7z(## 	+EFF  	
 #HO$5$566 	+JKK   =X&&DT4   r7   c                     |                     dd          }|s | ||g|R i |S |j        }|                                }|s!t          j        t          d                     | |j        |g|R i |S )z>Add --mq option to operate on patch repository instead of mainr%  Nr\  )r  r%  re  r   r  r   r   )r  r   rI   r   r   r%  r&  r  s           r4   	mqcommandr  {  s     
D$		B /tB.t...v...A			A 5k!2334444a)$)))&)))r7   c                 ,   |j         }g }t          |j                  t          |                    |                    }}|r9|                    |                     t          d          d          |z             |r9|                    |                     t          d          d          |z             |r:|                     t          d          d                    |          z             d S | 	                    t          d                     d S )Ns
   %d applied   qseries.applieds   %d unapplied   qseries.unapplieds   mq:     %s
s   , s   mq:     (empty queue)
)
r%  rk   r  r  rH   r  r   rX  r   rv  )r   rI   r&  r  r  us         r4   summaryhookr    s    A
Aqy>>3q{{40011qA E	!M**,>??!CDDD I	!O,,.BCCaGHHH /
?##ejjmm344444 	,--.....r7   s   mq()c                      t          j        |ddt          d                      fd j        j        D             t          j        fd|D                       S )zChangesets managed by MQ.r   s   mq takes no argumentsc                 N    h | ]!}|j                                                  "S r1   )rT   r  )r   r  rI   s     r4   r  zrevsetmq.<locals>.<setcomp>  s+    ;;;atAF|!!;;;r7   c                     g | ]}|v |	S r1   r1   )r   r  r  s     r4   rB  zrevsetmq.<locals>.<listcomp>  s    ???1!w,,Q,,,r7   )r   getargsr   r%  r  r   baseset)rI   subsetr  r  s   `  @r4   revsetmqr&    si     q!Q": ; ;<<<;;;;47?;;;G???????@@@r7   c                    ddd t          d          fgt          j        t          j        dt
                     t          j                            dt                     t          j        t          j        dt                    }|d                                        fd} |t          j                   t          j        d         }t          j                    D ]%\  }}||k    r |t          |d	i                      &d S )
Nr7   r&   s   operate on patch repositorys   imports   initrc   c                     |                                  D ]e\  }}t          j        |          d         }|d         }|j        r/t	          j        | |t                    }|d                                        fd S r  )r`  r   parsealiasesrC  r   wrapcommandr  rB  )cmdtablecmdr   funcmqopts       r4   dotablezextsetup.<locals>.dotable  s    "..** 	# 	#JC&s++A.C8D{ *8S)DDE!HOOE""""	# 	#r7   zhgext.mqr+  )r   r   r*  r   tabler  r   summaryhooksrg  r  r  rB  sysmodulesr
   )r   r   r/  
thismoduleextname	extmoduler.  s         @r4   extsetupr7    s    5$"@ A ABCE8>9h???UK000"8>7FCCE	!HOOE# # # # # GHNZ(J(355 8 8
""GGIz2667778 8r7   s   reds   yellows   greens   blue bold underlines
   black bolds   red bold)r  r  r  r  s   qseries.guardeds   qseries.missingr  r0   ){__doc__r   r#  r  r2  mercurial.i18nr   mercurial.noder   r   r   r   mercurial.pycompatr	   r
   r   	mercurialr   r   r   r   r   r   r   r   r   r  r   r   r  r   r   r   r   r   r   r   r   r   r    r   mercurial.utilsr!   r"   r#   r  
seriesoptsr+  command
testedwithconfigtable
configitemr+  KeyErrorr.   loadrO   normpathr  rQ   rj   r~   r{   r   r   r   r  r   r   r!  CATEGORY_CHANGE_ORGANIZATIONr  r  r  CATEGORY_IMPORT_EXPORTr  r9  CATEGORY_REPO_CREATIONr  
remoteoptsrP  r0  CATEGORY_COMMITTINGr   r  r  rb  re  rk  walkopts
commitoptsrR  r  r  	diffopts2CATEGORY_FILE_CONTENTSrG  CATEGORY_CHANGE_MANAGEMENTry  r|  r1  rr   r  r  r{  r  ry  r  r  r  r  r  r  r  r  r  r  r  revsetpredicater&  i18nfunctionsr7  
colortabler1   r7   r4   <module>rS     s/  7 7t 
			 				  



                          
                                             .          /Zqq)L'M'MNO

)
H
%
%
 #
!Y!+..
 

	
   
 
	   
 
	   
 
	   .JOH 
. 
. 
.        JOGGIIx-----
. 	   $ =- - - - - - - -  	  ( ( (V# # #Lq" q" q" q" q" q" q" q"h, , ,$	 	 	 	 	U[ 	 	 	K  K  K  K  K  K  K  K \@	 	 	 		waa 2334A677AfII	
	 A#$$5     	
GT11EFFGHA&''5     @ 	
HdAA:;;<=
JA())5	     > 		{D!!$E"F"FG	wQQ455qqzzB	xqq!<==>A:;;AfII	
 
vtQQ>??@	waa 899: AGHH/#  &4 4' &4n  6 	
ND!!$>"?"?@AA/  ; ; ; 		gtQQDEEFA:;;		
 A:;;		
 A455AgJJ	
, -. A,--/7  :]2 ]2 ]2; :]2@ 	N< #A)**,  , , , 		z4#A!B!BC  A5     	Ao5	    . 	A5	  	F 	F 	F 	A5	    $7 7 7 		waa CDDE	xqq!KLLM	vtQQ>??@	~tQQ'M%N%NO	wQQ=>>'

K	~tQQ'M%N%NO	wQQ=>>'

K 	 
 A9::,!  $   % $ F 		waa CDDE	vtQQ>??@ALMM		
 ACDD		
 AABBAgJJ	
 AABB		
 A?@@AgJJ	
9#H I$J K%L AFGG,W, , ,Z [, ,Z> 	w((7+;;A'((/    ( 		waa CDDE	waa :;;< 	
 A8993	 	 	C C	 	CL 	 A788		
 
xqq!?@@A	lD!!$I"J"JK	 A#$$5    < 		waa >??@	waa 2334 AABB5  H0 H0 H0V 	A5	  - - - -$  $   	 A788		
 
xqq!ABBCA>??		
 
waa ABBC	vtQQ3445	xqq!IJJK	wQQ?@@!!G**MA>??		
 
lD!!$I"J"JK14 A9::5=  @% % %A @%P 		vtQQ1223	wQQ@AA11W::NA788		
 
xqq!MNNO	lD!!$I"J"JK A*++5!  $! ! !% $!H 	A#$$5	  4 4 4 4n 		y$"6 7 78	y$"C D DE A"##5     		waa 7889	wQQ566'

C	xqq!;<<=	xqq//0	  A>??5  ! ! !H 		waa 5667	y$"C D DE	fdAAJKKL	j$"> ? ?@	 A*++5
 
 
n n
 
nb 	
Jaa @AABCA!""5	  % % %P 		wqq!=>>?	i"? @ @A	y%#6!7!78	i"8 9 9:	i"> ? ?@	hqq!FGGH A5  m m m m`	 	 	g4 g4 g4T+ + +! ! !,* * * / / /  ,)+-- A A A 
8 8 8: !!.%#' 


s   C. .,DD