
    6h                       S r SSKJr  SSKrSSKrSSKrSSKrSSKJrJ	r	J
r
JrJrJrJr  SSKJr  SSKJrJrJr  SSKJrJrJrJrJrJrJrJrJrJ r!J"r"J#r#J$r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r.  SS	K/J0r0J1r1  S
r2Sr3/ SQr4Sr5 " S S5      r6S<S jr7S=S jr8 " S S5      r9S>S jr: " S S5      r;S?S jr<S@S jr=S?S jr>S?S jr?S@S jr@SAS jrASBSCS jjrBS?S jrCSDS jrDS?S  jrES?S! jrFS" rGS# rHS<S$ jrIS<S% jrJS?S& jrKS?S' jrLSES( jrMSFS) jrNSGS* jrOSHS+ jrPSGS, jrQS?S- jrRS?S. jrSSIS/ jrTSJS0 jrUSGS1 jrVS?S2 jrWS3 rXSKS4 jrY      SLS5 jrZ  SKS6 jr[S?S7 jr\S?S8 jr]S?S9 jr^S?S: jr_SMS; jr`g)Na@  save and restore changes to the working directory

The "hg shelve" command saves changes made to the working directory
and reverts those changes, resetting the working directory to a clean
state.

Later on, the "hg unshelve" command restores the changes saved by "hg
shelve". Changes can be restored even after updating to a different
parent, in which case Mercurial's merge machinery will resolve any
conflicts if necessary.

You can have more than one shelved change outstanding at a time; each
shelved change has a distinct name. For details, see the help for "hg
shelve".
    )annotationsN)AnyDictIterableIteratorListSequenceTuple   )_)binhexnullrev)	bookmarksbundle2changegroupcmdutilcontext	discoveryerrorexchangehglockmdiffmerge
mergestatepatchphasespycompatrepairscmutiltemplatefiltersutilvfs)dateutil
stringutils   shelve-backups   shelved)s   hg   patch   shelves   shelve@localhostc                  6    \ rS rSrSSS jjrS	S jrS
S jrSrg)ShelfDirT   c                    U(       a9  [         R                  " UR                  R                  [        5      5      U l        g [         R                  " UR                  R                  [        5      5      U l        g N)vfsmodr$   join	backupdir	shelvedir)selfrepofor_backupss      2/usr/lib/python3/dist-packages/mercurial/shelve.py__init__ShelfDir.__init__U   s?    zz$((--	":;DHzz$((--	":;DH    c                .    [        U R                  U5      $ r-   )Shelfr$   )r2   names     r5   getShelfDir.get[   s    TXXt$$r8   c                    U R                   R                  5       n/ n[        5       nU Hz  nUR	                  SS5      S   nXS;   a  M  UR                  U5        U R                  U5      nUR                  5       (       d  MX  UR                  5       nUR                  Xu45        M|     [        USS9$ ! [         a    / s $ f = f)z2return all shelves in repo as list of (time, name)   .r   r   T)reverse)r$   listdirFileNotFoundErrorsetrsplitaddr<   existsmtimeappendsorted)r2   namesinfoseenfilenamer;   shelfrG   s           r5   listshelvesShelfDir.listshelves^   s    	HH$$&E uH??4+A.D|HHTNHHTNE<<>>KKMEKK&  dD)) ! 	I	s   B2 2C C)r$   NF)r4   boolreturnNone)r;   bytesrS   r:   )rS   zList[Tuple[float, bytes]])__name__
__module____qualname____firstlineno__r6   r<   rO   __static_attributes__ r8   r5   r*   r*   T   s    <%*r8   r*   c                z    [         R                  " U 5      =(       a    U R                  R                  SS5      S:H  $ )Nr(   s   store   internal)r   supportinternaluiconfigr3   s    r5   _use_internal_phaserb   s   s1    t$ 	?GGNN9h/;>r8   c                b    [        U 5      (       a  [        R                  $ [        R                  $ r-   )rb   r   internalsecretra   s    r5   _target_phaserf   z   s    1$776??JV]]Jr8   c                      \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrS
 rSS jrSS jrSSS jjrSS jrS rS S jrS!S jrSS jrS rSrg)"r:   ~   zRepresents a shelf, including possibly multiple files storing it.

Old shelves will have a .patch and a .hg file. Newer shelves will
also have a .shelve file. This class abstracts away some of the
differences and lets you work with the shelf as a whole.
c                    Xl         X l        g r-   r$   r;   )r2   r$   r;   s      r5   r6   Shelf.__init__   s    	r8   c                V    U R                  S5      =(       d    U R                  SS5      $ )N   .shelve   .patch   .hg)_existsr2   s    r5   rF   Shelf.exists   s!    ||J'J4<<	6+JJr8   c                .   ^  [        U 4S jU 5       5      $ )Nc              3  t   >#    U  H-  nTR                   R                  TR                  U-   5      v   M/     g 7fr-   r$   rF   r;   ).0extr2   s     r5   	<genexpr> Shelf._exists.<locals>.<genexpr>   s)     Dt488??499s?33ts   58)all)r2   extss   ` r5   rp   Shelf._exists   s    DtDDDr8   c                     U R                  S5      [        R                     $ ! [         a%    U R                  S5      [        R                     s $ f = f)Nrm   rn   )_statstatST_MTIMErB   rq   s    r5   rG   Shelf.mtime   sF    	8::j)$--88  	8::i(77	8s   !$ ,AAc                R    U R                   R                  U R                  U-   5      $ r-   )r$   r   r;   r2   rw   s     r5   r~   Shelf._stat   s    xx}}TYY_--r8   c                ~    [         R                  " U R                  U R                  S-   5      R	                  U5        g Nrm   )r!   simplekeyvaluefiler$   r;   write)r2   rK   s     r5   	writeinfoShelf.writeinfo   s*    ""488TYY-CDJJ4Pr8   c                R    U R                   R                  U R                  S-   5      $ r   ru   rq   s    r5   hasinfoShelf.hasinfo   s    xxtyy:566r8   c                z    [         R                  " U R                  U R                  S-   5      R	                  5       $ r   )r!   r   r$   r;   readrq   s    r5   readinfoShelf.readinfo   s.    ))HHdii*,

$&	r8   c           	     t   [         R                  " U5      nUS:X  a  SnS nOSnSnUR                  5       n[        R                  " XU/S9n[         R
                  " XUS5      nU R                  R                  U R                  S-   5      n	[        R                  " UR                  UU	UU R                  US9  g )	Ns   01s   HG10BZs   HG20s   BZ)missingrootsancestorsofr(   ro   )compression)r   safeversion
unfilteredr   outgoingmakechangegroupr$   r/   r;   r   writebundler_   )
r2   r3   basesnode	cgversionbtyper   r   cgbundle_filenames
             r5   r   Shelf.writebundle   s    ++D1	EKEK %%4&
 ((IN((--		F(:;GGHH#	
r8   c           
        U R                   S-   nU R                  U5      n [        U5      n[        R                  " UR
                  XCU R                  5      nUS   n[        R                  " UUUSSU R                  R                  U5      -   US9  US   nXx:X  a  UR                  S   S   n	X   nUUR                  5         $ ! UR                  5         f = f)Nro   s   tip   unshelves   bundle:)sourceurltargetphases   revduplicates)r;   r$   rf   r   
readbundler_   r   applybundler/   changesclose)
r2   r3   trrM   fpr   genpretip	shelvectx	shelverevs
             r5   r   Shelf.applybundle   s    99v%XXh	'-K%%dggrTXXFC&\F"x!88' VI"JJ'78<	 O	HHJBHHJs   BC Cc                @    U R                  U R                  S-   U5      $ )Nrn   rj   )r2   modes     r5   
open_patchShelf.open_patch   s    xx		I-t44r8   c           	         UR                  5       n[        X5      n[        R                  " 5       n[        R
                  " UU/U[        R                  " SS9US9  UR                  S5        U$ )NTgitoptsmatchr   )	r   _optimized_matchioBytesIOr   
exportfiler   diffoptsseek)r2   r3   r   r   r   s        r5   patch_from_nodeShelf.patch_from_node   s]      ,ZZ\FD)	
 	
	r8   c                     U R                  XR                  5       S   5      $ ! [        [        R                  4 a    U R                  5       s $ f = f)N   node)r   r   rB   r   RepoLookupErrorr   )r2   r3   s     r5   
load_patchShelf.load_patch   sJ    	%''mmog.FGG!5#8#89 	%??$$	%s   !$ *AAc                    SS jnU" U5       H,  nUR                  U5      (       a  M  UR                  U5      s  $    [        R                  " S5      e)Nc              3     #    U v   U R                  SS5      u  p[        R                  " S5       H  nSXU4-  v   M     g 7f)Nr?   r   s   %s-%d.%s)rD   	itertoolscount)baserw   is      r5   gennames'Shelf._backupfilename.<locals>.gennames   s>     JD!,ID__Q'!TcN22 (s   A Aunreachable)r   rU   )rF   r/   r   ProgrammingError)r2   	backupvfsrM   r   ns        r5   _backupfilenameShelf._backupfilename   sK    	3 (#A##A&& ~~a(( $
 $$]33r8   c                N   UR                  5       (       d  UR                  5         [         Hv  nU R                  S-   U-   nU R                  R                  U5      (       d  M7  [        R                  " U R                  R                  U5      U R                  X5      5        Mx     g Nr?   )
isdirmakedirshelvefileextensionsr;   r$   rF   r#   renamer/   r   )r2   r   suffixrM   s       r5   movetobackupShelf.movetobackup   su      *Fyy4'&0Hxxx((HHMM(+((= +r8   c                t    [          H.  nU R                  R                  U R                  S-   U-   5        M0     g r   )r   r$   	tryunlinkr;   r   s     r5   deleteShelf.delete  s,    'CHHtyy4/#56 (r8   c                *    UR                  5       U R                  5       S      nUR                  5       $ ! [        [        R
                  4 aB    U R                  R                  U R                  S-   5      n[        R                  " XU5      s $ f = f)Nr   rn   )r   r   filesrB   r   r   r$   r/   r;   r   changedfiles)r2   r_   r3   ctxrM   s        r5   changed_filesShelf.changed_files
  sw    	://#DMMOG$<=C99;!5#8#89 	:xx}}TYY%:;H%%b99	:s   36 ABB)r;   r$   N)r$   
vfsmod.vfsr;   rU   rS   rT   rS   rR   )r{   rU   rS   rR   )rS   float)rw   rU   rS   rT   )rS   contextmod.changectx)s   rb)r   rU   )rS   z
io.BytesIO)r   r   rM   rU   rS   rU   )r   r   rS   rT   )rV   rW   rX   rY   __doc__r6   rF   rp   rG   r~   r   r   r   r   r   r   r   r   r   r   r   r   rZ   r[   r8   r5   r:   r:   ~   s_    KE8.Q7

4.5%4	7:r8   r:   c                P    [         R                  " X U   R                  5       5      $ )z
Create a matcher so that prefetch doesn't attempt to fetch
the entire repository pointlessly, and as an optimisation
for movedirstate, if needed.
)r!   
matchfilesr   )r3   r   s     r5   r   r     s"     dJ$4$4$677r8   c                  ,   \ rS rSr% SrSrSrSrSrSr	Sr
S	\S
'   S\S'   S\S'   S\S'   S\S'   S	\S'   S\S'   S	\S'   S\S'   \SS j5       r\S S j5       r\S!S j5       r\S 5       r\   S"                 S#S jj5       r\S$S j5       rSrg)%shelvedstatei  zHandle persistence during unshelving operations.

Handles saving and restoring a shelved state. Ensures that different
versions of a shelved state are possible and handles them appropriately.
   s   shelvedstate   keeps   nokeeps   :no-active-bookmark   interactiverU   r;   contextmod.workingctxwctxr   
pendingctxList[bytes]parentsnodestoremovebranchtorestorerR   keepactivebookmarkinteractivec                    [        US   5      US'   [        US   5      US'   US   R                  S5       Vs/ s H  o"(       d  M  [        U5      PM     snUS'   US   R                  S5       Vs/ s H  o"(       d  M  [        U5      PM     snUS'   gs  snf s  snf ! [        [        4 a/  n[        R
                  " [        R                  " U5      5      eSnAff = f)z@Some basic shelvestate syntactic verification and transformation   originalwctx
   pendingctx   parents       nodestoremoveN)r   split
ValueErrorKeyErrorr   CorruptedStater&   forcebytestr)clsdherrs       r5   _verifyandtransform shelvedstate._verifyandtransform7  s    	E!$Q%7!8Ao"1]#34Am-.z]-@-@-FL-F!VSV-FLAjM !"2 3 9 9$ ?# ?11A ?#A M# H% 	E&&z'>'>s'CDD	Es@   8B! 
BBB! 3
BBB! 
B! !C 1*CC c                P   UR                  U R                  5      n [        UR                  5       R	                  5       5      n UR                  5         U$ ! [
         a/  n[        R                  " [        R                  " U5      5      eSnAff = f! UR                  5         f = f)z.Read version information from shelvestate fileN)r$   	_filenameintreadlinestripr	  r   r  r&   r  r   )r  r3   r   versionr  s        r5   _getversionshelvedstate._getversionD  s     XXcmm$	"++---/0G HHJ	  	E&&z'>'>s'CDD	E HHJs#   'A 
B!*BBB B%c                    / SQnUR                  U R                  5      n0 n U H#  nUR                  5       R                  5       XE'   M%     UR	                  5         U$ ! UR	                  5         f = f)z9Read the old position-based version of a shelvestate file)	s   version   namer  r  r  r     branchtorestorer   
   activebook)r$   r  r  r  r   )r  r3   keysr   r  keys         r5   _readoldshelvedstate._readoldP  sd    

 XXcmm$	,,.  HHJ HHJs   )A A0c                   U R                  U5      nX R                  :  a  U R                  U5      nOgX R                  :X  a9  [        R                  " UR
                  U R                  5      R                  SS9nO[        R                  " [        S5      5      eU R                  U5         U " 5       nUS   Ul        XS      Ul        XS      Ul        US   Ul        US   Ul        UR#                  S	S
5      Ul        UR#                  S5      U R&                  :H  Ul        S
Ul        UR#                  SS
5      U R,                  :w  a  UR#                  SS
5      Ul        UR#                  S5      U R.                  :H  Ul        U$ ! [        R2                  [4        4 a/  n[        R6                  " [8        R:                  " U5      5      eS nAff = f)NT)firstlinenonkeyvalsI   this version of shelve is incompatible with the version used in this repor  r  r  r  r  r  r8   r   r  r   )r  _versionr!  r!   r   r$   r  r   r   Abortr   r  r;   r   r   r   r   r<   r   _keepr   r   _noactivebook_interactiver  r   r
  r  r&   r  )r  r3   r  r  objr  s         r5   loadshelvedstate.loadl  s   //$'\\!T"A$**488S]]CHH#' I A ++:  	"	E%CzCHo./CH!M"23CNJ-CK !"2 3C"#%%(:C"@CuuW~2CH!$Cuu]C(C,=,==%&UU=#%>"eeN3s7G7GGCO 
 %%x0 	E&&z'>'>s'CDD	Es   ,CF G *G

Gc
                v   U[        UR                  5       5      [        UR                  5       5      SR                  UR                  R	                  5        V
s/ s H  n
[        U
5      PM     sn
5      SR                  U Vs/ s H  n[        U5      PM     sn5      UU(       a  U R
                  OU R                  U=(       d    U R                  S.nU	(       a  U R                  US'   [        R                  " UR                  U R                  5      R                  USU R                  -  S9  g s  sn
f s  snf )Nr  )r  r  r  r  r  r  r   r  r   s   %d)	firstline)r   r   r/   dirstater   r'  _nokeepr(  r)  r!   r   r$   r  r   r%  )r  r3   r;   originalwctxr   r   r   r   
activebookr  pr   rK   s                r5   saveshelvedstate.save  s      !2!2!45z01		4==3H3H3J"K3Ja3q63J"KL"ii(GAQ(GH /"&SYYCKK%:):):	
 #&#3#3D ""488S]];AAUS\\1 	B 	
 #L(Gs   D1D6c                L    UR                   R                  U R                  SS9  g )NT)ignoremissing)r$   
unlinkpathr  )r  r3   s     r5   clearshelvedstate.clear  s    CMM>r8   r[   N)r  Dict[bytes, Any]rS   rT   rS   r  )rS   r;  )Fr8   F)r;   rU   r1  r   r   r   r   r   r   rU   r   rR   r2  rU   r  rR   rS   rT   r   )rV   rW   rX   rY   r   r%  r  r'  r0  r(  r)  __annotations__classmethodr  r  r!  r+  r4  r9  rZ   r[   r8   r5   r   r     s;    HIEG*M!L K
$$
J
E 
E 	 	  6 ! !F  !
 
 ,	

 )
 #
 
 
 
 
 

 
8 ? ?r8   r   c                   U R                   R                  SS5      n[        U SS9nUR                  5       nUS:  a  U[	        U5      :  a  X1S-
     S   nOS nX1S   H+  u  pVXT:X  a  M  UR                  U5      R                  5         M-     g )Nr(   s
   maxbackupsT)r4   r   r   )r_   	configintr*   rO   lenr<   r   )r3   
maxbackups
backup_dirhgfilesbordermtimerG   r;   s          r5   cleanupoldbackupsrF    s    ""9m<J$D1J$$&GA~*s7|31n-a0{+t##%	 ,r8   c                X    U R                   nU(       a  [        R                  " U 5        U$ r-   )_activebookmarkr   
deactivate)r3   r   s     r5   _backupactivebookmarkrJ    s$    ))NT"r8   c                @    U(       a  [         R                  " X5        g g r-   )r   activate)r3   marks     r5   _restoreactivebookmarkrN    s    4& r8   c                "   U R                   nUR                  5       nS[        U5      ;  d   e S Ul        UR	                  5         U?U R                  5       b   eU R                   R                  S5        UR                  US5        g! U?f = f)z@Abort current transaction for shelve/unshelve, but keep dirstate
invalidatec                     g r-   r[   r[   r8   r5   <lambda>#_aborttransaction.<locals>.<lambda>  s    r8   N)r/  branchvarsrP  abortcurrenttransactionr   	setbranch)r3   r   dscurrent_branchs       r5   _aborttransactionr[    s     
B YY[NtBx''' %

M ""$,,,MMLL& Ms   B
 
Bc                "  ^ U4S jnUR                  S5      nU R                  =(       d    UR                  5       =(       d    SmTR                  SS5      mTR                  SS5      mTR	                  S5      (       a  TR                  SSS5      mU(       a  [        U 5      R                  U5      R                  5       (       a$  [        S	5      U-  n[        R                  " U5      eSU;   d  SU;   a  [        R                  " [        S
5      5      eUR	                  S5      (       a  [        R                  " [        S5      5      e U$ [        U 5      nU" 5        H,  nUR                  U5      R                  5       (       a  M)  Un  U$    U$ )z/Decide on the name this shelve is going to havec               3  b   >#    Tv   [         R                  " S5       H  n STU 4-  v   M     g 7f)Nr   s   %s-%02d)r   r   )r   labels    r5   r   getshelvename.<locals>.gennames  s-     #Aqz)) $s   ,/r  s   default   /   _   \r?   r   s*   a shelved change named '%s' already existss,   shelved change names can not contain slashess+   shelved change names can not start with '.')
r<   rH  rT  replace
startswithr*   rF   r   r   r&  )	r3   parentr   r   r;   e	shelf_dirr   r^  s	           @r5   getshelvenamerh    sS   *
 88GD  AFMMOAzEMM$%EMM%&EdD!,D>d#**,,?@4GA++a.  4<5D=++AB  ??4  ++a NOPP ! K TN	A==#**,,K 
 Kr8   c              #    #    [         1n[        R                  " 5       nUR                  U 5        U(       a  UR	                  5       n U R                  5       v   U R                  5        HS  nUR                  5       nXA;  d  M  UR                  U5        UR                  5       (       d  MB  UR                  U5        MU     U(       a  M  gg7f)zereturn all mutable ancestors for ctx (included)

Much faster than the revset ancestors(ctx) & draft()N)
r   collectionsdequerH   popleftr   r   revrE   mutable)r   rL   visitre  rm  s        r5   mutableancestorsrp    s      9DE	LL
mmohhjkkmF**,C>>##LL( $ %s   A=C$C+C	Cc                8   ^ ^^ UU 4S jmU4S jnU(       a  U$ T$ )Nc           
     `  > [        US5      nU(       a'  UR                  R                  SsoaR                  l        [        U5      nSU0n Sn	T
(       a,  [        R
                  " SSS0[        R                  " U5      D6n	UR                  R                  U5         UR                  U[        UR                  S5      UU	TS9sS S S 5        U(       a  WUR                  l        $ $ ! , (       d  f       O= f U(       a  WUR                  l        g g ! U(       a  WUR                  l        f f = f)	NmqFs   phasess
   new-commiteditforms   shelve.shelve   date)editorextrar[   )hasattrrs  checkappliedrf   r   getcommiteditorr   	strkwargsr_   configoverridecommit
shelveuserr<   )r_   r3   messager   r   hasmqsavedr   	overrideseditor_rw  rx  s             r5   
commitfunc!getcommitfunc.<locals>.commitfunc"  s   d#*.''*>*>'E77'#D)/=		-G!11 -191C1CD1I ''	2{{HHW%" #  32 ',$  322 ',$ u',$ s%   AD 'C&	D &
C40D D-c                   > [         R                  " U5      n[        R                  " US   U0 5      nUS   nT" XXTU5      $ )Nr?      message)r   byteskwargsr!   r   )r_   r3   patsr   r   r  r  s         r5   interactivecommitfunc,getcommitfunc.<locals>.interactivecommitfunc<  sB    ##D)d4j$3z""GD99r8   r[   )rx  r  rw  r  r  s   ` ` @r5   getcommitfuncr  !  s    -4: %0 ?Z?r8   c                
   UR                  [        R                  " US    X#5      S9nUR                  (       a1  U R                  [	        S5      [        UR                  5      -  5        g U R                  [	        S5      5        g )N)r   s4   nothing changed (%d missing files, see 'hg status')
s   nothing changed
)statusr!   r   deletedr   rA  )r_   r3   r  r   r   s        r5   _nothingtoshelvemessagingr  E  sb    ;;W]]4:tB;CD||
		FG$,, 	

 			!()*r8   c           
     n   S[        U5      0n[        U 5      R                  U5      nUR                  U5        [	        [        X   5      5      nUR                  XU5        UR                  S5       n[        R                  " X/U[        R                  " SS9US9  S S S 5        g ! , (       d  f       g = f)Nr   s   wbTr   r   )r   r*   r<   r   listrp  r   r   r   r   r   r   )r3   r   r;   r   rK   rN   r   r   s           r5   _shelvecreatedcommitr  P  s    SYDTNt$E	OOD!$*-.E	d4(			%	 B&"5>>d#;5	
 
!	 	 s   2+B&&
B4c                    U R                  [        R                  " U S    X5      SS9nUR                  (       a=  SR	                  UR                  5      US'   U S    R                  UR                  5        g g )NT)r   unknown       shelve_unknown)r  r!   r   r  r/   rE   )r3   r  r   rx  ss        r5   _includeunknownfilesr  \  s[    '--T
D?NAyy#(::aii#8 T
qyy! r8   c                \    [        U 5      (       a  UR                  5         g [        X5        g r-   )rb   r   r[  )r3   r   s     r5   _finishshelver  c  s    4  

$#r8   c                    UR                  5          [        R                  " U5        [        XX#5      sSSS5        $ ! , (       d  f       g= f)z$subcommand that creates a new shelveN)wlockr   checkunfinished_docreatecmd)r_   r3   r  r   s       r5   	createcmdr  j  s-    	%Bd1 
s	   "=
Ac                   US    nUR                  5       nUS   nUR                  5       nUR                  5       [        :w  a'  SUR	                  5       R                  SS5      S   -  nOSnUR                  S5      (       d  XS'   S =n	=p UR                  5       n	UR                  SS S	9n
UR                  S
S5      nUR                  SS5      =(       a    UR                  SS5      (       + n[        XU5      n[        U5      nSS0nU(       a0  UR                  R                  U5         [        XX?5        S S S 5        [        U5      (       aK  [        X#5      (       d;  UR                  R!                  US   R                  5       UR#                  5       5        [%        XSS9nU(       d  [&        R(                  " XUX#5      nOA[&        R*                  " U UUS S[&        R,                  /UQ70 [.        R0                  " U5      D6nU(       d/  [3        XX#5         [5        X5        [6        R8                  " X5        g[;        UU5      n[=        UUUU5        U R?                  [A        S5      U-  5        US   (       a<  UR                  RC                  U5         [D        RF                  " XU5        S S S 5        Oh[H        RJ                  " XRM                  5       5        [N        RP                  RS                  U5      nURU                  5       (       d  URW                  5         XqS   R                  5       :w  a9  [        X#5      (       d)  UR                  R!                  XqR#                  5       5        [Y        X5        [5        X5        [6        R8                  " X5        g ! , (       d  f       GNl= f! , (       d  f       N= f! [5        X5        [6        R8                  " X5        f = f)Nr   s   changes to: %s   
r   s   (changes in empty repository)r  r(   c                    g r-   r[   xs    r5   rR  _docreatecmd.<locals>.<lambda>  s    $r8   reportr   Fs   unknowns	   addremover]   r?   T)rw  s   shelved as %s
r   )-r   rT  rm  r   descriptionr  r<   r   transactionrh  rJ  r/  changing_filesr  _iswctxonnewbranch_isbareshelverX  rW  r  r   r~  dorecordrecordfilterr   r|  r  rN  lockmodreleaser   r  r  r   changing_parentsr!   movedirstater   updater   mergestatemodr   r   unresolvedcountresetr  )r_   r3   r  r   r   r   re  
origbranchdescr   r   r   r  includeunknownr;   rx  r  r   r   mss                       r5   r  r  q  s*   :DllnGQZFJzz|w 6#5#5#7#=#=eQ#G#JJ/88JZ!%%D%2?"yy{ i?hh~u5*e4 
TXX%>
 :
 T40.t4i(--d3$T= 4 d##M$,E,E MM##T
!!#T%<%<%> #5dC
>>"JCD##$$	 	 $$T*	D %b;( 	t4!' !t,T4u5
		!&'$./=//5$$T59 65 IIdKKM*))..t4B%%''
d**,,]45N5NMM##J0G0G0IJdt4!_ 43B 65 	t4!sF   B O ,N9C!O =AO N01CO 
N-(O 0
N>:O #O$c                    U (       + =(       aS    UR                  SS5      (       + =(       a5    UR                  SS5      (       + =(       a    UR                  SS5      (       + $ )Nr   Fs   includes   exclude)r<   )r  r   s     r5   r  r    sP     	,//	,U++	, U++	r8   c                P    U S    R                  5       U S   R                  5       :g  $ r   )rT  ra   s    r5   r  r    s'    :$t*"3"3"555r8   c                \   UR                  5          [        U5      n[        R                  " UR                  R	                  [
        5      5      nUR                  5        H0  u  pEUR                  U5      R                  U5        [        U5        M2     SSS5        g! , (       d  f       g= f)z#subcommand that deletes all shelvesN)
r  r*   r.   r$   r/   r0   rO   r<   r   rF  )r_   r3   rg  r   _mtimer;   s         r5   
cleanupcmdr    so     
TN	JJtxx}}Y78	%113LFMM$,,Y7d# 4 
s   BB
B+c                   U(       d  [         R                  " [        S5      5      eUR                  5          [        R
                  " UR
                  R                  [        5      5      nU Hp  n[        U5      R                  U5      nUR                  5       (       d"  [         R                  " [        S5      U-  5      eUR                  U5        [        U5        Mr     SSS5        g! , (       d  f       g= f)z)subcommand that deletes a specific shelves   no shelved changes specified!   shelved change '%s' not foundN)r   
InputErrorr   r  r.   r$   r/   r0   r*   r<   rF   r   rF  )r_   r3   r  r   r;   rN   s         r5   	deletecmdr    s    q!ABCC	JJtxx}}Y78	DTN&&t,E<<>>&&67$>  y)d#  
s   B*C**
C8c                T   [        U5      nSnU R                  5       (       d  U R                  5       nSnU R                  S5        [	        U5      nUR                  5        GH0  u  pxU(       a  X;  a  M  U R                  XS9  SnU R                  (       a  U R                  S5        MI  U R                  SS[        U5      -
  -  5        Sn	[        R                  " U5      n
S	[        R                  " U
S
S9-  nU R                  USS9  U R                  SS[        U5      -
  -  5        U	S-  n	UR                  U5      R                  U5       n UR                  5       nU(       d  OhUR!                  S5      (       dP  UR#                  5       nU R%                  5       (       a  [&        R(                  " XU	-
  5      nU R                  U5        OM  U R                  S5        US   (       d  US   (       d   SSS5        GM  UR+                  5       nUS   (       a5  [,        R.                  " [0        U5       H  u  nnU R                  UUS9  M     US   (       a.  [,        R2                  " XS9 H  u  nnU R                  UUS9  M     SSS5        GM3     g! , (       d  f       GMF  = f)z,subcommand that displays the list of shelvesP   s   shelve.newestr(   )r^  s   shelve.namer  r     s   (%s)T)abbrevs
   shelve.age      #r'   s   statN)width)rC   plain	termwidthpagerr*   rO   r   quietrA  r%   makedater"   ager<   r   r  rd  rstrip	formattedr&   ellipsis	readlinesr   	difflabeliter
diffstatui)r_   r3   r  r   r  	namelabelrg  rG   r;   useddater  r   liner  	difflineschunkr^  s                     r5   listcmdr    s   t9DE88:: IHHYI ,,.D$
'"	88HHUO
c$i()  '++D>>
M*
c#h'(
]]4 ++D1R{{}t,,;;=D||~~)224FHHTN  HHUONd7m 21 IH~$)OOD)$DLE5HHU%H0 %EG}$)$4$4Y$LLE5HHU%H0 %M' 21 / 21s   B(JBJ
J'	c                n   [        U5      n[        U5      S:X  a@  UR                  5       nU(       d  [        R                  " [        S5      5      eUS   u  pgU/nU HI  nUR                  U5      R                  5       (       a  M)  [        R                  " [        S5      U-  5      e   [        XX#5        g)z subcommand that displays shelvesr   s   there are no shelves to shows   cannot find shelf %sN)	r*   rA  rO   r   r&  r   r<   rF   r  )	r_   r3   r  r   rg  shelvesrG   r;   	shelfnames	            r5   	patchcmdsr    s    I
4yA~'')++a ?@AAajv	}}Y'..00++a 789DEE  Bd!r8   c                    UR                   U R                  R                  5       :w  a  [        R                  " [	        S5      5      eg)z'check parent while resuming an unshelves5   working directory parents do not match unshelve stateN)r   r/  r   r&  r   )r3   states     r5   checkparentsr  *  s:    }}--//kkFG
 	
 0r8   c                    [         R                  U5      nUR                  S5      c  UR                  US'   U$ ! [         a#    [
        R                  " U[        S5      5         g [        R                   a  nU R                  [        R                  " U5      S-   5        UR                  S5      (       a*  [        S5      n[        S5      n[        R                  " XVS9eUR                  S5      (       a4  [         R                  U5        [        R                  " [        S	5      5      e[        R                  " S
5      eS nAff = f)Nr   r   r     continues   corrupted shelved state files:   please run hg unshelve --abort to abort unshelve operationhint   abortsp   could not read shelved state file, your working copy may be in an unexpected state
please update to some commit
z=a corrupted shelvedstate exists without --abort or --continue)r   r+  r<   r   rB   r   wrongtooltocontinuer   r   r  debugr   bytestrr&  r9  r   )r_   r3   r   r  r  msgr  s          r5   _loadshelvedstater  2  s   !!$'88G$!JJDM :##D!K.9 
!!#&./88K  34CD ++c--XXht$++6  ((O 's   7: *E&E9CEEc           	        UR                  5           [        X5        [        R                  " UR                  5        UR
                  (       a:  UR
                  UR                  ;   a   [        R                  " XR
                  5        [        XUR                  UR                  5        [        U5      (       d!  [        R                  " XUR                  SSS9  [        R!                  U5        U R#                  [%        S5      UR&                  -  5         SSS5        g! [        R!                  U5        U R#                  [%        S5      UR&                  -  5        f = f! , (       d  f       g= f)z-subcommand that abort an in-progress unshelveFr(   backuptopics   unshelve of '%s' aborted
N)r   r  r   clean_updater   r   
_bookmarksr   rL  
mergefilesr   rb   r    r  r   r   r9  warnr   r;   r_   r3   r  s      r5   unshelveabortr  R  s    		C%u//0##(<(<(O""4)=)=>rU-=-=>&t,,e11%y t$GGA34uzzAB 
 t$GGA34uzzAB 
s#   E"CD!<E"!>EE""
E0c                    UR                  5          [        XSS05      n[        XU5      sSSS5        $ ! , (       d  f       g= f)z(logic to  abort unshelve using 'hg abortr  TN)r  r  r  r  s      r5   hgabortunshelver  e  s0    	!"Xt,<=Ru- 
s	   5
Ac                    U R                  SS05         [        R                  " XR                  5       5        [        R
                  " XU5        SSS5        g! , (       d  f       g= f)zHupdates to wctx and merges the changes from shelvectx into the
dirstate.   uis   quietTN)r}  r   r  r   r   revert)r_   r3   r   r   s       r5   r  r  l  sD     
		-t4	5
		$		$r+ 
6	5	5s   <A
A'c                    U(       ae  X!R                   R                  5       :w  aG  UR                   R                  X!R                  5       5        U R	                  [        S5      U-  5        g g g )Ns&   marked working directory as branch %s
)r/  rT  rX  rW  r  r   )r_   r3   r   s      r5   restorebranchr  t  sT    ?mm.B.B.DD1H1H1JK
		89OK	
 Er8   c                    UR                  S5      (       dh  [        R                  " UR                  R                  [        5      5      n[        U5      R                  U5      R                  U5        [        U5        gg)z&remove related files after an unshelver   N)r<   r.   r$   r/   r0   r*   r   rF  )r_   r3   r;   r   r   s        r5   unshelvecleanupr  |  sV    88GJJtxx}}Y78	4 --i8$ r8   c           
     x   UR                   nUR                  nUR                  5          [        X5        [        R
                  R                  U5      nUR                  5       (       a'  [        R                  " [        S5      [        S5      S9eXR                  S      nUR                  nUR                  R                  U5         UR                  UR                  R!                  5       UR"                  5        UR                  R%                  UR'                  5       5        SSS5        [)        U5      n	SU	0n
UR*                  R-                  U
S5         UR                  R                  U5         UR                  UR                  S   UR"                  5        SSS5        [/        XXuXC5      u  pSSS5        Wc)  UR                  n[        S	5      nU R1                  U5        OUR2                  R5                  U5        X   n[6        R8                  " U5        [;        XUR<                  U5        [?        XUR@                  5        [C        U5      (       d!  [D        RF                  " XUR2                  S
SS9  [H        RK                  U5        W(       d  [M        XUR                  U5        [O        XRP                  5        U R1                  [        S5      UR                  -  5        SSS5        g! , (       d  f       GN= f! , (       d  f       GNo= f! , (       d  f       GNj= f! , (       d  f       g= f)z.subcommand to continue an in-progress unshelves$   unresolved conflicts, can't continues/   see 'hg resolve', then 'hg unshelve --continue'r  r   Nrt  r   r   <   note: unshelved changes already existed in the working copy
Fr(   r  s   unshelve of '%s' complete
))r  r;   r   r  r  r   r   r  r   r&  r   r   r   r/  r  
setparentsr   nullidr   rW  rf   r_   r}  _createunshelvectxr  r   rH   r   r  r  r   r  r   rb   r    r  r   r9  r  rN  r   )r_   r3   r  r   r  basenamer  r   r   r   r  newnodeispartialunshelver  s                 r5   unshelvecontinuer    sk    ##KzzH	T!%%**40++9:IJ 
 q)*	%%
]]++D1OOE,,113T[[AMM 7 7 9: 2 $D)/=	WW##I{;//5a 0$++> 6);){*&G < ?((I)C IIcN &&w/IZ 2UZZ3b 5 56"4((LL%--e9 	4  Bejj$7t%9%9:
		!23ejj@Ac 
 21 65 <;% 
sV   BL+AK5&3L+L5*LL6D6L+5
L	?L+
LL
L(	#L++
L9c                    UR                  5          [        XSS05      n[        XUSUR                  05      sSSS5        $ ! , (       d  f       g= f)z,logic to resume unshelve using 'hg continue'r  Tr   N)r  r  r  r   r  s      r5   hgcontinueunshelver    s;    	!"[$,?@%'5::1FG 
s   'A
Ac                   UR                  5       n[        UR                  5      nUR                  (       d%  UR                  (       d  UR                  (       d  X54$ U R                  [        S5      5        SS0n[        USSS9n0 nSUS'   UR                  S5      US'   U R                  S	S
05         [        R                  " XU/ U5      n	SSS5        UW	   nX54$ ! , (       d  f       N= f)zETemporarily commit working copy changes before moving unshelve commitsL   temporarily committing pending changes (restore with 'hg unshelve --abort')
r]   r(   F)rx  r  rw  s    pending changes temporary commitr  rv  r  TN)r  	frozensetaddedmodifiedremovedr   r  r<   r}  r   r~  )
r_   r3   r   tmpwctxr  addedbeforerx  r  tempoptsr   s
             r5   _commitworkingcopychangesr    s     	AAGG$KJJ!''QYY##II	6	
 )$EUeLJH>HZ)HW			-t4	5~~b
BA 
64jG 
6	5s   3C
C+c                   UR                  5       nSn[        U5      R                  U5      nUR                  5       (       a  UR	                  5       S   nUb  XA;  a`  U R                  SS05         UR                  X5      nSSS5        Uc,  S[        WR                  5       5      0nUR                  U5        UW4$ X   nX4$ ! , (       d  f       NH= f)z5Recreate commit in the repository during the unshelveNr   r  T)
r   r*   r<   r   r   r}  r   r   r   r   )r_   r3   r   r  r   rN   r   rK   s           r5   _unshelverestorecommitr    s    ??DDTNx(E}}~~(|t' 1489))$3I : <S!123DOOD! ? J	? :9s   0C
Cc                `   UR                  5       US'   SUS'   / nU(       dN  UR                  UR                  5       UR                  5       UR                  5       UR	                  5       S9nUS4$ [        UR                  5       SSS9n[        R                  " U UUSS[        R                  /UQ70 [        R                  " U5      D6nUR                  UR                  5       UR                  5       UR                  5       S9n	U	(       a  [        X5      n
[        XX:5        U[        U	5      4$ )	aA  Handles the creation of unshelve commit and updates the shelve if it
was partially unshelved.

If interactive is:

  * False: Commits all the changes in the working directory.
  * True: Prompts the user to select changes to unshelve and commit them.
          Update the shelve with remaining changes.

Returns the node of the new commit formed and a bool indicating whether
the shelve was partially unshelved.Creates a commit ctx to unshelve
interactively or non-interactively.

The user might want to unshelve certain changes only from the stored
shelve in interactive. So, we would create two commits. One with requested
changes to unshelve at that time and the latter is shelved for future.

Here, we return both the newnode which is created interactively and a
bool to know whether the shelve is partly done or completely done.
r  Ts   interactive-unshelve)textrx  userr  F)r  rw  N)r  rx  r  )r  r~  rx  r  r  r  r   r  r  r   r|  r   r  rR   )r_   r3   r   r  r  r   r  r  r  snodems              r5   r
  r
    s,   . !,,.D$(D	 !D++&&(//#!!	  
 ~y0d4PJ
	 
	 

T
"	G KK""$oo^^  E
 T)T(6DKr8   c                b   UR                  S5      nUR                  5       UR                  5       R                  5       :X  a  U(       d  US4$ UR                  SS5      [        R                  S.nUR
                  R                  US5         U R                  [        S5      5        [        R                  " UU/ SQS	S
9nUR                  (       a  UR                  5         [        U[        U5      5       Vs/ s H  oR                  R                  U5      PM     nn[         R#                  UUUUUU	UR                  S5      U
U5	        [$        R&                  " S5      eUR(                  R+                  U5         UR-                  UR                  5       UR.                  5        SSS5        [1        XXX5      u  nnUc  Un[        S5      nU R                  U5        OUU   n[        R2                  " U5        SSS5        UU4$ s  snf ! , (       d  f       Nl= f! , (       d  f       UW4$ = f)zBRebase restored commit from its original location to a destinationr   F   toolr8   )r   s
   forcemergert  r   s   rebasing shelved changes
)s   working-copys   shelved changes   parent of shelved changeT)labelskeepconflictparentr   Nr  )r<   r   p1r   re   r_   r}  r  r   r   graftr  r   rangerA  	changelogr   r4  r   ConflictResolutionRequiredr/  r  r  r	  r
  r  )r_   r3   r   r   	oldtiprevr  pctxr  r   r   r   r  r  statsrm  r   r  r  r  s                      r5   _rebaserestoredcommitr.  -  s     ((>*K||~,,..{ % !%# 6$*MMI 
			;	7
		!123
  $	
   HHJ 5:)SY4O4OS##C(4O   !
 22;??]]++D1OOGLLNDKK8 2%7i;&
"" ?I)C IIcNWILL!] 
8` '''C  21? 
8	7` '''s9   A,H8$HAH;+H&AHH
H	H
H.c                   UR                  5       R                  S5      nU(       d  g [        UR                  S5      5      n[        U R	                  5       R
                  5      nXC-  U-
  nU S    R                  U5        g )Nr  r  )rx  r<   r  r  r  r  forget)r3   r   r  shelveunknown
addedaftertoforgets         r5   _forgetunknownfilesr4  z  sl     OO%))*;<Mm11%89M4;;=../J*k9HJhr8   c                0    [        X5        [        X5        g r-   )rN  r[  )r3   r+  r   r   s       r5   _finishunshelver6    s    40 dr8   c                    [        UR                  5       R                  5      n[        UR                  5       5      nUR	                  U5      nU(       a*  [        S5      n[        S5      n[        R                  " XgS9eg)zUCheck potential problems which may result from working
copy having untracked changes.s$   shelved change touches missing filess,   run hg status to see which files are missingr  N)rC   r  r  r   intersectionr   r   r&  )r_   r3   r   	wcdeletedshelvetouchedr8  r   r  s           r5   _checkunshelveuntrackedproblemsr;    sh     DKKM))*I	)*M))-8L56@Akk!'' r8   c                   [         R                  " U5      nUR                  S5      nUR                  S5      nUR                  S5      nU(       d  U(       d  [        R                  " U5        [        U5      nUR                  S5      (       a  UR                  US   5        U(       a5  UR                  S5      (       a  [        R                  " [        S5      5      eU(       d  U(       Ga   U(       a&  U(       a  [        R                  " [        S5      5      eU(       a  [        R                  " [        S5      5      eU(       a1  UR                  S	S
5      (       a  U R                  [        S5      5        [        XU5      nU(       a  [        XU5      $ U(       a&  U(       a  [        R                  " [        S5      5      eU(       a  [        XXs5      $ [        R                  " S5      e[        U5      S:  a  [        R                  " [        S5      5      eU(       de  [!        U5      R#                  5       nU(       d  [        R$                  " [        S5      5      eUS   S   nU R'                  [        S5      U-  5        OUS   n[!        U5      R                  U5      R)                  5       (       d"  [        R                  " [        S5      U-  5      e[+        XX5      $ )Nr  r  r   r  r   s,   --keep on --interactive is not yet supporteds"   cannot use both abort and continues:   cannot combine abort/continue with naming a shelved changer"  Fs   tool option will be ignored
s(   cannot use both continue and interactivez$neither abort nor continue specifiedr   s&   can only unshelve one change at a times   no shelved changes to apply!r   s   unshelving change '%s'
r  )r   r  r<   r   r  r  rH   r   r  r   r  r  r  r  r   rA  r*   rO   
StateErrorr  rF   _dounshelve)	r_   r3   shelvedr   abortf	continuefr  r  r  s	            r5   unshelvecmdrB    s:   %DXXhF%I((>*K)%7mGxxtG}%txx((=>
 	
 i""1%J#KLL""/  dhhw..GGA678!"D1 511;""=>  #Be::
 (()OPP	W	q!JKLL4.,,.""1%D#EFF1:a=
		!/08;<1:D>h'..00q!ABXMNNr00r8   c                   UR                  5       nS =pE UR                  5       nUR                  SS S9n[        U5      nUS   n[	        U5      n[        XX75      u  p[        XXR5      u  p[        XU5        SnUR                  5       UR                  5       R                  5       :w  a  UR                  5       n[        U UUUUUUU	UUU5      u  pSUR                  SS5      0nU R                  US5         [        XX{5        S S S 5        [        XU5        [        R!                  U5        [#        XXX5        UR$                  R'                  U5         [)        XU
5        S S S 5        U(       d  [+        XX#5        U(       a  UR-                  5         [.        R,                  " U5        g ! , (       d  f       N= f! , (       d  f       N`= f! U(       a  UR-                  5         [.        R,                  " U5        f = f)Nr   c                    g r-   r[   r  s    r5   rR  _dounshelve.<locals>.<lambda>  s    Dr8   r  r?   r8   r#  r"  )r   r   r  rA  rJ  r  r  r;  rT  r&  r.  r<   r}  r  r  r   r9  r6  r/  r  r4  r  r  r  )r_   r3   r  r   r   r   r+  r,  r   r  r  r   r   r  r  s                  r5   r>  r>    s   ??DD.yy{k.AI	Dz /t484N02H')<!6!6!88'..0O'<(
$	 ,TXXgs-CD	y+6r1 7b04 <]]))$/= 0 Bh5JJL 76
 0/
 JJLs=   C#G 8F+AG F<"G +
F95G <
G
G /G<r   r<  )r   rU   r   )rS   rU   )rS   zIterator[bytes]rQ   )r  rR   rw  rR   )r   rU   r;   rU   rS   rT   )r  zIterable[bytes]rS   rT   )r  zSequence[bytes]rS   rT   )r  r   rS   rT   )rS   r   )r   rU   rS   rT   )r;   rU   rS   rT   )r  rU   )r  rU   r  rR   rS   zTuple[bytes, bool])r  rU   rS   rT   )ar   
__future__r   rj  r   r   r   typingr   r   r   r   r   r	   r
   i18nr   r   r   r   r    r   r   r   r   r   
contextmodr   r   r   r   r   r  r   r   r   r  r   r   r   r    r!   r"   r#   r$   r.   utilsr%   r&   r0   r1   r   r  r*   rb   rf   r:   r   r   rF  rJ  rN  r[  rh  rp  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r.  r4  r6  r;  rB  r>  r[   r8   r5   <module>rL     s    #  	      
     .
 		3  !
* *>KR: R:j8S? S?l&'
'4%P)$!@H+	
"$2N"b6$$ ,1^""
@C&.,
 7BtH 2*7 #(7 7;7 7 tJ( J(Z	  	(81v1r8   