
    ǯei\                     H   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mZ ddlmZmZmZ erddlmZ e	j4                  Ze	j6                  Z G d	 d
      Zdedef   dedef   fdZdedef   dedef   fdZdedef   dedef   fdZy)zIndex utilities.)TemporaryFileSwappost_clear_cachedefault_indexgit_working_dir    N)wraps)TracebackType)AnyCallableTYPE_CHECKINGOptionalTypecast)LiteralPathLike_T)	IndexFilec            	       b    e Zd ZdZdZdeddfdZddZdee	e
      d	ee
   d
ee   ded   fdZy)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                 Z   || _         t        j                  |      \  }}t        j                  ||      \  }| _        t        j                  |       t        j                  t              5  t        j                  | j                   | j
                         d d d        y # 1 sw Y   y xY w)N)prefixdir)r   ospsplittempfilemkstempr   osclose
contextlibsuppressOSErrorreplace)selfr   dirnamebasenamefds        P/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/git/index/util.py__init__zTemporaryFileSwap.__init__'   s|    "IIi0!)!1!1w!OD
  ) 	;JJt~~t'9'9:	; 	; 	;s   -+B!!B*c                     | S N )r$   s    r(   	__enter__zTemporaryFileSwap.__enter__/   s        exc_typeexc_valexc_tbFc                     t        j                  | j                        r*t        j                  | j                  | j
                         y)NF)r   isfiler   r   r#   r   )r$   r/   r0   r1   s       r(   __exit__zTemporaryFileSwap.__exit__2   s1     ::d(()JJt))4>>:r.   )r   r   )__name__
__module____qualname____doc__	__slots__r   r)   r-   r   r   BaseExceptionr   r   r4   r,   r.   r(   r   r   !   si    6 /I;( ;t ;4./ -( '	
 
r.   r   func.r   c           	      X     t               dddt        dt        dt        f f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                 @     | g|i |}| j                          |S r+   )_delete_entries_cache)r$   r=   r>   rvalr;   s       r(   post_clear_cache_if_not_raisedz8post_clear_cache.<locals>.post_clear_cache_if_not_raisedG   s(    D*4*6*""$r.   r   r	   r   )r;   rB   s   ` r(   r   r   @   sA     4[[  PS XZ   *)r.   c           	      X     t               dddt        dt        dt        f fd       }|S )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   r=   r>   r   c                     | j                   | j                         k7  rt        dj                  z         | g|i |S )NzECannot call %r on indices that do not represent the default git index)
_file_path_index_pathAssertionErrorr5   )r$   r=   r>   r;   s      r(   check_default_indexz*default_index.<locals>.check_default_indexY   sK    ??d..00 WZ^ZgZgg  D*4*6**r.   rC   )r;   rI   s   ` r(   r   r   R   s?     4[++ +c +S +R + + r.   c           	      X     t               dddt        dt        dt        f fd       }|S )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   r=   r>   r   c                    t        j                         }t        j                  t        t        | j
                  j                               	  | g|i |t        j                  |       S # t        j                  |       w xY wr+   )r   getcwdchdirr   r   repoworking_tree_dir)r$   r=   r>   cur_wdr;   s       r(   set_git_working_dirz,git_working_dir.<locals>.set_git_working_dirj   s[    
h		 : :;<	.t.v.HHVBHHVs   A/ /BrC   )r;   rQ   s   ` r(   r   r   f   s?     4[+ c S R   r.   ) r8   __all__r    	functoolsr   r   os.pathpathr   structr   typesr   typingr	   r
   r   r   r   r   	git.typesr   r   r   	git.indexr   packunpackr   r   r   r   r,   r.   r(   <module>r]      s    
W   	     F E + +#
 {{	 >*8CG, *#r'1B *$b) hsBw.? ((37+ b0A r.   