a
    `ºDf%(  ã                   @   sð   d dgZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZmZmZ ddlmZ ddlmZmZmZ dd	lmZmZmZ erÄdd
lmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ed Z$G dd „ d e
ƒZ%G dd„ de%ƒZ&dS )ÚObjectÚIndexObjecté    N)ÚWorkTreeRepositoryUnsupported)Ú	LazyMixinÚ
bin_to_hexÚjoin_path_nativeÚstream_copyé   )Úget_object_type_by_name)ÚAnyÚTYPE_CHECKINGÚUnion)ÚAnyGitObjectÚGitObjectTypeStringÚPathLike)ÚOStream)Ú	Reference)ÚRepo)ÚBlob)Ú	Submodule)ÚTree)r   r   r   c                       s&  e Zd ZU dZdZdZejejej	ej
fZdZdZeedf ed< deddœ‡ fd	d
„Zedeedf edœdd„ƒZedeedœdd„ƒZeddœ‡ fdd„Zeedœdd„Zeedœdd„Zedœdd„Zedœdd„Zedœdd „Z e!edœd!d"„ƒZ"e!d#dœd$d%„ƒZ#d#d d&œd'd(„Z$‡  Z%S ))r   ar  Base class for classes representing git object types.

    The following four leaf classes represent specific kinds of git objects:

    * :class:`Blob <git.objects.blob.Blob>`
    * :class:`Tree <git.objects.tree.Tree>`
    * :class:`Commit <git.objects.commit.Commit>`
    * :class:`TagObject <git.objects.tag.TagObject>`

    See :manpage:`gitglossary(7)` on:

    * "object": https://git-scm.com/docs/gitglossary#def_object
    * "object type": https://git-scm.com/docs/gitglossary#def_object_type
    * "blob": https://git-scm.com/docs/gitglossary#def_blob_object
    * "tree object": https://git-scm.com/docs/gitglossary#def_tree_object
    * "commit object": https://git-scm.com/docs/gitglossary#def_commit_object
    * "tag object": https://git-scm.com/docs/gitglossary#def_tag_object

    :note:
        See the :class:`~git.types.AnyGitObject` union type of the four leaf subclasses
        that represent actual git object types.

    :note:
        :class:`~git.objects.submodule.base.Submodule` is defined under the hierarchy
        rooted at this :class:`Object` class, even though submodules are not really a
        type of git object. (This also applies to its
        :class:`~git.objects.submodule.root.RootModule` subclass.)

    :note:
        This :class:`Object` class should not be confused with :class:`object` (the root
        of the class hierarchy in Python).
    Z(0000000000000000000000000000000000000000s                       )ÚrepoÚbinshaÚsizeNÚtyper   )r   r   Úreturnc                    s:   t ƒ  ¡  || _|| _t|ƒdks6J d|t|ƒf ƒ‚dS )zýInitialize an object by identifying it by its binary sha.

        All keyword arguments will be set on demand if ``None``.

        :param repo:
            Repository this object is located in.

        :param binsha:
            20 byte SHA1
        é   z,Require 20 byte binary sha, got %r, len = %iN)ÚsuperÚ__init__r   r   Úlen)Úselfr   r   ©Ú	__class__© ú]/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/git/objects/base.pyr   d   s    
þzObject.__init__r   )r   Úidr   c                 C   s   |  t|ƒ¡S )a"  
        :return:
            New :class:`Object` instance of a type appropriate to the object type behind
            `id`. The id of the newly created object will be a binsha even though the
            input id may have been a `~git.refs.reference.Reference` or rev-spec.

        :param id:
            :class:`~git.refs.reference.Reference`, rev-spec, or hexsha.

        :note:
            This cannot be a ``__new__`` method as it would always call :meth:`__init__`
            with the input id which is not necessarily a binsha.
        )Z	rev_parseÚstr)Úclsr   r%   r#   r#   r$   Úneww   s    z
Object.new)r   Úsha1r   c                 C   sB   || j krtdƒ||ƒS |j |¡}t|jƒ||jƒ}|j|_|S )zª
        :return:
            New object instance of a type appropriate to represent the given binary sha1

        :param sha1:
            20 byte binary sha1.
        s   commit)ÚNULL_BIN_SHAr
   ÚodbÚinfor   r   r   )r'   r   r)   ÚoinfoÚinstr#   r#   r$   Únew_from_shaˆ   s    	
zObject.new_from_sha©Úattrr   c                    s2   |dkr"| j j | j¡}|j| _ntƒ  |¡ dS )zRetrieve object information.r   N)r   r+   r,   r   r   r   Ú_set_cache_)r    r1   r-   r!   r#   r$   r2   š   s    
zObject._set_cache_)Úotherr   c                 C   s   t |dƒsdS | j|jkS )z3:return: ``True`` if the objects have the same SHA1r   F©Úhasattrr   ©r    r3   r#   r#   r$   Ú__eq__¢   s    
zObject.__eq__c                 C   s   t |dƒsdS | j|jkS )z::return: ``True`` if the objects do not have the same SHA1r   Tr4   r6   r#   r#   r$   Ú__ne__¨   s    
zObject.__ne__©r   c                 C   s
   t | jƒS )zE:return: Hash of our id allowing objects to be used in dicts and sets)Úhashr   ©r    r#   r#   r$   Ú__hash__®   s    zObject.__hash__c                 C   s   | j S )z=:return: String of our SHA1 as understood by all git commands)Úhexshar;   r#   r#   r$   Ú__str__²   s    zObject.__str__c                 C   s   d| j j| jf S )z::return: String with pythonic representation of our objectz<git.%s "%s">)r"   Ú__name__r=   r;   r#   r#   r$   Ú__repr__¶   s    zObject.__repr__c                 C   s   t | jƒ d¡S )z6:return: 40 byte hex version of our 20 byte binary shaÚascii)r   r   Údecoder;   r#   r#   r$   r=   º   s    zObject.hexshar   c                 C   s   | j j | j¡S )z³
        :return:
            File-object compatible stream to the uncompressed raw data of the object

        :note:
            Returned streams must be read in order.
        )r   r+   Ústreamr   r;   r#   r#   r$   Údata_streamÀ   s    	zObject.data_stream)Úostreamr   c                 C   s   | j j | j¡}t||ƒ | S )zªWrite our data directly to the given output stream.

        :param ostream:
            File-object compatible stream object.

        :return:
            self
        )r   r+   rC   r   r   )r    rE   Zistreamr#   r#   r$   Ústream_dataË   s    	
zObject.stream_data)&r?   Ú
__module__Ú__qualname__Ú__doc__ZNULL_HEX_SHAr*   ÚdbtypZstr_blob_typeZstr_tree_typeZstr_commit_typeZstr_tag_typeÚTYPESÚ	__slots__r   r   r   Ú__annotations__Úbytesr   Úclassmethodr&   r   r(   r/   r2   r   Úboolr7   r8   Úintr<   r>   r@   Úpropertyr=   rD   rF   Ú__classcell__r#   r#   r!   r$   r   &   s4   
!ü
c                       sŽ   e Zd ZdZdZdZddeedef ede	f ddœ‡ fdd„Z
ed	œd
d„Zeddœ‡ fdd„Zeed	œdd„ƒZee	d	œdd„ƒZ‡  ZS )r   a|  Base for all objects that can be part of the index file.

    The classes representing git object types that can be part of the index file are
    :class:`~git.objects.tree.Tree and :class:`~git.objects.blob.Blob`. In addition,
    :class:`~git.objects.submodule.base.Submodule`, which is not really a git object
    type but can be part of an index file, is also a subclass.
    )ÚpathÚmoderT   Nr   )r   r   rU   rT   r   c                    s.   t ƒ  ||¡ |dur|| _|dur*|| _dS )a¥  Initialize a newly instanced :class:`IndexObject`.

        :param repo:
            The :class:`~git.repo.base.Repo` we are located in.

        :param binsha:
            20 byte sha1.

        :param mode:
            The stat-compatible file mode as :class:`int`.
            Use the :mod:`stat` module to evaluate the information.

        :param path:
            The path to the file in the file system, relative to the git repository
            root, like ``file.ext`` or ``folder/other.ext``.

        :note:
            Path may not be set if the index object has been created directly, as it
            cannot be retrieved without knowing the parent tree.
        N)r   r   rU   rT   )r    r   r   rU   rT   r!   r#   r$   r   ç   s
    zIndexObject.__init__r9   c                 C   s
   t | jƒS )zˆ
        :return:
            Hash of our path as index items are uniquely identifiable by path, not by
            their data!
        )r:   rT   r;   r#   r#   r$   r<     s    zIndexObject.__hash__r0   c                    s2   |t jv r"td|t| ƒjf ƒ‚ntƒ  |¡ d S )Nz[Attribute '%s' unset: path and mode attributes must have been set during %s object creation)r   rL   ÚAttributeErrorr   r?   r   r2   )r    r1   r!   r#   r$   r2     s    
ÿÿzIndexObject._set_cache_c                 C   s   t  | j¡S )zA:return: Name portion of the path, effectively being the basename)ÚospÚbasenamerT   r;   r#   r#   r$   Úname  s    zIndexObject.namec                 C   s(   | j jdurt| j j| jƒS tdƒ‚dS )a&  
        :return:
            Absolute path to this index object in the file system (as opposed to the
            :attr:`path` field which is a path relative to the git repository).

            The returned path will be native to the system and contains ``\`` on
            Windows.
        Nz"working_tree_dir was None or empty)r   Zworking_tree_dirr   rT   r   r;   r#   r#   r$   Úabspath   s    
zIndexObject.abspath)NN)r?   rG   rH   rI   rL   Z_id_attribute_rN   r   rQ   r   r   r<   r&   r2   rR   rY   rZ   rS   r#   r#   r!   r$   r   Ù   s$     û

ú!)'Ú__all__Úos.pathrT   rW   Z	gitdb.typÚtyprJ   Zgit.excr   Zgit.utilr   r   r   r   Úutilr
   Útypingr   r   r   Z	git.typesr   r   r   Z
gitdb.baser   Zgit.refs.referencer   Zgit.repor   Zblobr   Zsubmodule.baser   Útreer   ZIndexObjUnionr   r   r#   r#   r#   r$   Ú<module>   s$    4