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 @@ ...@@ -156,8 +156,8 @@
return return
if self._bbvfs: if self._bbvfs:
ui = lastui = self lastui = self
elif lastui and lastui._bbvfs: elif lastui and lastui._bbvfs:
# certain ui instances exist outside the context of # certain ui instances exist outside the context of
# a repo, so just default to the last blackbox that # a repo, so just default to the last blackbox that
# was seen. # was seen.
...@@ -160,7 +160,7 @@ ...@@ -160,7 +160,7 @@
elif lastui and lastui._bbvfs: elif lastui and lastui._bbvfs:
# certain ui instances exist outside the context of # certain ui instances exist outside the context of
# a repo, so just default to the last blackbox that # a repo, so just default to the last blackbox that
# was seen. # was seen.
ui = lastui pass
else: else:
return return
...@@ -165,3 +165,4 @@ ...@@ -165,3 +165,4 @@
else: else:
return return
lastui._log(event, msg, opts)
...@@ -167,4 +168,5 @@ ...@@ -167,4 +168,5 @@
if getattr(ui, '_bbinlog', False): def _log(self, event, msg, opts):
if getattr(self, '_bbinlog', False):
# recursion and failure guard # recursion and failure guard
return return
...@@ -169,5 +171,5 @@ ...@@ -169,5 +171,5 @@
# recursion and failure guard # recursion and failure guard
return return
ui._bbinlog = True self._bbinlog = True
default = self.configdate('devel', 'default-date') default = self.configdate('devel', 'default-date')
date = dateutil.datestr(default, date = dateutil.datestr(default,
...@@ -172,8 +174,8 @@ ...@@ -172,8 +174,8 @@
default = self.configdate('devel', 'default-date') default = self.configdate('devel', 'default-date')
date = dateutil.datestr(default, date = dateutil.datestr(default,
ui.config('blackbox', 'date-format')) self.config('blackbox', 'date-format'))
user = procutil.getuser() user = procutil.getuser()
pid = '%d' % procutil.getpid() pid = '%d' % procutil.getpid()
formattedmsg = msg[0] % msg[1:] formattedmsg = msg[0] % msg[1:]
rev = '(unknown)' rev = '(unknown)'
changed = '' changed = ''
...@@ -175,8 +177,8 @@ ...@@ -175,8 +177,8 @@
user = procutil.getuser() user = procutil.getuser()
pid = '%d' % procutil.getpid() pid = '%d' % procutil.getpid()
formattedmsg = msg[0] % msg[1:] formattedmsg = msg[0] % msg[1:]
rev = '(unknown)' rev = '(unknown)'
changed = '' changed = ''
ctx = ui._bbrepo[None] ctx = self._bbrepo[None]
parents = ctx.parents() parents = ctx.parents()
rev = ('+'.join([hex(p.node()) for p in parents])) rev = ('+'.join([hex(p.node()) for p in parents]))
...@@ -181,5 +183,5 @@ ...@@ -181,5 +183,5 @@
parents = ctx.parents() parents = ctx.parents()
rev = ('+'.join([hex(p.node()) for p in 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)): ctx.dirty(missing=True, merge=False, branch=False)):
changed = '+' changed = '+'
...@@ -184,9 +186,9 @@ ...@@ -184,9 +186,9 @@
ctx.dirty(missing=True, merge=False, branch=False)): ctx.dirty(missing=True, merge=False, branch=False)):
changed = '+' changed = '+'
if ui.configbool('blackbox', 'logsource'): if self.configbool('blackbox', 'logsource'):
src = ' [%s]' % event src = ' [%s]' % event
else: else:
src = '' src = ''
try: try:
fmt = '%s %s @%s%s (%s)%s> %s' fmt = '%s %s @%s%s (%s)%s> %s'
args = (date, user, rev, changed, pid, src, formattedmsg) args = (date, user, rev, changed, pid, src, formattedmsg)
...@@ -187,10 +189,10 @@ ...@@ -187,10 +189,10 @@
src = ' [%s]' % event src = ' [%s]' % event
else: else:
src = '' src = ''
try: try:
fmt = '%s %s @%s%s (%s)%s> %s' fmt = '%s %s @%s%s (%s)%s> %s'
args = (date, user, rev, changed, pid, src, formattedmsg) 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) fp.write(fmt % args)
except (IOError, OSError) as err: except (IOError, OSError) as err:
self.debug('warning: cannot write to blackbox.log: %s\n' % self.debug('warning: cannot write to blackbox.log: %s\n' %
...@@ -198,7 +200,7 @@ ...@@ -198,7 +200,7 @@
# do not restore _bbinlog intentionally to avoid failed # do not restore _bbinlog intentionally to avoid failed
# logging again # logging again
else: else:
ui._bbinlog = False self._bbinlog = False
def setrepo(self, repo): def setrepo(self, repo):
self._bbrepo = 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