o
    Uh                     @   sN   d 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	 d	ZdS )
zStash handling.    N   )GitFile)commit_treeiter_fresh_objects)drop_reflog_entryread_reflogs
   refs/stashc                   @   sp   e Zd ZdZefdddZedd Zdd	 Ze	d
d Z
dddZdd ZdddZdd ZdefddZdS )StashzPA Git stash.

    Note that this doesn't currently update the working tree.
    returnNc                 C   s   || _ || _d S N)_ref_repo)selfreporef r   a/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/dulwich/stash.py__init__'   s   
zStash.__init__c                 C   s   t j| j dt | jS )Nlogs)ospathjoinr   	commondirfsdecoder   r   r   r   r   _reflog_path+   s   zStash._reflog_pathc                 C   s\   z"t | jd}ttt|W  d    W S 1 sw   Y  W d S  ty-   g  Y S w )Nrb)r   r   reversedlistr   FileNotFoundError)r   fr   r   r   stashes/   s   (zStash.stashesc                 C   s   | |S )z&Create a new stash from a Repo object.r   )clsr   r   r   r   	from_repo6   s   zStash.from_repoc                 C   s   t | jd}t||dd W d   n1 sw   Y  t| dkr1t| j | jj| j= dS |dkrA| d j	| jj| j< dS dS )z Drop entry with specified index.zrb+T)rewriteNr   )
openr   r   lenr   remover   refsr   new_sha)r   indexr   r   r   r   drop;   s   z
Stash.dropc                 C   s
   t | jr
   )NotImplementedErrorpopr   r)   r   r   r   r,   F   s   
z	Stash.popc           
      C   s   i }|dur
||d< |dur||d< | j  }|| j j}| j jd	d|d| j  gdd|}t| j jt|t	| j j
| j jd}|du rOd| 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commitr4   	do_commitheadr   r   r   fsencoder   r'   r   )
r   r.   r/   r1   commit_kwargsr)   index_tree_idindex_commit_idstash_tree_idcidr   r   r   pushI   sJ   	


		z
Stash.pushc                 C   s   t |  | S r
   )r   r    r-   r   r   r   __getitem__~      zStash.__getitem__c                 C   s   t t|  S r
   )r%   r   r    r   r   r   r   __len__   rA   zStash.__len__)r	   N)NNN)__name__
__module____qualname____doc__DEFAULT_STASH_REFr   propertyr   r    classmethodr"   r*   r,   r?   r@   intrB   r   r   r   r   r   !   s    



5r   )rF   r   filer   r)   r   r   reflogr   r   rG   r   r   r   r   r   <module>   s   