changeset 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
files hgext/blackbox.py tests/test-blackbox.t tests/test-tags.t
diffstat 3 files changed, 22 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/blackbox.py	Tue Feb 09 19:16:06 2016 +0000
+++ b/hgext/blackbox.py	Tue Feb 09 15:44:13 2016 +0000
@@ -10,10 +10,15 @@
 
 Logs event information to .hg/blackbox.log to help debug and diagnose problems.
 The events that get logged can be configured via the blackbox.track config key.
+
+If you want to record whether the repository is dirty (a `+` sign, as you'd
+get when using :hg:`id`), you can set the blackbox.dirty config key.
+
 Examples::
 
   [blackbox]
   track = *
+  dirty = True
 
   [blackbox]
   track = command, commandfinish, commandexception, exthook, pythonhook
@@ -140,6 +145,7 @@
                 pid = str(util.getpid())
                 formattedmsg = msg[0] % msg[1:]
                 rev = '(unknown)'
+                changed = ''
                 if util.safehasattr(self, '_bbrepo'):
                     ctx = self._bbrepo[None]
                     if ctx.rev() is not None:
@@ -147,9 +153,14 @@
                     else:
                         parents = ctx.parents()
                         rev = ('+'.join([hexfn(p.node()) for p in parents]))
+                        if (self.configbool('blackbox', 'dirty', False) and (
+                            any(self._bbrepo.status()) or
+                            any(ctx.sub(s).dirty() for s in ctx.substate)
+                        )):
+                            changed = '+'
                 try:
-                    fp.write('%s %s @%s (%s)> %s' %
-                        (date, user, rev, pid, formattedmsg))
+                    fp.write('%s %s @%s%s (%s)> %s' %
+                        (date, user, rev, changed, pid, formattedmsg))
                     fp.flush()
                 except IOError as err:
                     self.debug('warning: cannot write to blackbox.log: %s\n' %
--- a/tests/test-blackbox.t	Tue Feb 09 19:16:06 2016 +0000
+++ b/tests/test-blackbox.t	Tue Feb 09 15:44:13 2016 +0000
@@ -12,13 +12,13 @@
 
   $ echo a > a
   $ hg add a
-  $ hg id > /dev/null
-  $ hg blackbox
+  $ hg id --config blackbox.dirty=True > /dev/null
+  $ hg blackbox --config blackbox.dirty=True
   1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> add a
   1970/01/01 00:00:00 bob @(unknown) (5000)> add a exited 0 after * seconds (glob)
-  1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> id
-  1970/01/01 00:00:00 bob @(unknown) (5000)> id exited 0 after * seconds (glob)
-  1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> blackbox
+  1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000+ (5000)> id
+  1970/01/01 00:00:00 bob @(unknown) (5000)> id --config blackbox.dirty=True exited 0 after * seconds (glob)
+  1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000+ (5000)> blackbox
 
 incoming change tracking
 
--- a/tests/test-tags.t	Tue Feb 09 19:16:06 2016 +0000
+++ b/tests/test-tags.t	Tue Feb 09 15:44:13 2016 +0000
@@ -216,6 +216,10 @@
   $ hg merge 1
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
+  $ hg blackbox -l3
+  1970/01/01 00:00:00 bob @c8edf04160c7f731e4589d66ab3ab3486a64ac28 (5000)> merge 1
+  1970/01/01 00:00:00 bob @(unknown) (5000)> merge 1 exited 0 after * seconds (glob)
+  1970/01/01 00:00:00 bob @c8edf04160c7f731e4589d66ab3ab3486a64ac28+b9154636be938d3d431e75a7c906504a079bfe07 (5000)> blackbox -l3
   $ hg id
   c8edf04160c7+b9154636be93+ tip
   $ hg status