##// END OF EJS Templates
blackbox: do not cache file objects...
Jun Wu -
r34111:cf04db16 default
parent child Browse files
Show More
@@ -80,7 +80,6 b' def wrapui(ui):'
80 80 if src is None:
81 81 self._partialinit()
82 82 else:
83 self._bbfp = getattr(src, '_bbfp', None)
84 83 self._bbinlog = False
85 84 self._bbrepo = getattr(src, '_bbrepo', None)
86 85 self._bbvfs = getattr(src, '_bbvfs', None)
@@ -88,7 +87,6 b' def wrapui(ui):'
88 87 def _partialinit(self):
89 88 if util.safehasattr(self, '_bbvfs'):
90 89 return
91 self._bbfp = None
92 90 self._bbinlog = False
93 91 self._bbrepo = None
94 92 self._bbvfs = None
@@ -143,16 +141,7 b' def wrapui(ui):'
143 141 if not '*' in self.track and not event in self.track:
144 142 return
145 143
146 if self._bbfp:
147 ui = self
148 elif self._bbvfs:
149 try:
150 self._bbfp = self._openlogfile()
151 except (IOError, OSError) as err:
152 self.debug('warning: cannot write to blackbox.log: %s\n' %
153 err.strerror)
154 del self._bbvfs
155 self._bbfp = None
144 if self._bbvfs:
156 145 ui = self
157 146 else:
158 147 # certain ui instances exist outside the context of
@@ -160,12 +149,12 b' def wrapui(ui):'
160 149 # was seen.
161 150 ui = lastui
162 151
163 if not ui or not ui._bbfp:
152 if not ui:
164 153 return
165 154 if not lastui or ui._bbrepo:
166 155 lastui = ui
167 156 if ui._bbinlog:
168 # recursion guard
157 # recursion and failure guard
169 158 return
170 159 try:
171 160 ui._bbinlog = True
@@ -188,19 +177,21 b' def wrapui(ui):'
188 177 else:
189 178 src = ''
190 179 try:
191 fp = ui._bbfp
192 180 fmt = '%s %s @%s%s (%s)%s> %s'
193 181 args = (date, user, rev, changed, pid, src, formattedmsg)
194 fp.write(fmt % args)
195 fp.flush()
196 except IOError as err:
182 with ui._openlogfile() as fp:
183 fp.write(fmt % args)
184 except (IOError, OSError) as err:
197 185 self.debug('warning: cannot write to blackbox.log: %s\n' %
198 186 err.strerror)
187 # do not restore _bbinlog intentionally to avoid failed
188 # logging again
189 else:
190 ui._bbinlog = False
199 191 finally:
200 ui._bbinlog = False
192 pass
201 193
202 194 def setrepo(self, repo):
203 self._bbfp = None
204 195 self._bbinlog = False
205 196 self._bbrepo = repo
206 197 self._bbvfs = repo.vfs
General Comments 0
You need to be logged in to leave comments. Login now