# HG changeset patch # User Bryan O'Sullivan # Date 2013-03-26 23:27:51 # Node ID 17f6644a2fbca63c37880ffbd8bc43e05a14837f # Parent 6b827d84d286bf299ede4c677d56727f991e2111 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. diff --git a/hgext/blackbox.py b/hgext/blackbox.py --- a/hgext/blackbox.py +++ b/hgext/blackbox.py @@ -47,6 +47,15 @@ def wrapui(ui): 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 @@ def wrapui(ui): 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