Mercurial > hg
comparison hgext/blackbox.py @ 40993:49d48489a16b
blackbox: resurrect recursion guard
If I added ui.log() to hg.repository() function, test-merge-subrepos.t
exploded. The problem is that the blackbox may create new repository instance
while logging is active, and the created repository owns its new ui derived
from the baseui, not from the ui which is processing the active logging.
I tried to work around the issue in ui.log(), but that turned out to be not
easy. We shouldn't globally lock the ui.log() since there may be more than
one active repo/ui instances in threaded environment. We could store the
logging state in thread-local storage, but that seems unnecessarily complex.
So this patch reintroduces the _inlog flag to per-repository logger instances.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 15 Dec 2018 19:05:42 +0900 |
parents | 03127e580980 |
children | 876494fd967d |
comparison
equal
deleted
inserted
replaced
40992:1de3364320af | 40993:49d48489a16b |
---|---|
94 def __init__(self, ui, repo): | 94 def __init__(self, ui, repo): |
95 self._repo = repo | 95 self._repo = repo |
96 self._trackedevents = set(ui.configlist('blackbox', 'track')) | 96 self._trackedevents = set(ui.configlist('blackbox', 'track')) |
97 self._maxfiles = ui.configint('blackbox', 'maxfiles') | 97 self._maxfiles = ui.configint('blackbox', 'maxfiles') |
98 self._maxsize = ui.configbytes('blackbox', 'maxsize') | 98 self._maxsize = ui.configbytes('blackbox', 'maxsize') |
99 self._inlog = False | |
99 | 100 |
100 def tracked(self, event): | 101 def tracked(self, event): |
101 return b'*' in self._trackedevents or event in self._trackedevents | 102 return b'*' in self._trackedevents or event in self._trackedevents |
102 | 103 |
103 def log(self, ui, event, msg, opts): | 104 def log(self, ui, event, msg, opts): |
105 # self._log() -> ctx.dirty() may create new subrepo instance, which | |
106 # ui is derived from baseui. So the recursion guard in ui.log() | |
107 # doesn't work as it's local to the ui instance. | |
108 if self._inlog: | |
109 return | |
110 self._inlog = True | |
111 try: | |
112 self._log(ui, event, msg, opts) | |
113 finally: | |
114 self._inlog = False | |
115 | |
116 def _log(self, ui, event, msg, opts): | |
104 default = ui.configdate('devel', 'default-date') | 117 default = ui.configdate('devel', 'default-date') |
105 date = dateutil.datestr(default, ui.config('blackbox', 'date-format')) | 118 date = dateutil.datestr(default, ui.config('blackbox', 'date-format')) |
106 user = procutil.getuser() | 119 user = procutil.getuser() |
107 pid = '%d' % procutil.getpid() | 120 pid = '%d' % procutil.getpid() |
108 rev = '(unknown)' | 121 rev = '(unknown)' |