[PATCH] extensions: move wrapfilecache function from fsmonitor
Yuya Nishihara
yuya at tcha.org
Thu Jun 8 11:53:19 EDT 2017
On Thu, 08 Jun 2017 10:51:38 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie at google.com>
> # Date 1496933093 14400
> # Thu Jun 08 10:44:53 2017 -0400
> # Node ID ff739458783d32b8b0ce97a6771513caf280c09b
> # Parent 04c19c8082410049465e2cdc510e24801530c94b
> extensions: move wrapfilecache function from fsmonitor
>
> It makes more sense to put this in core, so other extensions can
> trivially get access to it without having to rely on importing
> fsmonitor.
>
> diff --git a/hgext/fsmonitor/__init__.py b/hgext/fsmonitor/__init__.py
> --- a/hgext/fsmonitor/__init__.py
> +++ b/hgext/fsmonitor/__init__.py
> @@ -561,7 +561,8 @@ def wrapdirstate(orig, self):
> return ds
>
> def extsetup(ui):
> - wrapfilecache(localrepo.localrepository, 'dirstate', wrapdirstate)
> + extensions.wrapfilecache(
> + localrepo.localrepository, 'dirstate', wrapdirstate)
> if pycompat.sysplatform == 'darwin':
> # An assist for avoiding the dangling-symlink fsevents bug
> extensions.wrapfunction(os, 'symlink', wrapsymlink)
> @@ -709,21 +710,3 @@ def reposetup(ui, repo):
> return overridestatus(orig, self, *args, **kwargs)
>
> repo.__class__ = fsmonitorrepo
> -
> -def wrapfilecache(cls, propname, wrapper):
> - """Wraps a filecache property. These can't be wrapped using the normal
> - wrapfunction. This should eventually go into upstream Mercurial.
> - """
> - assert callable(wrapper)
> - for currcls in cls.__mro__:
> - if propname in currcls.__dict__:
> - origfn = currcls.__dict__[propname].func
> - assert callable(origfn)
> - def wrap(*args, **kwargs):
> - return wrapper(origfn, *args, **kwargs)
> - currcls.__dict__[propname].func = wrap
> - break
> -
> - if currcls is object:
> - raise AttributeError(
> - _("type '%s' has no property '%s'") % (cls, propname))
IIRC, Jun had a bad time with this. Is this a good pattern to reliably
wrap filecache?
More information about the Mercurial-devel
mailing list