[PATCH 2 of 7] blackbox: send debug message to logger by core ui
Yuya Nishihara
yuya at tcha.org
Tue Nov 27 07:57:39 EST 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1541925286 -32400
# Sun Nov 11 17:34:46 2018 +0900
# Node ID 29e1cd661c3c67c2099af4dd21631bee0df172ed
# Parent ee25cad69149d026527056398ec6df3f9122e5a6
blackbox: send debug message to logger by core ui
Since the core ui.log() may recurse into ui.log() through ui.debug(), it
must guard against recursion.
The ui extension class can finally be removed.
diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -52,7 +52,6 @@ from mercurial import (
encoding,
pycompat,
registrar,
- ui as uimod,
)
from mercurial.utils import (
dateutil,
@@ -129,7 +128,6 @@ def _openlogfile(ui, vfs):
class blackboxlogger(object):
def __init__(self, ui):
self._repo = None
- self._inlog = False
self._trackedevents = set(ui.configlist('blackbox', 'track'))
@property
@@ -158,10 +156,6 @@ class blackboxlogger(object):
_lastlogger._log(ui, event, msg, opts)
def _log(self, ui, event, msg, opts):
- if self._inlog:
- # recursion guard
- return
- self._inlog = True
default = ui.configdate('devel', 'default-date')
date = dateutil.datestr(default, ui.config('blackbox', 'date-format'))
user = procutil.getuser()
@@ -189,25 +183,10 @@ class blackboxlogger(object):
self._repo = None
ui.debug('warning: cannot write to blackbox.log: %s\n' %
encoding.strtolocal(err.strerror))
- else:
- self._inlog = False
def setrepo(self, repo):
self._repo = repo
-def wrapui(ui):
- class blackboxui(ui.__class__):
- def debug(self, *msg, **opts):
- super(blackboxui, self).debug(*msg, **opts)
- if self.debugflag:
- self.log('debug', '%s', ''.join(msg))
-
- ui.__class__ = blackboxui
- uimod.ui = blackboxui
-
-def uisetup(ui):
- wrapui(ui)
-
def uipopulate(ui):
ui.setlogger(b'blackbox', blackboxlogger(ui))
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1521,6 +1521,7 @@ class ui(object):
'''
if self.debugflag:
self._writemsg(self._fmsgout, type='debug', *msg, **opts)
+ self.log(b'debug', b'%s', b''.join(msg))
def edit(self, text, user, extra=None, editform=None, pending=None,
repopath=None, action=None):
@@ -1740,8 +1741,14 @@ class ui(object):
if l.tracked(event)]
if not activeloggers:
return
- for logger in activeloggers:
- logger.log(self, event, msg, opts)
+ # guard against recursion from e.g. ui.debug()
+ registeredloggers = self._loggers
+ self._loggers = {}
+ try:
+ for logger in activeloggers:
+ logger.log(self, event, msg, opts)
+ finally:
+ self._loggers = registeredloggers
def label(self, msg, label):
'''style msg based on supplied label
More information about the Mercurial-devel
mailing list