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

blackbox: rename variables to prepare extracting core logic from ui wrapper

I'm going to add ui.setlogger() function so that I can enable logging feature
in command server without extending ui.__class__. This prepares for it.

"self" will be a logger instance, so this patch renames some of them to "ui".
parent 9c3c697267db
No related branches found
No related tags found
No related merge requests found
......@@ -91,7 +91,7 @@
default='%Y/%m/%d %H:%M:%S',
)
lastui = None
_lastlogger = None
def _openlogfile(ui, vfs):
def rotate(oldpath, newpath):
......@@ -149,10 +149,10 @@
self.log('debug', '%s', ''.join(msg))
def log(self, event, *msg, **opts):
global lastui
global _lastlogger
super(blackboxui, self).log(event, *msg, **opts)
if not '*' in self.track and not event in self.track:
return
if self._bbvfs:
......@@ -153,14 +153,14 @@
super(blackboxui, self).log(event, *msg, **opts)
if not '*' in self.track and not event in self.track:
return
if self._bbvfs:
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
_lastlogger = self
elif _lastlogger and _lastlogger._bbvfs:
# certain logger instances exist outside the context of
# a repo, so just default to the last blackbox logger that
# was seen.
pass
else:
return
......@@ -163,6 +163,6 @@
# was seen.
pass
else:
return
lastui._log(event, msg, opts)
_lastlogger._log(self, event, msg, opts)
......@@ -168,6 +168,6 @@
def _log(self, event, msg, opts):
def _log(self, ui, event, msg, opts):
if getattr(self, '_bbinlog', False):
# recursion and failure guard
return
self._bbinlog = True
......@@ -170,6 +170,6 @@
if getattr(self, '_bbinlog', False):
# recursion and failure guard
return
self._bbinlog = True
default = self.configdate('devel', 'default-date')
default = ui.configdate('devel', 'default-date')
date = dateutil.datestr(default,
......@@ -175,5 +175,5 @@
date = dateutil.datestr(default,
self.config('blackbox', 'date-format'))
ui.config('blackbox', 'date-format'))
user = procutil.getuser()
pid = '%d' % procutil.getpid()
formattedmsg = msg[0] % msg[1:]
......@@ -182,6 +182,6 @@
ctx = self._bbrepo[None]
parents = ctx.parents()
rev = ('+'.join([hex(p.node()) for p in parents]))
if (self.configbool('blackbox', 'dirty') and
if (ui.configbool('blackbox', 'dirty') and
ctx.dirty(missing=True, merge=False, branch=False)):
changed = '+'
......@@ -186,9 +186,9 @@
ctx.dirty(missing=True, merge=False, branch=False)):
changed = '+'
if self.configbool('blackbox', 'logsource'):
if ui.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)
......@@ -189,9 +189,9 @@
src = ' [%s]' % event
else:
src = ''
try:
fmt = '%s %s @%s%s (%s)%s> %s'
args = (date, user, rev, changed, pid, src, formattedmsg)
with _openlogfile(self, self._bbvfs) as fp:
with _openlogfile(ui, self._bbvfs) as fp:
fp.write(fmt % args)
except (IOError, OSError) as err:
......@@ -196,7 +196,7 @@
fp.write(fmt % args)
except (IOError, OSError) as err:
self.debug('warning: cannot write to blackbox.log: %s\n' %
encoding.strtolocal(err.strerror))
ui.debug('warning: cannot write to blackbox.log: %s\n' %
encoding.strtolocal(err.strerror))
# do not restore _bbinlog intentionally to avoid failed
# logging again
else:
......@@ -219,5 +219,6 @@
return
if util.safehasattr(ui, 'setrepo'):
ui.setrepo(repo)
logger = ui
logger.setrepo(repo)
......@@ -223,3 +224,3 @@
# Set lastui even if ui.log is not called. This gives blackbox a
# Set _lastlogger even if ui.log is not called. This gives blackbox a
# fallback place to log.
......@@ -225,7 +226,7 @@
# fallback place to log.
global lastui
if lastui is None:
lastui = ui
global _lastlogger
if _lastlogger is None:
_lastlogger = logger
repo._wlockfreeprefix.add('blackbox.log')
......
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