[PATCH 04 of 10] chgserver: add utilities to wrap and unwrap functions
Jun Wu
quark at fb.com
Thu Jun 30 12:58:59 EDT 2016
# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1467279489 -3600
# Thu Jun 30 10:38:09 2016 +0100
# Node ID c02da7bd56e98cf4e905550859031079ed9beb18
# Parent 169a0f4db80746bcd7ae1e04ae1daa2e4e0d9872
# Available At https://bitbucket.org/quark-zju/hg-draft
# hg pull https://bitbucket.org/quark-zju/hg-draft -r c02da7bd56e9
chgserver: add utilities to wrap and unwrap functions
We want to wrap and unwrap functions. So we record what is wrapped and
restore them later.
diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -713,3 +713,18 @@ def uisetup(ui):
# start another chg. drop it to avoid possible side effects.
if 'CHGINTERNALMARK' in os.environ:
del os.environ['CHGINTERNALMARK']
+
+def _wrapfunc(obj, name, newfunc, wraplist):
+ # like extensions.wrapfunction, but log what is wrapped to wraplist
+ oldfunc = getattr(obj, name)
+ extensions.wrapfunction(obj, name, newfunc)
+ newfunc = getattr(obj, name)
+ wraplist.append((obj, name, oldfunc, newfunc))
+
+def _unwrapfuncs(wraplist):
+ for obj, name, oldfunc, newfunc in wraplist:
+ if getattr(obj, name) == newfunc:
+ setattr(obj, name, oldfunc)
+ else:
+ raise RuntimeError('%s cannot be restored' % name)
+ wraplist[:] = []
More information about the Mercurial-devel
mailing list