VL ie#dZddlmZmZmZddlmZddlmZm Z ddl m Z ddl m Z dZGdd ZGd d ZGd d ZGddZdZGddeeeZy)z8Contains implementations of database retrieveing objects)join LazyMixin hex_to_bin) force_text) BadObjectAmbiguousObjectName)chain)reduce) ObjectDBR ObjectDBW FileDBBase CompoundDB CachingDBc4eZdZdZdZdZdZdZdZdZ y) r zkDefines an interface for object database lookup. Objects are identified either by their 20 byte bin shac|jSN)has_objselfshas S/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/gitdb/db/base.py __contains__zObjectDBR.__contains__s ||ctd)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 databaseTo be implemented in subclassNotImplementedErrorrs r has_objectzObjectDBR.has_object"s""ABBrctd)zW :return: OInfo instance :param sha: bytes binary sha :raise BadObject:rrrs rinfozObjectDBR.info+""ABBrctd)z[:return: OStream instance :param sha: 20 bytes binary sha :raise BadObject:rrrs rstreamzObjectDBR.stream1r!rct)z+:return: amount of objects in this databaserrs rsizezObjectDBR.size7 !##rct)zGReturn iterator yielding 20 byte shas for all objects in this data baserr%s rsha_iterzObjectDBR.sha_iter;r'rN) __name__ __module__ __qualname____doc__rrr r#r&r)rrr r s(>CC C $$rr c(eZdZdZdZdZdZdZy)r z6Defines an interface to create objects in the databasecd|_yr_ostream)rargskwargss r__init__zObjectDBW.__init__Fs  rc,|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)rr#cstreams r set_ostreamzObjectDBW.set_ostreamJs-- rc|jS)z Return the output stream :return: overridden output stream this instance will write to, or None if it will write to the default streamr1r%s rostreamzObjectDBW.ostreamVs }}rctd)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 writtenrr)ristreams rstorezObjectDBW.store^s""ABBrN)r*r+r,r-r5r8r:r=r.rrr r Bs@  Crr c.eZdZdZfdZdZdZxZS)r z}Provides basic facilities to retrieve files of interest, including caching facilities to help mapping hexsha's to objectsc0t|||_y)aYInitialize 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 rr5zFileDBBase.__init__qs #rc|jS)z':return: path at which this db operates)rAr%s rrBzFileDBBase.root_path|s rc@t|jt|S)z~ :return: the given relative path relative to our database root, allowing to pontentially access datafiles)rrAr)r rela_paths rdb_pathzFileDBBase.db_pathsDOOZ %:;;r)r*r+r,r-r5rBrG __classcell__rCs@rr r ls>$z'_databases_recursive..sIRjZ.HbIc3BK|]}t|ts|ywrrQrSs rrVz'_databases_recursive..sC2 2z(BBCrWN)rRr databasesextend_databases_recursiveappend)databaseoutputdbscdbs rr[r[sZ(J'  " I3IICC .C f - .  hrcZeZdZdZfdZdZdZdZdZdZ dZ d Z d d Z d Z xZS) rzA database which delegates calls to sub-databases. Databases are stored in the lazy-loaded _dbs attribute. Define _set_cache_ to update it with your databasescx|dk(rt|_y|dk(rt|_yt||y)N_dbs _db_cache)listrcdictrdr@ _set_cache_)rattrrCs rrgzCompoundDB._set_cache_s1 6>DI [ !VDN G  %rc |j|S#t$rYnwxYw|jD]&}|j|s||j|<|cSt |)zL:return: database containing the given 20 byte sha :raise BadObject:)rdKeyErrorrcrr)rrrUs r _db_queryzCompoundDB._db_querysh  >>#& &   )) B}}S!&(s#   ns  cF |j|y#t$rYywxYw)NTF)rkrrs rrzCompoundDB.has_objects(  NN3   s   cB|j|j|Sr)rkr rs rr zCompoundDB.infos~~c"'',,rcB|j|j|Sr)rkr#rs rr#zCompoundDB.streams~~c"))#..rc@tdd|jDdS)z.:return: total size of all contained databasesc ||zSrr.)xys rz!CompoundDB.size..s 1q5rc3<K|]}|jywr)r&rSs rrVz"CompoundDB.size..s*I2779*Ir)r rcr%s rr&zCompoundDB.sizes(*Ityy*I1MMrc4td|jDS)Nc3<K|]}|jywr)r)rSs rrVz&CompoundDB.sha_iter..s9r{{}9ru)r rcr%s rr)zCompoundDB.sha_iters9tyy9::rc,t|jS)z7:return: tuple of database instances we use for lookups)tuplercr%s rrYzCompoundDB.databasessTYYrc|jjd}|jD]'}t|ts||j |z})|S)NF)rdclearrcrRrrM)rrLstatrUs rrMzCompoundDB.update_cachesN )) /B"i(.. /  rct}t||t|}t|}|dzdk7rt |dz}n t |}d}|D]L}d} t |dr|j |}n|j||}|s9|r||k7r t||}N|s t||S#t$rYiwxYw)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: r0Npartial_to_complete_sha_hex) rer[rlenrhasattrrpartial_to_complete_sharr)rpartial_hexsharYlen_partial_hexshapartial_binsha candidaterU full_bin_shas rrz&CompoundDB.partial_to_complete_sha_hexs F T9-#N3 0  !Q &'(<=N'7N  )BL 2<=#%#A#A.#QL#%#=#=nN`#aL l!:-n==(  )"N+ +  s0B11 B=<B=rN)r*r+r,r-rgrkrr r#r&r)rYrMrrHrIs@rrrs;; &(-/N;  #rrN)r- gitdb.utilrrrgitdb.utils.encodingr gitdb.excrr itertoolsr functoolsr __all__r r r rr[rr.rrrss ? ,  N$$$$R%C%CT<<8 O O"  nIynr