bgZdZddlZddlmZejZddlZddlmZddlm Z ddl m Z m Z ddl mZddlmZmZmZmZdd lmZd Zd ZeefZdd d ededededd edediZed edededdedeiZdejzZdZdZdZdZ dZ!GddZ"dZ#dZ$dZ%Gdd e&Z'Gd!d"e'Z(d#Z)d$Z*d%Z+d&Z,d/d'Z-d(Z.efd)Z/d*Z0d+Z1d,Z2d-Z3 dd.l4m1Z1dS#e5$rYdSwxYw)0zContains basic c-functions which usually contain performance critical code Keeping this code separate from the beginning makes it easier to out-source it into c later, if requiredNbyte_ord)islice)reduce) NULL_BYTE BYTE_SPACE) force_text) str_blob_typestr_commit_type str_tree_type str_tag_type)StringIO OFS_DELTA REF_DELTAi) is_loose_objectloose_object_header_infomsb_sizepack_object_header_info write_objectloose_object_header stream_copyapply_delta_datais_equal_canonical_shaconnect_deltasDeltaChunkListcreate_pack_object_headerc||_|S)zTruncate the given delta to the given size :param size: size relative to our target offset, may not be 0, must be smaller or equal to our size :return: dts)dsizes Z/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/gitdb/fun.py_set_delta_rboundr+?s AD Hrc|dkrdS|xj|z c_|xj|z c_|xj|zc_|j|j|d|_|S)zMove the delta by the given amount of bytes, reducing its size so that its right bound stays static :param bytes: amount of bytes to move, must be smaller than delta size :return: drN)tosor'data)r(bytess r*_move_delta_lboundr1Ks_  zzDDEMDDDDEMDDDDEMDDv HrcNt|j|j|j|jSN) DeltaChunkr-r'r.r/)srcs r*delta_duplicater6]s cfcfcfch 7 77rc|j'|||j|j|jzdS|jt|jkr||jd|jdS||jdS)zApply own data to the target buffer :param bbuf: buffer providing source bytes for copy operations :param write: write method to call with data to writeN)r/r.r'len)dcbbufwrites r*delta_chunk_applyr<as w d25&'((((( 53rw<<   E"'&25&/ " " " " " E"'NNNNNrc.eZdZdZdZdZdZdZdZdS)r4zhRepresents a piece of a delta, it can either add new data, or copy existing one from a source bufferr-r'r.r/c>||_||_||_||_dSr3r>)selfr-r'r.r/s r*__init__zDeltaChunk.__init__s" rc@d|j|j|j|jpdfzS)NzDeltaChunk(%i, %i, %s, %s)r>r@s r*__repr__zDeltaChunk.__repr__s#+tw$)/WY.ZZZrc |j|jzSr3)r-r'rDs r*rboundzDeltaChunk.rboundsw  rc|jduS)zB:return: True if the instance has data to add to the target streamN)r/rDs r*has_datazDeltaChunk.has_datasy$$rN) __name__ __module__ __qualname____doc__ __slots__rArErGrIrr*r4r4tsd  I [[[ !!!%%%%%rr4cd}t|}||krN||zdz }||}|j|kr|}n*||ks |j|kr|S|dz}||kNt|dz S)z:return: index at which the given absofs should be inserted. The index points to the DeltaChunk with a target buffer absofs that equals or is greater than absofs. **Note:** global method for performance only, it belongs to DeltaChunkListrrr)r8r-rG)dclabsofslohimidr9s r*_closest_indexrVs B SB r''Bw!m X 56>>BB YY[[6 ! !RUf__JqB r'' s88a<rc2|D]}t|||dS)aUApply the chain's changes and write the final result using the passed write function. :param bbuf: base buffer containing the base of all deltas contained in this list. It will only be used if the chunk in question does not have a base chain. :param write: function taking a string of bytes to write to the outputN)r<)rQr:r;r9s r*delta_list_applyrXs2++"dE****++rct||}||}t|}|j}|j|krrt |j|j|j|j}t|||jz t|j||_||||jz}|dz }||kr|r||}|j|kr:|t |j|j|j|j||jz}nDt |j|j|j|j}||_||||jz}dS|dz }||kr|dSdSdSdS)zx:return: Subsection of this list at the given absolute offset, with the given size in bytes. :return: NonerN) rVr8appendr-r4r'r.r/r1min) rQrRr)ndclcdicdslenlappendtcds r*delta_list_slicerbs[ f % %C SB s88DkG urubg663///SVT""   q *** X 5D== GJrubeRUBG<< = = = BEMDDRUBE25"'::CCF GCLLL CFND E q ***********rcLeZdZdZeZdZdZdZdZ dZ d dZ d S) r#aZList with special functionality to deal with DeltaChunks. There are two types of lists we represent. The one was created bottom-up, working towards the latest delta, the other kind was created top-down, working from the latest delta down to the earliest ancestor. This attribute is queryable after all processing with is_reversed.c`t|dkrdS|dS)z,:return: rightmost extend in bytes, absoluter)r8rGrDs r*rGzDeltaChunkList.rbounds* t99>>1Bx   rcFt|dkrdS|djS)z5:return: leftmost byte at which this chunklist startsr)r8r-rDs r*lboundzDeltaChunkList.lbounds" t99>>1AwzrcT||z S)z6:return: size of bytes as measured by our delta chunks)rGrgrDs r*r)zDeltaChunkList.sizes{{}}t{{}},,rc$t|||S)z_Only used by public clients, internally we only use the global routines for performance)rX)r@r:r;s r*applyzDeltaChunkList.applys dE222rc 2t|}|dkr|Sd}d}||kr||}|dz }|j||dz |z dkrt}||j}t ||dz D]1}||}||jd|j2|||dz =|} ||t|t| d| t|}|dz}d}||dz }||k|S)zoAlter the list to reduce the amount of nodes. Currently we concatenate add-chunks :return: selfrrNr) r8r/rr-ranger;r'getvalueinsertr4) r@r_ifirst_data_indexr9ndr.xxdcbufs r*compresszDeltaChunkList.compresssR4yy !88K $hhaB FAw#/AE rrecp|dkrB|d|ksJtdd|Dd|ksJt|dkrdS|D]B}|jdksJ|rt|j|jksJCt |dt|dz }t|}|t||D]>\}}||j ksJ|j |jz|j ksJ?dS)zVerify the list has non-overlapping chunks only, and the total size matches target_size :param target_size: if not -1, the total size of the chain must be target_size :raise AssertionError: if the size doesn't matchrec ||zSr3rO)rrys r*z0DeltaChunkList.check_integrity..*s q1urc3$K|] }|jV dSr3r&).0r(s r* z1DeltaChunkList.check_integrity..*s$.B.Bqt.B.B.B.B.B.BrrrNr) rGrr8r'rIr/riternextzipr-)r@ target_sizer9leftrightlftrgts r*check_integrityzDeltaChunkList.check_integrity#sW   8??$$ 3333,,.B.BT.B.B.BAFF+UUUU t99q== F - -B519999{{}} -27||ru,,,,dAs4yy1}--T  D%(( - -HC::<<36))))6CF?cf,,,,, - -rN)re) rJrKrLrMtuplerNrGrgr)rjrurrOrr*r#r#s.. I!!!  ---333 )))V------rr#c,eZdZdZeZdZdS)TopdownDeltaChunkListzSRepresents a list which is generated by feeding its ancestor streams one by onec2d}d}t|}t}||kr||}|dz }|j|dz } |dd=t||j|j||j|jz }|D]}|xj|z c_t|dkr|d||dz <n`||d} ||dz d=|||| t|}|t|dz z }||k||krdSdS)a=Connect this chain with the next level of our base delta chunklist. The goal in this game is to mark as many of our chunks rigid, hence they cannot be changed by any of the upcoming bases anymore. Once all our chunks are marked like that, we can stop all processing :param bdcl: data chunk list being one of our bases. They must be fed in consecutively and in order, towards the earliest ancestor delta :return: True if processing was done. Use it to abort processing of remaining streams if False is returnedrrNFT)r8listr/rbr.r'r-extend) r@bdclnfcdcir_cclr9ofscdcpost_dcis r*connect_with_next_basez,TopdownDeltaChunkList.connect_with_next_baseHsN4yyffDjjcB 1HCw"qAAA T25"% 5 5 5%"%-C  # 3xx1}} #AS1W  :qN C    H%%%4yys3xx!|#MDjjV $;;5trN)rJrKrLrMrrNrrOrr*rrBs8  I;;;;;rrcptt|dd\}}|dz|z}|dko|dzdkS)z :return: True the file contained in memory map m appears to be a loose object. Only the first two bytes are neededNrxr)mapord)mb0b1words r*rrsBae__FB !Gr>D : *4"9**rcd}t||}|d|tt \}}|t |fS)z :return: tuple(type_string, uncompressed_size_in_bytes) the type string of the object as well as its uncompressed size in bytes. :param m: memory map from which to read the compressed object datai N) decompressobj decompressfindrsplitrint)rdecompress_sizehdr type_namer)s r*rrsa O // $ $Q 8 8C.388I.../55jAAOIt c$ii rct|d}d}|dz dz}|dz}d}|dzr/t||}|dz }||dz|zz }|dz }|dz/|||fS)a1 :return: tuple(type_id, uncompressed_size_in_bytes, byte_offset) The type_id should be interpreted according to the ``type_id_to_type_map`` map The byte-offset specifies the start of the actual zlib compressed datastream :param m: random-access memory, like a string or memory maprrrrr)r/crotype_idr)ss r*rrs aA AAvlG r6D A d( T!W   Q Ta Q d( T1 rcd}t}|dz|dzz}|dz}|r$||dz|dz}|dz}|$|||S)z :return: string defining the pack header comprised of the object type and its incompressed size in bytes :param obj_type: pack type_id of the object :param obj_size: uncompressed size in bytes of the following object streamrrrrrr) bytearrayrZ)obj_typeobj_sizerrs r*r$r$s} A ++C Q8c>*A NH  1t8 tOQ  JJqMMM Jrcd}d}t|}d}||kr,|||z}||dz|dzzz}|dz }|dzsd}n||k,|std||z|fS) z :return: tuple(read_bytes, size) read the msb size from the given random access data starting at the given byte offsetrFrrrrTz2Could not find terminating MSB byte in data stream)r8AssertionError)r/offsetr)rolhit_msbrs r*rrs D A D AG a%% V  Ta!e## Q4x G  a%% SQRRR v:t rcPdt||fzdS)z :return: bytes representing the loose object header, which is immediately followed by the content stream of size 'size'z%s %iascii)r encode)typer)s r*rrs* D))40 0 8 8 A AArcld}||t||z }|t||||z }|S)a0 Write the object as identified by type, size and source_stream into the target_stream :param type: type string of the object :param size: amount of bytes to write from source_stream :param read: read method of a stream providing the content data :param write: write method of the output stream :param close_target_stream: if True, the target stream will be closed when the routine exits, even if an error is thrown :return: The actual amount of bytes written to stream, which includes the header and a trailing newliner)rr)rr)readr; chunk_sizetbws r*rrsG C55$T400 1 11C;tUD* 5 55C Jrcd} t|||z }||}t|}||z }||||ks||krnK|S)z Copy a stream up to size bytes using the provided read and write methods, in chunks of chunk_size **Note:** its much like stream_copy utility, but operates just using methodsr)r[r8)rr;r)rdbwcsr/data_lens r*rrsq C  TCZ ( ( tBxxt99 x d b==C4KK   Jrc d}tx}}t|D]>\}}|}|j}t |\}}t ||\}} d} ||krt ||} |dz }| dzr=d\} } | dzrt ||} |dz }| dzr | t ||dzz} |dz }| dzr | t ||d zz} |dz }| dzr | t ||d zz} |dz }| d zrt ||} |dz }| d zr | t ||dzz} |dz }| d zr | t ||d zz} |dz }| sd } | | z}|| ks||krn~|t| | | d| | z } nL| r;|t| | d|||| z|| z }| | z } ntd||k| |dkr| |snt}@|S)aM Read the condensed delta chunk information from dstream and merge its information into a list of existing delta chunks :param dstreams: iterable of delta stream objects, the delta to be applied last comes first, then all its ancestors in order :return: DeltaChunkList, containing all operations to applyNrrrrrrrr @unexpected delta opcode 0) r enumeraterr)rrrZr4 ValueErrorrurr#)dstreamstdclrQdsidsdbdelta_buf_sizero base_sizerrrcp_offcp_sizerGs r*r"r"s D&(((C$X&&DDR WWYY || 9!"a;.  BqE A FA4x) >"&H AZZFFAHs2a5zzQ/FFAHs2a5zzR/0FFAHs2a5zzR/0FFAH!"Q%jjGFAHBqE a0GFAHBqE b 01GFA&%G')W$$** :c7FDAABBBw > :c1aAa!eG==>>>Qq !<===Y.  `  77..s33  Krcdd}|}||kr||}|dz }|dzrd\}} |dzr ||}|dz }|dzr|||dzz}|dz }|dzr|||dzz}|dz }|dzr|||d zz}|dz }|dzr ||} |dz }|d zr| ||dzz} |dz }|d zr| ||dzz} |dz }| sd } || z} | | ks| |krnK||||| zn-|r|||||z||z }ntd ||k||ks JddS)a Apply data from a delta buffer using a source buffer to the target file :param src_buf: random access data from which the delta was created :param src_buf_size: size of the source buffer in bytes :param delta_buf_size: size for the delta buffer in bytes :param delta_buf: random access delta data :param write: write method taking a chunk of bytes **Note:** transcribed to python from the similar routine in patch-delta.crrrrrrrrrrrrrzdelta replay has gone wildN)r) src_buf src_buf_size delta_bufrr;rorrrrrGs r*r r ms A B n   qE Q t8$ :"OFGD AQD 2a5A:&QD 2a5B;'QD 2a5B;'QD Q%QD BqEQJ'QD BqERK(Q "!g%F  \)) E'&'!112 3 3 3 3  : E"Qq1uW+    FAA899 9O n  X     <     rc|dz}|d||d|krdS||z r@t|dt|t|dz z dzrdSdS)a: :return: True if the given lhs and rhs 20 byte binary shas The comparison will take the canonical_length of the match sha into account, hence the comparison will only use the last 4 bytes for uneven canonical representations :param match: less than 20 byte sha :param sha1: 20 byte sharNFrerT)rr8)canonical_lengthmatchsha1 binary_lengths r*r!r!s|%)M ^m^^m^ 444u-' eBi 8DUa,@#A#A AT Iu 4r)r")r)6rMzlib gitdb.utilrrmmap itertoolsr functoolsr gitdb.constrrgitdb.utils.encodingr gitdb.typr r r r iorrr delta_typestype_id_to_type_maptype_to_type_id_mapPAGESIZEr__all__r+r1r6r<r4rVrXrbrr#rrrrr$rrrrr"r r!gitdb_speedups._perf ImportErrorrOrr*rsV    " --------++++++  )$ s}}|s { { Q11! DM !  f       $888&%%%%%%%%B*+++Fe-e-e-e-e-Te-e-e-RAAAAANAAAP+++    *,.BBB6@*6RRRj9=9=9=x( 33333333   DD sC##C,+C,