o ]LbC@s2ddlmZddlZddlZddlmZddlmZmZddl m Z m Z m Z ddl mZmZmZm Z mZmZddlmZd d Zd d Zd dZd(ddZd(ddZd(ddZd(ddZd(ddZeeeeeedZddhZe eZ!ddZ"d(ddZ#d d!Z$Gd"d#d#e%Z&Gd$d%d%e%Z'e(Z)d&d'Z*dS)))absolute_importN)_)hexnullrev)delattrgetattrsetattr)errorobsoletephasespycompattagsutil) repoviewutilcCs,t|d}|j|tj}t|}||BS)akRevision candidates to be hidden This is a standalone function to allow extensions to wrap it. Because we use the set of immutable changesets as a fallback subset in branchmap (see mercurial.utils.repoviewutils.subsettable), you cannot set "public" changesets as "hideable". Doing so would break multiple code assertions and lead to crashes.sobsolete)r getrevs _phasecache getrevsetr localhiddenphases frozenset)repo obsoletes internalsr4/usr/lib/python3/dist-packages/mercurial/repoview.py hideablerevs#s rcs|jt}|dd|dD|fdd|jDi}t|j||i|rGj j |fdd|D| dddl m }|j |}|rs|rs|j|jfD]}j |durr|qa|S) z8revisions blocking hidden changesets from being filteredcSsg|]}|qSrrev).0parrrr 7szpinnedrevs..Ncsg|]}|qSrr)rbmclrrr 8sc3s|] }|dVqdSrNr)rtrrr >szpinnedrevs..r) mergestate) changelogsetupdateparents _bookmarksvaluestagsmod readlocaltagsuiindexget_revdiscardr'readactiveunresolvedcountlocalotheradd)rpinnedrr'msnoder)r#rr pinnedrevs2s&     r>cCsNt|}|r%||D]}|tkr ||vr ||||q |sdSdS)aQreveals contiguous chains of hidden ancestors of 'revs' by removing them from 'hidden' - pfunc(r): a funtion returning parent of 'r', - hidden: the (preliminary) hidden revisions, to be updated - revs: iterable of revnum, (Ancestors are revealed exclusively, i.e. the elements in 'revs' are *not* revealed) N)listpoprremoveappend)pfunchiddenrevsstackprrr_revealancestorsPs    rHcCsh|jjrJt|}|r0t|t|}|r||8}|jj}|j|tj }||}t |||t |S)zbcompute the set of hidden revision to filter During most operation hidden should be filtered.) r( filteredrevsrr)r> parentrevsrrr mutablephasesrHr)rvisibilityexceptionsrDrCmutablevisiblerrr computehiddencs  rOcCs$|jjrJ|j|tj}t|S)zcompute the set of revision that can never be exposed through hgweb Changeset in the secret phase (or above) should stay unaccessible.)r(rIrrr remotehiddenphasesr)rrLsecretsrrr computesecretvs rRcCs4|jjrJt|d}t|d}|rt||BS|S)zcompute the set of revision that should be filtered when used a server Secret and hidden changeset should not pretend to be here.visible served.hidden)r(rI filterrevsr)rrLhiddensrQrrrcomputeunserveds    rWcCs2|jjrJ|j|rt|j|tjStSN)r(rIrhasnonpublicphasesrrr rK)rrLrrrcomputemutables  rZcsd|jjrJ|jt}|j|}|r#t|tfdd|D}td|}tt |tS)a/Everything impactable by mutable revision The immutable filter still have some chance to get invalidated. This will happen when: - you garbage collect hidden changeset, - public phase is moved backward, - something is changed in the filtering (this could be fixed) This filter out any mutable changeset and any public changeset that may be impacted by something happening to a mutable revision. This is achieved by filtered everything with a revision number equal or higher than the first mutable changeset is filtered.c3s|]}|VqdSrXr)rrr"rrr&sz$computeimpactable..r) r(rIlenrnonpublicphaserootsminmaxrr xrange)rrL firstmutablerootsrr"rcomputeimpactables   rc)rSvisible-hiddenrTsserveds immutablebaserSrdcs|dddur dSttjdddfdd}tj}|dtvrKt D]fd d }|t|<|vrJ||||<q-S) zinitialize extra filter and return its id If extra filtering is configured, we make sure the associated filtered view are declared and return the associated id. s experimentalsextra-filter-revsNssha1 cs |dS)N%r)fname)fidrrs zextrafilter..recs0t|g|Ri|}t|}||BSrX) filtertablerrE)rargskwargsbaserevs extrarevs)frevsnamerrextrafilteredrevssz&extrafilter..extrafilteredrevs) configr sysbytesrDIGESTS hexdigestr subsettablerk_basefiltername)r0combinerwrrr)rirprqr extrafilters     rzcCs||jvrE|jddr0d}||;}|jjr(|jjr(tj||jj|jjddn|j d|t |}|r<||j |S|| |j|<|j|S)zreturns set of filtered revision for this filter name visibilityexceptions is a set of revs which must are exceptions for hidden-state and must be visible. They are dynamic and hence we should not cache it's resultsdevelsdebug.repo-filterss"computing revision filter for "%s"sdebug.filters: )fotherfprefixsdebug.filters: %s ) filteredrevcacher0 configbool tracebackflag debugflagrdebugstacktrace_fout_ferrdebugrk unfiltered)r filternamerLmsgfuncrrrrUs"   rUcCs.t|}||_Gdddt|j}||_|S)Nc@ eZdZdS)z(wrapchangelog..filteredchangelogN__name__ __module__ __qualname__rrrrfilteredchangelogr)copyrIfilteredchangelogmixin __class__) unfichangelogrIr#rrrr wrapchangelogs rcseZdZddZddZddZdfd d Zd d Zdfd d ZfddZ fddZ fddZ fddZ fddZ fddZZS)rcCs2tt|dddD] }||jvr|Sq dS)z!filtered version of revlog.tiprevrNr r`r\rI)selfirrrtiprev s  zfilteredchangelogmixin.tiprevcCs&d|ko t|kno||jvS)z'filtered version of revlog.__contains__r)r\rIrrrrr __contains__s&z#filteredchangelogmixin.__contains__csfdd}|S)z#filtered version of revlog.__iter__c3s*ttD] }|jvr|VqdSrXr)rrrr filterediters  z5filteredchangelogmixin.__iter__..filterediterr)rrrrr__iter__s zfilteredchangelogmixin.__iter__rNc#s.tt|||D] }||jvr|Vq dS)zfiltered version of revlog.revsN)superrrErI)rstartstoprrrrrEs  zfilteredchangelogmixin.revscCsRtj}||dr t|}|j}||dr||@}n||}|D]}t||S)zraise the appropriate error if 'revs' contains a filtered revision This returns a version of 'revs' to be used thereafter by the caller. In particular, if revs is an iterator, it is converted into a set. __next__first)r safehasattrr)rI intersectionr FilteredIndexError)rrErrI offendersrrrr_checknofilteredinrevs$s     z-filteredchangelogmixin._checknofilteredinrevscsN|durz|j|jWSty|YSw||}tt||SrX) r1headrevsfilteredrIAttributeError _headrevsrrrheadrevs)rrErrrr9s   zfilteredchangelogmixin.headrevscs$|jrJtt|j|i|dSrX)rIrrstrip)rrlrmrrrrEs zfilteredchangelogmixin.stripcs6tt||}||jvrtt||jtd|S)zfiltered version of revlog.revs filtered node) rrrrIr FilteredLookupErrorr display_idr)rr=r[rrrrKs  zfilteredchangelogmixin.revc$||jvr t|tt||S)zfiltered version of revlog.node)rIr rrrr=rrrrr=T  zfilteredchangelogmixin.nodecr)z"filtered version of revlog.linkrev)rIr rrrlinkrevrrrrrZrzfilteredchangelogmixin.linkrevcr)z%filtered version of revlog.parentrevs)rIr rrrrJrrrrrJ`rz!filteredchangelogmixin.parentrevscr)z filtered version of revlog.flags)rIr rrrflagsrrrrrfrzfilteredchangelogmixin.flagsr$rX)rrrrrrrErrrrr=rrJr __classcell__rrrrr s    rc@sXeZdZdZdddZeddZddZdd d Zd d Z d dZ ddZ ddZ dS)repoviewaProvide a read/write view of a repo through a filtered changelog This object is used to access a filtered version of a repository without altering the original repository object itself. We can not alter the original object for two main reasons: - It prevents the use of a repo with multiple filters at the same time. In particular when multiple threads are involved. - It makes scope of the filtering harder to control. This object behaves very closely to the original repository. All attribute operations are done on the original repository: - An access to `repoview.someattr` actually returns `repo.someattr`, - A write to `repoview.someattr` actually sets value of `repo.someattr`, - A deletion of `repoview.someattr` actually drops `someattr` from `repo.__dict__`. The only exception is the `changelog` property. It is overridden to return a (surface) copy of `repo.changelog` with some revisions filtered. The `filtername` attribute of the view control the revisions that need to be filtered. (the fact the changelog is copied is an implementation detail). Unlike attributes, this object intercepts all method calls. This means that all methods are run on the `repoview` object with the filtered `changelog` property. For this purpose the simple `repoview` class must be mixed with the actual class of the repository. This ensures that the resulting `repoview` object have the very same methods than the repo object. This leads to the property below. repoview.method() --> repo.__class__.method(repoview) The inheritance has to be done dynamically because `repo` can be of any subclasses of `localrepo`. Eg: `bundlerepo` or `statichttprepo`. NcCsJt|d|t|d|t|ddt|ddt|d|dS)N_unfilteredrepor _clcachekey_clcache_visibilityexceptions)object __setattr__)rrrrLrrr__init__s zrepoview.__init__c Cs|j}|j}|j}t|}||dd}td|jt||j|j}Wdn1s/wY|j }||t ||j f}|durP|j|usN||j krPd}|durk|r[t ||n|}t|d|t|d||S)z_return a filtered version of the changeset this changelog must not be used for writingrzrepo filter for %sNrr)rr(r1r\rtimedcmrrUrrhash_delayedrrrr) runfir unfiindexunfilenunfinoderEr#newkeyrrrr(s$zrepoview.changelogcCs|jS)z&Return an unfiltered version of a repo)rrrrrrszrepoview.unfilteredcCs"||jkr |s |S|||S)z)Return a filtered version of a repository)rrfiltered)rrqrLrrrrszrepoview.filteredcCsd|jjt|j|fS)Nz <%s:%s %r>)rrr sysstrrrrrrr__repr__s  zrepoview.__repr__cC t|j|SrX)rrrattrrrr __getattr__ zrepoview.__getattr__cCst|j||SrX)r r)rrvaluerrrrszrepoview.__setattr__cCrrX)rrrrrr __delattr__rzrepoview.__delattr__rX) rrr__doc__rpropertyr(rrrrrrrrrrrms "   rcCsHt|}|dur|}|dur|SGdddt|}t|t|<|S)zBCreate a new type with the repoview mixin and the given base classNc@r)znewtype..filteredrepoNrrrrr filteredreporr)_filteredrepotypesgetrweakrefref)baserclsrrrrnewtypes rrX)+ __future__rrri18nrr=rrr rrr r4r r r rr.rutilsrrr>rHrOrRrWrZrcrk filter_has_wcr?rxrzrUrrrrWeakKeyDictionaryrrrrrrs@        !   dj