§
    ÎÑßje#  ã                   óä   — 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dS )z8Contains implementations of database retrieveing objectsé    )ÚjoinÚ	LazyMixinÚ
hex_to_bin)Ú
force_text)Ú	BadObjectÚAmbiguousObjectName)Úchain)Úreduce)Ú	ObjectDBRÚ	ObjectDBWÚ
FileDBBaseÚ
CompoundDBÚ	CachingDBc                   ó6   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	dS )	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     úA/opt/saltstack/salt/lib/python3.11/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Ô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Ô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ðCð Cð CðCð Cð Cð$ð $ð $ð$ð $ð $ð $ð $r   r   c                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )r   z6Defines an interface to create objects in the databasec                 ó   — d | _         d S 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ÔBÐBr   N)r*   r+   r,   r-   r5   r8   r:   r=   r.   r   r   r   r   B   s[   € € € € € à@Ð@ðð ð ð
ð 
ð 
ðð ð ð	Cð 	Cð 	Cð 	Cð 	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                 óV   •— t          ¦   «                              ¦   «          || _        dS )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                 óF   — 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¥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dS )r   z/A database which uses caches to speed-up accessFc                 ó   — dS )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   ˆ   s4   € € € € € à9Ð9ðOð Oð Oð Oð Oð Or   r   c                 ó  — t          | t          ¦  «        rT|                      ¦   «         }|                     d„ |D ¦   «         ¦  «         d„ |D ¦   «         D ]}t	          ||¦  «         ŒdS |                     | ¦  «         dS )zfFill output list with database from db, in order. Deals with Loose, Packed
    and compound databases.c              3   óD   K  — | ]}t          |t          ¦  «        °|V — Œd S r   ©Ú
isinstancer   ©Ú.0Údbs     r   ú	<genexpr>z'_databases_recursive.<locals>.<genexpr>ž   s1   è è € ÐIÐI˜R­j¸½ZÑ.HÔ.HÐI�bÐIÐIÐIÐIÐIÐIr   c              3   óD   K  — | ]}t          |t          ¦  «        ¯|V — Œd S r   rQ   rS   s     r   rV   z'_databases_recursive.<locals>.<genexpr>Ÿ   s1   è è € ÐCÐC˜2­
°2µzÑ(BÔ(BÐC�BÐCÐCÐCÐCÐCÐCr   N)rR   r   Ú	databasesÚextendÚ_databases_recursiveÚappend)ÚdatabaseÚoutputÚdbsÚcdbs       r   rZ   rZ   ™   sœ   € õ �(�JÑ'Ô'ð  Ø× Ò Ñ"Ô"ˆØ�ŠÐIÐI 3ÐIÑIÔIÑIÔIÐIØCÐC ÐCÑ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                 ó¶   •— |dk    rt          ¦   «         | _        d S |dk    rt          ¦   «         | _        d S t	          ¦   «                              |¦  «         d S )NÚ_dbsÚ	_db_cache)Úlistrb   Údictrc   r@   Ú_set_cache_)r   ÚattrrC   s     €r   rf   zCompoundDB._set_cache_­   sS   ø€ Ø�6Š>ˆ>Ý™œˆDŒIˆIˆIØ�[Ò Ð Ý!™VœVˆDŒNˆNˆNå‰GŒG×Ò Ñ%Ô%Ð%Ð%Ð%r   c                 ó¶   — 	 | j         |         S # t          $ r Y nw xY w| j        D ]%}|                     |¦  «        r|| j         |<   |c S Œ&t	          |¦  «        ‚)zL:return: database containing the given 20 byte sha
        :raise BadObject:)rc   ÚKeyErrorrb   r   r   )r   r   rU   s      r   Ú	_db_queryzCompoundDB._db_queryµ   sƒ   € ð
	Ø”> #Ô&Ð&øÝð 	ð 	ð 	ØˆDð	øøøð ”)ð 	ð 	ˆBØ�}Š}˜SÑ!Ô!ð Ø&(�”˜sÑ#Ø�	�	�	ðõ ˜‰nŒnÐs   ‚ �
›c                 óT   — 	 |                       |¦  «         dS # t          $ r Y dS w xY w)NTF)rj   r   r   s     r   r   zCompoundDB.has_objectÉ   s@   € ð	Ø�NŠN˜3ÑÔÐØ�4øÝð 	ð 	ð 	Ø�5�5ð	øøøs   ‚ ™
'¦'c                 óR   — |                       |¦  «                             |¦  «        S r   )rj   r    r   s     r   r    zCompoundDB.infoÑ   s"   € Ø�~Š~˜cÑ"Ô"×'Ò'¨Ñ,Ô,Ð,r   c                 óR   — |                       |¦  «                             |¦  «        S r   )rj   r#   r   s     r   r#   zCompoundDB.streamÔ   s"   € Ø�~Š~˜cÑ"Ô"×)Ò)¨#Ñ.Ô.Ð.r   c                 óD   — 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  — | ]}|                      ¦   «         V — Œd S r   )r&   rS   s     r   rV   z"CompoundDB.size.<locals>.<genexpr>Ù   s*   è è € Ð*IÐ*I¸¨2¯7ª7©9¬9Ð*IÐ*IÐ*IÐ*IÐ*IÐ*Ir   r   )r
   rb   r%   s    r   r&   zCompoundDB.size×   s)   € åÐ(Ð(Ð*IÐ*I¸t¼yÐ*IÑ*IÔ*IÈ1ÑMÔMÐMr   c                 ó2   — t          d„ | j        D ¦   «         Ž S )Nc              3   ó>   K  — | ]}|                      ¦   «         V — Œd S r   )r)   rS   s     r   rV   z&CompoundDB.sha_iter.<locals>.<genexpr>Ü   s*   è è € Ð9Ð9¨�r—{’{‘}”}Ð9Ð9Ð9Ð9Ð9Ð9r   )r	   rb   r%   s    r   r)   zCompoundDB.sha_iterÛ   s   € ÝÐ9Ð9¨t¬yÐ9Ñ9Ô9Ð:Ð:r   c                 ó*   — t          | j        ¦  «        S )z7:return: tuple of database instances we use for lookups)Útuplerb   r%   s    r   rX   zCompoundDB.databasesâ   s   € å�T”YÑÔÐr   Fc                 óª   — | j                              ¦   «          d}| j        D ]/}t          |t          ¦  «        r||                     |¦  «        z  }Œ0|S )NF)rc   Úclearrb   rR   r   rM   )r   rL   ÚstatrU   s       r   rM   zCompoundDB.update_cacheæ   s\   € àŒ×ÒÑÔÐØˆØ”)ð 	/ð 	/ˆBÝ˜"�iÑ(Ô(ð /Ø˜Ÿš¨Ñ.Ô.Ñ.�øð ˆr   c                 óÚ  — t          ¦   «         }t          | |¦  «         t          |¦  «        }t          |¦  «        }|dz  dk    rt	          |dz   ¦  «        }nt	          |¦  «        }d}|D ]m}d}	 t          |d¦  «        r|                     |¦  «        }n|                     ||¦  «        }n# t          $ r Y ŒNw xY w|r|r||k    rt          |¦  «        ‚|}Œn|st          |¦  «        ‚|S )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)
rd   rZ   r   Úlenr   Úhasattrr~   Úpartial_to_complete_shar   r   )r   Úpartial_hexsharX   Úlen_partial_hexshaÚpartial_binshaÚ	candidaterU   Úfull_bin_shas           r   r~   z&CompoundDB.partial_to_complete_sha_hexñ   s7  € õ
 ‘F”Fˆ	Ý˜T 9Ñ-Ô-Ð-Ý# NÑ3Ô3ˆÝ  Ñ0Ô0ÐØ Ñ! QÒ&Ð&Ý'¨¸Ñ(<Ñ=Ô=ˆNˆNå'¨Ñ7Ô7ˆNð ˆ	Øð 	)ð 	)ˆBØˆLðÝ˜2Ð<Ñ=Ô=ð bØ#%×#AÒ#AÀ.Ñ#QÔ#Q�L�Là#%×#=Ò#=¸nÐN`Ñ#aÔ#a�Løøåð ð ð Ø�ðøøøð ð )Øð > ¨lÒ!:Ð!:Ý-¨nÑ=Ô=Ð=Ø(�	øð ð 	,Ý˜NÑ+Ô+Ð+ØÐs   Á1<B.Â.
B;Â:B;rN   )r*   r+   r,   r-   rf   rj   r   r    r#   r&   r)   rX   rM   r~   rH   rI   s   @r   r   r   ¦   sÑ   ø€ € € € € ð;ð ;ð
&ð &ð &ð &ð &ðð ð ð(ð ð ð-ð -ð -ð/ð /ð /ðNð Nð Nð;ð ;ð ;ð ð  ð  ð	ð 	ð 	ð 	ð#ð #ð #ð #ð #ð #ð #r   r   N)r-   Ú
gitdb.utilr   r   r   Úgitdb.utils.encodingr   Ú	gitdb.excr   r   Ú	itertoolsr	   Ú	functoolsr
   Ú__all__r   r   r   r   rZ   r   r.   r   r   ú<module>r�      s¬  ðð
 ?Ð >ðð ð ð ð ð ð ð ð ð ð ,Ð +Ð +Ð +Ð +Ð +ðð ð ð ð ð ð ð ð
 Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ð N€ð$$ð $$ð $$ð $$ð $$ñ $$ô $$ð $$ðR%Cð %Cð %Cð %Cð %Cñ %Cô %Cð %CðT<ð <ð <ð <ð <ñ <ô <ð <ð8Oð Oð Oð Oð Oñ Oô Oð Oð"	 ð 	 ð 	 ðnð nð nð nð n�˜I yñ nô nð nð nð nr   