Skip to content
Snippets Groups Projects
Commit c9876c00d292 authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

blackbox: extract _log() function which is called after lastui is resolved

This makes sure that self is the solo ui instance used in _log().
parent 4a38a67d0e96
No related branches found
No related tags found
No related merge requests found
......@@ -156,8 +156,8 @@
return
if self._bbvfs:
ui = lastui = self
lastui = self
elif lastui and lastui._bbvfs:
# certain ui instances exist outside the context of
# a repo, so just default to the last blackbox that
# was seen.
......@@ -160,7 +160,7 @@
elif lastui and lastui._bbvfs:
# certain ui instances exist outside the context of
# a repo, so just default to the last blackbox that
# was seen.
ui = lastui
pass
else:
return
......@@ -165,3 +165,4 @@
else:
return
lastui._log(event, msg, opts)
......@@ -167,4 +168,5 @@
if getattr(ui, '_bbinlog', False):
def _log(self, event, msg, opts):
if getattr(self, '_bbinlog', False):
# recursion and failure guard
return
......@@ -169,5 +171,5 @@
# recursion and failure guard
return
ui._bbinlog = True
self._bbinlog = True
default = self.configdate('devel', 'default-date')
date = dateutil.datestr(default,
......@@ -172,8 +174,8 @@
default = self.configdate('devel', 'default-date')
date = dateutil.datestr(default,
ui.config('blackbox', 'date-format'))
self.config('blackbox', 'date-format'))
user = procutil.getuser()
pid = '%d' % procutil.getpid()
formattedmsg = msg[0] % msg[1:]
rev = '(unknown)'
changed = ''
......@@ -175,8 +177,8 @@
user = procutil.getuser()
pid = '%d' % procutil.getpid()
formattedmsg = msg[0] % msg[1:]
rev = '(unknown)'
changed = ''
ctx = ui._bbrepo[None]
ctx = self._bbrepo[None]
parents = ctx.parents()
rev = ('+'.join([hex(p.node()) for p in parents]))
......@@ -181,5 +183,5 @@
parents = ctx.parents()
rev = ('+'.join([hex(p.node()) for p in parents]))
if (ui.configbool('blackbox', 'dirty') and
if (self.configbool('blackbox', 'dirty') and
ctx.dirty(missing=True, merge=False, branch=False)):
changed = '+'
......@@ -184,9 +186,9 @@
ctx.dirty(missing=True, merge=False, branch=False)):
changed = '+'
if ui.configbool('blackbox', 'logsource'):
if self.configbool('blackbox', 'logsource'):
src = ' [%s]' % event
else:
src = ''
try:
fmt = '%s %s @%s%s (%s)%s> %s'
args = (date, user, rev, changed, pid, src, formattedmsg)
......@@ -187,10 +189,10 @@
src = ' [%s]' % event
else:
src = ''
try:
fmt = '%s %s @%s%s (%s)%s> %s'
args = (date, user, rev, changed, pid, src, formattedmsg)
with _openlogfile(ui, ui._bbvfs) as fp:
with _openlogfile(self, self._bbvfs) as fp:
fp.write(fmt % args)
except (IOError, OSError) as err:
self.debug('warning: cannot write to blackbox.log: %s\n' %
......@@ -198,7 +200,7 @@
# do not restore _bbinlog intentionally to avoid failed
# logging again
else:
ui._bbinlog = False
self._bbinlog = False
def setrepo(self, repo):
self._bbrepo = repo
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment