
    .Phe#                         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     M/var/www/html/test/jupyter/venv/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     DOZ	%:%:;;;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IRjZ.H.HIb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C2
2z(B(BCBCCCCCCr   N)rR   r   	databasesextend_databases_recursiveappend)databaseoutputdbscdbs       r   rZ   rZ      s     (J''    ""II3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   zA 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>>DIII[  !VVDNNNGG%%%%%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#			 nn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@    	NN34 	 	 	55	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
    1q5 r   c              3   >   K   | ]}|                                 V  d S r   )r&   rS   s     r   rV   z"CompoundDB.size.<locals>.<genexpr>   s*      *I*I27799*I*I*I*I*I*Ir   r   )r
   rb   r%   s    r   r&   zCompoundDB.size   s)    ((*I*Ity*I*I*I1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9ty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    TY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   
 FF	T9---#N33 00!Q&&'(<==NN'77N 	 	) 	)BL2<== b#%#A#A.#Q#QLL#%#=#=nN`#a#aL     ) >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Iy n n n n nr   