comparison hgext/blackbox.py @ 18831:17f6644a2fbc

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.
author Bryan O'Sullivan <bryano@fb.com>
date Tue, 26 Mar 2013 16:27:51 -0700
parents ac0336471ba7
children 63a783d1ac85
comparison
equal deleted inserted replaced
18830:6b827d84d286 18831:17f6644a2fbc
45 if not '*' in self.track and not event in self.track: 45 if not '*' in self.track and not event in self.track:
46 return 46 return
47 47
48 if util.safehasattr(self, '_blackbox'): 48 if util.safehasattr(self, '_blackbox'):
49 blackbox = self._blackbox 49 blackbox = self._blackbox
50 elif util.safehasattr(self, '_bbopener'):
51 try:
52 self._blackbox = self._bbopener('blackbox.log', 'a')
53 except (IOError, OSError), err:
54 self.debug('warning: cannot write to blackbox.log: %s\n' %
55 err.strerror)
56 del self._bbopener
57 self._blackbox = None
58 blackbox = self._blackbox
50 else: 59 else:
51 # certain ui instances exist outside the context of 60 # certain ui instances exist outside the context of
52 # a repo, so just default to the last blackbox that 61 # a repo, so just default to the last blackbox that
53 # was seen. 62 # was seen.
54 blackbox = lastblackbox 63 blackbox = lastblackbox
63 self.debug('warning: cannot write to blackbox.log: %s\n' % 72 self.debug('warning: cannot write to blackbox.log: %s\n' %
64 err.strerror) 73 err.strerror)
65 lastblackbox = blackbox 74 lastblackbox = blackbox
66 75
67 def setrepo(self, repo): 76 def setrepo(self, repo):
68 try: 77 self._bbopener = repo.opener
69 self._blackbox = repo.opener('blackbox.log', 'a')
70 except (IOError, OSError), err:
71 self.debug('warning: cannot write to blackbox.log: %s\n' %
72 err.strerror)
73 self._blackbox = None
74 78
75 ui.__class__ = blackboxui 79 ui.__class__ = blackboxui
76 80
77 def uisetup(ui): 81 def uisetup(ui):
78 wrapui(ui) 82 wrapui(ui)