# HG changeset patch # User Martijn Pieters # Date 2016-06-17 19:06:09 # Node ID 36fbd72c2f39fef8ad52d7c559906c2bc388760c # Parent 0b5e9a6250422f3458d7e81168f65904b7aaedc1 scmutil: allow access to filecache descriptor on class To make it easier to patch the wrapped function, make it possible to access the filecache descriptor directly on the class (rather than have to use ClassObject.__dict__['attributename']). Returning `self` when the first argument to `__get__` is `None` makes the descriptor behave the same way `property` objects do. diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -66,6 +66,8 @@ class repofilecache(scmutil.filecache): """ def __get__(self, repo, type=None): + if repo is None: + return self return super(repofilecache, self).__get__(repo.unfiltered(), type) def __set__(self, repo, value): return super(repofilecache, self).__set__(repo.unfiltered(), value) diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -1205,6 +1205,9 @@ class filecache(object): return self def __get__(self, obj, type=None): + # if accessed on the class, return the descriptor itself. + if obj is None: + return self # do we need to check if the file changed? if self.name in obj.__dict__: assert self.name in obj._filecache, self.name