a +bC @sddlmZddlZddlZddlmZddlmZmZm Z ddl m Z m Z m Z mZddlmZddlmZdd lmZee jZd Zd d Zed ZddZddZddZddZ ddZ!ddZ"d%ddZ#ddZ$ddZ%dddddej&d d df d!d"Z'd#d$Z(dS)&)absolute_importN)_)binnullrevsha1nodeconstants)dagoperrormdiffpycompat) repository)sidedata)hashutilcCs^|tjkrt}||n.||kr0|}|}n|}|}t|}|||||S)zCompute the SHA-1 for revision data and its parents. This hash combines both the current file contents and its history in a manner that makes it easy to distinguish nodes with the same content in the revision graph. )rnullid _nullhashcopyupdatersha1digest)textp1p2sabrA/usr/lib64/python3.9/site-packages/mercurial/utils/storageutil.pyhashrevisionsha1$s     r cCsf|dddkrdSt|d}|d|}i}|D]}|dd\}}|||<q<||dfS)zParse metadata header from revision data. Returns a 2-tuple of (metadata, offset), where both can be None if there is no metadata. Nrr)NNs: r) METADATA_REsearchstart splitlinessplit)rrZmtextmetalkvrrr parsemetaAs   r)cs,t}dfdd|D}d||fS)z2Add metadata to fulltext to produce revision text.c3s|]}d||fVqdS)s%s: %s Nr).0r'r%rr Vr*zpackmeta..s %s %s)sortedjoin)r%rkeysZmetatextrr,rpackmetaSsr1cCst|d}|od|vS)Nrscensored)r))rr%rrriscensoredtextZs r2cCs*|ds|S|dd}||ddS)zExtract just the revision data from source text. Returns ``text`` unless it has a metadata header, in which case we return a new buffer without hte metadata. rrN) startswithindex)roffsetrrrfiltermetadata_s  r6cCsV||dtjkrdSt||d}|rRd|vrRd|vrR|dt|dfSdS)zResolve file revision copy metadata. Returns ``False`` if the file has no copy metadata. Otherwise a 2-tuple of the source filename and node. rFscopyscopyrev)parentsrrr)revisionr)storenoder%rrrfilerevisioncopiedls r;cCsr|drd|}n|}||\}}t|||}||kr>dS|||rV|dkS||rn|||kSdS)ahDetermines whether file data is equivalent to a stored node. Returns True if the passed file data would hash to the same value as a stored revision and False otherwise. When a stored revision is censored, filedata must be empty to have equivalence. When a stored revision has copy metadata, it is ignored as part of the compare. rs  Tr*F)r3r7r iscensoredrevZrenamedread)r9r:ZfiledataZ revisiontextrrZ computednoderrrfiledataequivalents    r?cCs@d}|dur.||krd}||7}||kr2|}n|}t|||S)z)Iterate over revision numbers in a store.rN)r Zxrange)Zstorelenr"stopsteprrriterrevssrCc Cst|tr@z ||WSty>td||tdYn0t|dvrrz|||WStjypYn0t|dvrzt |}|||WSt yYn0zBt|}d||krt z||WWStt fyYn0Wnt t fyYn0t||tddS)aResolve the file node for a value. ``store`` is an object implementing the ``ifileindex`` interface. ``fileid`` can be: * A 20 or 32 byte binary node. * An integer revision number * A 40 or 64 byte hex node. * A bytes that can be parsed as an integer representing a revision number. ``identifier`` is used to populate ``error.LookupError`` with an identifier for the store. Raises ``error.LookupError`` on failure. s%dsno match found) )(@N) isinstanceintr: IndexErrorr LookupErrorrlenr=r TypeError ValueError OverflowError)r9ZfileidZ identifierZrawnoder=rrr fileidlookups>           rPcCst}|d}i}t}|D]&} || } | || <| |kr|| q|r|d8}||} | |krn||n || ||D].} | tkr|| } | || <| |kr|| qqD||fS)aResolve information needed to strip revisions. Finds the minimum revision number that must be stripped in order to strip ``minlinkrev``. Returns a 2-tuple of the minimum revision number to do that and a set of all revision numbers that have linkrevs that would be broken by that strip. ``tiprev`` is the current tip-most revision. It is ``len(store) - 1``. ``headrevs`` is an iterable of head revisions. ``linkrevfn`` is a callable that receives a revision and returns a linked revision. ``parentrevsfn`` is a callable that receives a revision number and returns an iterable of its parent revision numbers. r)setaddpopremover)Z minlinkrevZtiprevZheadrevsZ linkrevfnZ parentrevsfnZ brokenrevsZ strippointZheadsZfuturelargelinkrevsheadZ headlinkrevZlinkrevpZplinkrevrrrresolvestripinfos,     rWFc ! #s:|j} |j|dkr(fdd|D}n@|dkrRfdd|D}t||j}ntfdd|D}d }| tjksz| r||d d }t}|D]}|t krq| |}||\}}|r||}nt }| tjkr|}n~| tj krt }nn| tj kr|}n^|t krH||vr|}n.| r2|||fvr2|}n|d urB|}nt }n|d urX|}nt }|t kr||r||||s|t }d }d }d }| rn| |s| |rz| |}Wn.tjy}z|j}WYd }~n d }~00|t krn|r||}nt| |}n`|t kr:| tjkr:| |}||n4|rL|||}nt| || |}||d }d }| rz||}Wntjyi}Yn0tj|| ||d \}}|rt|}|r||nd }d } |r| tO} ||d |d @B}||| || || ||||||| d V|}qd S)a Generic implementation of ifiledata.emitrevisions(). Emitting revision data is subtly complex. This function attempts to encapsulate all the logic for doing so in a backend-agnostic way. ``store`` Object conforming to ``ifilestorage`` interface. ``nodes`` List of revision nodes whose data to emit. ``resultcls`` A type implementing the ``irevisiondelta`` interface that will be constructed and returned. ``deltaparentfn`` (optional) Callable receiving a revision number and returning the revision number of a revision that the internal delta is stored against. This delta will be preferred over computing a new arbitrary delta. If not defined, a delta will always be computed from raw revision data. ``candeltafn`` (optional) Callable receiving a pair of revision numbers that returns a bool indicating whether a delta between them can be produced. If not defined, it is assumed that any two revisions can delta with each other. ``rawsizefn`` (optional) Callable receiving a revision number and returning the length of the ``store.rawdata(rev)``. If not defined, ``len(store.rawdata(rev))`` will be called. ``revdifffn`` (optional) Callable receiving a pair of revision numbers that returns a delta between them. If not defined, a delta will be computed by invoking mdiff code on ``store.revision()`` results. Defining this function allows a precomputed or stored delta to be used without having to compute on. ``flagsfn`` (optional) Callable receiving a revision number and returns the integer flags value for it. If not defined, flags value will be 0. ``deltamode`` constaint on delta to be sent: * CG_DELTAMODE_STD - normal mode, try to reuse storage deltas, * CG_DELTAMODE_PREV - only delta against "prev", * CG_DELTAMODE_FULL - only issue full snapshot. Whether to send fulltext revisions instead of deltas, if allowed. ``nodesorder`` ``revisiondata`` ``assumehaveparentrevisions`` ``sidedata_helpers`` (optional) If not None, means that sidedata should be included. See `revlogutil.sidedata.get_sidedata_helpers`. snodescsg|] }|qSrrr+nZfrevrr }r*z!emitrevisions..slinearcsh|] }|qSrrrXrZrr r*z emitrevisions..c3s|]}|VqdS)NrrXrZrrr-r*z emitrevisions..Nr)rr)r9sidedata_helpersr r=r) r:Zp1nodeZp2nodeZbasenodeflagsbaserevisionsizer8deltar protocol_flags)r:r=rZ linearizeZ parentrevsr.r ZCG_DELTAMODE_PREVrQrZCG_DELTAMODE_FULLZCG_DELTAMODE_P1r<Zrawdatar ZCensoredNodeErrorZ tombstonerLrRr Ztextdiffr sidedatamodZrun_sidedata_helpersZserialize_sidedataCG_FLAG_SIDEDATA)!r9ZnodesZ nodesorderZ resultclsZ deltaparentfnZ candeltafnZ rawsizefnZ revdifffnZflagsfnZ deltamodeZ revisiondataZassumehaveparentrevisionsr]ZfnodeZrevsZprevrevZ availabler=r:Zp1revZp2revZdeltaparentrevbaserevr8r`r_eZserialized_sidedataZsidedata_flagsZ old_sidedatar r^rarrZr emitrevisions(sQ                   rfcCsrtd}t||krdS||}t||}|d|t||krJdSd}t|}||kop|||||kS)aRDetermine if a delta represents censored revision data. ``baserev`` is the base revision this delta is encoded against. ``baselenfn`` is a callable receiving a revision number that resolves the length of the revision fulltext. Returns a bool indicating if the result of the delta represents a censored revision. s>lllFNs  censored:)structcalcsizerLr Zreplacediffheader)r`rdZ baselenfnZhlenZoldlenZnewlenrRZaddlenrrrdeltaiscensoreds   ri)rN))Z __future__rrergZi18nrr:rrrrr r r Z interfacesr Z revlogutilsr rbZutilsrrrrrcrcompiler r)r1r2r6r;r?rCrPrWZCG_DELTAMODE_STDrfrirrrrsB        % 89 k