##// END OF EJS Templates
revset: fix sorting key of wdir revision...
revset: fix sorting key of wdir revision It would go wrong on Python 2, and would crash on Python 3.

File last commit:

r46116:5ed6efed stable
r46293:b90d7e7f default
Show More
repoview.py
482 lines | 16.7 KiB | text/x-python | PythonLexer
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 # repoview.py - Filtered view of a localrepo object
#
# Copyright 2012 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Logilab SA <contact@logilab.fr>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
Gregory Szorc
repoview: use absolute_import
r25972 from __future__ import absolute_import
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 import copy
Yuya Nishihara
repoview: extract a factory function of proxy class...
r35248 import weakref
Gregory Szorc
repoview: use absolute_import
r25972
Martin von Zweigbergk
repoview: move changelog.rev() override to filteredchangelog...
r43754 from .i18n import _
from .node import (
hex,
nullrev,
)
Gregory Szorc
py3: manually import getattr where it is needed...
r43359 from .pycompat import (
Gregory Szorc
py3: manually import pycompat.delattr where it is needed...
r43360 delattr,
Gregory Szorc
py3: manually import getattr where it is needed...
r43359 getattr,
setattr,
)
Gregory Szorc
repoview: use absolute_import
r25972 from . import (
Martin von Zweigbergk
repoview: move changelog.headrevs() override to filteredchangelog...
r43752 error,
Gregory Szorc
repoview: use absolute_import
r25972 obsolete,
phases,
Yuya Nishihara
repoview: include filter name in repr for debugging
r35249 pycompat,
Gregory Szorc
repoview: use absolute_import
r25972 tags as tagsmod,
repoview: introduce a `experimental.extra-filter-revs` config...
r42417 util,
)
Augie Fackler
formatting: blacken the codebase...
r43346 from .utils import repoviewutil
Pierre-Yves David
clfilter: introduces a hidden filter...
r18242
Pierre-Yves David
repoview: extract hideable revision computation in a dedicated function...
r18293 def hideablerevs(repo):
Pierre-Yves David
hideablerevs: expand docstring to warn about possible traps...
r28780 """Revision candidates to be hidden
This is a standalone function to allow extensions to wrap it.
Pierre-Yves David
repoview: extract hideable revision computation in a dedicated function...
r18293
Pierre-Yves David
hideablerevs: expand docstring to warn about possible traps...
r28780 Because we use the set of immutable changesets as a fallback subset in
repoview: move subsettable in a dedicated module...
r42314 branchmap (see mercurial.utils.repoviewutils.subsettable), you cannot set
"public" changesets as "hideable". Doing so would break multiple code
assertions and lead to crashes."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 obsoletes = obsolete.getrevs(repo, b'obsolete')
Boris Feld
phases: add an internal phases...
r39333 internals = repo._phasecache.getrevset(repo, phases.localhiddenphases)
internals = frozenset(internals)
return obsoletes | internals
Pierre-Yves David
repoview: extract hideable revision computation in a dedicated function...
r18293
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
hidden: rename "revealedrevs" to "pinnedrevs" (API)...
r32580 def pinnedrevs(repo):
Martin von Zweigbergk
hidden: drop obsolete comment about cacheability...
r32579 """revisions blocking hidden changesets from being filtered
hidden: drop outdated comment about "dynamic" performance...
r32479 """
repoview: move '_getdynamicblock' next to 'hideablerevs'...
r32426
cl = repo.changelog
Martin von Zweigbergk
hidden: rename "revealedrevs" to "pinnedrevs" (API)...
r32580 pinned = set()
pinned.update([par.rev() for par in repo[None].parents()])
pinned.update([cl.rev(bm) for bm in repo._bookmarks.values()])
repoview: move '_getdynamicblock' next to 'hideablerevs'...
r32426
tags = {}
tagsmod.readlocaltags(repo.ui, repo, tags, {})
if tags:
index: use `index.get_rev` in `repoview.pinnedrevs`...
r43959 rev = cl.index.get_rev
pinned.update(rev(t[0]) for t in tags.values())
pinned.discard(None)
Matt Harbison
repoview: pin revisions for `local` and `other` when a merge is active...
r45972
# Avoid cycle: mercurial.filemerge -> mercurial.templater ->
# mercurial.templatefuncs -> mercurial.revset -> mercurial.repoview ->
# mercurial.mergestate -> mercurial.filemerge
from . import mergestate
ms = mergestate.mergestate.read(repo)
if ms.active():
Martin von Zweigbergk
repoview: don't crash if mergestate points to non-existent node...
r46116 for node in (ms.local, ms.other):
rev = cl.index.get_rev(node)
if rev is not None:
pinned.add(rev)
Matt Harbison
repoview: pin revisions for `local` and `other` when a merge is active...
r45972
Martin von Zweigbergk
hidden: rename "revealedrevs" to "pinnedrevs" (API)...
r32580 return pinned
repoview: move '_getdynamicblock' next to 'hideablerevs'...
r32426
hidden: simplify the computation of consistency blocker...
r32476
Martin von Zweigbergk
hidden: remove unnecessary 'domain' parameter from _revealancestors()...
r32582 def _revealancestors(pfunc, hidden, revs):
"""reveals contiguous chains of hidden ancestors of 'revs' by removing them
from 'hidden'
hidden: add a function returning ancestors of revs within a domain...
r32474
- pfunc(r): a funtion returning parent of 'r',
Martin von Zweigbergk
hidden: change _domainancestors() to _revealancestors()...
r32581 - hidden: the (preliminary) hidden revisions, to be updated
hidden: add a function returning ancestors of revs within a domain...
r32474 - revs: iterable of revnum,
Martin von Zweigbergk
hidden: make _revealancestors() reveal ancestors exclusively...
r32585 (Ancestors are revealed exclusively, i.e. the elements in 'revs' are
*not* revealed)
hidden: add a function returning ancestors of revs within a domain...
r32474 """
stack = list(revs)
while stack:
for p in pfunc(stack.pop()):
Martin von Zweigbergk
hidden: remove unnecessary 'domain' parameter from _revealancestors()...
r32582 if p != nullrev and p in hidden:
Martin von Zweigbergk
hidden: change _domainancestors() to _revealancestors()...
r32581 hidden.remove(p)
hidden: add a function returning ancestors of revs within a domain...
r32474 stack.append(p)
Augie Fackler
formatting: blacken the codebase...
r43346
Pulkit Goyal
repoview: add visibilityexception argument to filterrevs() and related fns...
r35509 def computehidden(repo, visibilityexceptions=None):
Pierre-Yves David
clfilter: introduces a hidden filter...
r18242 """compute the set of hidden revision to filter
During most operation hidden should be filtered."""
assert not repo.changelog.filteredrevs
David Soria Parra
repoview: cache hidden changesets...
r22151
hidden: unify the static and dynamic blocker logic...
r32478 hidden = hideablerevs(repo)
if hidden:
Martin von Zweigbergk
hidden: subtract pinned revs from hidden earlier...
r32586 hidden = set(hidden - pinnedrevs(repo))
Pulkit Goyal
repoview: add visibilityexception argument to filterrevs() and related fns...
r35509 if visibilityexceptions:
hidden -= visibilityexceptions
hidden: unify the static and dynamic blocker logic...
r32478 pfunc = repo.changelog.parentrevs
Boris Feld
phases: define an official tuple of mutable phases...
r38174 mutable = repo._phasecache.getrevset(repo, phases.mutablephases)
hidden: unify the static and dynamic blocker logic...
r32478
Martin von Zweigbergk
hidden: remove unnecessary guard condition...
r32587 visible = mutable - hidden
_revealancestors(pfunc, hidden, visible)
hidden: unify the static and dynamic blocker logic...
r32478 return frozenset(hidden)
Pierre-Yves David
clfilter: introduces a hidden filter...
r18242
Augie Fackler
formatting: blacken the codebase...
r43346
repoview: introduce a filter for serving hidden changesets...
r42295 def computesecret(repo, visibilityexceptions=None):
"""compute the set of revision that can never be exposed through hgweb
Changeset in the secret phase (or above) should stay unaccessible."""
assert not repo.changelog.filteredrevs
secrets = repo._phasecache.getrevset(repo, phases.remotehiddenphases)
return frozenset(secrets)
Augie Fackler
formatting: blacken the codebase...
r43346
Pulkit Goyal
repoview: add visibilityexception argument to filterrevs() and related fns...
r35509 def computeunserved(repo, visibilityexceptions=None):
Pierre-Yves David
clfilter: introduce a "unserver" filtering mode...
r18102 """compute the set of revision that should be filtered when used a server
Secret and hidden changeset should not pretend to be here."""
assert not repo.changelog.filteredrevs
# fast path in simple case to avoid impact of non optimised code
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 hiddens = filterrevs(repo, b'visible')
secrets = filterrevs(repo, b'served.hidden')
repoview: fix conditional around unserved changesets...
r42294 if secrets:
repoview: introduce a filter for serving hidden changesets...
r42295 return frozenset(hiddens | secrets)
Pierre-Yves David
performance: speedup computation of unserved revisions...
r18273 else:
return hiddens
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100
Augie Fackler
formatting: blacken the codebase...
r43346
Pulkit Goyal
repoview: add visibilityexception argument to filterrevs() and related fns...
r35509 def computemutable(repo, visibilityexceptions=None):
Pierre-Yves David
clfilter: add mutable filtering...
r18245 assert not repo.changelog.filteredrevs
# fast check to avoid revset call on huge repo
Joerg Sonnenberger
phases: provide a test and accessor for non-public phase roots...
r45674 if repo._phasecache.hasnonpublicphases(repo):
Joerg Sonnenberger
repoview: use the phasecache directly to determine mutable revisions...
r45675 return frozenset(repo._phasecache.getrevset(repo, phases.mutablephases))
Pierre-Yves David
clfilter: add mutable filtering...
r18245 return frozenset()
Augie Fackler
formatting: blacken the codebase...
r43346
Pulkit Goyal
repoview: add visibilityexception argument to filterrevs() and related fns...
r35509 def computeimpactable(repo, visibilityexceptions=None):
Pierre-Yves David
clfilter: add impactable filter...
r18246 """Everything impactable by mutable revision
Pierre-Yves David
documentation: update to new filter names...
r18462 The immutable filter still have some chance to get invalidated. This will
Pierre-Yves David
clfilter: add impactable filter...
r18246 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 egal or
higher than the first mutable changeset is filtered."""
assert not repo.changelog.filteredrevs
cl = repo.changelog
firstmutable = len(cl)
Joerg Sonnenberger
phases: provide a test and accessor for non-public phase roots...
r45674 roots = repo._phasecache.nonpublicphaseroots(repo)
if roots:
firstmutable = min(firstmutable, min(cl.rev(r) for r in roots))
Pierre-Yves David
repoview: protect `base` computation from weird phase root...
r18443 # protect from nullrev root
firstmutable = max(0, firstmutable)
Gregory Szorc
global: use pycompat.xrange()...
r38806 return frozenset(pycompat.xrange(firstmutable, len(cl)))
Pierre-Yves David
clfilter: add impactable filter...
r18246
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 # function to compute filtered set
Pierre-Yves David
filter: add a comment so that people do not forget to update subsettable...
r20196 #
Mads Kiilerich
comments: fix minor spelling issues found with spell checker
r20549 # When adding a new filter you MUST update the table at:
repoview: move subsettable in a dedicated module...
r42314 # mercurial.utils.repoviewutil.subsettable
Pierre-Yves David
filter: add a comment so that people do not forget to update subsettable...
r20196 # Otherwise your filter will have to recompute all its branches cache
# from scratch (very slow).
Augie Fackler
formatting: blacken the codebase...
r43346 filtertable = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'visible': computehidden,
b'visible-hidden': computehidden,
b'served.hidden': computesecret,
b'served': computeunserved,
b'immutable': computemutable,
b'base': computeimpactable,
Augie Fackler
formatting: blacken the codebase...
r43346 }
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100
repoview: add an explicit set of all filter that show the wc parents...
r44205 # set of filter level that will include the working copy parent no matter what.
filter_has_wc = {b'visible', b'visible-hidden'}
repoview: introduce a `experimental.extra-filter-revs` config...
r42417 _basefiltername = list(filtertable)
Augie Fackler
formatting: blacken the codebase...
r43346
repoview: introduce a `experimental.extra-filter-revs` config...
r42417 def extrafilter(ui):
"""initialize 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.
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 frevs = ui.config(b'experimental', b'extra-filter-revs')
repoview: introduce a `experimental.extra-filter-revs` config...
r42417 if frevs is None:
return None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fid = pycompat.sysbytes(util.DIGESTS[b'sha1'](frevs).hexdigest())[:12]
repoview: introduce a `experimental.extra-filter-revs` config...
r42417
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 combine = lambda fname: fname + b'%' + fid
repoview: introduce a `experimental.extra-filter-revs` config...
r42417
subsettable = repoviewutil.subsettable
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if combine(b'base') not in filtertable:
repoview: introduce a `experimental.extra-filter-revs` config...
r42417 for name in _basefiltername:
Augie Fackler
formatting: blacken the codebase...
r43346
repoview: introduce a `experimental.extra-filter-revs` config...
r42417 def extrafilteredrevs(repo, *args, **kwargs):
baserevs = filtertable[name](repo, *args, **kwargs)
extrarevs = frozenset(repo.revs(frevs))
return baserevs | extrarevs
Augie Fackler
formatting: blacken the codebase...
r43346
repoview: introduce a `experimental.extra-filter-revs` config...
r42417 filtertable[combine(name)] = extrafilteredrevs
if name in subsettable:
subsettable[combine(name)] = combine(subsettable[name])
return fid
Augie Fackler
formatting: blacken the codebase...
r43346
Pulkit Goyal
repoview: add visibilityexception argument to filterrevs() and related fns...
r35509 def filterrevs(repo, filtername, visibilityexceptions=None):
"""returns 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 result"""
Pierre-Yves David
clfilter: add a cache on repo for set of revision to filter for a given set....
r18101 if filtername not in repo.filteredrevcache:
repoview: add a 'devel.debug.repo-filter' option...
r44192 if repo.ui.configbool(b'devel', b'debug.repo-filters'):
repoview: display stack trace along side the debug message...
r44194 msg = b'computing revision filter for "%s"'
msg %= filtername
if repo.ui.tracebackflag and repo.ui.debugflag:
# XXX use ui.write_err
util.debugstacktrace(
msg,
f=repo.ui._fout,
otherf=repo.ui._ferr,
prefix=b'debug.filters: ',
)
else:
repo.ui.debug(b'debug.filters: %s\n' % msg)
Pierre-Yves David
clfilter: add a cache on repo for set of revision to filter for a given set....
r18101 func = filtertable[filtername]
Pulkit Goyal
repoview: add visibilityexception argument to filterrevs() and related fns...
r35509 if visibilityexceptions:
return func(repo.unfiltered, visibilityexceptions)
Pierre-Yves David
clfilter: add a cache on repo for set of revision to filter for a given set....
r18101 repo.filteredrevcache[filtername] = func(repo.unfiltered())
return repo.filteredrevcache[filtername]
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
repoview: extract a function for wrapping changelog...
r43746 def wrapchangelog(unfichangelog, filteredrevs):
cl = copy.copy(unfichangelog)
cl.filteredrevs = filteredrevs
Martin von Zweigbergk
repoview: wrap changelog class when filtering...
r43747
Martin von Zweigbergk
repoview: use class literal for creating filteredchangelog...
r43910 class filteredchangelog(filteredchangelogmixin, cl.__class__):
pass
cl.__class__ = filteredchangelog
Martin von Zweigbergk
repoview: wrap changelog class when filtering...
r43747
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 return cl
Martin von Zweigbergk
repoview: move changelog.__contains__() override to filteredchangelog...
r43749
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 class filteredchangelogmixin(object):
def tiprev(self):
"""filtered version of revlog.tiprev"""
for i in pycompat.xrange(len(self) - 1, -2, -1):
if i not in self.filteredrevs:
return i
Martin von Zweigbergk
repoview: move changelog.__iter__() override to filteredchangelog...
r43750
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 def __contains__(self, rev):
"""filtered version of revlog.__contains__"""
return 0 <= rev < len(self) and rev not in self.filteredrevs
Martin von Zweigbergk
repoview: move changelog.__iter__() override to filteredchangelog...
r43750
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 def __iter__(self):
"""filtered version of revlog.__iter__"""
Martin von Zweigbergk
repoview: move changelog.__iter__() override to filteredchangelog...
r43750
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 def filterediter():
for i in pycompat.xrange(len(self)):
Martin von Zweigbergk
repoview: move changelog.revs() override to filteredchangelog...
r43751 if i not in self.filteredrevs:
yield i
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 return filterediter()
def revs(self, start=0, stop=None):
"""filtered version of revlog.revs"""
for i in super(filteredchangelogmixin, self).revs(start, stop):
if i not in self.filteredrevs:
yield i
Martin von Zweigbergk
repoview: move changelog.headrevs() override to filteredchangelog...
r43752
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 def _checknofilteredinrevs(self, revs):
"""raise 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.
"""
safehasattr = util.safehasattr
if safehasattr(revs, '__next__'):
# Note that inspect.isgenerator() is not true for iterators,
revs = set(revs)
Martin von Zweigbergk
repoview: move changelog.headrevs() override to filteredchangelog...
r43752
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 filteredrevs = self.filteredrevs
if safehasattr(revs, 'first'): # smartset
offenders = revs & filteredrevs
else:
offenders = filteredrevs.intersection(revs)
Martin von Zweigbergk
repoview: move changelog.headrevs() override to filteredchangelog...
r43752
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 for rev in offenders:
raise error.FilteredIndexError(rev)
return revs
Martin von Zweigbergk
repoview: move changelog.headrevs() override to filteredchangelog...
r43752
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 def headrevs(self, revs=None):
if revs is None:
try:
return self.index.headrevsfiltered(self.filteredrevs)
# AttributeError covers non-c-extension environments and
# old c extensions without filter handling.
except AttributeError:
return self._headrevs()
Martin von Zweigbergk
repoview: move changelog.headrevs() override to filteredchangelog...
r43752
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 revs = self._checknofilteredinrevs(revs)
return super(filteredchangelogmixin, self).headrevs(revs)
def strip(self, *args, **kwargs):
# XXX make something better than assert
# We can't expect proper strip behavior if we are filtered.
assert not self.filteredrevs
super(filteredchangelogmixin, self).strip(*args, **kwargs)
Martin von Zweigbergk
repoview: move changelog.strip() override to filteredchangelog...
r43753
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 def rev(self, node):
"""filtered version of revlog.rev"""
r = super(filteredchangelogmixin, self).rev(node)
if r in self.filteredrevs:
raise error.FilteredLookupError(
hex(node), self.indexfile, _(b'filtered node')
)
return r
Martin von Zweigbergk
repoview: move changelog.node() override to filteredchangelog...
r43755
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 def node(self, rev):
"""filtered version of revlog.node"""
if rev in self.filteredrevs:
raise error.FilteredIndexError(rev)
return super(filteredchangelogmixin, self).node(rev)
def linkrev(self, rev):
"""filtered version of revlog.linkrev"""
if rev in self.filteredrevs:
raise error.FilteredIndexError(rev)
return super(filteredchangelogmixin, self).linkrev(rev)
Martin von Zweigbergk
repoview: move changelog.linkrev() override to filteredchangelog...
r43756
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 def parentrevs(self, rev):
"""filtered version of revlog.parentrevs"""
if rev in self.filteredrevs:
raise error.FilteredIndexError(rev)
return super(filteredchangelogmixin, self).parentrevs(rev)
Martin von Zweigbergk
repoview: move changelog.parentrevs() override to filteredchangelog...
r43757
Martin von Zweigbergk
repoview: define filteredchangelog as a top-level (non-local) class...
r43797 def flags(self, rev):
"""filtered version of revlog.flags"""
if rev in self.filteredrevs:
raise error.FilteredIndexError(rev)
return super(filteredchangelogmixin, self).flags(rev)
Martin von Zweigbergk
repoview: extract a function for wrapping changelog...
r43746
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 class repoview(object):
"""Provide 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
Mads Kiilerich
spelling: fix some minor issues found by spell checker
r18644 subclasses of `localrepo`. Eg: `bundlerepo` or `statichttprepo`.
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 """
Pulkit Goyal
repoview: add visibilityexceptions as an optional argument to repo.filtered()...
r35508 def __init__(self, repo, filtername, visibilityexceptions=None):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 object.__setattr__(self, '_unfilteredrepo', repo)
object.__setattr__(self, 'filtername', filtername)
object.__setattr__(self, '_clcachekey', None)
object.__setattr__(self, '_clcache', None)
Pulkit Goyal
repoview: add visibilityexceptions as an optional argument to repo.filtered()...
r35508 # revs which are exceptions and must not be hidden
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 object.__setattr__(self, '_visibilityexceptions', visibilityexceptions)
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100
Mads Kiilerich
spelling: fix some minor issues found by spell checker
r18644 # not a propertycache on purpose we shall implement a proper cache later
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 @property
def changelog(self):
"""return a filtered version of the changeset
this changelog must not be used for writing"""
# some cache may be implemented later
Pierre-Yves David
repoview: cache filtered changelog...
r18445 unfi = self._unfilteredrepo
unfichangelog = unfi.changelog
Pierre-Yves David
repoview: bypass changelog method to computed cache key...
r27258 # bypass call to changelog.method
unfiindex = unfichangelog.index
Martin von Zweigbergk
index: don't include nullid in len()...
r38887 unfilen = len(unfiindex)
Pierre-Yves David
repoview: bypass changelog method to computed cache key...
r27258 unfinode = unfiindex[unfilen - 1][7]
Augie Fackler
tracing: add a couple of trace points on obsolete and repoview...
r43534 with util.timedcm('repo filter for %s', self.filtername):
revs = filterrevs(unfi, self.filtername, self._visibilityexceptions)
Pierre-Yves David
repoview: cache filtered changelog...
r18445 cl = self._clcache
Pierre-Yves David
repoview: bypass changelog method to computed cache key...
r27258 newkey = (unfilen, unfinode, hash(revs), unfichangelog._delayed)
FUJIWARA Katsunori
repoview: discard filtered changelog if index isn't shared with unfiltered...
r28265 # if cl.index is not unfiindex, unfi.changelog would be
# recreated, and our clcache refers to garbage object
Augie Fackler
formatting: blacken the codebase...
r43346 if cl is not None and (
cl.index is not unfiindex or newkey != self._clcachekey
):
Pierre-Yves David
repoview: bypass changelog method to computed cache key...
r27258 cl = None
Pierre-Yves David
repoview: cache filtered changelog...
r18445 # could have been made None by the previous if
if cl is None:
Martin von Zweigbergk
repoview: avoid wrapping changelog if there's nothing to filter...
r43759 # Only filter if there's something to filter
cl = wrapchangelog(unfichangelog, revs) if revs else unfichangelog
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 object.__setattr__(self, '_clcache', cl)
object.__setattr__(self, '_clcachekey', newkey)
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 return cl
def unfiltered(self):
"""Return an unfiltered version of a repo"""
return self._unfilteredrepo
Pulkit Goyal
repoview: add visibilityexceptions as an optional argument to repo.filtered()...
r35508 def filtered(self, name, visibilityexceptions=None):
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 """Return a filtered version of a repository"""
Pulkit Goyal
repoview: add visibilityexceptions as an optional argument to repo.filtered()...
r35508 if name == self.filtername and not visibilityexceptions:
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 return self
Pulkit Goyal
repoview: add visibilityexceptions as an optional argument to repo.filtered()...
r35508 return self.unfiltered().filtered(name, visibilityexceptions)
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100
Yuya Nishihara
repoview: include filter name in repr for debugging
r35249 def __repr__(self):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 return '<%s:%s %r>' % (
Augie Fackler
formatting: blacken the codebase...
r43346 self.__class__.__name__,
pycompat.sysstr(self.filtername),
self.unfiltered(),
)
Yuya Nishihara
repoview: include filter name in repr for debugging
r35249
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 # everything access are forwarded to the proxied repo
def __getattr__(self, attr):
return getattr(self._unfilteredrepo, attr)
def __setattr__(self, attr, value):
return setattr(self._unfilteredrepo, attr, value)
def __delattr__(self, attr):
return delattr(self._unfilteredrepo, attr)
Yuya Nishihara
repoview: extract a factory function of proxy class...
r35248
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
repoview: extract a factory function of proxy class...
r35248 # Python <3.4 easily leaks types via __mro__. See
# https://bugs.python.org/issue17950. We cache dynamically created types
# so they won't be leaked on every invocation of repo.filtered().
_filteredrepotypes = weakref.WeakKeyDictionary()
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
repoview: extract a factory function of proxy class...
r35248 def newtype(base):
"""Create a new type with the repoview mixin and the given base class"""
if base not in _filteredrepotypes:
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
repoview: extract a factory function of proxy class...
r35248 class filteredrepo(repoview, base):
pass
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
repoview: extract a factory function of proxy class...
r35248 _filteredrepotypes[base] = filteredrepo
return _filteredrepotypes[base]