
    q&f@                        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
 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" ddl#m$Z$m%Z% dZ&d	Z'g d
Z(dZ) G d d      Z*d Z+d Z, G d d      Z-d Z. G d d      Z/d Z0d Z1d Z2d Z3d Z4d Z5d:dZ6d Z7d Z8d Z9d Z:d  Z;d! Z<d" Z=d# Z>d$ Z?d% Z@d& ZAd' ZBd( ZCd) ZDd* ZEd+ ZFd, ZGd- ZHd. ZId/ ZJd0 ZKd1 ZLd2 ZMd3 ZNd4 ZOd5 ZPd6 ZQd7 ZRd8 ZSd9 ZTy);a@  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".
    N   )_)binhexnullrev)	bookmarksbundle2changegroupcmdutil	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                        e Zd ZddZd Zd Zy)ShelfDirc                     |r8t        j                  |j                  j                  t                    | _        y t        j                  |j                  j                  t                    | _        y N)vfsmodr   join	backupdir	shelvedir)selfrepofor_backupss      2/usr/lib/python3/dist-packages/mercurial/shelve.py__init__zShelfDir.__init__H   s?    zz$((--	":;DHzz$((--	":;DH    c                 .    t        | j                  |      S r#   )Shelfr   )r(   names     r+   getzShelfDir.getN   s    TXXt$$r-   c                 z   	 | j                   j                         }g }t               }|D ]r  }|j	                  dd      d   }||v r|j                  |       | j                  |      }|j                         sP|j                         }|j                  ||f       t t        |d      S # t        $ r g cY S w xY w)z2return all shelves in repo as list of (time, name)   .r   r   T)reverse)r   listdirFileNotFoundErrorsetrsplitaddr1   existsmtimeappendsorted)r(   namesinfoseenfilenamer0   shelfr;   s           r+   listshelveszShelfDir.listshelvesQ   s    	HH$$&E u 		'H??4+A.Dt|HHTNHHTNE<<>KKMEKK&		' dD)) ! 	I	s   B, ,B:9B:NF)__name__
__module____qualname__r,   r1   rC    r-   r+   r!   r!   G   s    <%*r-   r!   c                 n    t        j                  |       xr | j                  j                  dd      dk(  S )Nr   s   store   internal)r   supportinternaluiconfigr)   s    r+   _use_internal_phaserO   f   s1    t$ 	?GGNN9h/;>r-   c                 X    t        |       rt        j                  S t        j                  S r#   )rO   r   internalsecretrN   s    r+   _target_phaserS   m   s    1$76??JV]]Jr-   c                   x    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd ZddZd Zd Zd Zd Zd Zd Zy)r/   a  Represents 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                      || _         || _        y r#   r   r0   )r(   r   r0   s      r+   r,   zShelf.__init__y   s    	r-   c                 L    | j                  d      xs | j                  dd      S )N   .shelve   .patch   .hg)_existsr(   s    r+   r:   zShelf.exists}   s!    ||J'J4<<	6+JJr-   c                 ,     t         fd|D              S )Nc              3   n   K   | ],  }j                   j                  j                  |z          . y wr#   r   r:   r0   ).0extr(   s     r+   	<genexpr>z Shelf._exists.<locals>.<genexpr>   s&     D488??499s?3Ds   25)all)r(   extss   ` r+   r[   zShelf._exists   s    DtDDDr-   c                     	 | j                  d      t        j                     S # t        $ r% | j                  d      t        j                     cY S w xY w)NrX   rY   )_statstatST_MTIMEr6   r\   s    r+   r;   zShelf.mtime   sF    	8::j)$--88  	8::i(77	8s   !$ +AAc                 R    | j                   j                  | j                  |z         S r#   )r   rg   r0   r(   ra   s     r+   rf   zShelf._stat   s    xx}}TYY_--r-   c                 |    t        j                  | j                  | j                  dz         j	                  |       y NrX   )r   simplekeyvaluefiler   r0   write)r(   r?   s     r+   	writeinfozShelf.writeinfo   s*    ""488TYY-CDJJ4Pr-   c                 R    | j                   j                  | j                  dz         S rl   r_   r\   s    r+   hasinfozShelf.hasinfo   s    xxtyy:566r-   c                 x    t        j                  | j                  | j                  dz         j	                         S rl   )r   rm   r   r0   readr\   s    r+   readinfozShelf.readinfo   s.    ))HHdii*,

$&	r-   c                 z   t        j                  |      }|dk(  rd}d }nd}d}|j                         }t        j                  |||g      }t        j
                  |||d      }| j                  j                  | j                  dz         }	t        j                  |j                  ||	|| j                  |       y )	Ns   01s   HG10BZs   HG20s   BZ)missingrootsancestorsofr   rZ   )compression)r
   safeversion
unfilteredr   outgoingmakechangegroupr   r%   r0   r	   writebundlerL   )
r(   r)   basesnode	cgversionbtyperx   r{   cgbundle_filenames
             r+   r}   zShelf.writebundle   s    ++D1	EKEK %%u4&
 ((xIN((--		F(:;GGHH#	
r-   c           
         | j                   dz   }| j                  |      }	 t        |      }t        j                  |j
                  ||| j                        }|d   }t        j                  |||dd| j                  j                  |      z   |       |d   }||k(  r|j                  d   d   }	||	   }||j                          S # |j                          w xY w)NrZ   s   tip   unshelves   bundle:)sourceurltargetphases   revduplicates)r0   r   rS   r   
readbundlerL   r	   applybundler%   changesclose)
r(   r)   trrA   fpr   genpretip	shelvectx	shelverevs
             r+   r   zShelf.applybundle   s    99v%XXh	'-K%%dggr8TXXFC&\F"x!88' VI"JJ'78<	 O	HHJBHHJs   BC Cc                 @    | j                  | j                  dz   |      S )NrY   rV   )r(   modes     r+   
open_patchzShelf.open_patch   s    xx		I-t44r-   c                     |j                         }t        ||      }t        j                         }t	        j
                  ||g|t        j                  d      |       |j                  d       |S )NTgitoptsmatchr   )	rz   _optimized_matchioBytesIOr   
exportfiler   diffoptsseek)r(   r)   r   r   r   s        r+   patch_from_nodezShelf.patch_from_node   s_      t,ZZ\FD)	
 	
	r-   c                     	 | j                  || j                         d         S # t        t        j                  f$ r | j                         cY S w xY w)N   node)r   rt   r6   r   RepoLookupErrorr   )r(   r)   s     r+   
load_patchzShelf.load_patch   sL    	%''dmmog.FGG!5#8#89 	%??$$	%s   "% )AAc                 l    d } ||      D ]&  }|j                  |      r|j                  |      c S  y )Nc              3      K   |  | j                  dd      \  } }t        j                  d      D ]  }d| ||fz    y w)Nr3   r   s   %s-%d.%s)r8   	itertoolscount)basera   is      r+   gennamesz'Shelf._backupfilename.<locals>.gennames   sH     JD!,ID#__Q' 3!T1cN223s   ?A)r:   r%   )r(   	backupvfsrA   r   ns        r+   _backupfilenamezShelf._backupfilename   s:    	3 (# 	)A##A& ~~a((	)r-   c                 4   |j                         s|j                          t        D ]o  }| j                  dz   |z   }| j                  j                  |      s1t        j                  | j                  j                  |      | j                  ||             q y Nr3   )
isdirmakedirshelvefileextensionsr0   r   r:   r   renamer%   r   )r(   r   suffixrA   s       r+   movetobackupzShelf.movetobackup   sv     * 	Fyy4'&0Hxxx(HHMM(+((H=	r-   c                 p    t         D ]-  }| j                  j                  | j                  dz   |z          / y r   )r   r   	tryunlinkr0   rj   s     r+   deletezShelf.delete   s1    ' 	7CHHtyy4/#56	7r-   c                 (   	 |j                         | j                         d      }|j                         S # t        t        j
                  f$ rB | j                  j                  | j                  dz         }t        j                  |||      cY S w xY w)Nr   rY   )rz   rt   filesr6   r   r   r   r%   r0   r   changedfiles)r(   rL   r)   ctxrA   s        r+   changed_fileszShelf.changed_files   sy    	://#DMMOG$<=C99;!5#8#89 	:xx}}TYY%:;H%%b$99	:s   36 ABBN)s   rb)rE   rF   rG   __doc__r,   r:   r[   r;   rf   ro   rq   rt   r}   r   r   r   r   r   r   r   r   rH   r-   r+   r/   r/   q   s_    KE8.Q7

4.5%	)	7:r-   r/   c                 P    t        j                  | | |   j                               S )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   )r)   r   s     r+   r   r     s$     dDJ$4$4$677r-   c                       e Zd ZdZdZdZdZdZdZdZ	e
d        Ze
d	        Ze
d
        Ze
d        Ze
	 	 	 dd       Ze
d        Zy)shelvedstatezHandle 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   interactivec                    	 t        |d         |d<   t        |d         |d<   |d   j                  d      D cg c]  }|st        |       c}|d<   |d   j                  d      D cg c]  }|st        |       c}|d<   yc c}w c c}w # t        t        f$ r-}t	        j
                  t        j                  |            d}~ww xY w)z@Some basic shelvestate syntactic verification and transformation   originalwctx
   pendingctx   parents       nodestoremoveN)r   split
ValueErrorKeyErrorr   CorruptedStater   forcebytestr)clsdherrs       r+   _verifyandtransformz shelvedstate._verifyandtransform  s    	E!$Q%7!8Ao"1]#34Am-.z]-@-@-FL!SVLAjM !"2 3 9 9$ ?#1A#A M# H% 	E&&z'>'>s'CDD	Es@   8B BBB +B3B B 
B C (CCc                 J   |j                  | j                        }	 t        |j                         j	                               }	 |j                          |S # t
        $ r-}t        j                  t        j                  |            d}~ww xY w# |j                          w xY w)z.Read version information from shelvestate fileN)r   	_filenameintreadlinestripr   r   r   r   r   r   )r   r)   r   versionr   s        r+   _getversionzshelvedstate._getversion(  s     XXcmm$	"++---/0G HHJ	  	E&&z'>'>s'CDD	E HHJs#   'A 	B (BBB B"c                     g d}|j                  | j                        }i }	 |D ]#  }|j                         j                         ||<   % 	 |j	                          |S # |j	                          w xY w)z9Read the old position-based version of a shelvestate file)	s   version   namer   r   r   r      branchtorestorer   
   activebook)r   r   r   r   r   )r   r)   keysr   r   keys         r+   _readoldzshelvedstate._readold4  sk    

 XXcmm$	 /,,.#/ HHJ HHJs   (A A0c                    | j                  |      }|| j                  k  r| j                  |      }nh|| j                  k(  r;t        j                  |j
                  | j                        j                  d      }nt        j                  t        d            | j                  |       	  |        }|d   |_        ||d      |_        ||d      |_        |d   |_        |d   |_        |j#                  d	d
      |_        |j#                  d      | j&                  k(  |_        d
|_        |j#                  dd
      | j,                  k7  r|j#                  dd
      |_        |j#                  d      | j.                  k(  |_        |S # t        j2                  t4        f$ r-}t        j6                  t9        j:                  |            d }~ww xY w)NT)firstlinenonkeyvalsI   this version of shelve is incompatible with the version used in this repor   r   r   r   r   r   r-   r   r   r   )r   _versionr   r   rm   r   r   rs   r   Abortr   r   r0   wctx
pendingctxparentsnodestoremover1   branchtorestore_keepkeepactivebookmark_noactivebook_interactiveinteractiver   r   r   r   bytestr)r   r)   r   r   objr   s         r+   loadzshelvedstate.loadP  s   //$'S\\!T"A$**488S]]CHH#' I A ++:  	"	>%CzCHAo./CH!!M"23CNJ-CK !"2 3C"#%%(:C"@CuuW~2CH!$Cuu]C(C,=,==%&UU=#%>"eeN3s7G7GGCO 
 %%x0 	>&&x'7'7'<==	>s   -CF G!(G		Gc
                 P   |t        |j                               t        |j                               dj                  |j                  j	                         D 
cg c]  }
t        |
       c}
      dj                  |D cg c]  }t        |       c}      ||r| j
                  n| j                  |xs | j                  d}|	r| j                  |d<   t        j                  |j                  | j                        j                  |d| j                  z         y c c}
w c c}w )Nr   )r   r   r   r   r   r   r   r   r   s   %d)	firstline)r   r   r%   dirstater   r   _nokeepr   r   r   rm   r   r   rn   r   )r   r)   r0   originalwctxr   r   r   r   
activebookr   pr   r?   s                r+   savezshelvedstate.savet  s      !2!2!45z01		4==3H3H3J"Ka3q6"KL"ii(GAQ(GH /"&SYYCKK%:):):	
 #&#3#3D ""488S]];AAUS\\1 	B 	
 #L(Gs   D D#c                 R    |j                   j                  | j                  d       y )NT)ignoremissing)r   
unlinkpathr   )r   r)   s     r+   clearzshelvedstate.clear  s    CMM>r-   N)Fr-   F)rE   rF   rG   r   r   r   r   r   r   r   classmethodr   r   r   r   r  r  rH   r-   r+   r   r     s     HIEG*M!L
E 
E 	 	  6 ! !F  
 
8 ? ?r-   r   c                    | j                   j                  dd      }t        | d      }|j                         }|dkD  r|t	        |      k  r||dz
     d   }nd }||d  D ]*  \  }}||k(  r|j                  |      j                          , y )Nr   s
   maxbackupsT)r*   r   r   )rL   	configintr!   rC   lenr1   r   )r)   
maxbackups
backup_dirhgfilesbordermtimer;   r0   s          r+   cleanupoldbackupsr    s    ""9m<J$D1J$$&GA~*s7|3j1n-a0z{+ &tKt##%	&r-   c                 L    | j                   }|rt        j                  |        |S r#   )_activebookmarkr   
deactivate)r)   r   s     r+   _backupactivebookmarkr    s$    ))NT"r-   c                 6    |rt        j                  | |       y y r#   )r   activate)r)   marks     r+   _restoreactivebookmarkr    s    4& r-   c                    | j                   }|j                         }dt        |      vsJ 	 d |_        |j	                          |`| j                         J | j                   j                  d       |j                  |d       y# |`w xY w)z@Abort current transaction for shelve/unshelve, but keep dirstate
invalidatec                       y r#   rH   rH   r-   r+   <lambda>z#_aborttransaction.<locals>.<lambda>      r-   N)r   branchvarsr  abortcurrenttransactionrn   	setbranch)r)   r   dscurrent_branchs       r+   _aborttransactionr#    s     
B YY[NtBx''' %

M ""$,,,MMLL& Ms   B Bc                    fd}|j                  d      }| j                  xs |j                         xs dj                  dd      j                  dd      j	                  d      rj                  ddd      |rt        |       j                  |      j                         r#t        d	      |z  }t        j                  |      d|v sd|v rt        j                  t        d
            |j	                  d      rt        j                  t        d            |S t        |       } |       D ]&  }|j                  |      j                         r#|} |S  |S )z/Decide on the name this shelve is going to havec               3   \   K    t        j                  d      D ]  } d| fz    y w)Nr   s   %s-%02d)r   r   )r   labels    r+   r   zgetshelvename.<locals>.gennames  s3     # 	*Aqz))	*s   ),r   s   default   /   _   \r3   r   s*   a shelved change named '%s' already existss,   shelved change names can not contain slashess+   shelved change names can not start with '.')
r1   r  r  replace
startswithr!   r:   r   r   r   )	r)   parentr   r   r0   e	shelf_dirr   r&  s	           @r+   getshelvenamer/    sG   *
 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	
 Kr-   c              #   n  K   t         h}t        j                         }|j                  |        |r|j	                         } | j                          | j                         D ]J  }|j                         }||vs|j                  |       |j                         s:|j                  |       L |ryyw)zireturn all mutable ancestors for ctx (included)

    Much faster than the revset ancestors(ctx) & draft()N)
r   collectionsdequer<   popleftr   r   revr9   mutable)r   r@   visitr,  r4  s        r+   mutableancestorsr7    s      9DE	LL
mmohhjkkm 	)F**,C$>>#LL(	) s   A8B5;!B5B53B5c                 *      fdfd}|r|S S )Nc           	      (   t        |d      }|r(|j                  j                  dc}|j                  _        t        |      }d|i}	 d}	
r*t	        j
                  dddit        j                  |      }	|j                  j                  |      5  |j                  |t        |j                  d      ||	      cd d d        |r|j                  _        S S # 1 sw Y   nxY w	 |r|j                  _        y y # |r|j                  _        w w xY w)	NmqFs   phasess
   new-commiteditforms   shelve.shelve   date)editorextrarH   )hasattrr:  checkappliedrS   r   getcommiteditorr   	strkwargsrL   configoverridecommit
shelveuserr1   )rL   r)   messager   r   hasmqsavedr   	overrideseditor_r>  r?  s             r+   
commitfuncz!getcommitfunc.<locals>.commitfunc  s   d#*.''*>*>'E477'#D)/=		-G!11 -191C1CD1I ''	2 {{HHW%" #   ',$    ',$ u',$ s%   A	C; *C;	C; C"C; ;Dc                     t        j                  |      }t        j                  |d   |i       }|d   } | ||||      S )Nr3      message)r   byteskwargsr   r   )rL   r)   patsr   r   rG  rL  s         r+   interactivecommitfuncz,getcommitfunc.<locals>.interactivecommitfunc   sF    ##D)d4j$3z""dGUD99r-   rH   )r?  r   r>  rQ  rL  s   ` ` @r+   getcommitfuncrR    s    -4: %0 ?Z?r-   c                    |j                  t        j                  |d    ||            }|j                  r1| j                  t	        d      t        |j                        z         y | j                  t	        d             y )N)r   s4   nothing changed (%d missing files, see 'hg status')
s   nothing changed
)statusr   r   deletedr   r	  )rL   r)   rP  r   rg   s        r+   _nothingtoshelvemessagingrV  )  sd    ;;W]]4:tTB;CD||
		FG$,, 	

 			!()*r-   c           	      r   dt        |      i}t        |       j                  |      }|j                  |       t	        t        | |               }|j                  | ||       |j                  d      5 }t        j                  | |g|t        j                  d      |       d d d        y # 1 sw Y   y xY w)Nr   s   wbTr   r   )r   r!   r1   ro   listr7  r}   r   r   r   r   r   )r)   r   r0   r   r?   rB   r~   r   s           r+   _shelvecreatedcommitrY  4  s    SYDTNt$E	OOD!$t*-.E	dE4(			%	  
B4&"5>>d#;5	

 
 
s   40B--B6c                     | j                  t        j                  | d    ||      d      }|j                  r=dj	                  |j                        |d<   | d    j                  |j                         y y )NT)r   unknown       shelve_unknown)rT  r   r   r[  r%   r9   )r)   rP  r   r?  ss        r+   _includeunknownfilesr_  @  s]    '--T
D$?NAyy#(::aii#8 T
qyy! r-   c                 T    t        |       r|j                          y t        | |       y r#   )rO   r   r#  )r)   r   s     r+   _finishshelvera  G  s    4 

$#r-   c                     |j                         5  t        j                  |       t        | |||      cddd       S # 1 sw Y   yxY w)z$subcommand that creates a new shelveN)wlockr   checkunfinished_docreatecmd)rL   r)   rP  r   s       r+   	createcmdrf  N  s<    	 2%BdD12 2 2s	   #>Ac                 t   |d    }|j                         }|d   }|j                         }|j                         t        k7  r'd|j	                         j                  dd      d   z  }nd}|j                  d      s||d<   d x}	x}
}	 |j                         }	|j                  dd 	      }
|j                  d
d      }|j                  dd      xr |j                  dd       }t        |||      }t        |      }ddi}|r2|j                  j                  |      5  t        ||||       d d d        t        |      rGt        ||      s;|j                  j!                  |d   j                         |j#                                t%        ||d      }|st'        j(                  | ||||      }n?t'        j*                  | ||d dt&        j,                  g|i t/        j0                  |      }|s2t3        | |||       	 t5        ||       t7        j8                  |
|	       yt;        ||      }t=        ||||       | j?                  tA        d      |z         |d   r<|j                  jC                  |      5  tE        jF                  |||       d d d        nctI        jJ                  ||jM                                tN        jP                  jS                  |      }|jU                         s|jW                          ||d   j                         k7  r6t        ||      s*|j                  j!                  ||j#                                tY        ||
       t5        ||       t7        j8                  |
|	       y # 1 sw Y   OxY w# 1 sw Y   xY w# t5        ||       t7        j8                  |
|	       w xY w)Nr   s   changes to: %s   
r   s   (changes in empty repository)rN  r   c                      y r#   rH   xs    r+   r  z_docreatecmd.<locals>.<lambda>i  r  r-   reportr   Fs   unknowns	   addremoverJ   r3   T)r>  s   shelved as %s
r   )-r   r  r4  r   descriptionr   r1   r   transactionr/  r  r   changing_filesr_  _iswctxonnewbranch_isbareshelver   r  rR  r   rE  dorecordrecordfilterr   rC  rV  r  lockmodreleaser   rY  rT  r   changing_parentsr   movedirstater   updater   mergestatemodr   rs   unresolvedcountresetra  )rL   r)   rP  r   r   r   r,  
origbranchdescr   r   r   r   includeunknownr0   r?  rL  r   r   mss                       r+   re  re  U  sY   :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%>
 :
 T640.t4i(--d3 >$T4u=> d#M$,E MM##T
!!#T%<%<%> #5+dC
>>"dJdCD##$$	 	 $$T*	D %b$d;( 	t^4D!' !t,T4u5
		!&'$./=//5 :$$T659: : IIdFKKM*))..t4B%%'
d**,,]45NMM##J0G0G0IJdBt^4D!_> >B: : 	t^4D!sF   BN M:-CN $AN ;NCN :N?N NN $N7c                     |  xr= |j                  dd       xr( |j                  dd       xr |j                  dd       S )Nr   Fs   includes   exclude)r1   )rP  r   s     r+   rr  rr    sP     	,//	,U++	, U++	r-   c                 P    | d    j                         | d   j                         k7  S r   )r  rN   s    r+   rq  rq    s'    :$t*"3"3"555r-   c                 P   |j                         5  t        |      }t        j                  |j                  j	                  t
                    }|j                         D ]0  \  }}|j                  |      j                  |       t        |       2 	 ddd       y# 1 sw Y   yxY w)z#subcommand that deletes all shelvesN)
rc  r!   r$   r   r%   r&   rC   r1   r   r  )rL   r)   r.  r   _mtimer0   s         r+   
cleanupcmdr    s     
 $TN	JJtxx}}Y78	%113 	$LFDMM$,,Y7d#	$$ $ $s   BBB%c                    |st        j                  t        d            |j                         5  t	        j
                  |j
                  j                  t                    }|D ]i  }t        |      j                  |      }|j                         s!t        j                  t        d      |z        |j                  |       t        |       k 	 ddd       y# 1 sw Y   yxY w)z)subcommand that deletes a specific shelves   no shelved changes specified!   shelved change '%s' not foundN)r   
InputErrorr   rc  r$   r   r%   r&   r!   r1   r:   r   r  )rL   r)   rP  r   r0   rB   s         r+   	deletecmdr    s    q!ABCC	 	$JJtxx}}Y78	 	$DTN&&t,E<<>&&67$>  y)d#	$	$ 	$ 	$s   B!CC%c                    t        |      }d}| j                         s| j                         }d}| j                  d       t	        |      }|j                         D ]
  \  }}|r||vr| j                  ||       d}| j                  r| j                  d       A| j                  ddt        |      z
  z         d}	t        j                  |      }
d	t        j                  |
d
      z  }| j                  |d       | j                  ddt        |      z
  z         |	dz  }	|j                  |      j                  |      5 }	 |j                         }|sn]|j!                  d      sK|j#                         }| j%                         rt'        j(                  |||	z
        }| j                  |       np| j                  d       |d   s|d   s	 ddd       |j+                         }|d   r5t-        j.                  t0        |      D ]  \  }}| j                  ||        |d   r2t-        j2                  ||      D ]  \  }}| j                  ||        ddd        y# 1 sw Y   xY w)z,subcommand that displays the list of shelvesP   s   shelve.newestr   )r&  s   shelve.namerh  r      s   (%s)T)abbrevs
   shelve.age      #r   s   statN)width)r7   plain	termwidthpagerr!   rC   rn   quietr	  r   makedater   ager1   r   r   r+  rstrip	formattedr   ellipsis	readlinesr   	difflabeliter
diffstatui)rL   r)   rP  r   r  	namelabelr.  r;   r0   useddater  r   liner~  	difflineschunkr&  s                     r+   listcmdr    s8   t9DE88: IHHYI ,,. #1tD$
Y'"	88HHUO
c$i()  '++D>>
M*
c#h'(
]]4 ++D1 	1R{{}t,;;=D||~)224FHHTN  HHUONd7m	1 	1 IH~$)OOD)$D 1LE5HHU%H01G}$)$4$4Ye$L 1LE5HHU%H01'	1 	1#1	1 	1s   BI+BI++I5	c                 V   t        |      }t        |      dk(  r;|j                         }|st        j                  t        d            |d   \  }}|g}|D ]B  }|j                  |      j                         r#t        j                  t        d      |z         t        | |||       y)z subcommand that displays shelvesr   s   there are no shelves to shows   cannot find shelf %sN)	r!   r	  rC   r   r   r   r1   r:   r  )	rL   r)   rP  r   r.  shelvesr;   r0   	shelfnames	            r+   	patchcmdsr    s    I
4yA~'')++a ?@AAajtv F	}}Y'..0++a 789DEEF BdD!r-   c                     |j                   | j                  j                         k7  rt        j                  t	        d            y)z'check parent while resuming an unshelves5   working directory parents do not match unshelve stateN)r   r   r   r   r   )r)   states     r+   checkparentsr    s:    }}--//kkFG
 	
 0r-   c                 Z   	 t         j                  |      }|j                  d      |j                  |d<   |S # t        $ r# t        j                  |t        d             Y S t        j                  $ r}| j                  t        j                  |      dz          |j                  d      r-t        d      }t        d      }t        j                  ||      |j                  d      r3t         j                  |       t        j                  t        d	            Y d }~S d }~ww xY w)
Nr   r   rh     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
)r   r   r1   r   r6   r   wrongtooltocontinuer   r   r   debugr   r   r   r  )rL   r)   r   r  r   msgr  s          r+   _loadshelvedstater    s   !!$'88G$!JJDM* L)  :##D!K.9& L%  
!!#&./88K 34CD ++c--XXht$++6    L%s   59 (D*$D*6B)D%%D*c                    |j                         5  	 t        ||       t        j                  |j                         |j
                  r8|j
                  |j                  v r t        j                  ||j
                         t        | ||j                  |j                         t        |      s$t        j                  | ||j                  dd       t        j!                  |       | j#                  t%        d      |j&                  z         	 ddd       y# t        j!                  |       | j#                  t%        d      |j&                  z         w xY w# 1 sw Y   yxY w)z-subcommand that abort an in-progress unshelveFr   backuptopics   unshelve of '%s' aborted
N)r   r  r   clean_updater   r   
_bookmarksr   r  
mergefilesr   rO   r   r   r   r   r  warnr   r0   rL   r)   r  s      r+   unshelveabortr  2  s   	 C	Cu%u//0##(<(<(O""4)=)=>r4U-=-=>&t,e11%y t$GGA34uzzABC C t$GGA34uzzABC Cs#   EC D<E>EEE#c                     |j                         5  t        | |ddi      }t        | ||      cddd       S # 1 sw Y   yxY w)z(logic to  abort unshelve using 'hg abortr  TN)rc  r  r  r  s      r+   hgabortunshelver  E  s?    	 .!"dXt,<=Ru-. . .s	   7A c                     | j                  ddi      5  t        j                  ||j                                t	        j
                  | ||       ddd       y# 1 sw Y   yxY w)zLupdates to wctx and merges the changes from shelvectx into the
    dirstate.   uis   quietTN)rD  r   ry  r   r   revert)rL   r)   r   r   s       r+   r  r  L  sQ     
		-t4	5 ,
		$		$r4+, , ,s   <AA"c                     |rf||j                   j                         k7  rH|j                   j                  ||j                                | j	                  t        d      |z         y y y )Ns&   marked working directory as branch %s
)r   r  r   r  rT  r   )rL   r)   r   s      r+   restorebranchr  T  sX    ?dmm.B.B.DD1H1H1JK
		89OK	
 Er-   c                     |j                  d      sgt        j                  |j                  j                  t                    }t        |      j                  |      j                  |       t        |       yy)z&remove related files after an unshelver   N)r1   r$   r   r%   r&   r!   r   r  )rL   r)   r0   r   r   s        r+   unshelvecleanupr  \  sS    88GJJtxx}}Y78	4 --i8$ r-   c           
      N   |j                   }|j                  }|j                         5  t        ||       t        j
                  j                  |      }|j                         r)t        j                  t        d      t        d            ||j                  d      }|j                  }|j                  j                  |      5  |j                  |j                  j!                         |j"                         |j                  j%                  |j'                                ddd       t)        |      }	d|	i}
|j*                  j-                  |
d      5  |j                  j                  |      5  |j                  |j                  d   |j"                         ddd       t/        | |||||      \  }}ddd       )|j                  }t        d	      }| j1                  |       n |j2                  j5                  |       ||   }t7        j8                  |       t;        | ||j<                  |       t?        | ||j@                         tC        |      s$tE        jF                  | ||j2                  d
d       tH        jK                  |       stM        | ||j                  |       tO        ||jP                         | j1                  t        d      |j                  z         ddd       y# 1 sw Y   xY w# 1 sw Y   exY w# 1 sw Y   WxY w# 1 sw Y   yxY w)z.subcommand to continue an in-progress unshelves$   unresolved conflicts, can't continues/   see 'hg resolve', then 'hg unshelve --continue'r  r   Nr;  r   r   <   note: unshelved changes already existed in the working copy
Fr   r  s   unshelve of '%s' complete
))r   r0   r   r  rz  r   rs   r{  r   r   r   r   r   r   rw  
setparentsr   nullidrn   r  rS   rL   rD  _createunshelvectxrT  r   r<   r   ry  r  r   r  r   rO   r   r   r   r  r  r  r   )rL   r)   r  r   r   basenamer  r   r   r   rJ  newnodeispartialunshelver  s                 r+   unshelvecontinuer  d  s    ##KzzH	 1BT5!%%**40++9:IJ 
 q)*	%%
]]++D1 	;OOE,,113T[[AMM 7 7 9:	; $D)/=	WW##I{; 	//5 ?a 0$++>?);D)X{D*&G&	 ?((I)C IIcN &&w/WIZ 2tUZZ3b$ 5 56"4(LLD%--e9 	4  Bejj$7tU%9%9:
		!23ejj@Ac1B 1B	; 	;? ?	 	%1B 1BsV   BLAK4%3LL4*LL9D2L4K>	9LLLL	LL$c                     |j                         5  t        | |ddi      }t        | ||d|j                  i      cddd       S # 1 sw Y   yxY w)z,logic to resume unshelve using 'hg continue'r  Tr   N)rc  r  r  r   r  s      r+   hgcontinueunshelver    sN    	 H!"d[$,?@D%'5::1FGH H Hs   )AAc                    |j                         }t        |j                        }|j                  s|j                  s|j                  s||fS | j                  t        d             ddi}t        |dd      }i }d|d<   |j                  d      |d<   | j                  d	d
i      5  t        j                  | ||g |      }	ddd       |	   }||fS # 1 sw Y   xY w)zETemporarily commit working copy changes before moving unshelve commitsL   temporarily committing pending changes (restore with 'hg unshelve --abort')
rJ   r   F)r?  r   r>  s    pending changes temporary commitrN  r=  r  TN)rT  	frozensetaddedmodifiedremovedr   rR  r1   rD  r   rE  )
rL   r)   r   tmpwctxr^  addedbeforer?  rL  tempoptsr   s
             r+   _commitworkingcopychangesr    s     	AAGG$KJJ!''QYY##II	6	
 )$EUeLJH>HZ)HW			-t4	5 B~~b$
BAB4jGKB Bs   (CCc                    |j                         }d}t        |      j                  |      }|j                         r|j	                         d   }|||vr`| j                  ddi      5  |j                  ||      }ddd       |,dt        j                               i}|j                  |       |fS ||   }||fS # 1 sw Y   DxY w)z5Recreate commit in the repository during the unshelveNr   r  T)
rz   r!   r1   rq   rt   rD  r   r   r   ro   )rL   r)   r   r  r   rB   r   r?   s           r+   _unshelverestorecommitr    s    ??DDTNx(E}}~~(|t4' 1489 	4))$3I	4 <S!123DOOD! ? J	?	4 	4s   )B??Cc                 `   |j                         |d<   d|d<   g }|sQ|j                  |j                         |j                         |j                         |j	                               }|dfS t        |j                         dd      }t        j                  | ||ddt        j                  g|i t        j                  |      }|j                  |j                         |j                         |j                               }	|	rt        ||	      }
t        ||	||
       |t        |	      fS )	ay  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.
    rN  Ts   interactive-unshelve)textr?  userr  F)r   r>  N)r  r?  r  )rn  rE  r?  r  r  rR  r   rs  rt  r   rC  r   rY  bool)rL   r)   r   r  r   r   rP  r  rL  snodems              r+   r  r    s2   * !,,.D$(D	 !D++&&(//#!!	  
 ~y0d4PJ
	 
	 

T
"	G KK""$oo^^  E
 T5)T5(A6DKr-   c                 8   |j                  d      }|j                         |j                         j                         k(  r|s|dfS |j                  dd      t        j                  d}|j
                  j                  |d      5  | j                  t        d             t        j                  ||g dd	
      }|j                  r|j                          t        |t        |            D cg c]  }|j                  j                  |       }}t         j#                  ||||||	|j                  d      |
|	       t%        j&                  d      |j(                  j+                  |      5  |j-                  |j                         |j.                         ddd       t1        | |||||      \  }}||}t        d      }| j                  |       n||   }t        j2                  |       ddd       ||fS c c}w # 1 sw Y   hxY w# 1 sw Y   |fS xY w)zBRebase restored commit from its original location to a destinationr   F   toolr-   )r  s
   forcemerger;  r   s   rebasing shelved changes
)s   working-copys   shelved changes   parent of shelved changeT)labelskeepconflictparentr   Nr  )r1   r   p1r   rR   rL   rD  rT  r   r   graftr{  r   ranger	  	changelogr   r  r   ConflictResolutionRequiredr   rw  r  r  r  ry  )rL   r)   r   r   	oldtiprevr  pctxr  r   r   r   r   rJ  statsr4  r   r  r  r  s                      r+   _rebaserestoredcommitr    s     ((>*K||~,,..{ % !%# 6$*MMI 
			;	7 ."
		!123
  $	
   HHJ 5:)SY4O-0##C(M  !
 22;??]]++D1 	9OOGLLNDKK8	9%7i;&
"" ?I)C IIcNWILL!]."` '''C 	9 	9?."` '''s9   A)H/"G<AH/+HAH<HH
	HHc                     |j                         j                  d      }|sy t        |j                  d            }t        | j	                         j
                        }||z  |z
  }| d    j                  |       y )Nr]  r\  )r?  r1   r  r   rT  r  forget)r)   r   r  shelveunknown
addedaftertoforgets         r+   _forgetunknownfilesr  X  sn     OO%))*;<Mm11%89M4;;=../J]*k9HJhr-   c                 4    t        | |       t        | |       y r#   )r  r#  )r)   r  r   r   s       r+   _finishunshelver  d  s    40 dBr-   c                     t        |j                         j                        }t        |j                               }|j	                  |      }|r-t        d      }t        d      }t        j                  ||      y)zYCheck 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)r7   rT  rU  r   intersectionr   r   r   )rL   r)   r   	wcdeletedshelvetouchedr  r  r  s           r+   _checkunshelveuntrackedproblemsr  l  sj     DKKM))*I	)*M))-8L56@Akk!$'' r-   c                    t        j                  |      }|j                  d      }|j                  d      }|j                  d      }|s|st        j                  |       t        |      }|j                  d      r|j                  |d          |r/|j                  d      rt        j                  t        d            |s|r|r |rt        j                  t        d            |rt        j                  t        d            |r,|j                  d	d
      r| j                  t        d             t        | ||      }|rt        | ||      S |r |rt        j                  t        d            |rt        | |||      S t        |      dkD  rt        j                  t        d            |s_t        |      j!                         }|st        j"                  t        d            |d   d   }| j%                  t        d      |z         n|d   }t        |      j                        j'                         s!t        j                  t        d      |z        t)        | |||      S )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 interactiver   s&   can only unshelve one change at a times   no shelved changes to apply!r   s   unshelving change '%s'
r  )r   rO  r1   r   rd  rX  r<   r   r  r   r  r  r  r  r	  r!   rC   
StateErrorrT  r:   _dounshelve)	rL   r)   shelvedr   abortf	continuefr   r  r  s	            r+   unshelvecmdr  x  s&   %DXXhF%I((>*K)%7mGxxtG}%txx(=>
 	
 i""1%J#KLL""/  dhhw.GGA678!"dD1 T511;""=>  #BeT::	W	q!JKLL4.,,.""1%D#EFF1:a=
		!/08;<1:D>h'..0q!ABXMNNr4400r-   c                    |j                         }d x}}	 |j                         }|j                  dd       }t        |      }|d   }t	        |      }t        | |||      \  }	}
t        | |||      \  }}t        | ||       d}|j                         |j                         j                         k7  r|j                         }t        | |||||||	|||      \  }}d|j                  dd      i}| j                  |d      5  t        | |||       d d d        t        | ||       t        j!                  |       t#        ||||       |j$                  j'                  |      5  t)        |||
       d d d        |st+        | |||       |r|j-                          t/        j,                  |       y # 1 sw Y   xY w# 1 sw Y   MxY w# |r|j-                          t/        j,                  |       w xY w)Nr   c                      y r#   rH   rj  s    r+   r  z_dounshelve.<locals>.<lambda>  r  r-   rl  r3   r-   r  r  )rz   r   ro  r	  r  r  r  r  r  r  r  r1   rD  r  r  r   r  r  r   rp  r  r  rv  ru  )rL   r)   r  r   r   r   r  r  r   r  r  r   r   r  rJ  s                  r+   r  r    s   ??DD2.yy{k.AI	Dz /t48T4N0T2xHi'D)<!6!6!88'..0O'<(
$	$ ,TXXgs-CD	y+6 	2r4y1	2b$04 i^<]]))$/ 	>i=	> Bh5JJL	2 	2
	> 	>
 JJLs=   C-G F3AG %F?3G 3F<8G ?GG )G4rD   )Ur   r1  r   r   rg   i18nr   r   r   r   r    r   r	   r
   r   r   r   r   r   r   ru  r   r   r   rz  r   r   r   r   r   r   r   r   r$   utilsr   r   r&   r'   r   rF  r!   rO   rS   r/   r   r   r  r  r  r#  r/  r7  rR  rV  rY  r_  ra  rf  re  rr  rq  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rH   r-   r+   <module>r     s\     	    
     ,
 		3  !
* *>KO: O:d8G? G?T&'
'4%P)$!@H+	
"$2N"b6$$ ,1^""
8C&.,
 7BtH 2*5 pJ(Z	  	(31l1r-   