
    	^c                        d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	m
Z
 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/ ZId0 ZJd1 ZKd2 ZLd3 ZMd4 ZNd5 ZOd6 ZPd7 ZQd8 ZRd9 ZSd: ZTdS )<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dS )ShelfDirFc                     |r8t          j        |j                            t                              | _        d S t          j        |j                            t                              | _        d S N)vfsmodr   join	backupdir	shelvedir)selfrepofor_backupss      2/usr/lib/python3/dist-packages/mercurial/shelve.py__init__zShelfDir.__init__H   sP     	<z$(--	":":;;DHHHz$(--	":":;;DHHH    c                 ,    t          | j        |          S r#   )Shelfr   )r(   names     r+   getzShelfDir.getN   s    TXt$$$r-   c                    	 | j                                         }n# t          $ r g cY S w xY wg }t                      }|D ]}|                    dd          d         }||v r#|                    |           |                     |          }|                                sb|                                }|	                    ||f           t          |d          S )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    	H$$&&EE  	 	 	III	uu 		' 		'H??4++A.Dt||HHTNNNHHTNNE<<>> KKMMEKK&&&&dD))))s    ++NF)__name__
__module____qualname__r,   r1   rC    r-   r+   r!   r!   G   sF        < < < <% % %* * * * *r-   r!   c                 h    t          j        |           o| j                            dd          dk    S )Nr   s   store   internal)r   supportinternaluiconfigr)   s    r+   _use_internal_phaserO   f   s2    t$$ 	?GNN9h//;>r-   c                 P    t          |           rt          j        nt          j        S r#   )rO   r   internalsecretrN   s    r+   _target_phaserS   m   s    1$77J6??V]Jr-   c                   t    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S )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                 "    || _         || _        d S r#   r   r0   )r(   r   r0   s      r+   r,   zShelf.__init__y   s    			r-   c                 X    |                      d          p|                      dd          S )N   .shelve   .patch   .hg)_existsr(   s    r+   r:   zShelf.exists}   s'    ||J''J4<<	6+J+JJr-   c                 :     t           fd|D                       S )Nc              3   \   K   | ]&}j                             j        |z             V  'd S r#   r   r:   r0   ).0extr(   s     r+   	<genexpr>z Shelf._exists.<locals>.<genexpr>   s7      DD48??49s?33DDDDDDr-   )all)r(   extss   ` r+   r[   zShelf._exists   s&    DDDDtDDDDDDr-   c                     	 |                      d          t          j                 S # t          $ r( |                      d          t          j                 cY S w xY w)NrX   rY   )_statstatST_MTIMEr6   r\   s    r+   r;   zShelf.mtime   sZ    	8::j))$-88  	8 	8 	8::i((7777	8s   $' /AAc                 F    | j                             | j        |z             S r#   )r   rg   r0   r(   ra   s     r+   rf   zShelf._stat   s    x}}TY_---r-   c                 p    t          j        | j        | j        dz                                 |           d S NrX   )r   simplekeyvaluefiler   r0   write)r(   r?   s     r+   	writeinfozShelf.writeinfo   s2    "48TY-CDDJJ4PPPPPr-   c                 F    | j                             | j        dz             S rl   r_   r\   s    r+   hasinfozShelf.hasinfo   s    xty:5666r-   c                 j    t          j        | j        | j        dz                                             S rl   )r   rm   r   r0   readr\   s    r+   readinfozShelf.readinfo   s.    )Hdi*,
 

$&&	r-   c                 ^   t          j        |          }|dk    rd}d }nd}d}|                                }t          j        |||g          }t          j        |||d          }| j                            | j        dz             }	t          j
        |j        ||	|| j        |           d S )	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1	EKKEK  %u4&
 
 
 (xINN(--	F(:;;GH#	
 	
 	
 	
 	
 	
r-   c           
         | j         dz   }|                     |          }	 t          |          }t          j        |j        ||| j                  }|d         }t          j        |||dd| j                            |          z   |           |d         }||k    r|j	        d         d         }	||	         }||
                                 S # |
                                 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    9v%XXh	'--K%dgr8TXFFC&\F"x!8!88'    VI""J'78<	 O	HHJJJJBHHJJJJs   BC C#   rbc                 >    |                      | j        dz   |          S )NrY   rV   )r(   modes     r+   
open_patchzShelf.open_patch   s    xx	I-t444r-   c                     |                                 }t          ||          }t          j                    }t	          j        ||g|t          j        d          |           |                    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   sy       t,,Z\\FD)))	
 	
 	
 	
 	


	r-   c                     	 |                      ||                                 d                   S # t          t          j        f$ r |                                 cY S w xY w)N   node)r   rt   r6   r   RepoLookupErrorr   )r(   r)   s     r+   
load_patchzShelf.load_patch   sc    	%''dmmoog.FGGG!5#89 	% 	% 	%??$$$$$	%s   -0 *AAc                     d } ||          D ].}|                     |          s|                    |          c S /d S )Nc              3      K   | V  |                      dd          \  } }t          j        d          D ]}d| ||fz  V  d S )Nr3   r   s   %s-%d.%s)r8   	itertoolscount)basera   is      r+   gennamesz'Shelf._backupfilename.<locals>.gennames   sc      JJJD!,,ID#_Q'' 3 3!T1cN222223 3r-   )r:   r%   )r(   	backupvfsrA   r   ns        r+   _backupfilenamezShelf._backupfilename   si    	3 	3 	3 (## 	) 	)A##A&& ) ~~a((((()	) 	)r-   c                 :   |                                 s|                                 t          D ]j}| j        dz   |z   }| j                            |          rAt          j        | j                            |          | 	                    ||                     kd S Nr3   )
isdirmakedirshelvefileextensionsr0   r   r:   r   renamer%   r   )r(   r   suffixrA   s       r+   movetobackupzShelf.movetobackup   s       	 * 	 	Fy4'&0Hxx(( HMM(++((H==  	 	r-   c                 d    t           D ]'}| j                            | j        dz   |z              (d S r   )r   r   	tryunlinkr0   rj   s     r+   deletezShelf.delete   s@    ' 	7 	7CHty4/#56666	7 	7r-   N)r   )rE   rF   rG   __doc__r,   r:   r[   r;   rf   ro   rq   rt   r}   r   r   r   r   r   r   r   rH   r-   r+   r/   r/   q   s          K K KE E E8 8 8. . .Q Q Q7 7 7  

 
 
4  .5 5 5 5  % % %	) 	) 	)	 	 	7 7 7 7 7r-   r/   c                 \    t          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   
matchfilesfiles)r)   r   s     r+   r   r      s'     dDJ$4$4$6$67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dS )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 |d                             d          D             |d<   d |d                             d          D             |d<   dS # t          t          f$ r+}t	          j        t          j        |                    d}~ww xY w)	z@Some basic shelvestate syntactic verification and transformation   originalwctx
   pendingctxc                 0    g | ]}|t          |          S rH   r   r`   hs     r+   
<listcomp>z4shelvedstate._verifyandtransform.<locals>.<listcomp>  s#    LLL!LSVVLLLr-      parents    c                 0    g | ]}|t          |          S rH   r   r   s     r+   r   z4shelvedstate._verifyandtransform.<locals>.<listcomp>  s3     # # #1#A# # #r-      nodestoremoveN)r   split
ValueErrorKeyErrorr   CorruptedStater   forcebytestr)clsderrs      r+   _verifyandtransformz shelvedstate._verifyandtransform  s    	E!$Q%7!8!8Ao"1]#344AmLLQz]-@-@-F-FLLLAjM# # !"2 3 9 9$ ? ?# # #A H% 	E 	E 	E&z'>s'C'CDDD	Es   B B C &B;;C c                 r   |                     | j                  }	 t          |                                                                          }n8# t
          $ r+}t          j        t          j	        |                    d}~ww xY w	 |
                                 n# |
                                 w xY w|S )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     XXcm$$	"++----//00GG 	E 	E 	E&z'>s'C'CDDD	E  HHJJJJBHHJJJJs)   3A B 
B&B  BB B4c                    g d}|                     | j                  }i }	 |D ]+}|                                                                ||<   ,	 |                                 n# |                                 w xY w|S )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._readold,  s    

 

 

 XXcm$$	 / /,,..#/ HHJJJJBHHJJJJs   .A& &A<c                    |                      |          }|| j        k     r|                     |          }n`|| j        k    r4t          j        |j        | j                                      d          }n!t          j	        t          d                    |                     |           	  |             }|d         |_        ||d                  |_        ||d                  |_        |d         |_        |d         |_        |                    d	d
          |_        |                    d          | j        k    |_        d
|_        |                    dd
          | j        k    r|                    dd
          |_        |                    d          | j        k    |_        nD# t          j        t4          f$ r+}t          j        t9          j        |                    d }~ww xY w|S )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.loadH  s   //$''S\!!T""AA$$*48S]CCHH#' I  AA +:    	"""	>#%%CzCHAo./CH!!M"23CNJ-CK !"2 3C"#%%(:C"@"@CuuW~~2CH!$Cuu]C((C,===%&UU=#%>%>"eeN33s7GGCOO%x0 	> 	> 	>&x'7'<'<===	> 
s   -C9F' 'G(=&G##G(Fr-   c
           	         |t          |                                          t          |                                          d                    d |j                                        D                       d                    d |D                       ||r| j        n| j        |p| j        d}
|	r
| j        |
d<   t          j
        |j        | j                                      |
d| j        z             d S )Nr   c                 ,    g | ]}t          |          S rH   r   )r`   ps     r+   r   z%shelvedstate.save.<locals>.<listcomp>}  s    "K"K"Ka3q66"K"K"Kr-   c                 ,    g | ]}t          |          S rH   r   )r`   r   s     r+   r   z%shelvedstate.save.<locals>.<listcomp>~  s    (G(G(GAQ(G(G(Gr-   )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   r?   s              r+   savezshelvedstate.savel  s     !2!2!4!455z0011		"K"K4=3H3H3J3J"K"K"KLL"ii(G(G(G(G(GHH /"&7SYYCK%:):	
 	
  	4#&#3D "48S];;AAUS\1 	B 	
 	
 	
 	
 	
r-   c                 H    |j                             | j        d           d S )NT)ignoremissing)r   
unlinkpathr   )r   r)   s     r+   clearzshelvedstate.clear  s%    CM>>>>>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 [
E 	 	 [	   [6 ! ! [!F  
 
 
 [
8 ? ? [? ? ?r-   r   c                 \   | j                             dd          }t          | d          }|                                }|dk    r%|t	          |          k     r||dz
           d         }nd }||d          D ]3\  }}||k    r|                    |                                           4d S )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111J$$&&GA~~*s7||33j1n-a0z{{+ & &tKt##%%%%	& &r-   c                 @    | j         }|rt          j        |            |S r#   )_activebookmarkr   
deactivate)r)   r   s     r+   _backupactivebookmarkr    s)    )N #T"""r-   c                 8    |rt          j        | |           d S d S r#   )r   activate)r)   marks     r+   _restoreactivebookmarkr    s-     '4&&&&&' 'r-   c                     d}| j                             d|           |                                 | j                             d|           dS )z@Abort current transaction for shelve/unshelve, but keep dirstates   dirstate.shelveN)r  
savebackupabortrestorebackup)r)   r   dirstatebackupnames      r+   _aborttransactionr!    sM    +MT#5666HHJJJM&899999r-   c                 ,   fd}|                     d          }| j        p|                                pd                    dd                              dd                              d          r                    ddd          |rt          |                                |                                          r&t          d	          |z  }t          j	        |          d|v sd|v r!t          j	        t          d
                    |                    d          r!t          j	        t          d                    nGt          |           } |            D ]-}|                     |                                          s|} n.|S )z/Decide on the name this shelve is going to havec               3   T   K   V  t          j        d          D ]} d| fz  V  d S )Nr   s   %s-%02d)r   r   )r   labels    r+   r   zgetshelvename.<locals>.gennames  sK      ## 	* 	*Aqz)))))	* 	*r-   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  branchreplace
startswithr!   r:   r   r   r   )	r)   parentr   r   r0   e	shelf_dirr   r$  s	           @r+   getshelvenamer.    s   * * * * *
 88GD AFMMOOAzEMM$%%EMM%&&E -dD!,, D>>d##**,, 	!?@@4GA+a..  4<<5D==+ABB   ??4   	Q+a NOOPPP	Q TNN	 	 	A==##**,,  Kr-   c              #     K   t           h}t          j                    }|                    |            |r|                                } |                                 V  |                                 D ]X}|                                }||vr>|                    |           |	                                r|                    |           Y|dS dS )zireturn all mutable ancestors for ctx (included)

    Much faster than the revset ancestors(ctx) & draft()N)
r   collectionsdequer<   popleftr   r   revr9   mutable)ctxr@   visitr+  r3  s        r+   mutableancestorsr7    s       9DE	LL
 )mmoohhjjkkmm 	) 	)F**,,C$>>## )LL(((  ) ) ) ) )r-   Fc                 *      fdfd}|r|nS )Nc           	         t          j        |d          }|r|j        j        dc}|j        _        t	          |          }d|i}	 d}	
r%t          j        dddit          j        |          }	|j	        
                    |          5  |                    |t          |                    d          ||	          cd d d            |r||j        _        S S # 1 swxY w Y   	 |r||j        _        d S d S # |r||j        _        w xY w)	Ns   mqFs   phasess
   new-commiteditforms   shelve.shelve   date)editorextrarH   )r   safehasattrmqcheckappliedrS   r   getcommiteditorr   	strkwargsrL   configoverridecommit
shelveuserr1   )rL   r)   messager   r   hasmqsavedr   	overrideseditor_r=  r>  s             r+   
commitfuncz!getcommitfunc.<locals>.commitfunc  s    u-- 	F*.'*>'E47'#D))/=		-G !1  -191CD1I1I  ''	22  {{HHW%%" #          -',$$-          -',$$$- -u -',$,,,,s1   AC6 	3C<C6 CC6 C C6 6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  sL    #D))d4j$33z"z"dGUD999r-   rH   )r>  r   r=  rQ  rL  s   ` ` @r+   getcommitfuncrR    sO    - - - - - -4: : : : : %0?  Z?r-   c                 *   |                     t          j        |d          ||                    }|j        r9|                      t	          d          t          |j                  z             d S |                      t	          d                     d S )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    s    ;;W]4:tTBB;CCD| +
		FGG$, 	
 	
 	
 	
 	

 			!())*****r-   c           	         dt          |          i}t          |                               |          }|                    |           t	          t          | |                             }|                    | ||           |                    d          5 }t          j	        | |g|t          j        d          |           d d d            d S # 1 swxY w Y   d S )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    s   SYYDTNNt$$E	OOD!$t*--..E	dE4(((			%	 	  
B4&"5>d#;#;#;5	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   .CCCc                     |                      t          j        | d          ||          d          }|j        r?d                    |j                  |d<   | d                              |j                   d S d S )NT)r   unknown       shelve_unknown)rT  r   r   r[  r%   r9   )r)   rP  r   r>  ss        r+   _includeunknownfilesr_  &  st    '-T
D$??NNAy "#(::ai#8#8 T
qy!!!!!" "r-   c                 p    t          |           r|                                 d S t          | |           d S r#   )rO   r   r!  )r)   r   s     r+   _finishshelvera  -  s9    4   $





$#####r-   c                     |                                 5  t          j        |           t          | |||          cddd           S # 1 swxY w Y   dS )z$subcommand that creates a new shelveN)wlockr   checkunfinished_docreatecmd)rL   r)   rP  r   s       r+   	createcmdrf  4  s    	 2 2%%%BdD112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2s   &AAAc                    |d          }|                                 }|d         }|                                }|                                t          k    r2d|                                                    dd          d         z  }nd}|                    d          s||d<   d x}	x}
}	 |                                }	|                    dd 	          }
|                    d
d          }|                    dd          o|                    dd           }t          |||          }t          |          }ddi}|rt          ||||           t          |          rBt          ||          s2|j                            |d                                                    t!          ||d          }|st#          j        | ||||          }n6t#          j        | ||d dt"          j        g|R i t+          j        |          }|s:t/          | |||           	 t1          ||           t3          j        |
|	           dS t7          ||          }t9          ||||           |                     t=          d          |z             |d         rH|j                                        5  tA          j!        |||           d d d            n# 1 swxY w Y   nntE          j#        ||$                                           tJ          j&        '                    |          }|(                                s|)                                 ||d                                         k    r*t          ||          s|j                            |           tU          ||
           t1          ||           t3          j        |
|	           d S # t1          ||           t3          j        |
|	           w xY w)Nr   s   changes to: %s   
r   s   (changes in empty repository)rN  r   c                     d S r#   rH   xs    r+   <lambda>z_docreatecmd.<locals>.<lambda>O  s    $ r-   reportr   Fs   unknowns	   addremoverJ   r3   T)r=  s   shelved as %s
r   )+r   r(  r3  r   descriptionr   r1   r   transactionr.  r  r_  _iswctxonnewbranch_isbareshelver  	setbranchrR  r   rE  dorecordrecordfilterr   rC  rV  r  lockmodreleaser   rY  rT  r   parentchanger   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  ;  s8   :DllnnGQZFJzz||w 6#5#5#7#7#=#=eQ#G#G#JJ/88J  Z!%%D%2<"yy{{ i??hh~u55*e44 
TXX%>
 >
 :
 T6400.t44i( 	: tT5999d## 	9M$,E,E 	9 M##DJ$5$5$7$7888"5+dCCC
 	>"dJdCCDD#$	 	 	 	 $T**	 	D  	%b$d;;;( 	t^444D!!!!!' !t,,T4u555
		!&''$.///= 	++-- : :$T65999: : : : : : : : : : : : : : : IdFKKMM***)..t44B%%'' 


d**,,,,]45N5N,M##J///dBt^444D!!!!! 	t^444D!!!!s9   +E/O A(O *KO KO KC
O 'O-c                     |  oD|                     dd           o-|                     dd           o|                     dd           S )Nr   Fs   includes   exclude)r1   )rP  r   s     r+   rr  rr    sY     	,///	,U+++	, U+++	r-   c                 n    | d                                           | d                                          k    S r   )r(  rN   s    r+   rq  rq    s-    :$t*"3"3"5"555r-   c                    |                                 5  t          |          }t          j        |j                            t
                              }|                                D ]<\  }}|                    |                              |           t          |           =	 ddd           dS # 1 swxY w Y   dS )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     
 $ $TNN	Jtx}}Y7788	%1133 	$ 	$LFDMM$,,Y777d####	$$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s   BB55B9<B9c                    |s!t          j        t          d                    |                                5  t	          j        |j                            t                              }|D ]}t          |          	                    |          }|
                                s$t          j        t          d          |z            |                    |           t          |           	 ddd           dS # 1 swxY w Y   dS )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>    Dq!ABBCCC	 	$ 	$Jtx}}Y7788	 	$ 	$DTNN&&t,,E<<>> &677$>   y)))d####	$	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   B5C;;C?C?c                    t          |          }d}|                                 s|                                 }d}|                     d           t	          |          }|                                D ]c\  }}|r||vr|                     ||           d}| j        r|                     d           C|                     ddt          |          z
  z             d}	t          j
        |          }
d	t          j        |
d
          z  }|                     |d           |                     ddt          |          z
  z             |	dz  }	|                    |                              |          5 }	 |                                }|snl|                    d          sV|                                }|                                 rt'          j        |||	z
            }|                     |           n|                     d           |d         s|d         s	 ddd           |                                }|d         r7t-          j        t0          |          D ]\  }}|                     ||           |d         r3t-          j        ||          D ]\  }}|                     ||           ddd           n# 1 swxY w Y   edS )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    s.   t99DE88::  IHHYI ,,.. #1 #1t 	D$$
Y'''"	8 	HHUOOO
c$ii())) ''+D>>>>
M***
c#hh'(((
]]4  ++D11 	1R	{{}} t,, ;;==D||~~ G)24FFHHTNNN	 HHUOOON d7m 	1 	1 	1 	1 	1 	1 	1 IH~ 1$)OD)$D$D 1 1LE5HHU%H0000G} 1$)$4Ye$L$L$L 1 1LE5HHU%H0000)	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1#1 #1s   :B+K2BKK	K	c                    t          |          }t          |          dk    rE|                                }|s!t          j        t          d                    |d         \  }}|g}|D ]M}|                    |                                          s$t          j        t          d          |z            Nt          | |||           dS )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
4yyA~~'')) 	B+a ?@@AAAajtv F F	}}Y''..00 	F+a 7889DEEE	F BdD!!!!!r-   c                     |j         | j                                         k    r!t          j        t	          d                    dS )z'check parent while resuming an unshelves5   working directory parents do not match unshelve stateN)r   r  r   r   r   )r)   states     r+   checkparentsr    sE    }--////kFGG
 
 	
 0/r-   c                    	 t                               |          }|                    d          
|j        |d<   n# t          $ r% t          j        |t          d                     Y nt          j	        $ r}| 
                    t          j        |          dz              |                    d          r4t          d          }t          d          }t          j        ||          |                    d          r;t                               |           t          j        t          d	                    Y d }~nd }~ww xY w|S )
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    sh   !!$''88G$!JDM : : :#D!K..99999   
!#&&.///88K   	344C D +c----XXh 	t$$$+6   	 	 	 	 	$ Ls   9= ,E+E9CEEc                    |                                 5  	 t          ||           t          j        |j                   |j        r(|j        |j        v rt          j        ||j                   t          | ||j
        |j                   t          |          st          j        | ||j        dd           t                              |           |                     t%          d          |j        z             nI# t                              |           |                     t%          d          |j        z             w xY w	 ddd           dS # 1 swxY w Y   dS )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    s   	 C C	Cu%%%u/000# ?(<(O(O"4)=>>>r4U-=>>>&t,, e1%y    t$$$GGA344uzABBBB t$$$GGA344uzABBBBBC C C C C C C C C C C C C C C C C Cs+   EB!C=8AE=AEEEEc                     |                                 5  t          | |ddi          }t          | ||          cddd           S # 1 swxY w Y   dS )z(logic to  abort unshelve using 'hg abortr  TN)rc  r  r  r  s      r+   hgabortunshelver  (  s    	 . .!"dXt,<==Ru--. . . . . . . . . . . . . . . . . .s   $AA
A
c                     |                      ddi          5  t          j        ||                                           t	          j        | ||           ddd           dS # 1 swxY w Y   dS )zLupdates to wctx and merges the changes from shelvectx into the
    dirstate.   uis   quietTN)rD  r   rz  r   r   revert)rL   r)   r   r   s       r+   r  r  /  s     
		-t4	5	5 , ,
	$		$$$r4+++, , , , , , , , , , , , , , , , , ,s   >A##A'*A'c                     |r^||j                                         k    rC|j                             |           |                     t	          d          |z             d S d S d S )Ns&   marked working directory as branch %s
)r  r(  rs  rT  r   )rL   r)   r   s      r+   restorebranchr  7  sy     
?dm.B.B.D.DDD000
		899OK	
 	
 	
 	
 	

 
DDr-   c                    |                     d          swt          j        |j                            t                              }t          |                               |                              |           t          |           dS dS )z&remove related files after an unshelver   N)r1   r$   r   r%   r&   r!   r   r  )rL   r)   r0   r   r   s        r+   unshelvecleanupr  ?  sy    88G  Jtx}}Y7788	4  --i888$   r-   c                 |   |j         }|j        }|                                5  t          ||           t          j                            |          }|                                r0t          j	        t          d          t          d                    ||j        d                  }|j        }|j                                        5  |                    |j                                        |j                   |j                            |                                           ddd           n# 1 swxY w Y   t)          |          }	d|	i}
|j                            |
d          5  |j                                        5  |                    |j        d         |j                   t/          | |||||          \  }}ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |,|j        }t          d	          }|                     |           n"|j                            |           ||         }t7          j        |           t;          | ||j        |           t?          | ||j                    tC          |          stE          j#        | ||j        d
d           tH          %                    |           |stM          | ||j        |           tO          ||j(                   |                     t          d          |j        z             ddd           dS # 1 swxY w Y   dS )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  r{  r   rs   r|  r   r   r   r   r   r  rx  
setparentsr   nullidrn   currenttransactionrS   rL   rD  _createunshelvectxrT  r   r<   r   rz  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  G  s1    #KzH	 1B 1BT5!!!%**400 	+9::IJJ   
 q)*	%
]'')) 	; 	;OOE,1133T[AAAM 7 7 9 9:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; $D))/=	W##I{;; 	 	++--  a 0$+>>>-?i;. .**              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ?(I) C IIcNNNN &&w///WIZ   2tUZ333b$ 5666"4(( 	LD%-e9    	4     	8Bej$777tU%9:::
		!233ej@AAAc1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1B 1Bs   B'L1
AD5)L15D9	9L1<D9	=1L1.G)>GG)GG)GG)L1)G-	-L10G-	1D3L11L58L5c                     |                                 5  t          | |ddi          }t          | ||d|j        i          cddd           S # 1 swxY w Y   dS )z,logic to resume unshelve using 'hg continue'r  Tr   N)rc  r  r  r   r  s      r+   hgcontinueunshelver    s    	 H H!"d[$,?@@D%'5:1FGGH H H H H H H H H H H H H H H H H Hs   ,AAAc                    |                                 }t          |j                  }|j        s|j        s|j        s||fS |                      t          d                     ddi}t          |dd          }i }d|d<   |                    d          |d<   |                     d	d
i          5  t          j
        | ||g |          }	ddd           n# 1 swxY w Y   ||	         }||fS )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AG$$KJ $!' $QY $##II	6	
 	
   )$EUeLLLJH>HZ))HW			-t4	5	5 B B~b$
BAAB B B B B B B B B B B B B B B4jGKs   0CCCc                    |                                 }d}t          |                              |          }|                                r|                                d         }|||vr|                     ddi          5  |                    ||          }ddd           n# 1 swxY w Y   |8dt          |                                          i}|	                    |           n||         }||fS )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TNNx((E}} )~~(|t4'' 14899 	4 	4))$33I	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 <S!1!1223DOOD!!!J	?s   B''B+.B+c                    |                                 |d<   d|d<   g }|se|                    |                                 |                                |                                |                                          }|dfS t          |                                dd          }t          j        | ||ddt          j        g|R i t          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  )ro  rE  r>  r  r  rR  r   rt  ru  r   rC  r   rY  bool)rL   r)   r   r  r   r   rP  r  rL  snodems              r+   r  r    s{   * !,,..D$(D	 !D ++&&((//##!!!!	  
 
 ~y00d4PPPJ
	 
	 	 	 
T
"
"	 	G KK""$$oo^^   E
  7T5))T5(A666DKKr-   c                 l   |                     d          }|                                |                                                                k    r|s|dfS |                     dd          t          j        d}j                            |d          5  |                     t          d                     t          j
        |g dd	
          }|j        r|                                 fdt          |t                              D             }t                              |||||	|                     d          |
|	  	         t#          j        d          j                                        5                      |                                j                   t/          | ||||          \  }}ddd           n# 1 swxY w Y   |'|}t          d          }|                     |           n|         }t          j        |           ddd           n# 1 swxY w Y   ||fS )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keepconflictparentc                 D    g | ]}j                             |          S rH   )	changelogr   )r`   r3  r)   s     r+   r   z)_rebaserestoredcommit.<locals>.<listcomp>  s6       -0##C((  r-   r   Nr  )r1   r   p1r   rR   rL   rD  rT  r   r   graftr|  r   ranger  r   r  r   ConflictResolutionRequiredr  rx  r  r  r  rz  )rL   r)   r   r   	oldtiprevr  pctxr  r   r   r   r   rJ  statsr   r  r  r  s    `                r+   _rebaserestoredcommitr    s     ((>**K||~~,,....{. % !%# 6 6$*M I 
			;	7	7 ." ."
		!122333  
  $	
 	
 	
   	@HHJJJ   49)SYY4O4O  M !!
 
 
 2;???]'')) 	 	OOGLLNNDK888);D)X{D* *&G&	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ?I) C IIcNNNNWIL!!!]." ." ." ." ." ." ." ." ." ." ." ." ." ." ."` '''s9   C#H':AG?H'G	H'G	AH''H+.H+c                 2   |                                                     d          }|sd S t          |                    d                    }t          |                                 j                  }||z  |z
  }| d                              |           d S )Nr]  r\  )r>  r1   r  r   rT  r  forget)r)   r   r  shelveunknown
addedaftertoforgets         r+   _forgetunknownfilesr  ;  s     OO%%))*;<<M m11%8899M4;;==.//J]*k9HJhr-   c                     t          | |           |                                 j                            ||           t	          | |           d S r#   )r  rz   r  r   r!  )r)   r  r   r   s       r+   _finishunshelver  G  sM    4000
 	OO%%i444dBr-   c                 *   t          |                                j                  }t          |                                          }|                    |          }|r4t          d          }t          d          }t          j        ||          dS )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  Q  s     DKKMM)**I	))**M))-88L (566@AAk!$''''( (r-   c                    t          j        |          }|                    d          }|                    d          }|                    d          }|s|st          j        |           t          |          }|                    d          r|                    |d                    |r6|                    d          r!t          j        t          d                    |s|r|r#|r!t          j        t          d                    |r!t          j        t          d                    |r8|                    d	d
          r"| 
                    t          d                     t          | ||          }|rt          | ||          S |r#|r!t          j        t          d                    |rt          | |||          S nt          |          dk    r!t          j        t          d                    |sxt          |                                          }|s!t          j        t          d                    |d         d         }|                     t          d          |z             n|d         }t          |                              |                                          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	  ]  s   %%DXXhF%%I((>**K &) &%%%7mmGxx &tG}%%% 
txx(( 
=>>
 
 	
    	Mi 	M"1%J#K#KLLL 	"/     	9dhhw.. 	9GGA677888!"dD11 	; T5111 	;; 	;"=>>    	;#BeT:::	;	W		q!JKKLLL 4..,,.. 	G"1%D#E#EFFF1:a=
		!/008;<<<<1:D>>h''..00 Oq!ABBXMNNNr44000r-   c                 T   |                                 }d x}}	 |                                }|                    dd           }t          |          }|d         }t	          |          }t          | |||          \  }	}
t          | |||          \  }}t          | ||           d}|                                |	                                                                k    r|                                }t          | |||||||	|||          \  }}d|                    dd          i}|                     |d          5  t          | |||           d d d            n# 1 swxY w Y   t          | ||           t                              |           t#          ||||           t%          |||
           |st'          | |||           |r|                                 t+          j        |           d S # |r|                                 t+          j        |           w xY w)Nr   c                     d S r#   rH   rj  s    r+   rl  z_dounshelve.<locals>.<lambda>  s    D r-   rm  r3   r-   r  r  )rz   r   rp  r  r  r  r  r  r(  r  r  r1   rD  r  r  r   r
  r  r  r  rw  rv  )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AII	Dz /t448T4NN0T2xHHi'D)<<<!6!6!8!888'..00O'<(
 (
$	$ ,TXXgs-C-CD	y+66 	2 	2r4y111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2b$0004   i^<<<D)[999  	6Bh555 	JJLLL  	JJLLLs1   D)G; E"G; "E&&G; )E&*A%G; ;,H'rD   )Ur   r0  r   r   rg   i18nr   r   r   r   r    r   r	   r
   r   r   r   r   r   r   rv  r   r   r   r{  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33  !
* * * * * * * *>  K K KG7 G7 G7 G7 G7 G7 G7 G7T8 8 8G? G? G? G? G? G? G? G?T& & &  ' ' '
: : :% % %P) ) )$!@ !@ !@ !@H+ + +	
 	
 	
" " "$ $ $2 2 2K" K" K"\  6 6 6$ $ $$ $ $ ,1 ,1 ,1^" " ""
 
 
  8C C C&. . ., , ,
 
 
     7B 7B 7BtH H H     2  *5  5  5 pJ( J( J(Z	  	  	      	( 	( 	(31 31 31l0 0 0 0 0r-   