^cdZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z m Z mZmZmZmZmZddlmZmZejd ZejZejZejZejZd Zd Zd Z d Z!dZ"dZ#dZ$ej%Z%ej&Z&dZ'dZ(dZ)ee(Z*ee)Z+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3ee2Z4ee3Z5ee1Z6dZ7dZ8ee8Z9dZ:dZ;dZej?dAdZ@e'fd ZAd!e'fd"ZBej?d#ZCej?d$ZDej?d%ZEd&ZFGd'd(ZGd)ZHd*ZId+ZJd,ZKd-ZLd.ZMiZNd/ZOd0ZPd1ZQd2ZReOd3d4ZSeOd5d6ZTeOd7d8ZUeOd9d:ZVeOd;d<ZWeOd=d>ZXd?ZY dBd@ZZdS)CaObsolete 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. N)_)getattr)binhex)encodingerrorobsutilphasespolicypycompatutil)dateutilhashutilparsers createmarkerss allowunstablesallowdivergencesexchangecd|z}|jd|}||S |jddS#tjtf$rht |jdd}d|vrYdS|jdd}|r|d||vcYSwxYw) TReturns True if the given repository has the given obsolete option enabled. s evolution.%s experimentalNs evolutionsallTsevolution.createmarkersr) ui configboolr ConfigErrorAttributeErrorset configlistconfigadd)repooption configkey newconfigresults 4/usr/lib/python3/dist-packages/mercurial/obsolete.py_getoptionvaluer$ms &(I""?I>>I w!!/<@@@  ~ .    TW''FFGG V  44GNN?4NOO  ) JJ' ( ( (  sAAB?6B?>B?ct|t}|r@t|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 exchangevalues r# getoptionsr.s)/?@@ '.>?? )$0BCC'k::    ,-O]  c,t||S)r)r.)rrs r# isenabledr1s d  F ##r/s>BIB20ss20sc#JK||kr|||tz}|tz }tt|\}}}}d}|r4t|z} |||| z}tt|z|}|| z }||||z} t | |kr3t jtd|t | fz||z }t| } | dd d\} } t| t| f} n#t$rd} YnwxYwd}d| vr-| dd| ddf}n"d| vr| ddf}nd | vrd}|N td |D}|D]}t |d krd}nn#t j$rd}YnwxYwtt%| } |||| | |fV||kdSdS) NsIparsing obsolete marker: metadata is too short, %d bytes expected, got %ddates0 0 )grsp2sp1p0c34K|]}t|VdSN)r.0ps r# z"_fm0readmarkers..s(881A888888r/) _fm0fsize_unpack _fm0fixed _fm0fnodesize_fm0nodelenr Abortr_fm0decodemetapopsplitfloatint ValueErrortuplebinasciiErrorsorteditems)dataoffstopcurnumsucmdsizeflagspresucssmetadatawhenoffsetdateparentsr;s r#_fm0readmarkersr_s **3y() y%,Y%<%<"s  &AsS1W}%C8f,c22D 1HCcFl*+ x==F " "+83x==) *  v !(++ #<<88>>tDDLD&;;F +DD   DDD  H  ||E400(,,ud2K2KLGG h  ||E4002GG h  G   8888888 A1vv||"&$>     0 01122D%49999g ******s% A D++ D:9D:5G GGc|\}}}}}}|tzr!tjtdt |}|\}}d||fz|d<|2|sd|d<t |dD]\} } t | |d| z<t|}t|} tt| zz} | t|||g} | |t| g| R|zS)Ns-cannot handle sha256 with old obsstore formats%r %ir4r/r6rsp%i) usingsha256r rDrdict enumerater_fm0encodemetarCr@rBextend_pack)markerrWrXrVrZr]r^timetzir;rTformatrPs r#_fm0encodeonemarkerrls06-Cuhg {Ok!LMMNNNH~~HHD" D":-HW "!HUOgq)) * *DAq#&q66HVaZ h''H YYF (V+ ,F CMM5# .DKK  $   ( **r/cD]/\}}d|vsd|vrtdd|vrtd0dfdtDS)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'c*g|]}d||fzS)s%s:%sr3)r:kmetas r# z"_fm0encodemeta..s&EEE1x1d1g,.EEEr/)rOrJjoinrN)rrkeyvalues` r#rdrdsjjllEE U 3;;%3,,KLL L E>>CDD D  ::EEEEt EEE F FFr/czi}|dD]"}|r|dd\}}|||<#|S)z8Return string to string dictionary from encoded version.rornr)rG)rPdlrurvs r#rErE"sP A ZZ    q))JCAcF Hr/s>IdhHBBBs32ssBBc#Kt}t}t}t}t}t }t } t} t} t} tj tj } ||kro|| z}| |||\}}}}}}}||zr|}|}n|}|}| |||||z\}||z }|dkr||z}|||f}n|||zz}| ||z|||}||kr|}d}n6|dkr||z}|||f}n|||zz}| ||z|||}|| |zz}| d| |zz|||}g}tdt|dD]D}|||z}|||dzz}|||||||f|}E|||t#|||dzf|fV||kmdSdS)Nr>r<)_fm1parentnonera_fm1nodesha1size_fm1nodesha256size _fm1nodesha1_fm1nodesha256_fm1metapairsize _fm1metapair _fm1fsizer?structStruct _fm1fixedunpackrangerCappendrK) rPrQrRnoneflagsha2flagsha1sizesha2sizesha1fmtsha2fmtmetasizemetafmtfsizerufixedo1tsecsrirVrTnumparnummetanodefmtnodesizepreco2rXo3r^ metapairsizerZidxs r#_fm1purereadmarkersrZssHHH!HGGHG E F]9 % % ,F ** 5[6DDh''B6'F*DBK88D X  BGG q[[hBBrE{nGGh''BfWv-tBrE{;;G8g%%vdg&78$r#v,GG C --q11  C|C((Bl37++B OOT#b&\42;7 8 8 8CCT5%//D"r'?GLLLLY ******r/c |\}}}}}}t}|tzrt}t|}d|z} |t} nt|} | | z } || z} t t|z} t | z| z} |ddz}d|d|||| t||g}|||||t| }|D]\}}t|}t|}|dkrd||fz}tj ||dkrd|||fz}tj || || ||||zz }||d<t| g|Rg}|D]/\}}| || |0d |S)Nrr~rsLobsstore 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)r/)rrarrCrrrre _calcsizer ProgrammingErrorrrfrt)rgrWrXrVrZr]r^_fm1noderT numextranodesr formatnodes formatmetarkrirP totalsizerurvlklvmsgs r#_fm1encodeonemarkerrs06-CuhgH {"! YYFJMW ]*KH -J  $z 1F aBB $q'2uffc(mmS IDKK G&!!I U XX ZZ 88+b C(-- - 88:R !C(-- - B BR"W DG & 4 !D U C E 88D>>r/cnttdd}|st|||S||||S)Nfm1readmarkers)rrr)rPrQrRnatives r#_fm1readmarkersrsB W. 5 5F 4"4d333 6$T " ""r/c>td|dddS)N>Brr)r?)rPs r#_readmarkerversionrs 5$qs) $ $Q ''r/ct|}|sd}|t|}|tvr(td|z}t j|||t|d|||fS)z(Read and enumerate markers from raw datarNs+parsing obsolete marker: unknown version %rversionr)rrCformatsrr UnknownVersion)rPrQrR diskversionrs r# _readmarkersrs%T**K  |4yy'!!>??+M"3 <<<<  ,Q/c4@@ @@r/c"td|S)Nr)rfrs r# encodeheaderrs   r/Fc#zKt|d}|rt|V|D]}||VdSNr)rr)markers addheaderr encodeonergs r# encodemarkersrse #I$7#####  i  r/c|D]=}||dt|>dS)Nr setdefaultrr) successorsrmarks r#_addsuccessorsrsJ88d1gsuu--11$777788r/c|D]B}|dD]7}||t|8CdSrr) predecessorsrrsucs r#_addpredecessorsrs^::7 : :C  # #C / / 3 3D 9 9 9 9 :::r/c|D]F}|d}|:|D]7}||t|8GdS)Nr)childrenrrr^r;s r# _addchildrenrse88q'   8 8##Asuu--11$7777 88r/cp|D]2}|j|dvr!tjtd3dS)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 rDr)rrrs r#_checkinvalidmarkersrsY  ;$q' ! !+1  "r/ceZdZdZdZedfdZedZdZ dZ dZ e Z ed Z dd ZdZdZedZedZedZedZedZedZdZdZdZd S)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) )sprecssuccssflagsmetar4sparentsFcpi|_||_tj||_||_||_dSr8)cachessvfsweakrefref_repo_defaultformat _readonly)selfrr defaultformatreadonlys r#__init__zobsstore.__init__1s4  [&& +!r/c^|}|d}tj||S)Nz(using the obsstore of a deallocated repo)rr r)rrrs r#rz obsstore.repo9s/ JJLL 9>$    DIs"A22 A?>A?c|jS)zgTrue if marker creation is disabled Remove me in the future when obsolete marker is always on.)rrs r#rzobsstore.readonlyYs ~r/r3rNc tt|}|i}|md|vr(tj|d}nA|,|dd}|tj}ntj}|t zrJt|dkrt||D]$} t| dkrt| %nIt|dkrt||D]$} t| dkrt| %||vr$td| ztt| }|D]{\} } | d| d1#t$r>tjd t#j| t#j| fzwxYwt'|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). Nr4devels default-date r=zin-marker cycle with %szutf-8sEobsstore metadata must be valid UTF-8 sequence (key = %r, value = %r))rIr parsedaterF configdatemakedaterarCrJrrKrNrOdecodeUnicodeDecodeErrorr rr bytestrbytesrr) r transactionrsuccsflagr^r]rZrsuccrqvrgs r#createzobsstore.create`sL.4yy  H <("")(,,w*?*?@@}}X??<#,..D(** +  +4yyB &&& + +t99??$T***# +4yyB &&& + +t99??$T***# 5==6CDD D 0 01122  DAq !!!!!!!%   ,.'**H,*F))AG1c|jr!tjtdt }|jj}g}|D]D}|||ddvr.||vr*||||E|r| dd} | }|d|d t||dk|j } || |n#|wxYw|jd} | | |||| |jt+|jd d } d | t/|zz|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 reporr3rsabr/s obsmarkersNsnew_obsmarkers0%d)rr rDrrrgetrrrtellrtr_versionwriteclosechangesupdate _addmarkersrclearrIhookargsrC) rrrknown getsuccessorsnewmfr\rP addedmarkerspreviouss r#rz obsstore.adds > +JKK +   A adB////AUNN !  1   +u--A  V444xx c6Q; N NOO   &.22=AAL'##C(((   S$ ' ' ' K     {+//0A4HHII278c#hh;N2O ./3xxs &A,D''D=cRt|\}}|||S)zfmerge a binary stream of markers inside the obsstore Returns the number of new markers added.)rr)rrrPrrs r# mergemarkerszobsstore.mergemarkerss*(--xx W---r/c6|jdS)Nr)rtryreadrs r#rzobsstore._datasy  ---r/cht|jdkrt|jS|jSr)rCrrrrs r#rzobsstore._versions. tz??a  %dj11 1& &r/c|j}|sgSt|\|_}t|}t |j||Sr8)rrrlistrr)rrPrs r#rz obsstore._allsLz I!-d!3!3 ww--TY000r/c4i}t||j|Sr8)rr)rrs r#rzobsstore.successorss z49---r/c4i}t||j|Sr8)rr)rrs r#rzobsstore.predecessorss ty111r/c4i}t||j|Sr8)rr)rrs r#rzobsstore.childrensXty)))r/c||jvSr8)__dict__)rattrs r#rzobsstore._cachedst}$$r/ct|}|j|z|_|j||drt |j||drt|j||drt|j |t|j |dS)Nrrr) r'rrrerrrrrrrrr)rrrawdatas r#rzobsstore._addmarkerssw--Z')  !!! << % % 5 4?G 4 4 4 << ' ' 9 T. 8 8 8 << # # 1  0 0 0TY00000r/ct|}t}t|}|j}|j}|j}|rt}|D]} ||| dd|| dD} || d|| dD} || ||z}d|D}||z}||z}||z}||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.r3c"g|] }|d | Srr3r:rs r#rsz,obsstore.relevantmarkers..s!KKKadK!KKKr/c"g|] }|d | Sr2r3r3s r#rsz,obsstore.relevantmarkers..s!OOO!A$O!OOOr/ch|] }|d S)rr3r3s r# z+obsstore.relevantmarkers.."s111QAaD111r/)rrrrrr) rnodes pendingnodes seenmarkers seennodesprecursorsmarkers succsmarkersrdirectcurrentpruneds r#relevantmarkerszobsstore.relevantmarkerss75zz ee  %%  - = &UUF' & & /33GR@@AAAKKX\\'2%>%>KKK f%%%OO\%5%5gr%B%BOOO f%%%% k !F11&111L 6 !K I %L  %I &r/)r3rNNNN)__name__ __module__ __qualname____doc__fields _fm1versionrpropertyrrrr__bool__rr rr" propertycacherrrrrrrrr@r3r/r#rrsHF2=u""""X H X   A5A5A5A5F%%%N.....].'']' ]] ] ] %%% 1 1 1r/rc |dd}i}|||d<t|t }t||jfd|i|}|rA|r?|t dtt|z|S)z(Create an obsstore instance from a repo.sformatsobsstore-versionNrrs3obsolete feature not enabled but %i markers found! ) configintr1r&rrwarnrrCr')rrrkwargsrstores r# makestorerO)sLL,?@@M F "/T#3444H T49 B Bx B6 B BE     E F F$u++     Lr/cV|d|D]}|tvr|cSdS)z|Return the newest version listed in both versions and our local formats. Returns None if no common version exists. T)reverseN)sortr)versionsr s r# commonversionrT<sC  MM$M  <<HHH  4r/ici}g}tdz}|D]l}t|}t||ztkrg}d}|||||t|z }mt t |D]K\}}dtdtg|z} tj | |d|z<L|S)zencode markers into a dict suitable for pushkey exchange - binary data is base85 encoded - split in chunks smaller than 5300 bytesr}rr/rsdump%i) _maxpayloadrlrCrrcreversedrtrf _fm0versionr b85encode) rkeysparts currentlenrgnextdata currentpartrpartrPs r#_pushkeyescaper`Ps D EqJ$$&v.. x==: % 3 3KJ LL % % %8$$$c(mm# x//55 Txxuk223d:;; $t 4 4Y_ Kr/cV|jsiStt|jS)zList markers over pushkey)rr`rNrs r# listmarkersrcfs) = &// 0 00r/c8|ds,|jtd|zdS|r,|jtd|zdSt j|}|5|d5}|j |||  dddddddS#1swxYwYddddS#1swxYwYdS)zPush markers over pushkeysdumpsunknown key: %rFsunexpected old value for %rspushkey: obsolete markersNT) startswithrrLrr b85decodelockrrr"invalidatevolatilesets)rruoldrrPtrs r# pushmarkerrkms >>' " "  Q)**S0111u   Q566<===u >#  D d&&'CDD ""2t,,, ##%%%s6D.1C7 D7C; ;D>C; ?DDDcfd}|S)zADecorator to register a function as computing the cache for a setcztvr&d}tj|tfz|t<|S)Ns;duplicated registration for volatileset '%s' (existing: %r)) cachefuncsr r)funcrnames r# decoratorzcachefor..decoratorsB :  PC(j6F/G)GHH H 4 r/r3)rprqs` r#cacheforrrs$ r/cN|}tjd|5|jst cdddS||jjvr"t |||jj|<|jj|cdddS#1swxYwYdS)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 frozensetrrn)rrps r#getrevsrws ??  D lD ) )**} ;;******** t}+ + +)3D)9$)?)?DM  &}#D) ******************sB ABB!BcXd|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) _filecacherrrrbs r#clearobscachesrzs6do%% ""$$$$$&%r/cL|j|tjS)z-the set of mutable revision in the repository) _phasecache getrevsetr mutablephasesrbs r# _mutablerevsrs   % %dF,@ A AAr/obsoletec|jjt|}|jjjt fd|DS)zthe set of obsolete revisionsc3DK|]}||VdSr8r3)r:rgetnodeisobss r#r<z&_computeobsoleteset..s:??1UU771::->->?Q??????r/) changelognoderrr __contains__rv)r notpublicrrs @@r#_computeobsoletesetrsPn!GT""I M $ 1E ????? ??? ? ??r/orphanc|jj}t|}t|d}||z }t }t |D]/}||D]!}||vs||vr||n"0t|S)z7the set of non obsolete revisions with obsolete parentsr)r parentrevsrrwrrNrrv)rpfuncmutableobsoleteothersunstablerr;s r#_computeorphansetrs N %E4  Gt[))H x FuuH F^^q  AH}}X  Q!. X  r/ suspendedc|jt|dtfdt|dDS)z9the set of obsolete parents with non obsolete descendantsrc3$K|] }|v|V dSr8r3)r:r suspendeds r#r<z'_computesuspendedset..s'MM1a9nnQnnnnMMr/r)r ancestorsrwrv)rrs @r#_computesuspendedsetrsQ((y)A)ABBI MMMMk : :MMM M MMr/sextinctcDt|dt|dz S)z.s4441!4Q444r/r)rrrrrrrrFrr successorssetsrCrrv) r divergentrnewermaprrrr toprocessseenrnewers r#_computecontentdivergentsetrsQI}HH ^ Fyy788BBvc{{$((r22II uu B==??1%Dt|| HHTNNN8##&tTBBBB44444E5zzA~~ c"""   X266tR@@ A A A B Y  r/cFtj|}|d|dzD]S}|d|z||Tt |ddS)Nrrr)rsha1rrrrdigest)relationuser folddigestr;s r# makefoldidrst$$J a[8A; &$$%!%%''/***!&&((#### z  "" # #BQB ''r/c n|i}d|vrK|jddp|j}tj||d<|jdd}|r|r||d<|jdd}|d 5} g} |D]!} | d } t| ts| f} t| d krEt| d d kr,d } tj | t| d zd}t| }d |krt| |d}t| d D]g\}}| d }|}t| d kr|| d |||d<d|z|d<d|z|d<|s&tjt%d|zd|}td|D}d}|s+td|D}||vr$tjt%d|z|r't+j||}d|z|t*j<| ||||fi#| D]I}|\}}}}|j| |||||||j|jJ ddddS#1swxYwYdS)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 %dr}sfold-idrsfold-idxs fold-sizes$cannot obsolete public changeset: %ss see 'hg help phases' for details)hintc3>K|]}|VdSr8r)r:rYs r#r<z createmarkers..`s*551affhh555555r/c3>K|]}|VdSr8rr9s r#r<z createmarkers..cs*!C!Cq!&&((!C!C!C!C!C!Cr/s#changeset %s cannot obsolete itself)r^r]rZr)rrusernamer fromlocalrrrrKrCr rrrccopyrrrDrrr^r geteffectflagEFFECTFLAGFIELDrrr filteredrevcacher)r relationsr r]rZ operationluser useoperationsaveeffectflagrj markerargsrelrrfoldidfoldsizefoldidxrrX localmetadatanprecnsucsnpare effectflagargss r# createmarkersrs(h GNN8%6 7 7 M47;K;K;M;M %.u557%%5L+ +!*W''2N   4 5 5@* 0 H0 HCq6LlE22 / , <  1$$SV)9)9H,S3s1v;;->???F<((H8||#C'):;;!*<!;!;$ H$ H 1v (  s88a<<!((Q000%06M*-16M+.27(2BM,/||~~+ABBTI@ 5555555D!!C!CDLLNN!C!C!CCCEE>>+@AADH "P")!6tT!B!BJ=BZ=OM'"9: !!5% "FGGGGI$ HL * *D15 .E5% M &7 !     ! ' ' ) ) ) ) *i@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*s(I4L**L.1L.)NN)rNNN)[rDrLrri18nrr rrrrrrr r r r rutilsrr importmodrpackrfrr?calcsizerrIr&r'r(r)r$r.r1rrarXr@rBr>rAr_rlrdrErFrrrrrrrrrrrrrrnogcrrrrrrrrrOrTrVr`rcrkrnrrrwrzrrrrrrrrrr3r/r#rse<<|  & 9 % %  - O " $#'    <.$$$   ! ,   Ii  (## 5:5:5:p+++* G G G   X   9\**Y~.. Ii  9\**<M<M<M~...b###/#67/#67  ((( A A A  A%!!!!&+K    88 8 :: : 88 8    GGGGGGGGT&   " ,111         * * *& % % %BBB  +@@@ )" ,NNN  *DDD   2     4(((BFh*h*h*h*h*h*r/