o ]Lb2@szddlmZddlZddlmZddlmZmZmZe dZ ddZ d d Z Gd d d e Zd dZGddde ZdS))absolute_importN)nullrev)dagoppolicypycompatparserscGst|ts t|}t|vrtSt|dkr|Sdt|>d}dgt|d}t|D] \}}d|>||<q-d|d>}t}t|}t|d} | dkr|r| } | d8} || s\qK|| } | |kr||d8}| |kr||| | |O} | |vr|| hS| |kr|| D]$} || } | tkrq| dkr| || <|d7}q| | kr|| | O<qn|| D]} | tkrq|| } | r| |kr|d8}| || <q| dkr|sQ|S)zReturns a set with the heads of all common ancestors of all nodes, heads(::nodes[0] and ::nodes[1] and ...) . pfunc must return a list of parent vertices for a given vertex. rr) isinstancesetrlenmax enumerateadd)pfuncnodesallseenseeninpoisongca interestingnvvsvpspr4/usr/lib/python3/dist-packages/mercurial/ancestor.pycommonancestorsheadss`             rcs4fdd}tg|R}t|dkr|S||S)z Returns the common ancestors of a and b that are furthest from a root (as measured by longest path). pfunc must return a list of parent vertices for a given vertex. csi}t|d}dg|}dg|}g}tt|D]\}}d||<d|>}|||<d||<|||fq|d} | dkrt|dkr| } | d8} || } | dkrSq:|| } | D]o} | tkrbq[|| }|| }|| kr| d|| <|| kr|| d7<| || <|r||d8<||dkr||=q[| |dkr|| B}||krq[||| <||d||d7<||d8<||dkr||=q[|| d8<|| dkr|| =| dkrt|dksDt|dkrgSd|D]}|Oqfdd|DS)Nrrcsh|] \}}|@r|qSrr).0rrkrr sz-ancestors..deepest..)r r sortedappendr r setdefault)rrcountdepthrmappingrrbrrdvrrdprnsprr!rdeepestWsn           # zancestors..deepestr)rr )r orignodesr/rrr.r ancestorsOs 8 r1c@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)incrementalmissingancestorsapersistent state used to calculate missing ancestors incrementally Although similar in spirit to lazyancestors below, this is a separate class because trying to support contains and missingancestors operations with the same internal data structures adds needless complexity.cCs&t||_|js|jt||_dSN)r basesrrr)selfrr4rrr__init__s   z$incrementalmissingancestors.__init__cCs|jo|jthkS)z0whether the common set has any non-trivial bases)r4rr5rrrhasbasessz$incrementalmissingancestors.hasbasescCs|j|dS)z)grow the ancestor set by adding new basesN)r4update)r5newbasesrrraddbasessz$incrementalmissingancestors.addbasescCst|j|jSr3)rheadrevsr4rr7rrr basesheadssz&incrementalmissingancestors.basesheadscs|j}|j}|||t|sdSt|tfdd|D}t||kr+dSt t |ddD]}||vr=q6||| ||t||krRdSq6dS)z:remove all ancestors of bases from the set revs (in place)Nc3s|] }|krdVqdS)rNrr rstartrr szBincrementalmissingancestors.removeancestorsfrom..r) r4rdifference_updatediscardrr sumr rxrangeminr9)r5revsr4r keepcountcurrrr@rremoveancestorsfroms&     z/incrementalmissingancestors.removeancestorsfromc Cs:t|}|j}|j}||}|||sgStt|t|}g}t|tdD]l}|s0ng||vrP| |||D]} | | | | | | q=q*||vrc| || ||} |} n ||vrl|} |} nq*||D]$} | tkrxqq| | vs| |vr| | | | | | qq| | qqq*| |S)areturn all the ancestors of revs that are not ancestors of self.bases This may include elements from revs. Equivalent to the revset (::revs - ::self.bases). Revs are returned in revision number order, which is a topological order.rC)r r4r intersectionrDr rrGrremoverErr%reverse) r5rI revsvisit basesvisitr bothvisitrAmissingrKr thisvisit othervisitrrrmissingancestorssN               z,incrementalmissingancestors.missingancestorsN) __name__ __module__ __qualname____doc__r6r8r;r=rLrVrrrrr2s r2ccs6th}tj}tj}tj}|j}|r$dd|D} ||t| n.g} t| |D]$} || \} } | |vrC|| | || | |vrQ|| | || q-| r| d } | |kr_dS| V|| \} } | |vr| | dkrx| | d<n|| | || n|| | |vr|| | || | sTdSdS)NcSsg|]}| qSrrr>rrr sz&_lazyancestorsiter..rr)rheapqheappushheappop heapreplacerr9heapify) parentrevsinitrevsstoprev inclusiverr]r^r_seevisitr?p1p2currentrrr_lazyancestorsitersJ              rjc@s2eZdZd ddZddZeZddZd d Zd S) lazyancestorsrFcsJ||_fdd|D|_|_||_t|_t|j|j|j|j|_dS)aCreate a new object generating ancestors for the given revs. Does not generate revs lower than stoprev. This is computed lazily starting from revs. The object supports iteration and membership. cl should be a changelog and revs should be an iterable. inclusive is a boolean that indicates whether revs should be included. Revs lower than stoprev will not be generated. Result does not include the null revision.csg|]}|kr|qSrrr>rcrrr[Nsz*lazyancestors.__init__..N) _parentrevs _initrevs_stoprev _inclusiver _containsseenrj _containsiter)r5rrIrcrdrrlrr6As  zlazyancestors.__init__cCs(z tt|WdStyYdSw)z*False if the set is empty, True otherwise.TF)nextiter StopIterationr7rrr __nonzero__Ws   zlazyancestors.__nonzero__cCst|j|j|j|jS)aGenerate the ancestors of _initrevs in reverse topological order. If inclusive is False, yield a sequence of revision numbers starting with the parents of each revision in revs, i.e., each revision is *not* considered an ancestor of itself. Results are emitted in reverse revision number order. That order is also topological: a child is always emitted before its parent. If inclusive is True, the source revisions are also yielded. The reverse revision number order is still enforced.)rjrmrnrorpr7rrr__iter__as zlazyancestors.__iter__cCs|j}||vr dS|j}|durdS|durdS|j}z t|}||||kr,WdS||kr3WdSqty@d|_YdSw)z5Test whether target is an ancestor of self._initrevs.TNF)rqrrrrsru)r5targetrrtrerevrrr __contains__ps, zlazyancestors.__contains__N)rF)rWrXrYr6rv__bool__rwrzrrrrrk@s   rk) __future__rr\noderrrr importmodrrr1objectr2rjrkrrrrs   9G~,