Comments
Patch
@@ -7,8 +7,10 @@
from __future__ import absolute_import
+import contextlib
import imp
import os
+import sys
from .i18n import (
_,
@@ -127,20 +129,31 @@ def load(ui, name, path):
fn(loaded=True)
return mod
+@contextlib.contextmanager
+def _checkuiescape(name, ui):
+ nref = sys.getrefcount(ui)
+ yield
+ nrefchange = sys.getrefcount(ui) - nref
+ if nrefchange > 0 and (ui.configbool('devel', 'all-warnings')
+ or ui.configbool('devel', 'check-uiescape')):
+ ui.develwarn('"ui" escaped from %s' % name, stacklevel=None)
+
def _runuisetup(name, ui):
- uisetup = getattr(_extensions[name], 'uisetup', None)
- if uisetup:
- uisetup(ui)
+ with _checkuiescape('%s.uisetup' % name, ui):
+ uisetup = getattr(_extensions[name], 'uisetup', None)
+ if uisetup:
+ uisetup(ui)
def _runextsetup(name, ui):
- extsetup = getattr(_extensions[name], 'extsetup', None)
- if extsetup:
- try:
- extsetup(ui)
- except TypeError:
- if extsetup.func_code.co_argcount != 0:
- raise
- extsetup() # old extsetup with no ui argument
+ with _checkuiescape('%s.extsetup' % name, ui):
+ extsetup = getattr(_extensions[name], 'extsetup', None)
+ if extsetup:
+ try:
+ extsetup(ui)
+ except TypeError:
+ if extsetup.func_code.co_argcount != 0:
+ raise
+ extsetup() # old extsetup with no ui argument
def loadall(ui):
result = ui.configitems("extensions")
@@ -1164,6 +1164,7 @@ class ui(object):
return
msg = 'devel-warn: ' + msg
if stacklevel is None:
+ self.write_err('%s\n' % msg)
self.log('develwarn', msg)
return
stacklevel += 1 # get in develwarn
@@ -1,4 +1,3 @@
-
$ cat << EOF > buggylocking.py
> """A small extension that tests our developer warnings
> """
@@ -74,6 +73,18 @@
> all-warnings=1
> EOF
+ $ cat << EOF > uiescape.py
+ > a = []
+ > def uisetup(ui):
+ > ui.write('ui escaping\n')
+ > a.append(ui)
+ > EOF
+
+ $ hg --config extensions.uiescape=uiescape.py version -q
+ ui escaping
+ devel-warn: "ui" escaped from uiescape.uisetup
+ Mercurial * (glob)
+
$ hg init lock-checker
$ cd lock-checker
$ hg buggylocking