o ]LbC @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||kr|}|}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)textp1p2sabr=/usr/lib/python3/dist-packages/mercurial/utils/storageutil.pyhashrevisionsha1$s     r cCsf|dddkr dSt|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)rrmtextmetalkvrrr 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 Vszpackmeta..s %s %s)sortedjoin)r&rkeysmetatextrr-rpackmetaSs r3cCst|d}|o d|vS)Nrscensored)r*)rr&rrriscensoredtextZs  r4cCs*|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  r8cCsV||dtjkr dSt||d}|r)d|vr)d|vr)|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|dr d|}n|}||\}}t|||}||krdS|||r+|dkS||r7|||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)r5r9r iscensoredrevrenamedread)r;r<filedata revisiontextrr computednoderrrfiledataequivalents   rEcCs@d}|dur||kr d}||7}||kr|}n|}t|||S)z)Iterate over revision numbers in a store.rN)r xrange)storelenr"stopsteprrriterrevssrKc Cst|trz||WStytd||tdwt|dvr7z|||WStjy6Ynwt|dvrSz t |}|||WSt yRYnwz!t|}d||kr`t z||WWStt fyrYnwWn t t fyYnwt||td)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) )(@) isinstanceintr< IndexErrorr LookupErrorrlenr?r TypeError ValueError OverflowError)r;fileid identifierrawnoder?rrr fileidlookupsJ         r[cCst}|d}i}t}|D]} || } | || <| |kr!|| q|rZ|d8}||} | |kr7||n|| ||D]} | tkrW|| } | || <| |krW|| q@|s$||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) minlinkrevtiprevheadrevs linkrevfn parentrevsfn brokenrevs strippointheadsfuturelargelinkrevshead headlinkrevlinkrevpplinkrevrrrresolvestripinfos2      rnFc ! #s |j} |j|dkrfdd|D}n |dkr*fdd|D}t||j}n tfdd|D}d }| tjks>| rG||d d }t}|D]@}|t krTqL| |}||\}}|rf||}nt }| tjkrp|}n9| tj krxt }n1| tj kr|}n)|t kr||vr|}n| r|||fvr|}n|d ur|}n t }n |d ur|}nt }|t kr|r|||st }d }d }d }| r*| |s| |rz| |}Wntjy}z |j}WYd }~nd }~ww|t kr|r||}n8t| |}n0|t kr| tjkr| |}||n|r|||}n t| || |}||d }d }| rYz||}Wn tjyEi}Yn wtj|| ||d \}}|rYt|}|r`||nd }d } |rv| tO} ||d |d @B}||| || || ||||||| d V|}qLd 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,nfrevrr }z!emitrevisions..slinearcsh|]}|qSrrrorqrr rtz emitrevisions..c3s|]}|VqdS)Nrrorqrrr.sz emitrevisions..Nr)rr)r;sidedata_helpersr r?r) r<p1nodep2nodebasenodeflagsbaserevisionsizer:deltar protocol_flags)r<r?r linearize parentrevsr/r CG_DELTAMODE_PREVr\rCG_DELTAMODE_FULLCG_DELTAMODE_P1r>rawdatar CensoredNodeError tombstonerTr]r textdiffr sidedatamodrun_sidedata_helpersserialize_sidedataCG_FLAG_SIDEDATA)!r;nodes nodesorder resultcls deltaparentfn candeltafn rawsizefn revdifffnflagsfn deltamode revisiondataassumehaveparentrevisionsrvfnoderevsprevrev availabler?r<p1revp2revdeltaparentrevbaserevr:r|r{eserialized_sidedatasidedata_flags old_sidedatar rzr}rrqr emitrevisions(sQ             rcCsrtd}t||kr dS||}t||}|d|t||kr%dSd}t|}||ko8|||||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:)structcalcsizerTr replacediffheader)r|r baselenfnhlenoldlennewlenr]addlenrrrdeltaiscensoreds   r)rN)) __future__rreri18nrr<rrrrr r r interfacesr revlogutilsr rutilsrrrrrrcompiler r*r3r4r8r=rErKr[rnCG_DELTAMODE_STDrrrrrrsD         %89  k