Ë
    ómxie#  ã                   óÄ   — d Z ddlmZmZmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZ dZ G d„ d	«      Z G d
„ d«      Z G d„ d«      Z G d„ d«      Zd„ Z G d„ deee«      Zy)z8Contains implementations of database retrieveing objectsé    )ÚjoinÚ	LazyMixinÚ
hex_to_bin)Ú
force_text)Ú	BadObjectÚAmbiguousObjectName)Úchain)Úreduce)Ú	ObjectDBRÚ	ObjectDBWÚ
FileDBBaseÚ
CompoundDBÚ	CachingDBc                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)	r   zkDefines an interface for object database lookup.
    Objects are identified either by their 20 byte bin shac                 ó   — | j                   S ©N)Úhas_obj©ÚselfÚshas     úD/home/htdocs/ttos/venv/lib/python3.12/site-packages/gitdb/db/base.pyÚ__contains__zObjectDBR.__contains__   s   € Ø�|‰|Ðó    c                 ó   — t        d«      ‚)zê
        Whether the object identified by the given 20 bytes
            binary sha is contained in the database

        :return: True if the object identified by the given 20 bytes
            binary sha is contained in the databaseúTo be implemented in subclass©ÚNotImplementedErrorr   s     r   Ú
has_objectzObjectDBR.has_object"   s   € ô "Ð"AÓBÐBr   c                 ó   — t        d«      ‚)zW :return: OInfo instance
        :param sha: bytes binary sha
        :raise BadObject:r   r   r   s     r   ÚinfozObjectDBR.info+   ó   € ô "Ð"AÓBÐBr   c                 ó   — t        d«      ‚)z[:return: OStream instance
        :param sha: 20 bytes binary sha
        :raise BadObject:r   r   r   s     r   ÚstreamzObjectDBR.stream1   r!   r   c                 ó   — t        «       ‚)z+:return: amount of objects in this databaser   ©r   s    r   ÚsizezObjectDBR.size7   ó   € ä!Ó#Ð#r   c                 ó   — t        «       ‚)zGReturn iterator yielding 20 byte shas for all objects in this data baser   r%   s    r   Úsha_iterzObjectDBR.sha_iter;   r'   r   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    r#   r&   r)   © r   r   r   r      s(   „ ñ>òòCòCòCò$ó$r   r   c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)r   z6Defines an interface to create objects in the databasec                 ó   — d | _         y r   ©Ú_ostream)r   ÚargsÚkwargss      r   Ú__init__zObjectDBW.__init__F   s	   € Øˆ�r   c                 ó,   — | j                   }|| _         |S )ab  
        Adjusts the stream to which all data should be sent when storing new objects

        :param stream: if not None, the stream to use, if None the default stream
            will be used.
        :return: previously installed stream, or None if there was no override
        :raise TypeError: if the stream doesn't have the supported functionalityr1   )r   r#   Úcstreams      r   Úset_ostreamzObjectDBW.set_ostreamJ   s   € ð —-‘-ˆØˆŒØˆr   c                 ó   — | j                   S )z¤
        Return the output stream

        :return: overridden output stream this instance will write to, or None
            if it will write to the default streamr1   r%   s    r   ÚostreamzObjectDBW.ostreamV   s   € ð �}‰}Ðr   c                 ó   — t        d«      ‚)a¿  
        Create a new object in the database
        :return: the input istream object with its sha set to its corresponding value

        :param istream: IStream compatible instance. If its sha is already set
            to a value, the object will just be stored in the our database format,
            in which case the input stream is expected to be in object format ( header + contents ).
        :raise IOError: if data could not be writtenr   r   )r   Úistreams     r   ÚstorezObjectDBW.store^   s   € ô "Ð"AÓBÐBr   N)r*   r+   r,   r-   r5   r8   r:   r=   r.   r   r   r   r   B   s   „ á@òò
òó	Cr   r   c                   ó.   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zˆ xZS )r   z}Provides basic facilities to retrieve files of interest, including
    caching facilities to help mapping hexsha's to objectsc                 ó0   •— t         ‰| �  «        || _        y)aY  Initialize this instance to look for its files at the given root path
        All subsequent operations will be relative to this path
        :raise InvalidDBRoot:
        **Note:** The base will not perform any accessablity checking as the base
            might not yet be accessible, but become accessible before the first
            access.N)Úsuperr5   Ú
_root_path)r   Ú	root_pathÚ	__class__s     €r   r5   zFileDBBase.__init__q   s   ø€ ô 	‰ÑÔØ#ˆ�r   c                 ó   — | j                   S )z':return: path at which this db operates)rA   r%   s    r   rB   zFileDBBase.root_path|   s   € à�‰Ðr   c                 ó@   — t        | j                  t        |«      «      S )z~
        :return: the given relative path relative to our database root, allowing
            to pontentially access datafiles)r   rA   r   )r   Ú	rela_paths     r   Údb_pathzFileDBBase.db_path€   s   € ô �D—O‘O¤Z°	Ó%:Ó;Ð;r   )r*   r+   r,   r-   r5   rB   rG   Ú__classcell__©rC   s   @r   r   r   l   s   ø„ ñ>ô$òö<r   r   c                   ó   — e Zd ZdZdd„Zy)r   z/A database which uses caches to speed-up accessc                  ó   — y)ar  
        Call this method if the underlying data changed to trigger an update
        of the internal caching structures.

        :param force: if True, the update must be performed. Otherwise the implementation
            may decide not to perform an update if it thinks nothing has changed.
        :return: True if an update was performed as something change indeedNr.   )r   Úforces     r   Úupdate_cachezCachingDB.update_cache�   s   � r   N©F)r*   r+   r,   r-   rM   r.   r   r   r   r   ˆ   s   „ á9ôOr   r   c                 óÌ   — t        | t        «      rC| j                  «       }|j                  d„ |D «       «       d„ |D «       D ]  }t	        ||«       Œ y|j                  | «       y)zfFill output list with database from db, in order. Deals with Loose, Packed
    and compound databases.c              3   óB   K  — | ]  }t        |t        «      rŒ|–— Œ y ­wr   ©Ú
isinstancer   ©Ú.0Údbs     r   ú	<genexpr>z'_databases_recursive.<locals>.<genexpr>ž   s   è ø€ ÒI˜R¬j¸¼ZÕ.H”bÑIùó   ‚˜c              3   óB   K  — | ]  }t        |t        «      sŒ|–— Œ y ­wr   rQ   rS   s     r   rV   z'_databases_recursive.<locals>.<genexpr>Ÿ   s   è ø€ ÒC˜2¬
°2´zÕ(B”BÑCùrW   N)rR   r   Ú	databasesÚextendÚ_databases_recursiveÚappend)ÚdatabaseÚoutputÚdbsÚcdbs       r   r[   r[   ™   sZ   € ô �(œJÔ'Ø× Ñ Ó"ˆØ�‰ÑI 3ÔIÔIÙC ÔCò 	.ˆCÜ   fÕ-ñ	.ð 	�‰�hÕr   c                   óZ   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zdd
„Zd„ Zˆ xZS )r   z§A database which delegates calls to sub-databases.

    Databases are stored in the lazy-loaded _dbs attribute.
    Define _set_cache_ to update it with your databasesc                 óx   •— |dk(  rt        «       | _        y |dk(  rt        «       | _        y t        ‰| �  |«       y )NÚ_dbsÚ	_db_cache)Úlistrc   Údictrd   r@   Ú_set_cache_)r   ÚattrrC   s     €r   rg   zCompoundDB._set_cache_­   s1   ø€ Ø�6Š>Ü›ˆD�IØ�[Ò Ü!›VˆD�Nä‰GÑ Õ%r   c                 óÀ   — 	 | j                   |   S # t        $ r Y nw xY w| j                  D ]&  }|j                  |«      sŒ|| j                   |<   |c S  t	        |«      ‚)zL:return: database containing the given 20 byte sha
        :raise BadObject:)rd   ÚKeyErrorrc   r   r   )r   r   rU   s      r   Ú	_db_queryzCompoundDB._db_queryµ   sh   € ð
	Ø—>‘> #Ñ&Ð&øÜò 	Ùð	úð —)‘)ò 	ˆBØ�}‰}˜SÕ!Ø&(�—‘˜sÑ#Ø’	ð	ô
 ˜‹nÐs   ‚ ‘	œc                 óF   — 	 | j                  |«       y# t        $ r Y yw xY w)NTF)rk   r   r   s     r   r   zCompoundDB.has_objectÉ   s(   € ð	Ø�N‰N˜3ÔØøÜò 	Ùð	ús   ‚ ”	 Ÿ c                 óB   — | j                  |«      j                  |«      S r   )rk   r    r   s     r   r    zCompoundDB.infoÑ   s   € Ø�~‰~˜cÓ"×'Ñ'¨Ó,Ð,r   c                 óB   — | j                  |«      j                  |«      S r   )rk   r#   r   s     r   r#   zCompoundDB.streamÔ   s   € Ø�~‰~˜cÓ"×)Ñ)¨#Ó.Ð.r   c                 ó@   — t        d„ d„ | j                  D «       d«      S )z.:return: total size of all contained databasesc                 ó   — | |z   S r   r.   )ÚxÚys     r   ú<lambda>z!CompoundDB.size.<locals>.<lambda>Ù   s
   €  1 q¡5€ r   c              3   ó<   K  — | ]  }|j                  «       –— Œ y ­wr   )r&   rS   s     r   rV   z"CompoundDB.size.<locals>.<genexpr>Ù   s   è ø€ Ò*I¸¨2¯7©7¯9Ñ*Iùó   ‚r   )r
   rc   r%   s    r   r&   zCompoundDB.size×   s   € äÑ(Ñ*I¸t¿y¹yÔ*IÈ1ÓMÐMr   c                 ó4   — t        d„ | j                  D «       Ž S )Nc              3   ó<   K  — | ]  }|j                  «       –— Œ y ­wr   )r)   rS   s     r   rV   z&CompoundDB.sha_iter.<locals>.<genexpr>Ü   s   è ø€ Ò9¨�r—{‘{—}Ñ9ùru   )r	   rc   r%   s    r   r)   zCompoundDB.sha_iterÛ   s   € ÜÑ9¨t¯y©yÔ9Ð:Ð:r   c                 ó,   — t        | j                  «      S )z7:return: tuple of database instances we use for lookups)Útuplerc   r%   s    r   rY   zCompoundDB.databasesâ   s   € ä�T—Y‘YÓÐr   c                 óª   — | j                   j                  «        d}| j                  D ]'  }t        |t        «      sŒ||j                  |«      z  }Œ) |S )NF)rd   Úclearrc   rR   r   rM   )r   rL   ÚstatrU   s       r   rM   zCompoundDB.update_cacheæ   sN   € à�‰×ÑÔØˆØ—)‘)ò 	/ˆBÜ˜"œiÕ(Ø˜Ÿ™¨Ó.Ñ.‘ð	/ð
 ˆr   c                 ó€  — t        «       }t        | |«       t        |«      }t        |«      }|dz  dk7  rt	        |dz   «      }nt	        |«      }d}|D ]L  }d}	 t        |d«      r|j                  |«      }n|j                  ||«      }|sŒ9|r||k7  rt        |«      ‚|}ŒN |st        |«      ‚|S # t        $ r Y Œiw xY w)z¾
        :return: 20 byte binary sha1 from the given less-than-40 byte hexsha (bytes or str)
        :param partial_hexsha: hexsha with less than 40 byte
        :raise AmbiguousObjectName: é   r   Ú0NÚpartial_to_complete_sha_hex)
re   r[   r   Úlenr   Úhasattrr€   Úpartial_to_complete_shar   r   )r   Úpartial_hexsharY   Úlen_partial_hexshaÚpartial_binshaÚ	candidaterU   Úfull_bin_shas           r   r€   z&CompoundDB.partial_to_complete_sha_hexñ   sç   € ô
 “Fˆ	Ü˜T 9Ô-Ü# NÓ3ˆÜ  Ó0ÐØ Ñ! QÒ&Ü'¨¸Ñ(<Ó=‰Nä'¨Ó7ˆNð ˆ	Øò 	)ˆBØˆLðÜ˜2Ð<Ô=Ø#%×#AÑ#AÀ.Ó#Q‘Là#%×#=Ñ#=¸nÐN`Ó#a�Lò
 Ù ¨lÒ!:Ü-¨nÓ=Ð=Ø(‘	ð	)ñ" Ü˜NÓ+Ð+ØÐøô ò Ùðús   Á0B1Â1	B=Â<B=rN   )r*   r+   r,   r-   rg   rk   r   r    r#   r&   r)   rY   rM   r€   rH   rI   s   @r   r   r   ¦   s;   ø„ ñ;ô
&òò(ò-ò/òNò;ò ó	ö#r   r   N)r-   Ú
gitdb.utilr   r   r   Úgitdb.utils.encodingr   Ú	gitdb.excr   r   Ú	itertoolsr	   Ú	functoolsr
   Ú__all__r   r   r   r   r[   r   r.   r   r   ú<module>r�      ss   ðñ
 ?÷ñ õ ,÷õ
 Ý ð N€÷$$ñ $$÷R%Cñ %C÷T<ñ <÷8Oñ Oò"	 ôn�˜I yõ nr   