
                         b    d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
mZ dZ G d d	e      Zy)
zStash handling.    )absolute_importN)GitFile)commit_treeiter_fresh_objects)drop_reflog_entryread_reflogs
   refs/stashc                   `    e Zd ZdZefdZed        Zd Ze	d        Z
d Zd Zdd	Zd
 Zd Zy)StashzPA Git stash.

    Note that this doesn't currently update the working tree.
    c                      || _         || _        y N)_ref_repo)selfreporefs       lib/third_party/dulwich/stash.py__init__zStash.__init__,   s    	
    c                     t         j                  j                  | j                  j	                         dt        j
                  | j                              S )Nlogs)ospathjoinr   	commondirfsdecoder   r   s    r   _reflog_pathzStash._reflog_path0   s8    ww||JJ  "FBKK		,B
 	
r   c                     	 t        | j                  d      5 }t        t        t	        |                  cd d d        S # 1 sw Y   y xY w# t
        $ r g cY S w xY w)Nrb)r   r   reversedlistr   FileNotFoundError)r   fs     r   stasheszStash.stashes6   sI    	**D1Q[^ 45 211  	I	s+   A ?	A AA A AAc                      | |      S )z&Create a new stash from a Repo object. )clsr   s     r   	from_repozStash.from_repo=   s     4yr   c                    t        | j                  d      5 }t        ||d       ddd       t        |       dk(  rAt	        j
                  | j                         | j                  j                  | j                  = y|dk(  r1| d   j                  | j                  j                  | j                  <   yy# 1 sw Y   xY w)z Drop entry with specified index.zrb+T)rewriteNr   )
openr   r   lenr   remover   refsr   new_sha)r   indexr#   s      r   dropz
Stash.dropB   s    $##U+qa5 ,t9>IId''(

		*A:)-aDJJOODII&  ,+s   B44B=c                 ,    t        | j                        r   )NotImplementedErrorpopr   r0   s     r   r4   z	Stash.popM   s    !$((++r   Nc           	         i }|||d<   |||d<   | j                   j                         }|j                  | j                   j                        } | j                   j                  d	d|d| j                   j                         gdd|}t        | j                   j                  t        |t        j                  | j                   j                        | j                   j                              }|d| j                   j                         z   }| j                   j                         | j                   j                  | j                  <    | j                   j                  d	| j                  |||gdd|}	|	S )
zCreate a new stash.

        Args:
          committer: Optional committer name to use
          author: Optional author name to use
          message: Optional commit message
        N	committerauthors   Index stashT)r   treemessagemerge_heads	no_verify)object_stores   A stash on r&   )r   
open_indexcommitr=   	do_commitheadr   r   r   fsencoder   r.   r   )
r   r7   r8   r:   commit_kwargsr0   index_tree_idindex_commit_idstash_tree_idcids
             r   pushz
Stash.pushP   s[     )2M+&&,M(#

%%'TZZ%<%<=.$**.. 
"*+
 
 $JJ##DJJOO,!ZZ44
 ?$tzz'88G &*ZZ__%6

		""djj"" 
		()
 
 
r   c                 :    t        | j                               |   S r   )r!   r$   r5   s     r   __getitem__zStash.__getitem__   s    DLLN#E**r   c                 F    t        t        | j                                     S r   )r,   r!   r$   r   s    r   __len__zStash.__len__   s    4'((r   )NNN)__name__
__module____qualname____doc__DEFAULT_STASH_REFr   propertyr   r$   classmethodr(   r1   r4   rH   rJ   rL   r&   r   r   r
   r
   &   sX    
 "3  
 

  	9,3j+)r   r
   )rP   
__future__r   r   dulwich.filer   dulwich.indexr   r   dulwich.reflogr   r   rQ   objectr
   r&   r   r   <module>rY      s3   *  & 	   : " c)F c)r   