Patchwork [7,of,7] blackbox: initialize logger with repo instance

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 27, 2018, 12:57 p.m.
Message ID <2d10adb04855ae36aa05.1543323464@mimosa>
Download mbox | patch
Permalink /patch/36815/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 27, 2018, 12:57 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1541934338 -32400
#      Sun Nov 11 20:05:38 2018 +0900
# Node ID 2d10adb04855ae36aa059e072403b124a4416ffc
# Parent  47d8e701444c98d355794b1a398e25840557a2b1
blackbox: initialize logger with repo instance

The blackboxlogger is unusable without a repo. Let's simply initialize it
with a repo instance.

Patch

diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -139,17 +139,15 @@  class proxylogger(object):
 _lastlogger = proxylogger()
 
 class blackboxlogger(object):
-    def __init__(self, ui):
-        self._repo = None
+    def __init__(self, ui, repo):
+        self._repo = repo
         self._trackedevents = set(ui.configlist('blackbox', 'track'))
 
     @property
     def _bbvfs(self):
-        vfs = None
-        if self._repo:
-            vfs = self._repo.vfs
-            if not vfs.isdir('.'):
-                vfs = None
+        vfs = self._repo.vfs
+        if not vfs.isdir('.'):
+            vfs = None
         return vfs
 
     def tracked(self, event):
@@ -188,9 +186,6 @@  class blackboxlogger(object):
             ui.debug('warning: cannot write to blackbox.log: %s\n' %
                      encoding.strtolocal(err.strerror))
 
-    def setrepo(self, repo):
-        self._repo = repo
-
 def uipopulate(ui):
     ui.setlogger(b'blackbox', _lastlogger)
 
@@ -203,9 +198,8 @@  def reposetup(ui, repo):
 
     # Since blackbox.log is stored in the repo directory, the logger should be
     # instantiated per repository.
-    logger = blackboxlogger(ui)
+    logger = blackboxlogger(ui, repo)
     ui.setlogger(b'blackbox', logger)
-    logger.setrepo(repo)
 
     # Set _lastlogger even if ui.log is not called. This gives blackbox a
     # fallback place to log