##// END OF EJS Templates
profiling: move 'fp' closing logic into its own function...
profiling: move 'fp' closing logic into its own function We are about to make the logic more robust and reuse it in more place, we start by isolating what we have.

File last commit:

r32739:48d1e121 default
r32804:c0b2c8f2 default
Show More
repoview.py
245 lines | 9.1 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
Gregory Szorc
repoview: use absolute_import
r25972
from .node import nullrev
from . import (
obsolete,
phases,
tags as tagsmod,
)
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
branchmap (see mercurial.branchmap.subsettable), you cannot set "public"
changesets as "hideable". Doing so would break multiple code assertions and
lead to crashes."""
Pierre-Yves David
repoview: extract hideable revision computation in a dedicated function...
r18293 return obsolete.getrevs(repo, 'obsolete')
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:
rev, nodemap = cl.rev, cl.nodemap
Martin von Zweigbergk
hidden: rename "revealedrevs" to "pinnedrevs" (API)...
r32580 pinned.update(rev(t[0]) for t in tags.values() if t[0] in nodemap)
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)
Pierre-Yves David
clfilter: introduces a hidden filter...
r18242 def computehidden(repo):
"""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))
hidden: unify the static and dynamic blocker logic...
r32478 pfunc = repo.changelog.parentrevs
mutablephases = (phases.draft, phases.secret)
mutable = repo._phasecache.getrevset(repo, mutablephases)
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
Pierre-Yves David
clfilter: introduce a "unserver" filtering mode...
r18102 def computeunserved(repo):
"""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
Kevin Bullock
filtering: rename filters to their antonyms...
r18382 hiddens = filterrevs(repo, 'visible')
Pierre-Yves David
performance: speedup computation of unserved revisions...
r18273 if phases.hassecret(repo):
cl = repo.changelog
secret = phases.secret
getphase = repo._phasecache.phase
first = min(cl.rev(n) for n in repo._phasecache.phaseroots[secret])
revs = cl.revs(start=first)
secrets = set(r for r in revs if getphase(repo, r) >= secret)
return frozenset(hiddens | secrets)
else:
return hiddens
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100
Pierre-Yves David
clfilter: add mutable filtering...
r18245 def computemutable(repo):
"""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 check to avoid revset call on huge repo
Augie Fackler
cleanup: use __builtins__.any instead of util.any...
r25149 if any(repo._phasecache.phaseroots[1:]):
Pierre-Yves David
performance: speedup computation of mutable revisions...
r18274 getphase = repo._phasecache.phase
Kevin Bullock
filtering: rename filters to their antonyms...
r18382 maymutable = filterrevs(repo, 'base')
Pierre-Yves David
performance: speedup computation of mutable revisions...
r18274 return frozenset(r for r in maymutable if getphase(repo, r))
Pierre-Yves David
clfilter: add mutable filtering...
r18245 return frozenset()
Pierre-Yves David
clfilter: add impactable filter...
r18246 def computeimpactable(repo):
"""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)
for roots in repo._phasecache.phaseroots[1:]:
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)
Pierre-Yves David
clfilter: add impactable filter...
r18246 return frozenset(xrange(firstmutable, len(cl)))
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:
Pierre-Yves David
filter: add a comment so that people do not forget to update subsettable...
r20196 # mercurial.branchmap.subsettable
# Otherwise your filter will have to recompute all its branches cache
# from scratch (very slow).
Kevin Bullock
filtering: rename filters to their antonyms...
r18382 filtertable = {'visible': computehidden,
'served': computeunserved,
'immutable': computemutable,
'base': computeimpactable}
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100
Kevin Bullock
filtering: rename filters to their antonyms...
r18382 def filterrevs(repo, filtername):
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 """returns set of filtered revision for this filter name"""
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:
func = filtertable[filtername]
repo.filteredrevcache[filtername] = func(repo.unfiltered())
return repo.filteredrevcache[filtername]
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 """
def __init__(self, repo, filtername):
Pulkit Goyal
repoview: convert attribute names to unicodes on Python 3...
r31221 object.__setattr__(self, r'_unfilteredrepo', repo)
object.__setattr__(self, r'filtername', filtername)
object.__setattr__(self, r'_clcachekey', None)
object.__setattr__(self, r'_clcache', None)
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
unfilen = len(unfiindex) - 1
unfinode = unfiindex[unfilen - 1][7]
Pierre-Yves David
repoview: cache filtered changelog...
r18445 revs = filterrevs(unfi, self.filtername)
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
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:
cl = copy.copy(unfichangelog)
cl.filteredrevs = revs
Augie Fackler
repoview: specify setattr values as native strings
r31358 object.__setattr__(self, r'_clcache', cl)
object.__setattr__(self, r'_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
def filtered(self, name):
"""Return a filtered version of a repository"""
if name == self.filtername:
return self
return self.unfiltered().filtered(name)
# 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)