[PATCH 4 of 4] blackbox: guard against recursion from dirty check

timeless timeless at mozdev.org
Tue Mar 8 16:17:42 EST 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1457469299 0
#      Tue Mar 08 20:34:59 2016 +0000
# Node ID 816760dbefca222c90e87821ae7c663ef78b4fb7
# Parent  73f4cb2be4cad13d1dbc72f96611cada9b6fe19c
blackbox: guard against recursion from dirty check

diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -81,6 +81,7 @@
                 self._partialinit()
             else:
                 self._bbfp = src._bbfp
+                self._bbinlog = False
                 self._bbrepo = src._bbrepo
                 self._bbvfs = src._bbvfs
 
@@ -88,6 +89,7 @@
             if util.safehasattr(self, '_bbvfs'):
                 return
             self._bbfp = None
+            self._bbinlog = False
             self._bbrepo = None
             self._bbvfs = None
 
@@ -160,7 +162,15 @@
                 # was seen.
                 ui = lastui
 
-            if ui and ui._bbfp:
+            if not ui or not ui._bbfp:
+                return
+            if not lastui or ui._bbrepo:
+                lastui = ui
+            if ui._bbinlog:
+                # recursion guard
+                return
+            try:
+                ui._bbinlog = True
                 date = util.datestr(None, '%Y/%m/%d %H:%M:%S')
                 user = util.getuser()
                 pid = str(util.getpid())
@@ -186,11 +196,12 @@
                 except IOError as err:
                     self.debug('warning: cannot write to blackbox.log: %s\n' %
                                err.strerror)
-                if not lastui or ui._bbrepo:
-                    lastui = ui
+            finally:
+                ui._bbinlog = False
 
         def setrepo(self, repo):
             self._bbfp = None
+            self._bbinlog = False
             self._bbrepo = repo
             self._bbvfs = repo.vfs
 
diff --git a/tests/test-blackbox.t b/tests/test-blackbox.t
--- a/tests/test-blackbox.t
+++ b/tests/test-blackbox.t
@@ -191,5 +191,19 @@
   1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> log -r tip exited 0 after * seconds (glob)
   1970/01/01 00:00:00 bob @45589e459b2edfbf3dbde7e01f611d2c1e7453d7 (5000)> blackbox
 
+Test log recursion from dirty status check
+
+  $ cat > ../r.py <<EOF
+  > from mercurial import context, error, extensions
+  > x=[False]
+  > def status(orig, *args, **opts):
+  >     args[0].repo().ui.log("broken", "recursion?")
+  >     return orig(*args, **opts)
+  > def reposetup(ui, repo):
+  >     extensions.wrapfunction(context.basectx, 'status', status)
+  > EOF
+  $ hg id --config extensions.x=../r.py --config blackbox.dirty=True
+  45589e459b2e tip
+
 cleanup
   $ cd ..


More information about the Mercurial-devel mailing list