bgk#dZddlmZmZmZddlmZddlmZm Z ddl m Z ddl m Z dZGdd ZGd d ZGd d ZGddZdZGddeeeZdS)z8Contains implementations of database retrieveing objects)join LazyMixin hex_to_bin) force_text) BadObjectAmbiguousObjectName)chain)reduce) ObjectDBR ObjectDBW FileDBBase CompoundDB CachingDBc6eZdZdZdZdZdZdZdZdZ dS) r zkDefines an interface for object database lookup. Objects are identified either by their 20 byte bin shac|jSN)has_objselfshas ^/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/gitdb/db/base.py __contains__zObjectDBR.__contains__s |c td)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""ABBBrc td)zW :return: OInfo instance :param sha: bytes binary sha :raise BadObject:rrrs rinfozObjectDBR.info+""ABBBrc td)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>>CCCCCC CCC $$$$$$$$rr c*eZdZdZdZdZdZdZdS)r z6Defines an interface to create objects in the databasecd|_dSr_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 }rc td)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""ABBBrN)r*r+r,r-r5r8r:r=r.rrr r Bs[@@    C C C C Crr c.eZdZdZfdZdZdZxZS)r z}Provides basic facilities to retrieve files of interest, including caching facilities to help mapping hexsha's to objectscVt||_dS)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 rcFt|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_pathsDOZ %:%:;;;r)r*r+r,r-r5rBrG __classcell__rCs@rr r ls`>>$$$$$<<<<<<z'_databases_recursive..s1IIRjZ.H.HIbIIIIIIrc3DK|]}t|t|VdSrrQrSs rrVz'_databases_recursive..s1CC2 2z(B(BCBCCCCCCrN)rRr databasesextend_databases_recursiveappend)databaseoutputdbscdbs rrZrZs(J''   "" II3IIIIIICCCCC . .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 databasesc|dkrt|_dS|dkrt|_dSt |dS)N_dbs _db_cache)listrbdictrcr@ _set_cache_)rattrrCs rrfzCompoundDB._set_cache_sS 6>>DIII [ !VVDNNN GG   % % % % %rc |j|S#t$rYnwxYw|jD]%}||r||j|<|cS&t |)zL:return: database containing the given 20 byte sha :raise BadObject:)rcKeyErrorrbrr)rrrUs r _db_queryzCompoundDB._db_querys  >#& &    D )  B}}S!! &(s#  nns  cT ||dS#t$rYdSwxYw)NTF)rjrrs rrzCompoundDB.has_objects@  NN3   4   55 s  ''cR|||Sr)rjr rs rr zCompoundDB.infos"~~c""'',,,rcR|||Sr)rjr#rs rr#zCompoundDB.streams"~~c""))#...rcDtdd|jDdS)z.:return: total size of all contained databasesc ||zSrr.)xys rz!CompoundDB.size..s 1q5rc3>K|]}|VdSr)r&rSs rrVz"CompoundDB.size..s**I*I27799*I*I*I*I*I*Irr)r rbr%s rr&zCompoundDB.sizes)((*I*Ity*I*I*I1MMMrc2td|jDS)Nc3>K|]}|VdSr)r)rSs rrVz&CompoundDB.sha_iter..s*99r{{}}999999r)r rbr%s rr)zCompoundDB.sha_iters99ty999::rc*t|jS)z7:return: tuple of database instances we use for lookups)tuplerbr%s rrXzCompoundDB.databasessTYrFc|jd}|jD]/}t|tr|||z}0|S)NF)rcclearrbrRrrM)rrLstatrUs rrMzCompoundDB.update_caches\ ) / /B"i(( /... rct}t||t|}t|}|dzdkrt |dz}nt |}d}|D]m}d} t |dr||}n|||}n#t$rYNwxYw|r|r||krt||}n|st||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: r0Npartial_to_complete_sha_hex) rdrZrlenrhasattrr~partial_to_complete_sharr)rpartial_hexsharXlen_partial_hexshapartial_binsha candidaterU full_bin_shas rr~z&CompoundDB.partial_to_complete_sha_hexs7 FF T9---#N33 00  !Q & &'(<==NN'77N  ) )BL 2<==b#%#A#A.#Q#QLL#%#=#=nN`#a#aL     )>l!:!:-n===(  ,N++ +s1rs ?> ,+++++  N$$$$$$$$$$$$$$$$R%C%C%C%C%C%C%C%CT<<<<<<<<8 O O O O O O O O"    nnnnnIynnnnnr