o
    Ďik                     @   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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      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/home/jeff/fluffinator/venv/lib/python3.10/site-packages/git/index/typ.py__init__3   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>F   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__;   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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sizeextended_flagsN)r-   r.   r/   r0   int__annotations__bytesr   r
   r8   r9   r:   r;   r<   r=   r>   r?   r   r   r   r   r3   K   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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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__)clsrC   	__class__r   r   rE   j   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__u      zBaseIndexEntry.__str__c                 C   rI   )Nz(%o, %s, %i, %s)rJ   rM   r   r   r   __repr__x   rO   zBaseIndexEntry.__repr__c                 C   s   t | jdS )zhex version of our shaascii)r   r5   decoderM   r   r   r   rK   {   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_STAGESHIFTrM   r   r   r   rL      s   zBaseIndexEntry.stagec                 C      | j t@ dkS Nr   )r?   CE_EXT_SKIP_WORKTREErM   r   r   r   skip_worktree      zBaseIndexEntry.skip_worktreec                 C   rU   rV   )r?   CE_EXT_INTENT_TO_ADDrM   r   r   r   intent_to_add   rY   zBaseIndexEntry.intent_to_addr   blobrL   c                 C   s   | |j |j|t> |jfS )z9:return: Fully equipped BaseIndexEntry at the given stage)r4   r5   rT   r!   )rF   r\   rL   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   r_   r   r   r   to_blob   s   zBaseIndexEntry.to_blobr   )r-   r.   r/   r0   r   r   r@   rB   r   rE   strrN   rP   propertyrK   rL   r2   rX   r[   classmethodr   r]   r`   __classcell__r   r   rG   r   r   a   s0    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   rM   r   r   r   ctime   s   zIndexEntry.ctimec                 C   rf   )z:See :attr:`ctime` property, but returns modification time.r7   )r   r   r@   r   r9   rM   r   r   r   mtime   r^   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!   )rF   ri   timer   r   r   	from_base   s   
&zIndexEntry.from_baser   r\   rL   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   rT   r!   r>   )rF   r\   rL   rj   r   r   r   r]      s   zIndexEntry.from_blobN)ri   r   r   r   ra   )r-   r.   r/   r0   rc   r   r@   rg   rh   rd   rk   r   r]   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_NAMEMASKrS   CE_EXTENDEDCE_VALIDrT   rW   rZ   r   r3   r   r   r   r   r   r   <module>   s,    "?