Mercurial > hg
changeset 40759:fdc6eb1d650d
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.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 11 Nov 2018 17:34:46 +0900 |
parents | eb5948f29c60 |
children | ffd574c144d2 |
files | hgext/blackbox.py mercurial/ui.py |
diffstat | 2 files changed, 9 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/blackbox.py Sat Nov 17 20:23:50 2018 +0900 +++ b/hgext/blackbox.py Sun Nov 11 17:34:46 2018 +0900 @@ -52,7 +52,6 @@ encoding, pycompat, registrar, - ui as uimod, ) from mercurial.utils import ( dateutil, @@ -129,7 +128,6 @@ 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 @@ _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 @@ 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))
--- a/mercurial/ui.py Sat Nov 17 20:23:50 2018 +0900 +++ b/mercurial/ui.py Sun Nov 11 17:34:46 2018 +0900 @@ -1521,6 +1521,7 @@ ''' 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 @@ 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