[PATCH 06 of 10] chgserver: wrap ui/extsetup to learn how to do confighash dynamically

Jun Wu quark at fb.com
Thu Jun 30 12:59:01 EDT 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1467292155 -3600
#      Thu Jun 30 14:09:15 2016 +0100
# Node ID ae943c113c1b9f68313f0dfd7304e07dad53be75
# Parent  50d862642eb658dc28ca878a4ded89ab7303e3a9
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r ae943c113c1b
chgserver: wrap ui/extsetup to learn how to do confighash dynamically

This patch uses the new learnconfighash context manager to learn what configs
extensions are accessing and include them in confighash.

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -763,3 +763,21 @@ class _learnconfighash(object):
     def __exit__(self, exc_type, exc_value, traceback):
         _unwrapfuncs(self._wraplist)
         self._ui = None
+
+def _wrappedsetup(orig, extname, ui):
+    if extname == 'chgserver':
+        # do not learn what chgserver accesses
+        if orig.__name__ == '_runextsetup':
+            # reach the last ui/extsetup, stop wrapping
+            _unwrapfuncs(_setupwraplist)
+        return orig(extname, ui)
+    with _learnconfighash(ui, extname):
+        return orig(extname, ui)
+
+# wrap before any uisetup or extsetup is called. usually, extensions should
+# do these outside *setup functions. however, chgserver has to do the wrappings
+# right here for now. it should be able to have a better place after we move
+# chgserver.py to mercurial/.
+_setupwraplist = []
+_wrapfunc(extensions, '_runuisetup', _wrappedsetup, _setupwraplist)
+_wrapfunc(extensions, '_runextsetup', _wrappedsetup, _setupwraplist)


More information about the Mercurial-devel mailing list