U
    æ¥¡cÄ  ã                   @   s”   d Z ddlmZmZ ddlmZ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 dd	lmZ er|dd
lmZ dZG dd„ de	ƒZdS )zBModule with our own gitdb implementation - it uses the git commandé    )Ú
bin_to_hexÚ
hex_to_bin)ÚOInfoÚOStream)ÚGitDB)ÚLooseObjectDB)Ú	BadObject)ÚGitCommandError)ÚTYPE_CHECKING)ÚPathLike)ÚGit)ÚGitCmdObjectDBr   c                       sZ   e Zd ZdZedddœ‡ fdd„Zeedœdd	„Zee	dœd
d„Z
eedœdd„Z‡  ZS )r   a=  A database representing the default git object store, which includes loose
    objects, pack files and an alternates file

    It will create objects only in the loose object database.
    :note: for now, we use the git command to do all the lookup, just until he
        have packs and the other implementations
    r   N)Ú	root_pathÚgitÚreturnc                    s   t t| ƒ |¡ || _dS )z8Initialize this instance with the root and a git commandN)Úsuperr   Ú__init__Ú_git)Úselfr   r   ©Ú	__class__© ú*/tmp/pip-unpacked-wheel-_pbxsds5/git/db.pyr   "   s    zGitCmdObjectDB.__init__)Úbinshar   c                 C   s&   | j  t|ƒ¡\}}}tt|ƒ||ƒS )N)r   Úget_object_headerr   r   r   )r   r   ÚhexshaÚtypenameÚsizer   r   r   Úinfo'   s    zGitCmdObjectDB.infoc                 C   s*   | j  t|ƒ¡\}}}}tt|ƒ|||ƒS )z)For now, all lookup is done by git itself)r   Zstream_object_datar   r   r   )r   r   r   r   r   Ústreamr   r   r   r   +   s    zGitCmdObjectDB.stream)Úpartial_hexshar   c              
   C   sR   z| j  |¡\}}}t|ƒW S  ttfk
rL } zt|ƒ|‚W 5 d}~X Y nX dS )zñ:return: Full binary 20 byte sha from the given partial hexsha
        :raise AmbiguousObjectName:
        :raise BadObject:
        :note: currently we only raise BadObject as git does not communicate
            AmbiguousObjects separatelyN)r   r   r   r	   Ú
ValueErrorr   )r   r    r   Z	_typenameÚ_sizeÚer   r   r   Úpartial_to_complete_sha_hex2   s
    
z*GitCmdObjectDB.partial_to_complete_sha_hex)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úbytesr   r   r   r   Ústrr$   Ú__classcell__r   r   r   r   r      s
   r   N)r(   Zgit.utilr   r   Z
gitdb.baser   r   Zgitdb.dbr   r   Z	gitdb.excr   Zgit.excr	   Útypingr
   Z	git.typesr   Zgit.cmdr   Ú__all__r   r   r   r   r   Ú<module>   s   