Patchwork [5,of,8,v2] blackbox: refactor use of vfs as _bbvfs

login
register
mail settings
Submitter timeless@mozdev.org
Date Feb. 8, 2016, 6:15 a.m.
Message ID <99aa1e5f3b7e24afe979.1454912107@waste.org>
Download mbox | patch
Permalink /patch/13040/
State Accepted
Commit a6db1163befab45bbe70a7dc13c12d7f6ab1a114
Headers show

Comments

timeless@mozdev.org - Feb. 8, 2016, 6:15 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1454892456 0
#      Mon Feb 08 00:47:36 2016 +0000
# Node ID 99aa1e5f3b7e24afe97954d95a5107858888240e
# Parent  f62002c3837f6e1a746db59a2210c5bc7fa4f0a4
blackbox: refactor use of vfs as _bbvfs

Patch

diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -51,23 +51,23 @@ 
         def _openlogfile(self):
             def rotate(oldpath, newpath):
                 try:
-                    os.unlink(newpath)
+                    self._bbvfs.unlink(newpath)
                 except OSError as err:
                     if err.errno != errno.ENOENT:
                         self.debug("warning: cannot remove '%s': %s\n" %
                                    (newpath, err.strerror))
                 try:
                     if newpath:
-                        os.rename(oldpath, newpath)
+                        self._bbvfs.rename(oldpath, newpath)
                 except OSError as err:
                     if err.errno != errno.ENOENT:
                         self.debug("warning: cannot rename '%s' to '%s': %s\n" %
                                    (newpath, oldpath, err.strerror))
 
-            fp = self._bbopener('blackbox.log', 'a')
+            fp = self._bbvfs('blackbox.log', 'a')
             maxsize = self.configbytes('blackbox', 'maxsize', 1048576)
             if maxsize > 0:
-                st = os.fstat(fp.fileno())
+                st = self._bbvfs.fstat(fp)
                 if st.st_size >= maxsize:
                     path = fp.name
                     fp.close()
@@ -77,7 +77,7 @@ 
                                newpath='%s.%d' % (path, i))
                     rotate(oldpath=path,
                            newpath=maxfiles > 0 and path + '.1')
-                    fp = self._bbopener('blackbox.log', 'a')
+                    fp = self._bbvfs('blackbox.log', 'a')
             return fp
 
         def log(self, event, *msg, **opts):
@@ -89,13 +89,13 @@ 
 
             if util.safehasattr(self, '_blackbox'):
                 blackbox = self._blackbox
-            elif util.safehasattr(self, '_bbopener'):
+            elif util.safehasattr(self, '_bbvfs'):
                 try:
                     self._blackbox = self._openlogfile()
                 except (IOError, OSError) as err:
                     self.debug('warning: cannot write to blackbox.log: %s\n' %
                                err.strerror)
-                    del self._bbopener
+                    del self._bbvfs
                     self._blackbox = None
                 blackbox = self._blackbox
             else:
@@ -119,7 +119,7 @@ 
                 lastblackbox = blackbox
 
         def setrepo(self, repo):
-            self._bbopener = repo.vfs
+            self._bbvfs = repo.vfs
 
     ui.__class__ = blackboxui
 
@@ -144,7 +144,7 @@ 
     '''view the recent repository events
     '''
 
-    if not os.path.exists(repo.join('blackbox.log')):
+    if not repo.vfs.exists('blackbox.log'):
         return
 
     limit = opts.get('limit')