
    ǯeiB                        d Z g dZddlmZ ddlZddlmZ ddlm	Z	 ddl
mZmZmZmZmZmZmZ ddlZddlZddlmZ ddlmZ dd	lmZmZ dd
lmZmZmZmZ ddl m!Z!m"Z" ddl#m$Z$m%Z%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z< ddl=m>Z> e8rddl?m@Z@ ddlAmBZB ddlCmDZD eez  ZE	 e. ZFdeGde>deGfdZHdeGdeGfdZIdeGdddeGddfdZJd eKdeKfd!ZLde(fd"e7e;e,d#f      d$e5eM   d%e;deMf   d&e:e(   ddf
d'ZNd$e5eM   de9eKeKf   fd(ZOd)e;e,e>eKf   de9e>eKf   fd*ZPd$e5eM   de9eKe4e9e>eKf   d#f   eMeMf   fd+ZQ	 d7d"e6e-   d,d-d.eRd/eKde9eMe6d0   f   f
d1ZSd2d0d3eKde,fd4ZTd,d-d5e7eM   de6e,   fd6ZUy)8zVStandalone functions to accompany the index implementation and make it more
versatile.)write_cache
read_cachewrite_tree_from_cache	entry_keystat_mode_to_index_modeS_IFGITLINKrun_commit_hook	hook_path    )BytesION)Path)S_IFDIRS_IFLNKS_IFMTS_IFREGS_ISDIRS_ISLNKS_IXUSR)IStream)str_tree_type)handle_process_outputsafer_popen)defencforce_bytes
force_textsafe_decode)HookExecutionErrorUnmergedEntriesError)traverse_tree_recursivetraverse_trees_recursivetree_to_stream)IndexFileSHA1Writerfinalize_process   )CE_EXTENDEDBaseIndexEntry
IndexEntryCE_NAMEMASKCE_STAGESHIFT)packunpack)	DictIOListSequenceTYPE_CHECKINGTupleTypeUnioncast)PathLike)GitCmdObjectDB)TreeCacheTup)	IndexFilenamegit_dirreturnc                 0    t        j                  |d|       S )zK:return: path to the given named hook in the given git repository directoryhooks)ospjoin)r8   r9   s     O/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/git/index/fun.pyr	   r	   >   s    88GWd++    pathc                 2    t        j                  |       d   S )Nr#   )r=   splitext)rA   s    r?   _has_file_extensionrD   C   s    <<a  r@   indexr7   argsc                    t        | |j                  j                        }t        j                  |t        j
                        syt        j                  j                         }t        t        j                  |j                              |d<   d|d<   |g}	 t        j                  dk(  rKt        |      s@t        |      j                  |j                  j                         j#                         }d|g}t%        |t'        |      z   |t(        j*                  t(        j*                  |j                  j                         }g }g }	t-        ||j.                  |	j.                  t0               dj3                  |      }
dj3                  |	      }|j4                  d	k7  r8t7        |
t8              }
t7        |t8              }t;        ||j4                  ||
      y# t<        $ r}t;        ||      |d}~ww xY w)
a:  Run the commit hook of the given name. Silently ignore hooks that do not exist.

    :param name:
        Name of hook, like ``pre-commit``.

    :param index:
        :class:`~git.index.base.IndexFile` instance.

    :param args:
        Arguments passed to hook file.

    :raise git.exc.HookExecutionError:
    NGIT_INDEX_FILE:
GIT_EDITORwin32zbash.exe)envstdoutstderrcwd r
   )r	   repor9   osaccessX_OKenvironcopyr   fspathrA   sysplatformrD   r   relative_toworking_diras_posixr   list
subprocessPIPEr   appendr"   r>   
returncoder   r   r   	Exception)r8   rE   rF   hprL   cmdrelative_hpprocessstdout_liststderr_listrM   rN   exs                r?   r   r   G   s    
4++	,B99R!
**//
C'		%**(=>CC$CM<<7"+>r+B r(..uzz/E/EFOOQK{+C$t*????

&&
 "$!#g{'9'9;;M;MO_`%%"/F/F$R););VVLL #  1 R(b01s   B*G 	G1G,,G1modec                     t        |       rt        S t        |       st        |       t        k(  rt        S t
        | t        z  xr dxs dz  S )zZConvert the given mode from a stat call to the corresponding index mode and
    return it.i  i  )r   r   r   r   r   r   r   )rj   s    r?   r   r   z   sA     t}t}t3dWn.7%88r@   entriesr&   streamextension_dataShaStreamClsc                     ||      }|j                   }|j                  }t        d | D              rdnd} |d        |t        d|t	        |                    | D ]h  } |       }	 ||j
                          ||j                         t        |j                        }
t        |
t              }t	        |      t        z  }|t	        |      k(  sJ d|j                  z         ||j                  t        z  z  }|j                  r	|t        z  } |t        d|j                   |j"                  |j$                  |j&                  |j(                  |j*                  |j,                  |	             |j                  r |t        d	|j                                ||        |       |	z
  d
z   dz  } |d|	|z    |       z
  z         k ||j                  |       |j/                          y)a  Write the cache represented by entries to a stream.

    :param entries:
        **Sorted** list of entries.

    :param stream:
        Stream to wrap into the AdapterStreamCls - it is used for final output.

    :param ShaStreamCls:
        Type to use when writing to the stream. It produces a sha while writing to it,
        before the data is passed on to the wrapped stream.

    :param extension_data:
        Any kind of data to write as a trailer, it must begin a 4 byte identifier,
        followed by its size (4 bytes).
    c              3   4   K   | ]  }|j                     y w)N)extended_flags).0entrys     r?   	<genexpr>zwrite_cache.<locals>.<genexpr>   s     Au++As            DIRC>LL)encodingz"Path %s too long to fit into index>LLLLLL20sH>H       N)tellwriteanyr)   lenctime_bytesmtime_bytesstrrA   r   r   r'   flagsCE_NAMEMASK_INVrr   r$   devinoderj   uidgidsizebinsha	write_sha)rl   rm   rn   ro   
stream_shar   r   versionrt   beginoffsetpath_strrA   plenr   	real_sizes                  r?   r   r      s   . f%J??DE AAAaqG	'N	$ugs7|
,-  <fe e uzz?!(V<4y;&s4y S"F"SS o56[ E		

				


	
 $tU1123dVk)A-3	ei/469:;9<@ !( r@   c           	          | j                  d      }|dk7  rt        d|z        t        t        t        t        f   t        d| j                  d                  }|\  }}|dv s
J d|z         ||fS )z>Return tuple(version_long, num_entries) from the given stream.   rx   zInvalid index file header: %rry   r}   )r#   rw   rv   z@Unsupported git index version %i, only 1, 2, and 3 are supported)readAssertionErrorr3   r0   intr*   )rm   type_idunpackedr   num_entriess        r?   read_headerr      s{    kk!nG'<wFGGE#s(OVE6;;u3E%FGH#G[im!cfm!mmKr@   rt   c                      t        |       dk(  r/| d   }t        |t              sJ |j                  |j                  fS t        t        t        t        f   |       } | S )z
    :return:
        Key suitable to be used for the
        :attr:`index.entries <git.index.base.IndexFile.entries>` dictionary.

    :param entry:
        One instance of type BaseIndexEntry or the path and the stage.
    r#   r
   )	r   
isinstancer%   rA   stager3   r0   r4   r   )rt   entry_firsts     r?   r   r      s[     5zQAh+~666  +"3"344 U8S=)51r@   c                    t        |       \  }}d}i }| j                  }| j                  }||k  r |       }t        d |d            d   }t        d |d            d   }	t        d |d            \  }
}}}}}}}d}|t        z  rt        d |d            d   }|t
        z  } ||      j                  t              } |       |z
  dz   dz  } |||z    |       z
         t        ||||||	|
|||||f      }||||j                  f<   |d	z  }||k  r| j                  d
      }t        |      dkD  sJ dt        |      z         |dd }|dd }||||fS )a  Read a cache file from the given stream.

    :return:
        tuple(version, entries_dict, extension_data, content_sha)

        * *version* is the integer version number.
        * *entries_dict* is a dictionary which maps IndexEntry instances to a path at a
          stage.
        * *extension_data* is ``""`` or 4 bytes of type + 4 bytes of size + size bytes.
        * *content_sha* is a 20 byte sha on all cache file contents.
    r
   z>8sr}   r{   .   r|   rw   r~   r#      zNIndex Footer was not at least a sha on content as it was only %i bytes in sizeiN)r   r   r   r*   r$   r'   decoder   r&   r   r   )rm   r   r   countrl   r   r   r   ctimemtimer   inorj   r   r   r   shar   rr   	path_sizerA   r   rt   rn   content_shas                            r?   r   r      s    'v.G[E8:G;;D;;D
+
fud1g&q)ud1g&q)7=mTR`Ma7b4c4c4e;#D$q'215NK'	I%%f-Vk)A-3	kI%/0D#udE5#sCQTVZ\jkl',u{{#$
! +
2 [[_N~# X[^_m[nn# !&K $DS)NWnk::r@   odbr5   slsir6   c           	      \   g }|j                   }|j                  }||k  r| |   }|j                  dk7  rt        |      |dz  }|j                  j                  d|      }|dk(  r6|j                  |j                  |j                  |j                  |d f       n|j                  || }	|}
|
|k  rD| |
   }|j                  j                  d|      }|dk(  s|j                  || |	k7  rn|
dz  }
|
|k  rDt        | |t        |dz
  |
      |dz         \  }}|j                  |t        |	f       |
}||k  rt               }t        ||j                         |j                  d       |j!                  t#        t$        t'        |j)                               |            }|j                  |fS )aN  Create a tree from the given sorted list of entries and put the respective
    trees into the given object database.

    :param entries:
        **Sorted** list of :class:`~git.index.typ.IndexEntry`\s.

    :param odb:
        Object database to store the trees in.

    :param si:
        Start index at which we should start creating subtrees.

    :param sl:
        Slice indicating the range we should process on the entries list.

    :return:
        tuple(binsha, list(tree_entry, ...))

        A tuple of a sha and a list of tree entries being a tuple of hexsha, mode, name.
    r
   r#   /r   N)startstopr   r   rA   findr`   r   rj   r   slicer   r   r    r   seekstorer   r   r   getvalue)rl   r   r   r   
tree_itemsciendrt   rboundbasexioentryorboundr   _tree_entry_listsioistreams                    r?   r   r   +  s   . (*J	B
''C
s(;;!&u--
ab)R<u||UZZBCIJ ::b(DBs(  ++**33b=FKK7$;t$Ca s( %:'3bSTfVXHY[ade[e$f!C!sGT23 B; s(D )C:syy)HHQKiis3<<>/BCHIGNNJ''r@   
tree_entryr   c                 @    t        | d   | d   |t        z  | d   f      S )Nr#   r
   rw   )r%   r(   )r   r   s     r?   _tree_entry_to_baseindexentryr   p  s*    :a=*Q--9OQ[\]Q^_``r@   	tree_shasc                 t   g }t        |      dv r2t        | |d   d      D ]  }|j                  t        |d              |S t        |      dkD  rt	        dt        |      z        t        | |d      D ]@  \  }}}||4||d   |d   k7  r|d   |d   k7  r|d   |d   k7  s!|d   |d   k7  rh|d   |d   k7  r]|d   |d   k7  rR|j                  t        |d             |j                  t        |d             |j                  t        |d             |d   |d   k7  s|d   |d   k7  r|j                  t        |d             |j                  t        |d             |d   |d   k7  s|d   |d   k7  s
|j                  t        |d             |j                  t        |d             B|F|d   |d   k7  s|d   |d   k7  s^|j                  t        |d             |j                  t        |d             |!|J |j                  t        |d             ||j                  t        |d             |d   |d   k7  s|d   |d   k7  r8|j                  t        |d             |j                  t        |d             &|j                  t        |d             C |S )	a7  
    :return:
        List of :class:`~git.index.typ.BaseIndexEntry`\s representing the aggressive
        merge of the given trees. All valid entries are on stage 0, whereas the
        conflicting ones are left on stage 1, 2 or 3, whereas stage 1 corresponds to the
        common ancestor tree, 2 to our tree and 3 to 'their' tree.

    :param tree_shas:
        1, 2 or 3 trees as identified by their binary 20 byte shas. If 1 or two, the
        entries will effectively correspond to the last given tree. If 3 are given, a 3
        way merge is performed.
    )r#   rw   r   rP   r
   rv   zCannot handle %i trees at oncer#   rw   )r   r   r`   r   
ValueErrorr   )r   r   outrt   r   ourstheirss          r?   aggressive_tree_merger   t  s    !#C 9~,S)B-D 	@EJJ4UA>?	@ 
 9~9C	NJKK 7sIrJ AGdF% Q47*tAw&)/CQSYZ[S\H\Q47*tAw&)/CQSYZ[S\H\ 

#@q#IJ

#@q#IJ

#@#KLaDG+tAw$q'/A

#@q#IJ 

#@#KL Aw$q')T!WQ-?

#@q#IJ

#@q#IJ >ayDG+vayDG/C

#@q#IJ

#@#KL |)))

8CD

8qAB 7fQi'47fQi+?JJ<T1EFJJ<VQGH JJ<T1EFCAGN Jr@   )r
   )V__doc____all__ior   rR   os.pathrA   r=   pathlibr   statr   r   r   r   r   r   r   r^   rX   
gitdb.baser   	gitdb.typr   git.cmdr   r   
git.compatr   r   r   r   git.excr   r   git.objects.funr   r   r    git.utilr!   r"   typr$   r%   r&   r'   r(   utilr)   r*   typingr+   r,   r-   r.   r/   r0   r1   r2   r3   	git.typesr4   git.dbr5   git.objects.treer6   r   r7   r   r   r   r	   rD   r   r   r   bytesr   r   r   r   r   r   r   r    r@   r?   <module>r      sm  	  	   M M M  
  # 6 C C < 
 ; T T  U T T %-  ,,C ,( ,s ,
!c !c !/M# /Mk /M# /M$ /Mf9# 9# 9 *..A	FeNL89:FuIF $+&F *+	F
 
FR	 5	 	 eCHo 	 eNHc9: uXs]?S 07;uI7;
3U8S=)<78%FG7;v LMB(*B($4B(:?B(EHB(
5$~&&'B(Jan aS a^ ac/ cHUO cPTUcPd cr@   