[PATCH 5 of 8] blackbox: log dirty state

timeless timeless at mozdev.org
Wed Feb 24 15:10:49 EST 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1455032653 0
#      Tue Feb 09 15:44:13 2016 +0000
# Node ID 1c7c84429436f4a27fed1749963458267c12288e
# Parent  f2cba1976f189c3b83c16da58925e88826662bcf
blackbox: log dirty state

If blackbox.dirty = True, use `+` to indicate dirty repositories.

diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -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' %
diff --git a/tests/test-blackbox.t b/tests/test-blackbox.t
--- a/tests/test-blackbox.t
+++ b/tests/test-blackbox.t
@@ -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
 
diff --git a/tests/test-tags.t b/tests/test-tags.t
--- a/tests/test-tags.t
+++ b/tests/test-tags.t
@@ -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


More information about the Mercurial-devel mailing list