o
    ﯪgK                     @   s  d Z g dZddlZddlmZ ddlZddlmZ ddl	Z	ddl
Z
ddlmZ ddlmZmZmZmZmZ ddlmZmZmZ erHddlmZ e	jZe	jZG d	d
 d
Zdedef dedef fddZdedef dedef fddZdedef dedef fddZdS )zIndex utilities.)TemporaryFileSwappost_clear_cachedefault_indexgit_working_dir    N)wraps)TracebackType)AnyCallableTYPE_CHECKINGOptionalType)LiteralPathLike_T)	IndexFilec                	   @   s^   e Zd ZdZdZdeddfddZddd	Zd
ee	e
  dee
 dee ded fddZdS )r   zUtility class moving a file to a temporary location within the same directory and
    moving it back on to where on object deletion.)	file_pathtmp_file_pathr   returnNc                 C   sr   || _ t|\}}tj||d\}| _t| t	t
 t| j | j W d    d S 1 s2w   Y  d S )N)prefixdir)r   ospsplittempfilemkstempr   osclose
contextlibsuppressOSErrorreplace)selfr   dirnamebasenamefd r$   J/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/git/index/util.py__init__'   s   
"zTemporaryFileSwap.__init__c                 C   s   | S Nr$   )r    r$   r$   r%   	__enter__/   s   zTemporaryFileSwap.__enter__exc_typeexc_valexc_tbFc                 C   s    t | jrt| j| j dS )NF)r   isfiler   r   r   r   )r    r)   r*   r+   r$   r$   r%   __exit__2   s   zTemporaryFileSwap.__exit__)r   r   )__name__
__module____qualname____doc__	__slots__r   r&   r(   r   r   BaseExceptionr   r   r-   r$   r$   r$   r%   r   !   s    

r   func.r   c              	      *   t  dddtdtdtf fdd}|S )zDecorator for functions that alter the index using the git command.

    When a git command alters the index, this invalidates our possibly existing entries
    dictionary, which is why it must be deleted to allow it to be lazily reread later.
    r    r   argskwargsr   c                    s"    | g|R i |}|    |S r'   )_delete_entries_cache)r    r6   r7   rvalr4   r$   r%   post_clear_cache_if_not_raisedG   s   z8post_clear_cache.<locals>.post_clear_cache_if_not_raisedr   r   r   )r4   r;   r$   r:   r%   r   @   s    r   c              	      r5   )zDecorator ensuring the wrapped method may only run if we are the default
    repository index.

    This is as we rely on git commands that operate on that index only.
    r    r   r6   r7   r   c                    s2   | j |  krtd j  | g|R i |S )NzECannot call %r on indices that do not represent the default git index)
_file_path_index_pathAssertionErrorr.   )r    r6   r7   r:   r$   r%   check_default_indexY   s
   z*default_index.<locals>.check_default_indexr<   )r4   r@   r$   r:   r%   r   R   s    	r   c              	      r5   )zDecorator which changes the current working dir to the one of the git
    repository in order to ensure relative paths are handled correctly.r    r   r6   r7   r   c              	      sJ   t  }t t| jj z | g|R i |W t | S t | w r'   )r   getcwdchdirstrrepoworking_tree_dir)r    r6   r7   cur_wdr:   r$   r%   set_git_working_dirj   s
   z,git_working_dir.<locals>.set_git_working_dirr<   )r4   rG   r$   r:   r%   r   f   s    r   )r1   __all__r   	functoolsr   r   os.pathpathr   structr   typesr   typingr   r	   r
   r   r   	git.typesr   r   r   	git.indexr   packunpackr   r   r   r   r$   r$   r$   r%   <module>   s&   ""&