# HG changeset patch # User timeless # Date 2016-03-08 20:34:59 # Node ID 63da8bd0c65e97a6f47a16475f22781c4c6ab2c7 # Parent 0767c2f624c633dfea28f891671cb4a19019d9cf 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 @@ def wrapui(ui): self._partialinit() else: self._bbfp = src._bbfp + self._bbinlog = False self._bbrepo = src._bbrepo self._bbvfs = src._bbvfs @@ -88,6 +89,7 @@ def wrapui(ui): if util.safehasattr(self, '_bbvfs'): return self._bbfp = None + self._bbinlog = False self._bbrepo = None self._bbvfs = None @@ -160,7 +162,15 @@ def wrapui(ui): # 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 @@ def wrapui(ui): 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 @@ log rotation 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 < 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 ..