o
     À{g%(  ã                   @   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rbd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                       s0  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dd	ed
df‡ fdd„Zedddeedf d
efdd„ƒZeddded
efdd„ƒZded
df‡ fdd„Zded
efdd„Zded
efdd„Zd
e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*d%d&„ƒZ#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).
    Ú(0000000000000000000000000000000000000000s                       )ÚrepoÚbinshaÚsizeNÚtyper   r   r   Úreturnc                    s:   t ƒ  ¡  || _|| _t|ƒdksJ 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__© úm/var/www/bot.gig.net.ua/public_html/telegram/P1/HellBot/venv/lib/python3.10/site-packages/git/objects/base.pyr   d   s   
þzObject.__init__Ú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.
        )Ú	rev_parseÚstr)Úclsr   r&   r$   r$   r%   Úneww   s   z
Object.newÚsha1c                 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Úattrc                    s4   |dkr| j j | j¡}|j| _dS tƒ  |¡ dS )zRetrieve object information.r   N)r   r-   r.   r   r   r   Ú_set_cache_)r!   r2   r/   r"   r$   r%   r3   š   s   zObject._set_cache_Úotherc                 C   s   t |dƒsdS | j|jkS )z3:return: ``True`` if the objects have the same SHA1r   F©Úhasattrr   ©r!   r4   r$   r$   r%   Ú__eq__¢   ó   
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   Tr5   r7   r$   r$   r%   Ú__ne__¨   r9   zObject.__ne__c                 C   ó
   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Úostreamc                 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-   rE   r   r   )r!   rG   Úistreamr$   r$   r%   Ústream_dataË   s   	
zObject.stream_data)r   r   )rG   r   r   r   )&rA   Ú
__module__Ú__qualname__Ú__doc__ÚNULL_HEX_SHAr,   ÚdbtypÚstr_blob_typeÚstr_tree_typeÚstr_commit_typeÚstr_tag_typeÚTYPESÚ	__slots__r   r   r   Ú__annotations__Úbytesr   Úclassmethodr(   r   r*   r1   r3   r   Úboolr8   r:   Úintr>   r@   rB   Úpropertyr?   rF   rI   Ú__classcell__r$   r$   r"   r%   r   &   s8   
 !ü 
c                       sœ   e Zd ZdZdZdZ		ddddededef dede	f d	df
‡ fd
d„Z
d	efdd„Zded	df‡ fdd„Zed	efdd„ƒZed	e	f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Úmoder\   Nr   r   r   r]   r   c                    s2   t ƒ  ||¡ |dur|| _|dur|| _dS 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   r]   r\   )r!   r   r   r]   r\   r"   r$   r%   r   ç   s   
ÿzIndexObject.__init__c                 C   r;   )zˆ
        :return:
            Hash of our path as index items are uniquely identifiable by path, not by
            their data!
        )r<   r\   r=   r$   r$   r%   r>     s   
zIndexObject.__hash__r2   c                    s0   |t jv rtd|t| ƒjf ƒ‚tƒ  |¡ d S )Nz[Attribute '%s' unset: path and mode attributes must have been set during %s object creation)r   rT   ÚAttributeErrorr   rA   r   r3   )r!   r2   r"   r$   r%   r3     s   
ÿÿzIndexObject._set_cache_c                 C   s   t  | j¡S )zA:return: Name portion of the path, effectively being the basename)ÚospÚbasenamer\   r=   r$   r$   r%   Úname  s   zIndexObject.namec                 C   s$   | j jdurt| j j| jƒS tdƒ‚)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   Úworking_tree_dirr   r\   r   r=   r$   r$   r%   Úabspath   s   
zIndexObject.abspath)NN)rA   rJ   rK   rL   rT   Ú_id_attribute_rV   r   rY   r   r   r>   r(   r3   rZ   ra   rc   r[   r$   r$   r"   r%   r   Ù   s.    ûþý
ü
ûú!)'Ú__all__Úos.pathr\   r_   Ú	gitdb.typÚtyprN   Úgit.excr   Úgit.utilr   r   r   r   Úutilr
   Útypingr   r   r   Ú	git.typesr   r   r   Ú
gitdb.baser   Úgit.refs.referencer   Úgit.repor   Úblobr   Úsubmodule.baser   Útreer   ÚIndexObjUnionr   r   r$   r$   r$   r%   Ú<module>   s&    4