comparison hgext/blackbox.py @ 28246:b862e793ec10

blackbox: log dirty state If blackbox.dirty = True, use `+` to indicate dirty repositories.
author timeless <timeless@mozdev.org>
date Tue, 09 Feb 2016 15:44:13 +0000
parents caa2a0c6fbb7
children d2c0527af364
comparison
equal deleted inserted replaced
28245:caa2a0c6fbb7 28246:b862e793ec10
8 8
9 """log repository events to a blackbox for debugging 9 """log repository events to a blackbox for debugging
10 10
11 Logs event information to .hg/blackbox.log to help debug and diagnose problems. 11 Logs event information to .hg/blackbox.log to help debug and diagnose problems.
12 The events that get logged can be configured via the blackbox.track config key. 12 The events that get logged can be configured via the blackbox.track config key.
13
14 If you want to record whether the repository is dirty (a `+` sign, as you'd
15 get when using :hg:`id`), you can set the blackbox.dirty config key.
16
13 Examples:: 17 Examples::
14 18
15 [blackbox] 19 [blackbox]
16 track = * 20 track = *
21 dirty = True
17 22
18 [blackbox] 23 [blackbox]
19 track = command, commandfinish, commandexception, exthook, pythonhook 24 track = command, commandfinish, commandexception, exthook, pythonhook
20 25
21 [blackbox] 26 [blackbox]
138 date = util.datestr(None, '%Y/%m/%d %H:%M:%S') 143 date = util.datestr(None, '%Y/%m/%d %H:%M:%S')
139 user = util.getuser() 144 user = util.getuser()
140 pid = str(util.getpid()) 145 pid = str(util.getpid())
141 formattedmsg = msg[0] % msg[1:] 146 formattedmsg = msg[0] % msg[1:]
142 rev = '(unknown)' 147 rev = '(unknown)'
148 changed = ''
143 if util.safehasattr(self, '_bbrepo'): 149 if util.safehasattr(self, '_bbrepo'):
144 ctx = self._bbrepo[None] 150 ctx = self._bbrepo[None]
145 if ctx.rev() is not None: 151 if ctx.rev() is not None:
146 rev = hexfn(ctx.node()) 152 rev = hexfn(ctx.node())
147 else: 153 else:
148 parents = ctx.parents() 154 parents = ctx.parents()
149 rev = ('+'.join([hexfn(p.node()) for p in parents])) 155 rev = ('+'.join([hexfn(p.node()) for p in parents]))
150 try: 156 if (self.configbool('blackbox', 'dirty', False) and (
151 fp.write('%s %s @%s (%s)> %s' % 157 any(self._bbrepo.status()) or
152 (date, user, rev, pid, formattedmsg)) 158 any(ctx.sub(s).dirty() for s in ctx.substate)
159 )):
160 changed = '+'
161 try:
162 fp.write('%s %s @%s%s (%s)> %s' %
163 (date, user, rev, changed, pid, formattedmsg))
153 fp.flush() 164 fp.flush()
154 except IOError as err: 165 except IOError as err:
155 self.debug('warning: cannot write to blackbox.log: %s\n' % 166 self.debug('warning: cannot write to blackbox.log: %s\n' %
156 err.strerror) 167 err.strerror)
157 if not lastfp or util.safehasattr(self, '_bbrepo'): 168 if not lastfp or util.safehasattr(self, '_bbrepo'):