o ]Lb@sdZddlmZddlZddlZddlmZddlmZddl m Z m Z ddl m Z mZmZmZmZmZmZdd lmZmZed ZejZejZejZejZd Zd Z d Z!dZ"ddZ#ddZ$ddZ%ej&Z&ej'Z'dZ(dZ)dZ*ee)Z+ee*Z,ddZ-ddZ.ddZ/ddZ0dZ1dZ2dZ3d Z4ee3Z5ee4Z6ee2Z7d!Z8d"Z9e8e9>Z:d#Z;ee;Zd(d)Z?e(e-e.fe1e?e>fiZ@d*d+ZAejBdfd,d-ZCe(fd.d/ZDd0e(fd1d2ZEejBd3d4ZFejBd5d6ZGejBd7d8ZHd9d:ZIGd;d<dZLd?d@ZMdAZNdBdCZOdDdEZPdFdGZQiZRdHdIZSdJdKZTdLdMZUdNdOZVeSdPdQdRZWeSdSdTdUZXeSdVdWdXZYeSdYdZd[ZZeSd\d]d^Z[eSd_d`daZ\dbdcZ] dgdddeZ^dS)haObsolete marker handling An obsolete marker maps an old changeset to a list of new changesets. If the list of new changesets is empty, the old changeset is said to be "killed". Otherwise, the old changeset is being "replaced" by the new changesets. Obsolete markers can be used to record and distribute changeset graph transformations performed by history rewrite operations, and help building new tools to reconcile conflicting rewrite actions. To facilitate conflict resolution, markers include various annotations besides old and news changeset identifiers, such as creation date or author name. The old obsoleted changeset is called a "predecessor" and possible replacements are called "successors". Markers that used changeset X as a predecessor are called "successor markers of X" because they hold information about the successors of X. Markers that use changeset Y as a successors are call "predecessor markers of Y" because they hold information about the predecessors of Y. Examples: - When changeset A is replaced by changeset A', one marker is stored: (A, (A',)) - When changesets A and B are folded into a new changeset C, two markers are stored: (A, (C,)) and (B, (C,)) - When changeset A is simply "pruned" from the graph, a marker is created: (A, ()) - When changeset A is split into B and C, a single marker is used: (A, (B, C)) We use a single marker to distinguish the "split" case from the "divergence" case. If two independent operations rewrite the same changeset A in to A' and A'', we have an error case: divergent rewriting. We can detect it because two markers will be created independently: (A, (B,)) and (A, (C,)) Format ------ Markers are stored in an append-only file stored in '.hg/store/obsstore'. The file starts with a version header: - 1 unsigned byte: version number, starting at zero. The header is followed by the markers. Marker format depend of the version. See comment associated with each format for details. )absolute_importN)_)getattr)binhex)encodingerrorobsutilphasespolicypycompatutil)dateutilhashutilparsers createmarkerss allowunstablesallowdivergencesexchangec Csd|}|jd|}|dur|Sz|jddWStjtfyGt|jdd}d|vr3YdS|jdd}|rA|d||vYSw) TReturns True if the given repository has the given obsolete option enabled. s evolution.%s experimentalNs evolutionsallTsevolution.createmarkersr) ui configboolr ConfigErrorAttributeErrorset configlistconfigadd)repooption configkey newconfigresultr"4/usr/lib/python3/dist-packages/mercurial/obsolete.py_getoptionvaluems  r$cCsNt|t}|rt|t}t|t}t|t}nd}d}d}t|t|t|t|iS)z5Returns dicts showing state of obsolescence features.F)r$createmarkersoptallowunstableoptallowdivergenceopt exchangeopt)rcreatemarkersvalue unstablevaluedivergencevalue exchangevaluer"r"r# getoptionss    r-cCs t||S)r)r-)rrr"r"r# isenableds r.s>BIB20ss20sccs||kr|||t}|t7}tt|\}}}}d}|r5t|} |||| }tt||}|| 7}||||} t| |krPttd|t| f||7}t | } z| dd d\} } t | t | f} Wn tyxd} Ynwd}d| vr| dd| ddf}nd| vr| ddf}nd | vrd}|durztd d |D}|D] }t|d krd}nqWn tyd}Ynwttt| } |||| | |fV||ksdSdS) Nr"sIparsing obsolete marker: metadata is too short, %d bytes expected, got %ddates0 0 )grsp2sp1p0css|]}t|VqdSN)r.0pr"r"r# z"_fm0readmarkers..) _fm0fsize_unpack _fm0fixed _fm0fnodesize_fm0nodelenr Abortr_fm0decodemetapopsplitfloatint ValueErrortuple TypeErrorsortedr iteritems)dataoffstopcurnumsucmdsizeflagspresucssmetadatawhenoffsetdateparentsr5r"r"r#_fm0readmarkerssd     rYcCs|\}}}}}}|t@rttdt|}|\}}d||f|d<|dur?|s-d|d<t|dD] \} } t| |d| <q2t|}t|} t t | } | t|||g} | |t | g| R|S)Ns-cannot handle sha256 with old obsstore formats%r %ir/r1rsp%i) usingsha256r r?rdict enumerater_fm0encodemetar>r;r=extend_pack)markerrQrRrPrTrWrXtimetzir5rNformatrJr"r"r#_fm0encodeonemarkers"  rfcsXtD]\}}d|vsd|vrtdd|vrtdqdfddtDS)zmReturn encoded metadata string to string mapping. Assume no ':' in key and no '' in both key and value.:s*':' and '' are forbidden in metadata key's#':' is forbidden in metadata value'csg|] }d||fqS)s%s:%sr")r4kmetar"r# sz"_fm0encodemeta..)r rIrEjoinrH)rkkeyvaluer"rjr#r^sr^cCs4i}|dD]}|r|dd\}}|||<q|S)z8Return string to string dictionary from encoded version.rhrgr)rB)rJdlrnror"r"r#r@"sr@s>IdhHBBBs32ssBBc cst}t}t}t}t}t}t} t} t} t } t t j } ||kr|| }| |||\}}}}}}}||@r;|}|}n|}|}| |||||\}||7}|dkr_||}|||f}n|||}| |||||}||kry|}d}n!|dkr||}|||f}n|||}| |||||}|| |}| d| ||||}g}tdt|dD]!}|||}|||d}|||||||f|}q|||t|||df|fV||ksdSdS)Nr>r<)_fm1parentnoner[_fm1nodesha1size_fm1nodesha256size _fm1nodesha1_fm1nodesha256_fm1metapairsize _fm1metapair _fm1fsizer:structStruct _fm1fixedunpackr xranger>appendrF) rJrKrLnoneflagsha2flagsha1sizesha2sizesha1fmtsha2fmtmetasizemetafmtfsizerufixedo1tsecsrcrPrNnumparnummetanodefmtnodesizepreco2rRo3rX metapairsizerTidxr"r"r#_fm1purereadmarkers\sZ     rcCs||\}}}}}}t}|t@rt}t|}d|} |durt} nt|} | | 7} || } tt|} t| | } |dd}d|d|||| t||g}|||durY||t| }|D];\}}t|}t|}|dkrzd||f}t ||dkrd|||f}t || || ||||7}q_||d<t | g|Rg}|D]\}}| || |qd |S)NrrvrsLobsstore metadata key cannot be longer than 255 bytes (key "%s" is %u bytes)s]obsstore metadata value cannot be longer than 255 bytes (value "%s" for key "%s" is %u bytes)rZ)rzr[r{r>rwr}rr_ _calcsizer ProgrammingErrorrr`rm)rarQrRrPrTrWrX_fm1noderN numextranodesr formatnodes formatmetarercrJ totalsizernrolklvmsgr"r"r#_fm1encodeonemarkersR              rcCs(ttdd}|st|||S||||S)Nfm1readmarkers)rrr)rJrKrLnativer"r"r#_fm1readmarkerss   rcCstd|dddS)N>Brr)r:)rJr"r"r#_readmarkerversionsrcCsZt|}|sd}|durt|}|tvr!td|}tj||d|t|d|||fS)z(Read and enumerate markers from raw datarNs+parsing obsolete marker: unknown version %rversionr)rr>formatsrr UnknownVersion)rJrKrL diskversionrr"r"r# _readmarkerss rcCs td|S)Nr)r`rr"r"r# encodeheader rFccs4t|d}|rt|V|D]}||VqdSNr)rr)markers addheaderr encodeonerar"r"r# encodemarkerss   rcCs&|D]}||dt|qdS)Nr setdefaultrr) successorsrmarkr"r"r#_addsuccessorssrcCs0|D]}|dD] }||t|qqdSrr) predecessorsrrsucr"r"r#_addpredecessorss  rcCs<|D]}|d}|dur|D] }||t|qqdS)Nr)childrenrrrXr5r"r"r# _addchildrensrcCs*|D]}|j|dvrttdqdS)zsearch for marker with invalid data and raise error if needed Exist as a separated function to allow the evolve extension for a more subtle handling. rs;bad obsolescence marker detected: invalid successors nullidN)nullidr r?r)rrrr"r"r#_checkinvalidmarkerssrc@seZdZdZdZedfddZddZdd Zd d Z e Z e d d Z      d)ddZ ddZddZeddZeddZeddZeddZedd Zed!d"Zd#d$Zd%d&Zd'd(ZdS)*obsstoreaStore obsolete markers Markers can be accessed with two mappings: - predecessors[x] -> set(markers on predecessors edges of x) - successors[x] -> set(markers on successors edges of x) - children[x] -> set(markers on predecessors edges of children(x) )sprecssuccssflagsmetar/sparentsFcCs"i|_||_||_||_||_dSr2)cachessvfsr_defaultformat _readonly)selfrr defaultformatreadonlyr"r"r#__init__3s  zobsstore.__init__cC t|jSr2)iter_allrr"r"r#__iter__;rzobsstore.__iter__cCrr2)r>rrr"r"r#__len__>rzobsstore.__len__c Csddlm}t|j|jrt|jdkS|ds=z |j dj dkWSt y<}z |j t j kr2WYd}~nd}~wwt|jS)Nr)statichttpreporobsstore)r isinstancerstatichttprepositoryr>_data_cachedrstatst_sizeOSErrorerrnoENOENTboolr)rrinstr"r"r# __nonzero__As     zobsstore.__nonzero__cCs|jS)zgTrue if marker creation is disabled Remove me in the future when obsolete marker is always on.)rrr"r"r#rTszobsstore.readonlyr"rNc Cs~t|}|dur i}|dur2d|vrt|d}n|dur.|dd}|dur-t}nt}|t@rPt|dkr@t||D] } t| dkrNt| qBnt|dkrZt||D] } t| dkrht| q\||vrxtdt t |t t t |}|D]&\} } z | d| dWqtytd t | t | fwt|t |||||f} t||| gS) a~obsolete: add a new obsolete marker * ensuring it is hashable * check mandatory metadata * encode metadata If you are a human writing code creating marker you want to use the `createmarkers` function in this module instead. return True if a new marker have been added, False if the markers already existed (no op). Nr/devels default-date r8zin-marker cycle with %szutf-8sEobsstore metadata must be valid UTF-8 sequence (key = %r, value = %r))rDr parsedaterA configdatemakedater[r>rEr sysstrrrFrHrIdecodeUnicodeDecodeErrorr rbytestrbytesrr) r transactionrsuccsflagrXrWrTrsuccrivrar"r"r#create[sX        zobsstore.createc Cs |jr ttdt}|jj}g}|D]}|||ddvr.||vr.||||q|rx| dd}z!| }|d|d t ||dk|j } || W|n|w|jd} | durm| |||| |jt|jd d } d | t||jd <t|S) zpAdd new markers to the store Take care of filtering duplicate. Return the number of new marker.s5creating obsolete markers is not enabled on this reporr"rsabrZs obsmarkersNsnew_obsmarkers0%d)rr r?rrrgetrrrtellrmr_versionwriteclosechangesupdate _addmarkersrclearrDhookargsr>) rrrknown getsuccessorsnewmfrVrJ addedmarkerspreviousr"r"r#rs8         z obsstore.addcCst|\}}|||S)zfmerge a binary stream of markers inside the obsstore Returns the number of new markers added.)rr)rrrJrrr"r"r# mergemarkerss  zobsstore.mergemarkerscCs |jdS)Nr)rtryreadrr"r"r#rs zobsstore._datacCst|jdkr t|jS|jSr)r>rrrrr"r"r#rs zobsstore._versioncCs4|j}|sgSt|\|_}t|}t|j||Sr2)rrrlistrr)rrJrr"r"r#rs z obsstore._allcCi}t||j|Sr2)rr)rrr"r"r#r zobsstore.successorscCr r2)rr)rrr"r"r#rr zobsstore.predecessorscCr r2)rr)rrr"r"r#rr zobsstore.childrencCs ||jvSr2)__dict__)rattrr"r"r#rrzobsstore._cachedcCsrt|}|j||_|j||drt|j||dr&t|j||dr1t |j |t |j |dS)Nrrr) r rrr_rrrrrrrrr)rrrawdatar"r"r#rs        zobsstore._addmarkersc Cst|}t}t|}|j}|j}|j}|r`t}|D]+} ||| ddd|| dD} || dd|| dD} || q||8}dd|D}||O}||8}||O}|s|S)aqreturn a set of all obsolescence markers relevant to a set of nodes. "relevant" to a set of nodes mean: - marker that use this changeset as successor - prune marker of direct children on this changeset - recursive application of the two rules on predecessors of these markers It is a set so you cannot rely on order.r"cSg|]}|ds|qSrr"r4rr"r"r#rlz,obsstore.relevantmarkers..cSrrr"rr"r"r#rlrcSsh|]}|dqS)rr"rr"r"r# z+obsstore.relevantmarkers..)rrrrrr) rnodes pendingnodes seenmarkers seennodesprecursorsmarkers succsmarkersrdirectcurrentprunedr"r"r#relevantmarkerss*    zobsstore.relevantmarkers)r"rNNNN)__name__ __module__ __qualname____doc__fields _fm1versionrrrr__bool__propertyrrrr propertycacherrrrrrrrrr"r"r"r#r!sD    E'       rcCsj|dd}i}|dur||d<t|t }t||jfd|i|}|r3|r3|tdtt||S)z(Create an obsstore instance from a repo.sformatsobsstore-versionNrrs3obsolete feature not enabled but %i markers found! ) configintr.r%rrwarnrr>r )rrrkwargsrstorer"r"r# makestore&s   r-cCs*|jdd|D] }|tvr|SqdS)z|Return the newest version listed in both versions and our local formats. Returns None if no common version exists. T)reverseN)sortr)versionsrr"r"r# commonversion9s r1ic Csi}g}td}|D]"}t|}t||tkr!g}d}|||||t|7}q tt|D]\}}dtdtg|} t | |d|<q3|S)zencode markers into a dict suitable for pushkey exchange - binary data is base85 encoded - split in chunks smaller than 5300 bytesrurrZrsdump%i) _maxpayloadrfr>rr]reversedrmr` _fm0versionr b85encode) rkeysparts currentlenranextdata currentpartrpartrJr"r"r#_pushkeyescapeMs  r<cCs|jsiStt|jS)zList markers over pushkey)rr<rHrr"r"r# listmarkerscsr>c Cs|ds|jtd|dS|r|jtd|dSt|}|1|d}|j |||  WdWddS1sLwYWddS1s\wYdS)zPush markers over pushkeysdumpsunknown key: %rFsunexpected old value for %rspushkey: obsolete markersNT) startswithrr*rr b85decodelockrrrinvalidatevolatilesets)rrnoldrrJtrr"r"r# pushmarkerjs  PrEcsfdd}|S)zADecorator to register a function as computing the cache for a setcs.tvrd}t|tf|t<|S)Ns;duplicated registration for volatileset '%s' (existing: %r)) cachefuncsr r)funcrnamer"r# decorators zcachefor..decoratorr")rIrJr"rHr#cachefor}s rKcCs~|}td|+|jstWdS||jjvr(t|||jj|<|jj|WdS1s8wYdS)zyReturn the set of revision that belong to the set Such access may compute the set and cache it for future usez getrevs %sN) unfilteredrtimedcmr frozensetrrF)rrIr"r"r#getrevss  $rOcCsd|jvr |jjdSdS)zRemove all obsolescence related cache from a repo This remove all cache in obsstore is the obsstore already exist on the repo. (We could be smarter here given the exact event that trigger the cache clearing)rN) _filecacherrrr=r"r"r#clearobscachess rQcCs|j|tjS)z-the set of mutable revision in the repository) _phasecache getrevsetr mutablephasesr=r"r"r# _mutablerevssrUobsoletecs2|jjt|}|jjjtfdd|DS)zthe set of obsolete revisionsc3s |] }|r|VqdSr2r"r4rgetnodeisobsr"r#r6sz&_computeobsoleteset..) changelognoderUrr __contains__rN)r notpublicr"rYr#_computeobsoletesets r`orphancCsj|jj}t|}t|d}||}t}t|D]}||D]}||vs(||vr/||nqqt|S)z7the set of non obsolete revisions with obsolete parentsrV)r\ parentrevsrUrOrrHrrN)rpfuncmutableobsoleteothersunstablerXr5r"r"r#_computeorphansets    rh suspendedcs.|jt|dtfddt|dDS)z9the set of obsolete parents with non obsolete descendantsrac3s|] }|vr|VqdSr2r"rW suspendedr"r#r6sz'_computesuspendedset..rV)r\ ancestorsrOrNr=r"rjr#_computesuspendedsetsrmsextinctcCst|dt|dS)z.r)rrr\r]rtrrrArr successorssetsr>rrN) r divergentrnewermaprzr{r]r toprocessseenrnewerr"r"r#_computecontentdivergentsets0     rcCsTt|}|d|dD]}|d|||q t|ddS)Nrrr)rsha1rr{r]rdigest)relationuser folddigestr5r"r"r# makefoldid s rc CsZ|duri}d|vr|jddp|j}t||d<|jdd}|r,|r,||d<|jdd}|d } g} |D]} | d } t| tsK| f} t | d krft | d d krfd } t | t | d d}t | }d |krwt | |d}t | d D]}\}}| d }|}t | d kr|| d |dur||d<d||d<d||d<|st jtd|dd|}tdd|D}d}|stdd|D}||vrt td||rt||}d||tj<| ||||fq|q=| D]}|\}}}}|jj| |||||||jd|jqWddS1s&wYdS)aAdd obsolete markers between changesets in a repo must be an iterable of ((,...), (, ...)[,{metadata}]) tuple. `old` and `news` are changectx. metadata is an optional dictionary containing metadata for this marker only. It is merged with the global metadata specified through the `metadata` argument of this function. Any string values in metadata must be UTF-8 bytes. Trying to obsolete a public changeset will raise an exception. Current user and date are used except if specified otherwise in the metadata attribute. This function operates within a transaction of its own, but does not take any lock on the repo. Nsuserrsuser.obsmarkerrsevolution.track-operations operationsevolution.effect-flagssadd-obsolescence-markerrrs/Fold markers can only have 1 successors, not %drusfold-idrsfold-idxs fold-sizes$cannot obsolete public changeset: %ss see 'hg help phases' for details)hintcs|]}|VqdSr2r])r4rSr"r"r#r6]r7z createmarkers..csrr2rr3r"r"r#r6`r7s#changeset %s cannot obsolete itself)rXrWrTr)rrusernamer fromlocalrrrrFr>r rrr]copyrrdr?rr]rXr geteffectflagEFFECTFLAGFIELDrrrfilteredrevcacher)r relationsrrWrT operationluser useoperationsaveeffectflagrD markerargsrelrrfoldidfoldsizefoldidxrrR localmetadatanprecnsucsnpare effectflagargsr"r"r# createmarkerss        &  $r)NN)rNNN)_r# __future__rrri18nrr rr]rrrrr r r r rutilsrr importmodrpackr`rr:calcsizerr(r%r&r'r(r$r-r.rvr[r4r;r=r9r<rYrfr^r@r%rrzr{rxryr~rw_fm1parentshift_fm1parentmaskr}r|rrrrrnogcrrrrrrrobjectrr-r1r2r<r>rErFrKrOrQrUr`rhrmrnr~rrrr"r"r"r#s =  $  8 ,?1