HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/git/index/__pycache__/fun.cpython-310.pyc
o

;j�B�@s�dZgd�ZddlmZddlZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZmZddlZddlZddlmZddlmZdd	lmZmZdd
lmZmZmZmZddl m!Z!m"Z"ddl#m$Z$m%Z%m&Z&dd
l'm(Z(m)Z)ddl*m+Z+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1m2Z2ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<ddl=m>Z>e8r�ddl?m@Z@ddlAmBZBddlCmDZDeeBZE	e.ZFdeGde>deGfdd�ZHdeGdeGfdd�ZIdeGddd eGddfd!d"�ZJd#eKdeKfd$d%�ZLde(fd&e7e;e,d'fd(e5eMd)e;deMfd*e:e(ddf
d+d,�ZNd(e5eMde9eKeKffd-d.�ZOd/e;e,e>eKfde9e>eKffd0d1�ZPd(e5eMde9eKe4e9e>eKfd'feMeMffd2d3�ZQ	dBd&e6e-d4d5d6eRd7eKde9eMe6d8ff
d9d:�ZSd;d8d<eKde,fd=d>�ZTd4d5d?e7eMde6e,fd@dA�ZUdS)CzVStandalone 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�returncCst�|d|�S)zK:return: path to the given named hook in the given git repository directoryZhooks)�osp�join)r7r8�r<�A/opt/saltstack/salt/lib/python3.10/site-packages/git/index/fun.pyr>sr�pathcCst�|�dS)Nr")r:�splitext)r>r<r<r=�_has_file_extensionCsr@�indexr6�argsc

Gs(t||jj�}t�|tj�sdStj��}tt�	|j
��|d<d|d<|g}z+tjdkr?t
|�s?t|��|jj���}d|g}t|t|�|tjtj|jjd�}Wntyc}zt||�|�d}~wwg}	g}
t||	j|
jt�d�|	�}d�|
�}|jd	kr�t|t�}t|t�}t||j||��dS)
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:
    NZGIT_INDEX_FILE�:Z
GIT_EDITOR�win32zbash.exe)�env�stdout�stderr�cwd�r	)rZrepor8�os�access�X_OK�environ�copyr�fspathr>�sys�platformr@r�relative_toZworking_dir�as_posixr�list�
subprocess�PIPE�	Exceptionrr�appendr!r;�
returncoderr)
r7rArBZhprE�cmdZrelative_hp�process�exZstdout_listZstderr_listrFrGr<r<r=rGs@


���




�r�modecCs8t|�rtSt|�st|�tkrtSt|t@rdpdBS)zZConvert the given mode from a stat call to the corresponding index mode and
    return it.i�i�)rr
rrrrr)r]r<r<r=rzs
r�entriesr%�stream�extension_data�ShaStreamClscCsT||�}|j}|j}tdd�|D��rdnd}|d�|td|t|���|D]s}|�}	||j�||j�t|j�}
t	|
t
d�}t|�t@}|t|�ksTJd|j��||jt
@B}
|jrb|
tO}
|td	|j|j|j|j|j|j|j|
�	�|jr�|td
|j��||�|�|	dd@}|d
|	||��q'|dur�|�|�|��dS)aWrite 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).
    css�|]}|jVqdS)N)�extended_flags)�.0�entryr<r<r=�	<genexpr>�s�zwrite_cache.<locals>.<genexpr>���DIRC�>LL)�encodingz"Path %s too long to fit into index�>LLLLLL20sH�>H�����N)�tell�write�anyr(�lenZctime_bytesZmtime_bytes�strr>rrr&�flags�CE_NAMEMASK_INVrbr#�dev�inoder]�uid�gid�size�binshaZ	write_sha)r^r_r`raZ
stream_sharprq�versionrd�beginoffsetZpath_strr>Zplenru�	real_sizer<r<r=r�sL


��

rcCs`|�d�}|dkrtd|��ttttftd|�d���}|\}}|dvs,Jd|��||fS)z>Return tuple(version_long, num_entries) from the given stream.�rhzInvalid index file header: %rrirm)r"rgrfz@Unsupported git index version %i, only 1, 2, and 3 are supported)�read�AssertionErrorr2r/�intr))r_Ztype_idZunpackedr}�num_entriesr<r<r=�read_header�s
r�rdcGsDt|�dkr|d}t|t�sJ�|j|jfSttttf|�}|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	)	rs�
isinstancer$r>�stager2r/r3r�)rdZentry_firstr<r<r=r�s
rc
CsPt|�\}}d}i}|j}|j}||kr�|�}td|d��d}td|d��d}	td|d��\}
}}}
}}}}d}|t@rGtd|d��d}|t@}||��t�}|�|dd@}||||��t||||||	|
||
|||f�}||||j	f<|d	7}||ks|�d
�}t
|�dks�Jdt
|���|d
d�}|dd
�}||||fS)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>8srmrk�.rlrgrnr"����zNIndex Footer was not at least a sha on content as it was only %i bytes in sizei��N)r�r�rpr)r#r&�decoderr%r�rs)r_r}r��countr^r�rpr~�ctime�mtimerw�inor]ryrzr{�sharurbZ	path_sizer>rrdr`Zcontent_shar<r<r=r�s8 �

�r�odbr4�sl�sir5cCsHg}|j}|j}||kr�||}|jdkrt|��|d7}|j�d|�}|dkr8|�|j|j|j|d�f�nH|j||�}	|}
|
|krf||
}|j�d|�}|dks]|j||�|	kr^n|
d7}
|
|ksEt	||t
|d|
�|d�\}
}|�|
t|	f�|
}||kst�}t
||j�|�d�|�ttt|���|��}|j|fS)aNCreate 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�rr>�findrXr|r]r�slicerr
rrq�seek�storerrrs�getvalue)r^r�r�r�Z
tree_itemsZci�endrdZrbound�baseZxiZoentryZorboundr�Z_tree_entry_list�sioZistreamr<r<r=r+s:
 � �"

r�
tree_entryr�cCs t|d|d|t>|df�S)Nr"r	rg)r$r')r�r�r<r<r=�_tree_entry_to_baseindexentryps r��	tree_shascCs�g}t|�dvrt||dd�D]
}|�t|d��q|St|�dkr+tdt|���t||d�D�]\}}}|dur�|dur�|dur�|d|dkr[|d|dkr[|d|dkss|d|dkr�|d|dkr�|d|dkr�|�t|d��|�t|d	��|�t|d��q1|d|dks�|d|dkr�|�t|d��q1|�t|d��q1|d|dks�|d|dkr�|�t|d��|�t|d	��q1|dur�q1|d|dks�|d|dkr�|�t|d��|�t|d��q1|du�r
|du�sJ�|�t|d��q1|du�r|�t|d��q1|d|dk�s*|d|dk�r;|�t|d	��|�t|d��q1|�t|d��q1|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"rgr�rIr	rfzCannot handle %i trees at onceNr"rg)rsrrXr��
ValueErrorr)r�r��outrdr�ZoursZtheirsr<r<r=�aggressive_tree_mergetsN
00  � �
	
$r�)r	)V�__doc__�__all__�ior
rJZos.pathr>r:�pathlibr�statrr
rrrrrrUrPZ
gitdb.baserZ	gitdb.typrZgit.cmdrrZ
git.compatrrrrZgit.excrrZgit.objects.funrrrZgit.utilr r!�typr#r$r%r&r'�utilr(r)�typingr*r+r,r-r.r/r0r1r2Z	git.typesr3Zgit.dbr4Zgit.objects.treer5r�r6rrvrtrr@rr�r�bytesrr�rrr�rr�r�r<r<r<r=�<module>s�$,3
���
��
�I$�
�;�����
�E"