bg dZddlmZddlmZmZddlmZmZddl m Z m Z ddl m Z mZddlmZdZGd d eeZd S) z*Contains the MemoryDatabase implementation) LooseObjectDB) ObjectDBR ObjectDBW)OStreamIStream) BadObjectUnsupportedOperation)ZippedStoreShaWriterDecompressMemMapReader)BytesIO)MemoryDBcReZdZdZfdZdZdZdZdZdZ dZ d Z d Z xZ 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 IOcttd|_t |_dS)Nzpath/doesnt/matter)super__init__r_dbdict_cache)self __class__s ]/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/gitdb/db/mem.pyrzMemoryDB.__init__'s:  !566ff c td)Nz$MemoryDB's always stream into memory)r )rstreams r set_ostreamzMemoryDB.set_ostream.s"#IJJJrc~t}|j||j|}||dt |d}t|j |j |j ||j |j <|S)NrF)close_on_deletion) r rrstorecloseseekr getvaluerbinshatypesizer)ristreamzstream decomp_streams rrzMemoryDB.store1s&(( W%%%(..))  Q/w/?/?/A/AUZ[[[ &-gnglGLZg&h&h GN#rc||jvSN)rrshas r has_objectzMemoryDB.has_object@sdk!!rc,||Sr))rr*s rinfoz MemoryDB.infoCs{{3rc |j|}|jd|S#t$r}t ||d}~wwxYw)Nr)rrr KeyErrorr)rr+ostreames rrzMemoryDB.streamGs[ (k#&G N   " " "N ( ( (C..a ' (s(+ A AA c*t|jSr))lenrrs rr$z MemoryDB.sizeQs4;rc4|jSr))rkeysr5s rsha_iterzMemoryDB.sha_iterTs{!!!rc"d}|D]}||r||}t|j}t |j|j||}|||dz }|S)arCopy 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,rr datarr#r$r)rr8odbcountr+r1sior%s r stream_copyzMemoryDB.stream_copyXs  C~~c"" kk#&&G'.--//00CglGL#sCCG IIg    QJEE r)__name__ __module__ __qualname____doc__rrrr,r.rr$r8r? __classcell__)rs@rr r sAA KKK   """   (((   """rr N)rCgitdb.db.looser gitdb.db.baserr gitdb.baserr gitdb.excrr gitdb.streamr r ior __all__r rrrMs 10((((((     MMMMMy)MMMMMr