# HG changeset patch # User Augie Fackler # Date 1496933093 14400 # Node ID de09138bf0f511c865cc6c6afa7eb481dee9762c # Parent c2cb0de2512055123517289f398b8b554c31a5ed 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 -r c2cb0de25120 -r de09138bf0f5 hgext/fsmonitor/__init__.py --- a/hgext/fsmonitor/__init__.py Wed Apr 26 16:05:22 2017 +0200 +++ b/hgext/fsmonitor/__init__.py Thu Jun 08 10:44:53 2017 -0400 @@ -561,7 +561,8 @@ 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 @@ 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)) diff -r c2cb0de25120 -r de09138bf0f5 mercurial/extensions.py --- a/mercurial/extensions.py Wed Apr 26 16:05:22 2017 +0200 +++ b/mercurial/extensions.py Thu Jun 08 10:44:53 2017 -0400 @@ -308,6 +308,25 @@ table[key] = tuple(newentry) return entry +def wrapfilecache(cls, propname, wrapper): + """Wraps a filecache property. + + These can't be wrapped using the normal wrapfunction. + """ + 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)) + def wrapfunction(container, funcname, wrapper): '''Wrap the function named funcname in container