diff hgext/blackbox.py @ 28245:caa2a0c6fbb7

blackbox: log working directory version Without this, while you could see the list of commands run, it wasn't possible to identify what they were doing, because commads could rely on revsets (including remote input which varies over time).
author timeless <timeless@mozdev.org>
date Tue, 09 Feb 2016 19:16:06 +0000
parents c17d7b1c40be
children b862e793ec10
line wrap: on
line diff
--- a/hgext/blackbox.py	Mon Feb 08 03:37:26 2016 +0000
+++ b/hgext/blackbox.py	Tue Feb 09 19:16:06 2016 +0000
@@ -35,6 +35,8 @@
 import re
 
 from mercurial.i18n import _
+from mercurial.node import hex
+
 from mercurial import (
     cmdutil,
     util,
@@ -64,6 +66,12 @@
     del filehandles[path]
     fp.close()
 
+def hexfn(node):
+    if node is None:
+        return None
+    else:
+        return hex(node)
+
 def wrapui(ui):
     class blackboxui(ui.__class__):
         @util.propertycache
@@ -131,17 +139,27 @@
                 user = util.getuser()
                 pid = str(util.getpid())
                 formattedmsg = msg[0] % msg[1:]
+                rev = '(unknown)'
+                if util.safehasattr(self, '_bbrepo'):
+                    ctx = self._bbrepo[None]
+                    if ctx.rev() is not None:
+                        rev = hexfn(ctx.node())
+                    else:
+                        parents = ctx.parents()
+                        rev = ('+'.join([hexfn(p.node()) for p in parents]))
                 try:
-                    fp.write('%s %s (%s)> %s' %
-                                   (date, user, pid, formattedmsg))
+                    fp.write('%s %s @%s (%s)> %s' %
+                        (date, user, rev, pid, formattedmsg))
                     fp.flush()
                 except IOError as err:
                     self.debug('warning: cannot write to blackbox.log: %s\n' %
                                err.strerror)
-                lastfp = fp
+                if not lastfp or util.safehasattr(self, '_bbrepo'):
+                    lastfp = fp
 
         def setrepo(self, repo):
             self._bbvfs = repo.vfs
+            self._bbrepo = repo
 
     ui.__class__ = blackboxui