D3559: narrow: only wrap dirstate functions once, instead of per-reposetup

Yuya Nishihara yuya at tcha.org
Wed May 16 08:00:19 EDT 2018


> -def setup(repo):
> +# Mapping of root:str to repo for repos that have the narrow requirement
> +# specified.
> +_rootrepomap = {}
> +
> +def _getrepo(ds):
> +    """Check if narrow is enabled for repo associated with `ds`; return repo."""
> +    return _rootrepomap.get(ds._root, None)

This might cause problem on long-running processes such as hgweb and
commandserver.

Instead, maybe we can extract a factory function of repo.dirstate() so that
the narrowrepo can easily override it.

```
class localrepository(object):
    @repofilecache('dirstate')
    def dirstate(self):
        return self._makedirstate()

...
    class narrowrepository(repo.__class__):
        def _makedirstate(self):
            d = super(...)
            return wrapdirstate(d)
```


More information about the Mercurial-devel mailing list