##// END OF EJS Templates
blackbox: extract _log() function which is called after lastui is resolved...
Yuya Nishihara -
r40668:c9876c00 default
parent child Browse files
Show More
@@ -156,41 +156,43 b' def wrapui(ui):'
156 return
156 return
157
157
158 if self._bbvfs:
158 if self._bbvfs:
159 ui = lastui = self
159 lastui = self
160 elif lastui and lastui._bbvfs:
160 elif lastui and lastui._bbvfs:
161 # certain ui instances exist outside the context of
161 # certain ui instances exist outside the context of
162 # a repo, so just default to the last blackbox that
162 # a repo, so just default to the last blackbox that
163 # was seen.
163 # was seen.
164 ui = lastui
164 pass
165 else:
165 else:
166 return
166 return
167 lastui._log(event, msg, opts)
167
168
168 if getattr(ui, '_bbinlog', False):
169 def _log(self, event, msg, opts):
170 if getattr(self, '_bbinlog', False):
169 # recursion and failure guard
171 # recursion and failure guard
170 return
172 return
171 ui._bbinlog = True
173 self._bbinlog = True
172 default = self.configdate('devel', 'default-date')
174 default = self.configdate('devel', 'default-date')
173 date = dateutil.datestr(default,
175 date = dateutil.datestr(default,
174 ui.config('blackbox', 'date-format'))
176 self.config('blackbox', 'date-format'))
175 user = procutil.getuser()
177 user = procutil.getuser()
176 pid = '%d' % procutil.getpid()
178 pid = '%d' % procutil.getpid()
177 formattedmsg = msg[0] % msg[1:]
179 formattedmsg = msg[0] % msg[1:]
178 rev = '(unknown)'
180 rev = '(unknown)'
179 changed = ''
181 changed = ''
180 ctx = ui._bbrepo[None]
182 ctx = self._bbrepo[None]
181 parents = ctx.parents()
183 parents = ctx.parents()
182 rev = ('+'.join([hex(p.node()) for p in parents]))
184 rev = ('+'.join([hex(p.node()) for p in parents]))
183 if (ui.configbool('blackbox', 'dirty') and
185 if (self.configbool('blackbox', 'dirty') and
184 ctx.dirty(missing=True, merge=False, branch=False)):
186 ctx.dirty(missing=True, merge=False, branch=False)):
185 changed = '+'
187 changed = '+'
186 if ui.configbool('blackbox', 'logsource'):
188 if self.configbool('blackbox', 'logsource'):
187 src = ' [%s]' % event
189 src = ' [%s]' % event
188 else:
190 else:
189 src = ''
191 src = ''
190 try:
192 try:
191 fmt = '%s %s @%s%s (%s)%s> %s'
193 fmt = '%s %s @%s%s (%s)%s> %s'
192 args = (date, user, rev, changed, pid, src, formattedmsg)
194 args = (date, user, rev, changed, pid, src, formattedmsg)
193 with _openlogfile(ui, ui._bbvfs) as fp:
195 with _openlogfile(self, self._bbvfs) as fp:
194 fp.write(fmt % args)
196 fp.write(fmt % args)
195 except (IOError, OSError) as err:
197 except (IOError, OSError) as err:
196 self.debug('warning: cannot write to blackbox.log: %s\n' %
198 self.debug('warning: cannot write to blackbox.log: %s\n' %
@@ -198,7 +200,7 b' def wrapui(ui):'
198 # do not restore _bbinlog intentionally to avoid failed
200 # do not restore _bbinlog intentionally to avoid failed
199 # logging again
201 # logging again
200 else:
202 else:
201 ui._bbinlog = False
203 self._bbinlog = False
202
204
203 def setrepo(self, repo):
205 def setrepo(self, repo):
204 self._bbrepo = repo
206 self._bbrepo = repo
General Comments 0
You need to be logged in to leave comments. Login now