ó
    ±“,je#  ã                   óÄ   • S r SSKJrJrJr  SSKJr  SSKJrJ	r	  SSK
Jr  SSKJr  Sr " S S	5      r " S
 S5      r " S S5      r " S S5      rS r " S S\\\5      rg)z8Contains implementations of database retrieveing objectsé    )ÚjoinÚ	LazyMixinÚ
hex_to_bin)Ú
force_text)Ú	BadObjectÚAmbiguousObjectName)Úchain)Úreduce)Ú	ObjectDBRÚ	ObjectDBWÚ
FileDBBaseÚ
CompoundDBÚ	CachingDBc                   ó<   • \ rS rSrSrS rS rS rS rS r	S r
S	rg
)r   é   zgDefines an interface for object database lookup.
Objects are identified either by their 20 byte bin shac                 ó   • U R                   $ ©N)Úhas_obj©ÚselfÚshas     Ú›C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\gitdb/db/base.pyÚ__contains__ÚObjectDBR.__contains__   s   € Ø�|‰|Ðó    c                 ó   • [        S5      e)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_objectÚObjectDBR.has_object"   s   € ô "Ð"AÓBÐBr   c                 ó   • [        S5      e)zF:return: OInfo instance
:param sha: bytes binary sha
:raise BadObject:r   r   r   s     r   ÚinfoÚObjectDBR.info+   ó   € ô "Ð"AÓBÐBr   c                 ó   • [        S5      e)zK:return: OStream instance
:param sha: 20 bytes binary sha
:raise BadObject:r   r   r   s     r   ÚstreamÚObjectDBR.stream1   r%   r   c                 ó   • [        5       e)z+:return: amount of objects in this databaser   ©r   s    r   ÚsizeÚObjectDBR.size7   ó   € ä!Ó#Ð#r   c                 ó   • [        5       e)zGReturn iterator yielding 20 byte shas for all objects in this data baser   r*   s    r   Úsha_iterÚObjectDBR.sha_iter;   r-   r   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r    r#   r'   r+   r/   Ú__static_attributes__r1   r   r   r   r      s(   † ñ>òòCòCòCò$õ$r   r   c                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	r   éB   z6Defines an interface to create objects in the databasec                 ó   • S U l         g r   ©Ú_ostream)r   ÚargsÚkwargss      r   Ú__init__ÚObjectDBW.__init__F   s	   € Øˆ�r   c                 ó*   • U R                   nXl         U$ )a:  
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 functionalityr;   )r   r'   Úcstreams      r   Úset_ostreamÚObjectDBW.set_ostreamJ   s   € ð —-‘-ˆØŒØˆr   c                 ó   • U R                   $ )zŒ
Return the output stream

:return: overridden output stream this instance will write to, or None
    if it will write to the default streamr;   r*   s    r   ÚostreamÚObjectDBW.ostreamV   s   € ð �}‰}Ðr   c                 ó   • [        S5      e)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   ÚstoreÚObjectDBW.store^   s   € ô "Ð"AÓBÐBr   r;   N)
r2   r3   r4   r5   r6   r?   rC   rF   rJ   r7   r1   r   r   r   r   B   s   † á@òò
òõ	Cr   r   c                   ó8   ^ • \ rS rSrSrU 4S jrS rS rSrU =r	$ )r   él   zyProvides basic facilities to retrieve files of interest, including
caching facilities to help mapping hexsha's to objectsc                 ó.   >• [         TU ]  5         Xl        g)a1  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)Úsuperr?   Ú
_root_path)r   Ú	root_pathÚ	__class__s     €r   r?   ÚFileDBBase.__init__q   s   ø€ ô 	‰ÑÔØ#�r   c                 ó   • U R                   $ )z':return: path at which this db operates©rP   r*   s    r   rQ   ÚFileDBBase.root_path|   s   € à�‰Ðr   c                 ó@   • [        U R                  [        U5      5      $ )zn
:return: the given relative path relative to our database root, allowing
    to pontentially access datafiles)r   rP   r   )r   Ú	rela_paths     r   Údb_pathÚFileDBBase.db_path€   s   € ô �D—O‘O¤Z°	Ó%:Ó;Ð;r   rU   )
r2   r3   r4   r5   r6   r?   rQ   rY   r7   Ú__classcell__©rR   s   @r   r   r   l   s   ø† ñ>õ$ò÷<ð <r   r   c                   ó"   • \ rS rSrSrSS jrSrg)r   éˆ   z/A database which uses caches to speed-up accessc                 ó   • g)aJ  
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 indeedNr1   )r   Úforces     r   Úupdate_cacheÚCachingDB.update_cache�   s   � r   r1   N©F)r2   r3   r4   r5   r6   ra   r7   r1   r   r   r   r   ˆ   s   † á9÷Or   r   c                 óØ   • [        U [        5      (       aD  U R                  5       nUR                  S U 5       5        S U 5        H  n[	        X15        M     gUR                  U 5        g)zbFill output list with database from db, in order. Deals with Loose, Packed
and compound databases.c              3   óT   #   • U  H  n[        U[        5      (       a  M  Uv •  M      g 7fr   ©Ú
isinstancer   ©Ú.0Údbs     r   Ú	<genexpr>Ú'_databases_recursive.<locals>.<genexpr>ž   s   é € ÐI¢3˜R¬j¸¼Z×.H—b‘b¢3ùó   ‚(Ÿ	(c              3   óT   #   • U  H  n[        U[        5      (       d  M  Uv •  M      g 7fr   rf   rh   s     r   rk   rl   Ÿ   s   é € ÐC¢˜2¬
°2´z×(B—B‘B¢ùrm   N)rg   r   Ú	databasesÚextendÚ_databases_recursiveÚappend)ÚdatabaseÚoutputÚdbsÚcdbs       r   rq   rq   ™   sW   € ô �(œJ×'Ñ'Ø× Ñ Ó"ˆØ�‰ÑI¡3ÓIÔIÙC¡ÖCˆCÜ  Ö-ò Dð 	�‰�hÕr   c                   óf   ^ • \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rS
 rSS jrS rSrU =r$ )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                 ó|   >• US:X  a  [        5       U l        g US:X  a  [        5       U l        g [        TU ]  U5        g )NÚ_dbsÚ	_db_cache)Úlistrz   Údictr{   rO   Ú_set_cache_)r   ÚattrrR   s     €r   r~   ÚCompoundDB._set_cache_­   s1   ø€ Ø�6‹>Ü›ˆD�IØ�[Ó Ü!›VˆD�Nä‰GÑ Õ%r   c                 óÎ   •  U R                   U   $ ! [         a     Of = fU R                   H+  nUR                  U5      (       d  M  X R                   U'   Us  $    [	        U5      e)zD:return: database containing the given 20 byte sha
:raise BadObject:)r{   ÚKeyErrorrz   r    r   )r   r   rj   s      r   Ú	_db_queryÚCompoundDB._db_queryµ   sd   € ð
	Ø—>‘> #Ñ&Ð&øÜó 	Ùð	úð —)”)ˆBØ�}‰}˜S×!Ó!Ø&(—‘˜sÑ#Ø’	ñ ô
 ˜‹nÐs   ‚ ‘
�c                 óH   •  U R                  U5        g! [         a     gf = f)NTF)rƒ   r   r   s     r   r    ÚCompoundDB.has_objectÉ   s(   € ð	Ø�N‰N˜3ÔØøÜó 	Ùð	ús   ‚ ”
! !c                 óB   • U R                  U5      R                  U5      $ r   )rƒ   r#   r   s     r   r#   ÚCompoundDB.infoÑ   s   € Ø�~‰~˜cÓ"×'Ñ'¨Ó,Ð,r   c                 óB   • U R                  U5      R                  U5      $ r   )rƒ   r'   r   s     r   r'   ÚCompoundDB.streamÔ   s   € Ø�~‰~˜cÓ"×)Ñ)¨#Ó.Ð.r   c                 ó@   • [        S S U R                   5       S5      $ )z.:return: total size of all contained databasesc                 ó
   • X-   $ r   r1   )ÚxÚys     r   Ú<lambda>Ú!CompoundDB.size.<locals>.<lambda>Ù   s   €  1¢5r   c              3   ó@   #   • U  H  oR                  5       v •  M     g 7fr   )r+   rh   s     r   rk   Ú"CompoundDB.size.<locals>.<genexpr>Ù   s   é € Ð*Iºy¸¯7©7¯9¨9ºyùó   ‚r   )r
   rz   r*   s    r   r+   ÚCompoundDB.size×   s   € äÑ(Ñ*I¸t¿yºyÓ*IÈ1ÓMÐMr   c                 ó4   • [        S U R                   5       6 $ )Nc              3   ó@   #   • U  H  oR                  5       v •  M     g 7fr   )r/   rh   s     r   rk   Ú&CompoundDB.sha_iter.<locals>.<genexpr>Ü   s   é € Ð9ªy¨—{‘{—}�}ªyùr“   )r	   rz   r*   s    r   r/   ÚCompoundDB.sha_iterÛ   s   € ÜÑ9¨t¯yªyÓ9Ð:Ð:r   c                 ó,   • [        U R                  5      $ )z7:return: tuple of database instances we use for lookups)Útuplerz   r*   s    r   ro   ÚCompoundDB.databasesâ   s   € ä�T—Y‘YÓÐr   c                 ó¸   • U R                   R                  5         SnU R                   H-  n[        U[        5      (       d  M  X#R                  U5      -  nM/     U$ )NF)r{   Úclearrz   rg   r   ra   )r   r`   Ústatrj   s       r   ra   ÚCompoundDB.update_cacheæ   sJ   € à�‰×ÑÔØˆØ—)”)ˆBÜ˜"œi×(Ó(ØŸ™¨Ó.Ñ.’ñ ð
 ˆr   c                 ó²  • [        5       n[        X5        [        U5      n[        U5      nUS-  S:w  a  [	        US-   5      nO[	        U5      nSnU H]  nSn [        US5      (       a  UR                  U5      nOUR                  XC5      n U(       d  MD  U(       a  XW:w  a  [        U5      eUnM_     U(       d  [        U5      eU$ ! [         a     M‚  f = f)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)
r|   rq   r   Úlenr   Úhasattrr£   Úpartial_to_complete_shar   r   )r   Úpartial_hexsharo   Úlen_partial_hexshaÚpartial_binshaÚ	candidaterj   Úfull_bin_shas           r   r£   Ú&CompoundDB.partial_to_complete_sha_hexñ   sà   € ô
 “Fˆ	Ü˜TÔ-Ü# NÓ3ˆÜ  Ó0ÐØ Ñ! QÓ&Ü'¨¸Ñ(<Ó=‰Nä'¨Ó7ˆNð ˆ	ÛˆBØˆLðÜ˜2Ð<×=Ñ=Ø#%×#AÑ#AÀ.Ó#Q‘Là#%×#=Ñ#=¸nÓ#a‘L÷
 ˆ|Þ Ó!:Ü-¨nÓ=Ð=Ø(’	ñ ö" Ü˜NÓ+Ð+ØÐøô ó Úðús   Á"CÁ<CÃ
CÃC)r{   rz   rc   )r2   r3   r4   r5   r6   r~   rƒ   r    r#   r'   r+   r/   ro   ra   r£   r7   r[   r\   s   @r   r   r   ¦   s@   ø† ñ;õ
&òò(ò-ò/òNò;ò ô	÷#ð #r   r   N)r6   Ú
gitdb.utilr   r   r   Úgitdb.utils.encodingr   Ú	gitdb.excr   r   Ú	itertoolsr	   Ú	functoolsr
   Ú__all__r   r   r   r   rq   r   r1   r   r   Ú<module>r³      ss   ðñ
 ?÷ñ õ ,÷õ
 Ý ð N€÷$$ñ $$÷R%Cñ %C÷T<ñ <÷8Oñ Oò"	 ôn�˜I yõ nr   