comparison mercurial/extensions.py @ 32722:de09138bf0f5

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.
author Augie Fackler <augie@google.com>
date Thu, 08 Jun 2017 10:44:53 -0400
parents f40dc6f7c12f
children ea1c2eb7abd3
comparison
equal deleted inserted replaced
32721:c2cb0de25120 32722:de09138bf0f5
306 if synopsis is not None: 306 if synopsis is not None:
307 newentry[2] += synopsis 307 newentry[2] += synopsis
308 table[key] = tuple(newentry) 308 table[key] = tuple(newentry)
309 return entry 309 return entry
310 310
311 def wrapfilecache(cls, propname, wrapper):
312 """Wraps a filecache property.
313
314 These can't be wrapped using the normal wrapfunction.
315 """
316 assert callable(wrapper)
317 for currcls in cls.__mro__:
318 if propname in currcls.__dict__:
319 origfn = currcls.__dict__[propname].func
320 assert callable(origfn)
321 def wrap(*args, **kwargs):
322 return wrapper(origfn, *args, **kwargs)
323 currcls.__dict__[propname].func = wrap
324 break
325
326 if currcls is object:
327 raise AttributeError(
328 _("type '%s' has no property '%s'") % (cls, propname))
329
311 def wrapfunction(container, funcname, wrapper): 330 def wrapfunction(container, funcname, wrapper):
312 '''Wrap the function named funcname in container 331 '''Wrap the function named funcname in container
313 332
314 Replace the funcname member in the given container with the specified 333 Replace the funcname member in the given container with the specified
315 wrapper. The container is typically a module, class, or instance. 334 wrapper. The container is typically a module, class, or instance.