o ]LbF@sxddlmZddlZddlmZddlmZddlmZm Z m Z m Z m Z m Z e jZe jZdZdd Zd@d d Zd@d dZddZ dAddZddZddZddZdBddZddZGdddeZdd Zd@d!d"Zd#d$Zd@d%d&Z d'd(Z!ej"d)d)d*Gd+d,d,eZ#ej"d)d)d*Gd-d.d.eZ$d/d0Z%d1d2Z&d3d4Z'dBd5d6Z(dCd8d9Z)d:d;Z*dBdd?Z,dS)D)absolute_importN)attrnullrev)errormdiffpatchpycompatscmutilsmartsetlccs6|durd}|dur t}|dkrdS|dkrtd|r!d}nd}||t|}g}t|d}|durAt|||dfd} |rt|\} } || } | |krgt|d}|durgt|||df| | k} | rv| |krv| } | V| d} | r| |kr|| D]}|t krt|||| fq|sEdSdS)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 pendingheapinputrevlastrevcurrevcurdepthfoundnewpdepthprevr%1/usr/lib/python3/dist-packages/mercurial/dagop.py _walkrevtreesJ         r'Fc#sigfdd}|rd}nd}|D]}||qrDt }|}||fV|D]}|d|D]}||q:q0srHJdS)zLike filectx.ancestors(), but can walk from multiple files/revisions, and includes the given fctxs themselves Yields (rev, {fctx, ...}) pairs in descending order. cs<t|}|vrt|<t| ||dSN)r intrevsetrradd)fctxrevvisit visitheapr%r&addvisit\s  z"filectxancestors..addvisitrN)rrpopparents)fctxs followfirstr1cutcr curfctxsparentr%r.r&filectxancestorsSs&      r:cCs ddt||D}t|ddS)zLike filectx.ancestors(), but can walk from multiple files/revisions, and includes the given fctxs themselves Returns a smartset. css|]\}}|VqdSr(r%).0r-_csr%r%r& zz#filerevancestors..Fiterasc)r: generatorset)r4r5genr%r%r&filerevancestorsts rCcsd|rdndjfdddur}nfdd}|fdd}t||||ddS) NrcsHz |dWStjy#dd|dDYSw)Ncs|]}|VqdSr(r-r;pctxr%r%r&r=r>z7_genrevancestors..plainpfunc..) parentrevsrWdirUnsupportedr3rE)clr6repor%r& plainpfuncs "z$_genrevancestors..plainpfunccsfdd|DS)Ncsg|]}|s|qSr%r%r;rcutfuncr%r& z6_genrevancestors....r%rE)rPrLr%r&sz"_genrevancestors..cs | Sr(r%rErOr%r&rSs Tr) changelogfilterr')rKrr5rrrPrr%)rJr6rPrLrKr&_genrevancestors~srWcCst||||||}t|ddS)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 Fr?)rWrA)rKrr5rrrPrBr%r%r& revancestorss  rXc cs|rd}nd}|j}|}|tkr |V|D]}|VqdSt|}||D](}||vr3|Vq)||d|D]}|tkrP||vrP|||Vnq child revs', offset from startrevcSsg|]}gqSr%r%)r;_revr%r%r&rQsz(_builddescendantsmap..r)rUr xrangelenrrHappendr)rKstartrevr5rJdescmapr p1revp2revr%r%r&_builddescendantsmapsrgcs4|t||fdd}t||||ddS)Ncs |Sr(r%rErdrcr%r&rs z(_genrevdescendantsofdepth..pfuncFrT)rYrgr')rKrr5rrrr%rhr&_genrevdescendantsofdepths ricCsB|dur|dus |tkrt|||}nt|||||}t|ddS)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. NTr?)rr^rirA)rKrr5rrrBr%r%r&revdescendantss   rjccszt|}|tkr|D]}|Vq dSt|}||ddD]}||D]}|tkr9||vr9|||Vnq%qdS)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)rYrr*r+)rrevsfn parentrevsfnrZr-r\r$r%r%r&descendantrevss   roc@sBeZdZdZdddZddZddZd d Zd d Zd dZ 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'. NcCs|dur |d||@}|j}|r|}n|s(|s(t|}|jddt|}||_|j |_ ||_ g|_ i|_ i|_i|_t|_||_t|_|dS)Ns%d:nullTrT)rfastdesc isdescendingistopor basesetrr_reporU _changelog_subset_tovisit _pendingcnt _pointers_parentsr _inputhead _inputtail _bottomrev _advanceinput)selfrKsubsetrcrqdesciterr%r%r&__init__9s(   zsubsetparentswalker.__init__cCst||S)zVLook up parents of the given revision in the subset, and returns as a smartset)r rtr3rr-r%r%r& parentssetVszsubsetparentswalker.parentssetcCs&||ddt|j|gDS)zLook up parents of the given revision in the subset The returned revisions are sorted by parent index (p1/p2). cSsg|]\}}|qSr%r%)r;_crNr%r%r&rQaz/subsetparentswalker.parents..) _scanparentssortedr{getrr%r%r&r3[s zsubsetparentswalker.parentscCs^z|j|}|dtkr|ddWS|WStjy.tdd|jdDYSw)Nr csrDr(rErFr%r%r&r=jr>z2subsetparentswalker._parentrevs..)rvrHrrrItuplerur3)rr-rr%r%r& _parentrevscs   zsubsetparentswalker._parentrevscCsH|jtkrdSz t|j|_WdSty#|j|_td|_YdSw)zBAdvance the input iterator and set the next revision to _inputheadNr)r|rrr} StopIterationr~)rr%r%r&rls  z!subsetparentswalker._advanceinputcs|j|j}|j|j}|j}|s|jtkr |dkr dS|s.t ||j | |j|d krJt ||j | |j|d ks6t | }||j krWdS|vr`||vr`q|v} |d|rv||vsrJg||<||itf\}}|r|D]-\} } | d8<| dksJ| |vrq|| | |f| dkr|| q|fdd|D}||} tfdd| D} | r|s|r{t| dkr||fg} n1||f||fg} |D]"} | d7<| dd| d7<| dd| d 7<qt| D]`\}}||ks%Jt || ||vrs||\}}| |\}}|D]*\} } | |vrf| d8<| dks[Jt| || || <qA| || <qA||q| |||<qt| dkrd gndd g}|r| rt| D]\}}||} ||| |fq|dksJnQ|rt| D]7\}}||\}}||vsJ||} |vr||| |f||q|d7<| ||<qd|krd ksJJ|s|jtksdSdS) zNScan ancestors until the parents of the specified stoprev are resolvedrNrcsh|] }|dkr|qS)rr%rM) pendingcntr%r& z3subsetparentswalker._scanparents..c3s|]}|vVqdSr(r%r;p)rr%r&r=r>z3subsetparentswalker._scanparents..12)rwrxryrzr{r|rrrrrrr~ setdefaultr2r*itemsrbr+clearrallracopy enumeraterYupdate)rstoprevtovisitpointersr3r- curactive unresolvedresolvedrNr7rHbothparentsactiveparentpointersr[rknownunresolved knownresolved chaincodesr%)rrr&rvs                  $z subsetparentswalker._scanparentsr() __name__ __module__ __qualname____doc__rrr3rrrr%r%r%r&rps % rpcCs|sgSt|}t|}t}i}|j}|j} |j} |rE| } | |vr*|| |s*q|| } | || <| D]} | |krB| |vrB| | q4|s|sJtS|sN|St|D]} || D] } | |vrb|| qXqR|SzSee revlog.reachableroots)r*listr+rbr2rtr)rminrootrootsheads includepathr/ reachabler\reacheddovisit nextvisitr-r3r9r%r%r&_reachablerootspuresB   rcCsH|stS|}t|}t|}|j||||}t|}||Sr)rtrYrrUreachablerootsr)rKrrrrrr%r%r&r(srcCs@t|||}t||\}}tdd|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. css|] \}}|dkVqdS)!Nr%)r;_styper%r%r&r=<sz _changesrange..)r allblocksdata blocksinrangeany)fctx1fctx2 linerange2diffoptsblocksfilteredblocks linerange1 diffinranger%r%r& _changesrange5src cst|jj}|}||f|||ffi}|rr|t|\}}| }|r1|dd}|s9||fVqd} |D])} t | |||\} } | pK| } | d| dkrUq=| | _ | | f|| | f<q=| rn||fV|sdSdS)zgYield ancestors of `fctx` with respect to the block of lines within `fromline`-`toline` range. NrFr) r rruui introfilectxlinkrevfilenoder2maxr3rr-_descendantrev) r,fromlinetoliner5rr/r7rplinrangerinrangeprr%r%r&blockancestors@s.     rc cs8z tt|||\}}Wn tyYn w||kr ||fVt|jj}|}||||ffi}| |gD]\}| |}d} | |D]F} z|| \} } Wn t y^YqKwt || | |\} }| pk| } ||vr||d|krt|||d\}}t|t|f}||f||<qK| r||fVq=dS)ziYield descendants of `fctx` with respect to the block of lines within `fromline`-`toline` range. FrN)rrrr rrurfilelogfilerev descendantsfilectxrHKeyErrorrziprYr)r,rrr7rrflr\r[rr]rrrlbsubsr%r%r&blockdescendantsbs<     rT)slotsfrozenc@s4eZdZeZeZejddZejddZdS) annotatelineF)defaultN) rrrribr,linenoskiptextr%r%r%r&rs  rc@s,eZdZeZeZeZeZdS)_annotatedfileN) rrrrrr4linenosskipsrr%r%r%r&rs  rcCs*|dr |dS|dtt|S)N )endswithcountintbool)rr%r%r& _countliness  rcCs2t|}td|d}t|g||dg||S)NrF)rr rangelistr)rr,nrr%r%r&_decoratelinessrcsfdd|D}|rdd|D}|D]7\}}|D]0\\}} } } } | dkrK|j|| j| | <|j|| j| | <|j|| j| | <qq|r|dd|D} t|D]W\}\}}|D]N\\}} } } }| || | krt| | D])}j||krt||| | d}|j|j|<|j|j|<dj|<q|qf| |d|| | | fqfq^| D]=\}}|D]6\}} } } t| | D])}j||krt||| | d}|j|j|<|j|j|<dj|<qqqS)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. cs$g|]}|tj|jjdfqS))opts)rrr)r;r9childrr%r&rQsz!_annotatepair..cSsg|] \}}|t|fqSr%)r)r;rrr%r%r&rQr=cSsg|]\}}|gfqSr%r%)r;r9_blocksr%r%r&rQrRrT) r4rrrrr r`rYrb)r3 childfctxr skipchildrpblocksr9ra1a2b1b2t remainingidx_tbkakr%rr& _annotatepairsR      rcs|g}i}|di}|r6|}||vrq ||}|||<|D]} || dd|| <| |vr3|| q|s |g|dd<i|r|d}|vrN|q?d} ||}|D] } | vrcd} || qV| r|t||} d} |dur||j|v} tfdd|D|| | |} |D]} || dkr| =|| =q|| d8<q| |<||=|sA|} d dt| j| j | j t | j DS) zrCore algorithm for filectx.annotate() `parents(fctx)` is a function returning a list of parent filectxs. rrNr TFcsg|]}|qSr%r%rhistr%r&rQrzannotate..cSsg|]}t|qSr%)rrMr%r%r&rQ+s)r2rrbrr _changeidrrr4rrr splitnewlinesr)baser3skiprevsrr/pcacheneededfrrreadycurrrar%rr&annotatesd      rr%c#s&|jddt|}g|fg}g}t}t|tj}tj}|D]} | |vr3||| || d| kr|| |fddt|D} | r|| d} || \} } | D]}||}| |d| |dO} q]t | D]}||=qun t |} | ghf|| }| kr|d |ddd|D}|d||D]}||vr||||| q|st |dkrd} |d}n|d|@sd}|dur||dO}|dD]}|Vq| r|| =ng|ddd<| ks9q"|D]}|dD]}|VqqdS) 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. TrTNcs g|] \}}|dvr|qS)rr%)r;r[grEr%r&rQs ztoposort..rrcSsg|]}|tkr|qSr%rrr%r%r&rQrR)rr*rheapifyrrr+removerr2extendreversedrarbr)r parentsfunc firstbranch unblockedgroupsr pendingsetrr currentrevmatching targetidxtrevstparentsr[grr3rrNrr%rEr&toposort1s| 3               ^  r#cCs8t|}th}|j}|D]}|||q |||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 parentsfnheadrevsr3upr-r%r%r&r&s  r&cCs|durt}t|p g}|h}|h}||ddD](}||D]!}||vr3||vr.||||||vr@||vr@||qq|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. Nrrk)rr*r+r)rmrnrcstoprevsrrr-r$r%r%r&headrevssubsets       r)cCsttt||dd}t}g}|rQ|}|dkr.| d}||vr-||||n!|| d||D]}|tksH||vsH||vrIq:||q:|st|t|ks[J|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. TrTrr) rrr&r*r2rbr+rra)rr%r/finishedresultr-r$r%r%r& linearize4s&      r,)F)FNNN)NN)r%)- __future__rr thirdpartyrnoderrrr r r r rtrArr'r:rCrWrXr^rgrirjroobjectrprrrrrsrrrrrrr#r&r)r,r%r%r%r&sN      5 !    r $ " (   F BH  %