o
    ﯪg                     @   s   d Z g dZddlm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mZmZ dd	lmZ er>dd
lmZ eZdZdZdZdZdZG dd dZG dd deZG dd deZG dd deZ dS )z#Additional types used by the index.)
BlobFilterBaseIndexEntry
IndexEntry	StageType    )b2a_hex)Path)Blob   )packunpack)
NamedTupleSequenceTYPE_CHECKINGTupleUnioncast)PathLike)Repoi  i 0  i @  i      c                   @   sD   e Zd ZdZdZdee ddfddZdee	e
f defd	d
ZdS )r   zPredicate to be used by
    :meth:`IndexFile.iter_blobs <git.index.base.IndexFile.iter_blobs>` allowing to
    filter only return blobs which match the given list of directories or files.

    The given paths are given relative to the repository.
    pathsr   returnNc                 C   s
   || _ dS )z
        :param paths:
            Tuple or list of paths which are either pointing to directories or to files
            relative to the current repository.
        Nr   )selfr    r   I/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/git/index/typ.py__init__0   s   
zBlobFilter.__init__
stage_blobc                 C   s   |d j }t|tr|nt|}| jD ]+}t|tr|nt|}|j}|j}t|t|kr/qtdd t||D r> dS qdS )Nr	   c                 s   s    | ]	\}}||kV  qd S )Nr   ).0ijr   r   r   	<genexpr>C   s    z&BlobFilter.__call__.<locals>.<genexpr>TF)path
isinstancer   r   partslenallzip)r   r   blob_pathlike	blob_pathpathliker!   filter_parts
blob_partsr   r   r   __call__8   s   

zBlobFilter.__call__)__name__
__module____qualname____doc__	__slots__r   r   r   r   r   r   boolr,   r   r   r   r   r   &   s
    r   c                   @   s   e Zd ZU dZeed< eed< eed< eed< edddZ	eed< edddZ
eed	< dZeed
< dZeed< dZeed< dZeed< dZeed< dS )BaseIndexEntryHelperzTyped named tuple to provide named attribute access for :class:`BaseIndexEntry`.

    This is needed to allow overriding ``__new__`` in child class to preserve backwards
    compatibility.
    modebinshaflagsr!   >LLr   ctime_bytesmtime_bytesdevinodeuidgidsizeN)r-   r.   r/   r0   int__annotations__bytesr   r
   r8   r9   r:   r;   r<   r=   r>   r   r   r   r   r3   H   s   
 r3   c                       s   e Zd ZdZdeeeeeef eeeeeeeeeeeef f dd f fddZ	de
fddZde
fdd	Zede
fd
dZedefddZeddededd fddZdddefddZ  ZS )r   a  Small brother of an index entry which can be created to describe changes
    done to the index in which case plenty of additional information is not required.

    As the first 4 data members match exactly to the :class:`IndexEntry` type, methods
    expecting a :class:`BaseIndexEntry` can also handle full :class:`IndexEntry`\s even
    if they use numeric indices for performance reasons.
    	inp_tupler   c                    s   t  j| g|R  S )z\Override ``__new__`` to allow construction from a tuple for backwards
        compatibility.)super__new__)clsrB   	__class__r   r   rD   e   s   	zBaseIndexEntry.__new__c                 C      d| j | j| j| jf S )Nz%o %s %i	%sr4   hexshastager!   r   r   r   r   __str__p      zBaseIndexEntry.__str__c                 C   rH   )Nz(%o, %s, %i, %s)rI   rL   r   r   r   __repr__s   rN   zBaseIndexEntry.__repr__c                 C   s   t | jdS )zhex version of our shaascii)r   r5   decoderL   r   r   r   rJ   v   s   zBaseIndexEntry.hexshac                 C   s   | j t@ t? S )a|  Stage of the entry, either:

            * 0 = default stage
            * 1 = stage before a merge or common ancestor entry in case of a 3 way merge
            * 2 = stage of entries from the 'left' side of the merge
            * 3 = stage of entries from the 'right' side of the merge

        :note:
            For more information, see :manpage:`git-read-tree(1)`.
        )r6   CE_STAGEMASKCE_STAGESHIFTrL   r   r   r   rK   {   s   zBaseIndexEntry.stager   blobrK   c                 C   s   | |j |j|t> |jfS )z9:return: Fully equipped BaseIndexEntry at the given stage)r4   r5   rS   r!   )rE   rT   rK   r   r   r   	from_blob      zBaseIndexEntry.from_blobrepor   c                 C   s   t || j| j| jS )z7:return: Blob using the information of this index entry)r   r5   r4   r!   )r   rW   r   r   r   to_blob   s   zBaseIndexEntry.to_blobr   )r-   r.   r/   r0   r   r   r?   rA   r   rD   strrM   rO   propertyrJ   rK   classmethodr   rU   rX   __classcell__r   r   rF   r   r   \   s(    r   c                   @   sn   e Zd ZdZedeeef fddZedeeef fddZe	dd	d
Z
e	ddededd fddZdS )r   a-  Allows convenient access to index entry data as defined in
    :class:`BaseIndexEntry` without completely unpacking it.

    Attributes usually accessed often are cached in the tuple whereas others are
    unpacked on demand.

    See the properties for a mapping between names and tuple indices.
    r   c                 C      t tttf td| jS )z
        :return:
            Tuple(int_time_seconds_since_epoch, int_nano_seconds) of the
            file's creation time
        r7   )r   r   r?   r   r8   rL   r   r   r   ctime   s   zIndexEntry.ctimec                 C   r^   )z:See :attr:`ctime` property, but returns modification time.r7   )r   r   r?   r   r9   rL   r   r   r   mtime   rV   zIndexEntry.mtimebaser   c                 C   s2   t ddd}t|j|j|j|j||dddddfS )z
        :return:
            Minimal entry as created from the given :class:`BaseIndexEntry` instance.
            Missing values will be set to null-like values.

        :param base:
            Instance of type :class:`BaseIndexEntry`.
        r7   r   )r
   r   r4   r5   r6   r!   )rE   ra   timer   r   r   	from_base   s   
&zIndexEntry.from_baser   rT   rK   c                 C   s6   t ddd}t|j|j|t> |j||dddd|jfS )z7:return: Minimal entry resembling the given blob objectr7   r   )r
   r   r4   r5   rS   r!   r>   )rE   rT   rK   rb   r   r   r   rU      s   zIndexEntry.from_blobN)ra   r   r   r   rY   )r-   r.   r/   r0   r[   r   r?   r_   r`   r\   rc   r   rU   r   r   r   r   r      s    	r   N)!r0   __all__binasciir   pathlibr   git.objectsr   utilr
   r   typingr   r   r   r   r   r   	git.typesr   git.repor   r?   r   CE_NAMEMASKrR   CE_EXTENDEDCE_VALIDrS   r   r3   r   r   r   r   r   r   <module>   s(    "7