blackbox: defer opening a log file until needed (issue3869)
authorBryan O'Sullivan <bryano@fb.com>
Tue, 26 Mar 2013 16:27:51 -0700
changeset 18831 17f6644a2fbc
parent 18830 6b827d84d286
child 18832 a911e5dc2b00
blackbox: defer opening a log file until needed (issue3869) Previously, we opened the log file when creating a repo object. This was inefficient (not all repo creation is going to result in a need to log something), but more importantly it broke subrepo updates when used on NFS. * perform an update in the master repo that triggers a subrepo clone * empty subrepo already exists, and has an open, empty blackbox.log file due to it being opened eagerly/prematurely * hg decides to blow away the skeletal subrepo (see use of shutil.rmtree in subrepo._get) * we crash, due to NFS treating a delete of an open file as really a rename to a hidden ".nfs" file Now that we open the blackbox log file on demand, no file exists at the time the empty subrepo is deleted, so the above problem does not occur.
hgext/blackbox.py
--- a/hgext/blackbox.py	Fri Mar 22 17:27:06 2013 -0500
+++ b/hgext/blackbox.py	Tue Mar 26 16:27:51 2013 -0700
@@ -47,6 +47,15 @@
 
             if util.safehasattr(self, '_blackbox'):
                 blackbox = self._blackbox
+            elif util.safehasattr(self, '_bbopener'):
+                try:
+                    self._blackbox = self._bbopener('blackbox.log', 'a')
+                except (IOError, OSError), err:
+                    self.debug('warning: cannot write to blackbox.log: %s\n' %
+                               err.strerror)
+                    del self._bbopener
+                    self._blackbox = None
+                blackbox = self._blackbox
             else:
                 # certain ui instances exist outside the context of
                 # a repo, so just default to the last blackbox that
@@ -65,12 +74,7 @@
                 lastblackbox = blackbox
 
         def setrepo(self, repo):
-            try:
-                self._blackbox = repo.opener('blackbox.log', 'a')
-            except (IOError, OSError), err:
-                self.debug('warning: cannot write to blackbox.log: %s\n' %
-                           err.strerror)
-                self._blackbox = None
+            self._bbopener = repo.opener
 
     ui.__class__ = blackboxui