##// END OF EJS Templates
blackbox: unindent "if True" block
Yuya Nishihara -
r40681:fff3e213 default
parent child Browse files
Show More
@@ -127,75 +127,73 b' def _openlogfile(ui, vfs):'
127 newpath=maxfiles > 0 and path + '.1')
127 newpath=maxfiles > 0 and path + '.1')
128 return vfs(name, 'a')
128 return vfs(name, 'a')
129
129
130 if True:
130 class blackboxlogger(object):
131 class blackboxlogger(object):
131 def __init__(self, ui):
132 def __init__(self, ui):
132 self.track = ui.configlist('blackbox', 'track')
133 self.track = ui.configlist('blackbox', 'track')
134
133
135 @property
134 @property
136 def _bbvfs(self):
135 def _bbvfs(self):
137 vfs = None
136 vfs = None
138 repo = getattr(self, '_bbrepo', None)
137 repo = getattr(self, '_bbrepo', None)
139 if repo:
138 if repo:
140 vfs = repo.vfs
139 vfs = repo.vfs
141 if not vfs.isdir('.'):
140 if not vfs.isdir('.'):
142 vfs = None
141 vfs = None
143 return vfs
142 return vfs
144
143
145 def log(self, ui, event, msg, opts):
144 def log(self, ui, event, msg, opts):
146 global _lastlogger
145 global _lastlogger
147 if not '*' in self.track and not event in self.track:
146 if not '*' in self.track and not event in self.track:
148 return
147 return
149
148
150 if self._bbvfs:
149 if self._bbvfs:
151 _lastlogger = self
150 _lastlogger = self
152 elif _lastlogger and _lastlogger._bbvfs:
151 elif _lastlogger and _lastlogger._bbvfs:
153 # certain logger instances exist outside the context of
152 # certain logger instances exist outside the context of
154 # a repo, so just default to the last blackbox logger that
153 # a repo, so just default to the last blackbox logger that
155 # was seen.
154 # was seen.
156 pass
155 pass
157 else:
156 else:
158 return
157 return
159 _lastlogger._log(ui, event, msg, opts)
158 _lastlogger._log(ui, event, msg, opts)
160
159
161 def _log(self, ui, event, msg, opts):
160 def _log(self, ui, event, msg, opts):
162 if getattr(self, '_bbinlog', False):
161 if getattr(self, '_bbinlog', False):
163 # recursion and failure guard
162 # recursion and failure guard
164 return
163 return
165 self._bbinlog = True
164 self._bbinlog = True
166 default = ui.configdate('devel', 'default-date')
165 default = ui.configdate('devel', 'default-date')
167 date = dateutil.datestr(default,
166 date = dateutil.datestr(default, ui.config('blackbox', 'date-format'))
168 ui.config('blackbox', 'date-format'))
167 user = procutil.getuser()
169 user = procutil.getuser()
168 pid = '%d' % procutil.getpid()
170 pid = '%d' % procutil.getpid()
169 formattedmsg = msg[0] % msg[1:]
171 formattedmsg = msg[0] % msg[1:]
170 rev = '(unknown)'
172 rev = '(unknown)'
171 changed = ''
173 changed = ''
172 ctx = self._bbrepo[None]
174 ctx = self._bbrepo[None]
173 parents = ctx.parents()
175 parents = ctx.parents()
174 rev = ('+'.join([hex(p.node()) for p in parents]))
176 rev = ('+'.join([hex(p.node()) for p in parents]))
175 if (ui.configbool('blackbox', 'dirty') and
177 if (ui.configbool('blackbox', 'dirty') and
176 ctx.dirty(missing=True, merge=False, branch=False)):
178 ctx.dirty(missing=True, merge=False, branch=False)):
177 changed = '+'
179 changed = '+'
178 if ui.configbool('blackbox', 'logsource'):
180 if ui.configbool('blackbox', 'logsource'):
179 src = ' [%s]' % event
181 src = ' [%s]' % event
180 else:
182 else:
181 src = ''
183 src = ''
182 try:
184 try:
183 fmt = '%s %s @%s%s (%s)%s> %s'
185 fmt = '%s %s @%s%s (%s)%s> %s'
184 args = (date, user, rev, changed, pid, src, formattedmsg)
186 args = (date, user, rev, changed, pid, src, formattedmsg)
185 with _openlogfile(ui, self._bbvfs) as fp:
187 with _openlogfile(ui, self._bbvfs) as fp:
186 fp.write(fmt % args)
188 fp.write(fmt % args)
187 except (IOError, OSError) as err:
189 except (IOError, OSError) as err:
188 ui.debug('warning: cannot write to blackbox.log: %s\n' %
190 ui.debug('warning: cannot write to blackbox.log: %s\n' %
189 encoding.strtolocal(err.strerror))
191 encoding.strtolocal(err.strerror))
190 # do not restore _bbinlog intentionally to avoid failed
192 # do not restore _bbinlog intentionally to avoid failed
191 # logging again
193 # logging again
192 else:
194 else:
193 self._bbinlog = False
195 self._bbinlog = False
196
194
197 def setrepo(self, repo):
195 def setrepo(self, repo):
198 self._bbrepo = repo
196 self._bbrepo = repo
199
197
200 def wrapui(ui):
198 def wrapui(ui):
201 class blackboxui(ui.__class__):
199 class blackboxui(ui.__class__):
General Comments 0
You need to be logged in to leave comments. Login now