Patchwork [3,of,8] blackbox: unindent "if True" block

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 15, 2018, 1:02 p.m.
Message ID <acb592903d0e8062e0a2.1542286964@mimosa>
Download mbox | patch
Permalink /patch/36606/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 15, 2018, 1:02 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1541924534 -32400
#      Sun Nov 11 17:22:14 2018 +0900
# Node ID acb592903d0e8062e0a2e8a5409bf9fe3262845f
# Parent  98b744aedd32e458d01b2ab9fb9e9e25ae0e7c34
blackbox: unindent "if True" block

Patch

diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -127,75 +127,73 @@  def _openlogfile(ui, vfs):
                        newpath=maxfiles > 0 and path + '.1')
     return vfs(name, 'a')
 
-if True:
-    class blackboxlogger(object):
-        def __init__(self, ui):
-            self.track = ui.configlist('blackbox', 'track')
+class blackboxlogger(object):
+    def __init__(self, ui):
+        self.track = ui.configlist('blackbox', 'track')
 
-        @property
-        def _bbvfs(self):
-            vfs = None
-            repo = getattr(self, '_bbrepo', None)
-            if repo:
-                vfs = repo.vfs
-                if not vfs.isdir('.'):
-                    vfs = None
-            return vfs
+    @property
+    def _bbvfs(self):
+        vfs = None
+        repo = getattr(self, '_bbrepo', None)
+        if repo:
+            vfs = repo.vfs
+            if not vfs.isdir('.'):
+                vfs = None
+        return vfs
 
-        def log(self, ui, event, msg, opts):
-            global _lastlogger
-            if not '*' in self.track and not event in self.track:
-                return
+    def log(self, ui, event, msg, opts):
+        global _lastlogger
+        if not '*' in self.track and not event in self.track:
+            return
 
-            if self._bbvfs:
-                _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
-            _lastlogger._log(ui, event, msg, opts)
+        if self._bbvfs:
+            _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
+        _lastlogger._log(ui, event, msg, opts)
 
-        def _log(self, ui, event, msg, opts):
-            if getattr(self, '_bbinlog', False):
-                # recursion and failure guard
-                return
-            self._bbinlog = True
-            default = ui.configdate('devel', 'default-date')
-            date = dateutil.datestr(default,
-                                    ui.config('blackbox', 'date-format'))
-            user = procutil.getuser()
-            pid = '%d' % procutil.getpid()
-            formattedmsg = msg[0] % msg[1:]
-            rev = '(unknown)'
-            changed = ''
-            ctx = self._bbrepo[None]
-            parents = ctx.parents()
-            rev = ('+'.join([hex(p.node()) for p in parents]))
-            if (ui.configbool('blackbox', 'dirty') and
-                ctx.dirty(missing=True, merge=False, branch=False)):
-                changed = '+'
-            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)
-                with _openlogfile(ui, self._bbvfs) as fp:
-                    fp.write(fmt % args)
-            except (IOError, OSError) as err:
-                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:
-                self._bbinlog = False
+    def _log(self, ui, event, msg, opts):
+        if getattr(self, '_bbinlog', False):
+            # recursion and failure guard
+            return
+        self._bbinlog = True
+        default = ui.configdate('devel', 'default-date')
+        date = dateutil.datestr(default, ui.config('blackbox', 'date-format'))
+        user = procutil.getuser()
+        pid = '%d' % procutil.getpid()
+        formattedmsg = msg[0] % msg[1:]
+        rev = '(unknown)'
+        changed = ''
+        ctx = self._bbrepo[None]
+        parents = ctx.parents()
+        rev = ('+'.join([hex(p.node()) for p in parents]))
+        if (ui.configbool('blackbox', 'dirty') and
+            ctx.dirty(missing=True, merge=False, branch=False)):
+            changed = '+'
+        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)
+            with _openlogfile(ui, self._bbvfs) as fp:
+                fp.write(fmt % args)
+        except (IOError, OSError) as err:
+            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:
+            self._bbinlog = False
 
-        def setrepo(self, repo):
-            self._bbrepo = repo
+    def setrepo(self, repo):
+        self._bbrepo = repo
 
 def wrapui(ui):
     class blackboxui(ui.__class__):