[PATCH 2 of 5 filtering part 2 V2] clfilter: add actual repo filtering mechanism

Kevin Bullock kbullock+mercurial at ringworld.org
Mon Dec 10 16:45:04 CST 2012


On 10 Dec 2012, at 11:30 AM, pierre-yves.david at logilab.fr wrote:

> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
> # Date 1355157839 -3600
> # Node ID 5a3d1c83343b403cf1e1393cdf2dde4f8512309b
> # Parent  9280d7beadd6f38c8623ea3137f2028c57cc349c
> clfilter: add actual repo filtering mechanism
> 
> We add a `filtered` method on repo. This method return instance of `repoproxy`
                                                       an instance
> that behave exactly as the original repository but with a filtered changelog
       behaves
> attribute. Filter are identified by a "name". Planed filter are `unserved`,
             Filters                            Planned filters
                                       [^^ " instead of ` suddenly?]
> `hidden` and `mutable`.  See the `repoproxier` docstring for details.
                                   `repoproxy`
> Mechanism to compute filtered revision are also installed. Some cache will be
  A mechanism                   revisions is
> installed in later commit.
> 
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -13,10 +13,11 @@ import scmutil, util, extensions, hook, 
> import match as matchmod
> import merge as mergemod
> import tags as tagsmod
> from lock import release
> import weakref, errno, os, time, inspect
> +import copy
> propertycache = util.propertycache
> filecache = scmutil.filecache
> 
> class repofilecache(filecache):
>     """All filecache usage on repo are done for logic that should be unfiltered
> @@ -55,10 +56,73 @@ def unfilteredmethod(orig):
>     """decorate method that always need to be run on unfiltered version"""
>     def wrapper(repo, *args, **kwargs):
>         return orig(repo.unfiltered(), *args, **kwargs)
>     return wrapper
> 
> +# function to compute filtered set
> +computefiltered = {}
> +
> +def _filteredrevs(repo, filtername):
> +    """returns set of filtered revision for this filter name"""
> +    return computefiltered[filtername](repo.unfiltered())
> +
> +class repoproxy(object):
> +    """Changelog filterered localrepo proxy object
> +
> +    This object act is a proxy for attribute operation. setattr is done on the
> +    initial repo, getattr is get from the parent (unless defined on proxy) and
> +    delattr operate on proxied repo.
> +
> +    The changelog attribute is overridden to return a copy of the original
> +    changelog but with some revision filtered.
> +
> +    You have to mix this class with the actual localrepo subclass to be able to
> +    use the very same logic than the proxied repo. See `filtered` method of
> +    local repo for details."""

This method of decorating the repo seems pretty awkward, particularly using a global dict to hold functions. If there are really going to only be a handful of filters, can't we have a handful of actual named mixin classes (derived from repoproxy)?

pacem in terris / мир / शान्ति / ‎‫سَلاَم‬ / 平和
Kevin R. Bullock



More information about the Mercurial-devel mailing list