
    g                     |    d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
mZ ddlmZmZ ddlmZ dZ G d	 d
ee      Zy)z*Contains the MemoryDatabase implementation    )LooseObjectDB)	ObjectDBR	ObjectDBW)OStreamIStream)	BadObjectUnsupportedOperation)ZippedStoreShaWriterDecompressMemMapReader)BytesIO)MemoryDBc                   R     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Z xZS )r   a/  A memory database stores everything to memory, providing fast IO and object
    retrieval. It should be used to buffer results and obtain SHAs before writing
    it to the actual physical storage, as it allows to query whether object already
    exists in the target storage before introducing actual IOc                 `    t         |           t        d      | _        t	               | _        y )Nzpath/doesnt/matter)super__init__r   _dbdict_cache)self	__class__s    A/var/www/openai/venv/lib/python3.12/site-packages/gitdb/db/mem.pyr   zMemoryDB.__init__'   s&     !56 f    c                     t        d      )Nz$MemoryDB's always stream into memory)r	   )r   streams     r   set_ostreamzMemoryDB.set_ostream.   s    "#IJJr   c                    t               }| j                  j                  |       | j                  j                  |      }|j	                          |j                  d       t        |j                         d      }t        |j                  |j                  |j                  |      | j                  |j                  <   |S )Nr   F)close_on_deletion)r
   r   r   storecloseseekr   getvaluer   binshatypesizer   )r   istreamzstreamdecomp_streams       r   r   zMemoryDB.store1   s    &(W%((..)Q /w/?/?/AUZ[&-gnngllGLLZg&hGNN#r   c                     || j                   v S N)r   r   shas     r   
has_objectzMemoryDB.has_object@   s    dkk!!r   c                 $    | j                  |      S r)   )r   r*   s     r   infozMemoryDB.infoC   s    {{3r   c                     	 | j                   |   }|j                  j                  d       |S # t        $ r}t	        |      |d }~ww xY w)Nr   )r   r   r    KeyErrorr   )r   r+   ostreames       r   r   zMemoryDB.streamG   sH    	(kk#&GNN"N 	(C.a'	(s   +. 	AAAc                 ,    t        | j                        S r)   )lenr   r   s    r   r$   zMemoryDB.sizeQ   s    4;;r   c                 6    | j                   j                         S r)   )r   keysr5   s    r   sha_iterzMemoryDB.sha_iterT   s    {{!!r   c                    d}|D ]  }|j                  |      r| j                  |      }t        |j                  j                               }t	        |j
                  |j                  ||      }|j                  |       |dz  } |S )ar  Copy the streams as identified by sha's yielded by sha_iter into the given odb
        The streams will be copied directly
        **Note:** the object will only be written if it did not exist in the target db

        :return: amount of streams actually copied into odb. If smaller than the amount
            of input shas, one or more objects did already exist in odbr      )r,   r   r   datar   r#   r$   r   )r   r8   odbcountr+   r1   sior%   s           r   stream_copyzMemoryDB.stream_copyX   s}     C~~c" kk#&G'..--/0CgllGLL#sCGIIgQJE  r   )__name__
__module____qualname____doc__r   r   r   r,   r.   r   r$   r8   r?   __classcell__)r   s   @r   r   r       s7    A
K" ( "r   r   N)rC   gitdb.db.looser   gitdb.db.baser   r   
gitdb.baser   r   	gitdb.excr   r	   gitdb.streamr
   r   ior   __all__r    r   r   <module>rM      s;   
 1 (



 
My) Mr   