^cddlZddlmZddlmZddlmZmZmZm Z m Z m Z e j Z e j Z dZdZd(d Zd(d Zd Z d)d Zd ZdZdZd*dZdZGddZdZd(dZdZd(dZdZejddGddZ ejddGddZ!dZ"d Z#d!Z$d*d"Z%d+d$Z&d%Z'd*d&Z(d'Z)dS),N)attrnullrev)errormdiffpatchpycompatscmutilsmartsetlc#nK|d}|t}|dkrdS|dkrtjd|rd}nd}||t |}g}t |d}|t j|||zdfd} |rt j|\} } || z} | |kr,t |d}|t j|||zdf| | k} | r | |kr| } | V| dz} | r9| |kr3|| D]'}|tkrt j|||z| f(|dSdS)a(Walk DAG using 'pfunc' from the given 'revs' nodes 'pfunc(rev)' should return the parent/child revisions of the given 'rev' if 'reverse' is True/False respectively. Scan ends at the stopdepth (exlusive) if specified. Revisions found earlier than the startdepth are omitted. Nrsnegative stopdepthr) maxlogdepthrProgrammingErrorsortiternextheapqheappushheappopr)pfuncrevs startdepth stopdepthreverseheapsignirevs pendingheapinputrevlastrevcurrevcurdepthfoundnewpdepthprevs 1/usr/lib/python3/dist-packages/mercurial/dagop.py _walkrevtreer's  A~~1}}$%:;;; IIg JJEKE4  H {X%8!$<===G K =55F" X  E4((H#{X-@!,DEEEW$  J..GLLLA  K**f  K K7??N;D&0IJJJ# KKKKKFc# Kig  fd}|rd}nd}|D] }||ratj  }|}||fV|D],}|d|D] }||-a rJdS)zLike filectx.ancestors(), but can walk from multiple files/revisions, and includes the given fctxs themselves Yields (rev, {fctx, ...}) pairs in descending order. ctj|}|vr't|<tj| ||dSN)r intrevsetrradd)fctxrevvisit visitheaps r&addvisitz"filectxancestors..addvisit[sZnT"" e  E#J N9sd + + + c tr(rN)rrpopparents) fctxs followfirstr3cutcr!curfctxsparentr1r2s @@r&filectxancestorsr<Rs EI  !=++,99V$$h ! !A))++dsd+ ! !     ! !r(cXdt||D}t|dS)zLike filectx.ancestors(), but can walk from multiple files/revisions, and includes the given fctxs themselves Returns a smartset. c3 K|] \}}|V dSr+).0r0_css r& z#filerevancestors..ys& D D833 D D D D D Dr(Fiterasc)r< generatorset)r6r7gens r&filerevancestorsrGss6 E D/{CC D D DC U + + ++r(c |rdndjfd  }n fd}|fd}t||||dS)Nrc |dS#tj$r/d|dDcYSwxYw)Nc3>K|]}|VdSr+r0r@pctxs r&rBz7_genrevancestors..plainpfunc..s*EE4DHHJJEEEEEEr() parentrevsrWdirUnsupportedr5)r0clr8repos r& plainpfuncz$_genrevancestors..plainpfuncsy F==%%dsd+ +$ F F FEE49+<+<+>+>tt+DEEE E E E Fs ;AAc2fd|DS)Nc*g|]}| |Sr?r?)r@rcutfuncs r& z6_genrevancestors....s&JJJ1wwqzzJQJJJr(r?)r0rVrRs r&z"_genrevancestors..s$JJJJ 3JJJr(c| Sr+r?)r0rVs r&rXz"_genrevancestors..s773<<'7r(Tr) changelogfilterr') rQrr7rrrVrrPr8rRs ` ` @@@r&_genrevancestorsr]}s BFFFFFFF JJJJJ{{777788 tZD I I IIr(cLt||||||}t|dS)aLike revlog.ancestors(), but supports additional options, includes the given revs themselves, and returns a smartset Scan ends at the stopdepth (exlusive) if specified. Revisions found earlier than the startdepth are omitted. If cutfunc is provided, it will be used to cut the traversal of the DAG. When cutfunc(X) returns True, the DAG traversal stops - revision X and X's ancestors in the traversal path will be skipped. This could be an optimization sometimes. Note: if Y is an ancestor of X, cutfunc(X) returning True does not necessarily mean Y will also be cut. Usually cutfunc(Y) also wants to return True in this case. For example, D # revancestors(repo, D, cutfunc=lambda rev: rev == B) |\ # will include "A", because the path D -> C -> A was not cut. B C # If "B" gets cut, "A" might want to be cut too. |/ A FrC)r]rE)rQrr7rrrVrFs r& revancestorsr_s50  dKY  C U + + ++r(c#vK|rd}nd}|j}|}|tkr|V|D]}|VdSt|}||D]U}||vr|V ||d|D],}|tkr||vr|||Vn-VdS)Nr)r[minrr-rrNr.) rQrr7r8rPfirstiseenxs r&_genrevdescendantsrfs B HHJJE    AGGGG  4yy  ADyy]]1%%dsd+  < child revs', offset from startrevcg|]}gSr?r?)r@_revs r&rWz(_builddescendantsmap..s777dr777r(r)r[rangelenrrNappendr)rQstartrevr7rPdescmapr!p1revp2revs r&_builddescendantsmaprqs B77eHc"gg66777G''(Q,''55}}V,, u H   EH$ % , ,V 4 4 4 5u//EX4E4E EH$ % , ,V 4 4 4 Nr(c|t||fd}t||||dS)Nc|z Sr+r?)r0rnrms r&rz(_genrevdescendantsofdepth..pfuncssX~&&r(FrZ)rarqr')rQrr7rrrrnrms @@r&_genrevdescendantsofdepthrts[xxzzH"4;??G'''''' tZE J J JJr(c|| |tkrt|||}nt|||||}t|dS)zLike revlog.descendants() but supports additional options, includes the given revs themselves, and returns a smartset Scan ends at the stopdepth (exlusive) if specified. Revisions found earlier than the startdepth are omitted. NTrC)rrfrtrE)rQrr7rrrFs r&revdescendantsrvs[y0I4L4L t[99' $ Z   T * * **r(c#Kt|}|tkr|D]}|VdSt|}||dzD]:}||D],}|tkr||vr|||Vn-;dS)akGenerate revision number descendants in revision order. Yields revision numbers starting with a child of some rev in ``revs``. Results are ordered by revision number and are therefore topological. Each revision is not considered a descendant of itself. ``revsfn`` is a callable that with no argument iterates over all revision numbers and with a ``start`` argument iterates over revision numbers beginning with that value. ``parentrevsfn`` is a callable that receives a revision number and returns an iterable of parent revision numbers, whose values may include nullrev. Nrstart)rarr-r.)rrevsfn parentrevsfnrbr0rdr%s r&descendantrevsr|s IIE 688  CIIII t99DvEAI&&& L%%  Dw44<<   r(c8eZdZdZd dZdZdZdZdZdZ dS) subsetparentswalkeraScan adjacent ancestors in the graph given by the subset This computes parent-child relations in the sub graph filtered by a revset. Primary use case is to draw a revisions graph. In the following example, we consider that the node 'f' has edges to all ancestor nodes, but redundant paths are eliminated. The edge 'f'->'b' is eliminated because there is a path 'f'->'c'->'b' for example. - d - e - / \ a - b - c - f If the node 'c' is filtered out, the edge 'f'->'b' is activated. - d - e - / \ a - b -(c)- f Likewise, if 'd' and 'e' are filtered out, this edge is fully eliminated since there is a path 'f'->'c'->'b'->'a' for 'f'->'a'. (d) (e) a - b - c - f Implementation-wise, 'f' is passed down to 'a' as unresolved through the 'f'->'e'->'d'->'a' path, whereas we do also remember that 'f' has already been resolved while walking down the 'f'->'c'->'b'->'a' path. When processing the node 'a', the unresolved 'f'->'a' path is eliminated as the 'f' end is marked as resolved. Ancestors are searched from the tipmost revision in the subset so the results can be cached. You should specify startrev to narrow the search space to ':startrev'. Nc||d||z}|j}|r |}na|s>|s*t j|}|dt|}||_|j |_ ||_ g|_ i|_ i|_i|_t |_||_t |_|dS)Ns%d:nullTrZ)rfastdesc isdescendingistopor basesetrr_repor[ _changelog_subset_tovisit _pendingcnt _pointers_parentsr _inputhead _inputtail _bottomrev _advanceinput)selfrQsubsetrmrdesciters r&__init__zsubsetparentswalker.__init__8s  YYz844v=F?  $xzzHH&&(( * *!)&11 D )))F||H .   !"! r(cPtj||S)zVLook up parents of the given revision in the subset, and returns as a smartset)r rr5rr0s r& parentssetzsubsetparentswalker.parentssetUs! S 1 1222r(c||dt|j|gDS)zLook up parents of the given revision in the subset The returned revisions are sorted by parent index (p1/p2). cg|]\}}|Sr?r?)r@_crUs r&rWz/subsetparentswalker.parents..`sBBBeb!BBBr() _scanparentssortedrgetrs r&r5zsubsetparentswalker.parentsZsF #BBvdm&7&7R&@&@AABBBBr(c |j|}|dtkr |ddS|S#tj$r9t d|jdDcYSwxYw)Nrc3>K|]}|VdSr+rKrLs r&rBz2subsetparentswalker._parentrevs..is*KKKKKKKKr()rrNrrrOtuplerr5)rr0rs r& _parentrevszsubsetparentswalker._parentrevsbs L?--c22DBx7""CRCy K$ L L LKK 40@0H0H0J0JKKKKK K K K Ls499ABBc|jtkrdS t|j|_dS#t$r|j|_tdz |_YdSwxYw)zBAdvance the input iterator and set the next revision to _inputheadNr)rrrr StopIterationr)rs r&rz!subsetparentswalker._advanceinputksc ?W $ $ F *"4?33DOOO * * *"oDO%kDOOOO *s/%AAc( |j|j}|j|j}|j}|s|jt krY|dkrdS|s/tj ||j | |j|d krAtj ||j | |j|d kAtj | }||j krdS|vr||vr|v} |d|r ||vsJg||<||itf\}}|r|D]f\} } | xxdzcc<| dksJ| |vr(|| | |f| dkr|| g|fd|D}||} t+fd| D} | r|s|r[t-| dkr||fg} ny||f||fg} |D]J} | xxdz cc<| dd| xxdz cc<| dd| xxdz cc<Kt1| D]\}}||ksJtj || ||vr||\}}| |\}}|D]F\} } | |vr8| xxdzcc<| dksJt3| || || <A| || <G||| |||<t-| dkrdgnddg}|rK| rIt1| D]*\}}||} ||| |f+|dksJn|rt1| D]j\}}||\}}||vsJ||} |vr3||| |f||U|xxdz cc<| ||<kd|cxkrd ksnJ|F|jt kWdSdS) zNScan ancestors until the parents of the specified stoprev are resolvedrNrc,h|]}|dk|S)rr?)r@rU pendingcnts r& z3subsetparentswalker._scanparents..s'EEE!:a=13D3DA3D3D3Dr(c3 K|]}|vV dSr+r?)r@prs r&rBz3subsetparentswalker._scanparents..s'#D#DAAK#D#D#D#D#D#Dr(12r()rrrrrrrrrrrrr setdefaultr4r-itemsrlr.clearrallrkcopy enumerateraupdate)rstoprevtovisitpointersr5r0 curactive unresolvedresolvedrUr9rNbothparentsactiveparentpointersrcrknownunresolved knownresolved chaincodesrrs @@r&rz subsetparentswalker._scanparentsus,-% >-o 0G33~~g&&!++ %w(8999""$$$/gaj[00w(8999""$$$/gaj[00=)))CT_$$j  S%8%8v I  ! !#q ) ) ) "'))))! #+<<b#%%[#A#A J F&,,.. ( (DAqqMMMQ&MMM%a=A----H}} AJ%%q#h///"!}q(( Q  """FEEExEEE))#..J ##D#D#D#D#D#D#D D D  %% 8 % 8h% 8z??a'''18&<%=NN$X.#**HMMOO<&N(88"1 * &q)!,Q///47///&q)!,Q///47////%j1188DAqs7777N7QB///H}}:B!6/=a/@, H$.$4$4$6$677DAq O33 *1  2 '1!}q'8'8'8'858OA ( (% L LD 4==DIIKKK Kr(ctj|||}tj||\}}t d|D}||fS)zReturn `(diffinrange, linerange1)` where `diffinrange` is True if diff from fctx2 to fctx1 has changes in linerange2 and `linerange1` is the new line range for fctx1. c3(K|] \}}|dkVdS)!Nr?)r@_stypes r&rBz _changesrange..;s*CC5etmCCCCCCr()r allblocksdata blocksinrangeany)fctx1fctx2 linerange2diffoptsblocksfilteredblocks linerange1 diffinranges r& _changesranger4se _UZZ\\5::<< B BF!&!4VZ!H!HNJCCNCCCCCK  ""r(c#tKtj|jj}|}||f|||ffi}|r|t|\}}| }|r |dd}|s||fVPd} |D]t} t| |||\} } | p| } | d| dkr.| | _ | | f|| | f<u| r||fV|dSdS)zgYield ancestors of `fctx` with respect to the block of lines within `fromline`-`toline` range. NrFr) r rrui introfilectxlinkrevfilenoder4maxr5rr0_descendantrev) r/fromlinetoliner7rr1r9rplinrangerinrangeprs r&blockancestorsr?sq~djm,,H     Dllnndmmoo .&7I0J KE   #e**-- : YY[[  BQBB Z-     = =A#0Az8#L#L Hj)G!} 1 -- !uuwwA /0*}E!))++qzz||+ , ,  Z-   1      r(c#K tt|||\}}||kr||fVn#t$rYnwxYwtj|jj}|}||||ffi}| |gD]}| |}d} | |D]} || \} } n#t$rYwxYwt|| | |\} }| p| } ||vrO||d|kr=t|||d\}}t|t!|f}||f||<| r||fVdS)ziYield descendants of `fctx` with respect to the block of lines within `fromline`-`toline` range. FrN)rrrr rrrfilelogfilerev descendantsfilectxrNKeyErrorrziprar)r/rrr9rrflrdrcrrerrrlbsubss r&blockdescendantsras  ^D(FCCDD : 99Z-         ~djm,,H B LLNNTHf#56 7D ^^T\\^^, - -   LLOOq!! $ $A  $Q ::    $1Az8#L#L Hj)G DyyT!WQZ:55z471:66S XXs3xx/ mDGG  Z-   )  s!2 ??' C33 D?DT)slotsfrozenceZdZejZejZejdZejdZdS) annotatelineF)defaultN) rrrribr/linenoskiptextr?r(r&rrsP 4799D TWYYF 475 ! ! !D 474 DDDr(rceZdZejZejZejZejZdS)_annotatedfileN) rrrrrr6linenosskipsrr?r(r&rrsD DGIIEdgiiG DGIIE 4799DDDr(rc|dr|dS|dtt|zS)N )endswithcountintbool)rs r& _countlinesr sK }}U!zz%   ::e  s4:: ..r(ct|}tjd|dz}t|g|z|dg|z|S)NrF)r r rangelistr)rr/nrs r&_decoratelinesrsEDA AE**G 4&1*gw{D A AAr(cfd|D}|r d|D}|D]c\}}|D][\\}} } } } | dkrK|j|| j| | <|j|| j| | <|j|| j| | <\d|rk|d|D} t |D]\}\}}|D]\\}} } } }| |z | | z krrt | | D]`}j||krMt ||| z z| dz }|j|j|<|j|j|<dj|<a| |d|| | | f| D]\}}|D]x\}} } } t | | D]`}j||krMt ||| z z| dz }|j|j|<|j|j|<dj|<ayS)ap Given parent and child fctxes and annotate data for parents, for all lines in either parent that match the child, annotate the child with the parent's data. Additionally, if `skipchild` is True, replace all other lines with parent annotate data as well such that child is never blamed for any lines. See test-annotate.py for unit tests. cVg|]%}|tj|jjf&S))opts)rrr)r@r;childrs r&rWz!_annotatepair..sC  ejxHHHIr(c6g|]\}}|t|fSr?)r)r@rrs r&rWz!_annotatepair..s'@@@!VAtF||$@@@r(=cg|] \}}|gf Sr?r?)r@r;_blockss r&rWz!_annotatepair..s AAAofgfb\AAAr(rT)r6rrrrrjrarl)r5 childfctxr skipchildrpblocksr;ra1a2b1b2t remainingidx_tbkaks ` ` r& _annotatepairr&sG A@@@@@"99#) 9 9  RRaDyy%+\"R%%8 BrE"'-~be'< be$%+\"R%%8 BrE"  9$/ BAAAA %.w%7%7 ? ? !C!&&(. ? ?$ RR"7b2g%%#Bmm33 ;r?i77!$R27^R!V!EKO06r0BEM"-.2EKO 3cN1%,,b"b"-=>>>> ?( / /NFF"( / /BBB--//B{2)33 rBwa88*0,r*: B,2N2,> b)*. B / / Lr(c R|g}i}|di}|re|}||vr||}|||<|D]7} || ddz|| <| |vr|| 8|e|g|dd<i|r|d}|vr|#d} ||}|D]} | vrd} || | r|t||} d} | |j|v} t fd|D|| | |} |D]%} || dkr| =|| =|| xxdzcc<&| |<||=||} dt| j| j | j tj | j DS) zrCore algorithm for filectx.annotate() `parents(fctx)` is a function returning a list of parent filectxs. rrNrTFc g|] }| Sr?r?)r@rhists r&rWzannotate..s%%%Qa%%%r(c g|] }t| Sr?)r)r@rUs r&rWzannotate..*s-     a   r()r4rrlrr _changeidr&rr6rrr splitnewlinesr)baser5skiprevsrr1pcacheneededfrrreadycurrrar)s @r&annotater5s7FE FAYF   IIKK ;;  WQZZq   A 1a((1,F1I Q   vE!!!H D  "I 99 IIKKK  AY  A}} Q   IIKKK!!&&((A..DI#K83  %%%%"%%%q$ 8D # #!9>>Qq 1IIINIIIIDGq ; > T A  QWai%2Eaf2M2MNN   r(r?c# K|dt|}g|fg}g}t}tj|tj}tj}|D]} | |vr"||| || d| kr|| |fdt|D} | ri| d} || \} } | D]0}||}| |d| |dz} 1t| D]}||=n't|} | ghf|| }| kr|d |dd|D}|d||D](}||vr"||||| )|st|dkr d} |d}n |d|zsd}|-||dz}|dD]}|V| r|| =n g|ddd<| kА|D]}|dD]}|VdS)a"Yield revisions from heads to roots one (topo) branch at a time. This function aims to be used by a graph generator that wishes to minimize the number of parallel branches and their interleaving. Example iteration order (numbers show the "true" order in a changelog): o 4 | o 1 | | o 3 | | | o 2 |/ o 0 Note that the ancestors of merges are understood by the current algorithm to be on the same branch. This means no reordering will occur behind a merge. TrZNc.g|]\}}|dv|S)rr?)r@rcgr0s r&rWztoposort..s&GGGda3!A$;;;;;r(rrc(g|]}|tk |Sr?r)r@rs r&rWztoposort..sBBBQa'kkqkkkr()rr-rheapifyrrr.removerr4extendreversedrkrlr)r parentsfunc firstbranch unblockedgroupsr pendingsetrr currentrevmatching targetidxtrevstparentsrcgrr5rrUr8r0s @r&toposortrI0sRf IIdIK  I29o FKJ M+mG~Hc"c" Z ' ' H[:+ . . . NN: & & &Z7;'''C   c " " "HGGGi&7&7GGGH" +(%LLOO "("3x!&&ABLLA'''1%HH"(++""Aq " KK  rC5k*** "Bj  1 S!!! qELL   BB++c"2"2BBBG qELL ! ! ! . .J&&NN1%%%H[1"--- v;;?? !IBUY& ~RU" AAGGGG"y))!BqE!!!HwZ|1  AGGGG r(ct|}th}|j}|D]}||||||S)aResolve the set of heads from a set of revisions. Receives an iterable of revision numbers and a callbable that receives a revision number and returns an iterable of parent revision numbers, possibly including nullrev. Returns a set of revision numbers that are DAG heads within the passed subset. ``nullrev`` is never included in the returned set, even if it is provided in the input set. )r-rrdifference_update)r parentsfnheadrevsr5upr0s r&rMrMs`4yyHiG B 99S>> w''' Or(c$|t}t|pg}|h}|h}||dzD]_}||D]Q}||vr.||vr||||||vr||vr||R`|S)aReturns the set of all revs that have no children with control. ``revsfn`` is a callable that with no arguments returns an iterator over all revision numbers in topological order. With a ``start`` argument, it returns revision numbers starting at that number. ``parentrevsfn`` is a callable receiving a revision number and returns an iterable of parent revision numbers, where values can include nullrev. ``startrev`` is a revision number at which to start the search. ``stoprevs`` is an iterable of revision numbers that, when encountered, will stop DAG traversal beyond them. Parents of revisions in this collection will be heads. Nrrx)rr-r.r;)rzr{rmstoprevsrrr0r%s r&headrevssubsetrQs 8>r""H I JEvHqL)))## L%% # #Dy  h&&MM#&&& #u}}X!5!5 T""" # Lr(cttt||d}t}g}|r|}|dkr5| dz }||vr*||||nP|| dz ||D]+}|tks||vs||vr||,|t|t|ksJ|S)aLinearize and topologically sort a list of revisions. The linearization process tries to create long runs of revs where a child rev comes immediately after its first parent. This is done by visiting the heads of the revs in inverse topological order, and for each visited rev, visiting its second parent, then its first parent, then adding the rev itself to the output list. Returns a list of revision numbers. TrZrr) rrrMr-r4rlr.rrk)rrLr1finishedresultr0r%s r& linearizerU3s# y114@@@ A AEuuH F #iikk 77$(C("" c""" S!!! LL# " " "! # # #7??d$&6&6$(:J:J T""""! #$ v;;#d)) # # # # Mr()F)FNNN)NN)r?)*r thirdpartyrnoderrrr r r r rrErr'r<rGr]r_rfrqrtrvr|r~rrrrrsrrr rr&r5rIrMrQrUr?r(r&rZs   $  2K2K2KjB,,,,JJJ,MQ,,,,<6   KKK + + + + @n0n0n0n0n0n0n0n0b!!!H    ###    D% % % Pd4   !!!!!!!! !d4   ! /// BBB CCCL????DDDDDN.""""J#####r(