blackbox: set lastui even if ui.log is not called (
issue5518)
`lastui` decides where (where is the `.hg`) to use if the current `ui`
object does not have a `_bbrepo` associated. Previously it only gets set in
`ui.log`, which means unless a `ui` with repo associated calls `log` with
tracked event, blackbox does not know where to write its log. This patch
makes `reposetup` set `lastui` so it so we could log some more events (see
test changes).
Differential Revision: https://phab.mercurial-scm.org/D655
--- a/hgext/blackbox.py Wed Sep 06 21:23:38 2017 -0700
+++ b/hgext/blackbox.py Mon Sep 18 16:01:03 2017 -0700
@@ -192,6 +192,13 @@
if util.safehasattr(ui, 'setrepo'):
ui.setrepo(repo)
+
+ # Set lastui even if ui.log is not called. This gives blackbox a
+ # fallback place to log.
+ global lastui
+ if lastui is None:
+ lastui = ui
+
repo._wlockfreeprefix.add('blackbox.log')
@command('^blackbox',
--- a/tests/test-blackbox.t Wed Sep 06 21:23:38 2017 -0700
+++ b/tests/test-blackbox.t Mon Sep 18 16:01:03 2017 -0700
@@ -15,6 +15,7 @@
$ echo a > a
$ hg add a
$ hg blackbox --config blackbox.dirty=True
+ 1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> init blackboxtest exited 0 after * seconds (glob)
1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> add a
1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> add a exited 0 after * seconds (glob)
1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000+ (5000)> blackbox
@@ -22,6 +23,7 @@
alias expansion is logged
$ hg confuse
$ hg blackbox
+ 1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> init blackboxtest exited 0 after * seconds (glob)
1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> add a
1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> add a exited 0 after * seconds (glob)
1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000+ (5000)> blackbox
@@ -174,6 +176,7 @@
$ hg init blackboxtest3
$ cd blackboxtest3
$ hg blackbox
+ 1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> init blackboxtest3 exited 0 after * seconds (glob)
1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> blackbox
$ mv .hg/blackbox.log .hg/blackbox.log-
$ mkdir .hg/blackbox.log
@@ -284,3 +287,41 @@
$ cd ..
#endif
+
+blackbox should work if repo.ui.log is not called (issue5518)
+
+ $ cat > $TESTTMP/raise.py << EOF
+ > from __future__ import absolute_import
+ > from mercurial import registrar, scmutil
+ > cmdtable = {}
+ > command = registrar.command(cmdtable)
+ > @command('raise')
+ > def raisecmd(*args):
+ > raise RuntimeError('raise')
+ > EOF
+
+ $ cat >> $HGRCPATH << EOF
+ > [blackbox]
+ > track = commandexception
+ > [extensions]
+ > raise=$TESTTMP/raise.py
+ > EOF
+
+ $ hg init $TESTTMP/blackbox-exception-only
+ $ cd $TESTTMP/blackbox-exception-only
+
+#if chg
+ (chg exits 255 because it fails to receive an exit code)
+ $ hg raise 2>/dev/null
+ [255]
+#else
+ (hg exits 1 because Python default exit code for uncaught exception is 1)
+ $ hg raise 2>/dev/null
+ [1]
+#endif
+
+ $ head -1 .hg/blackbox.log
+ 1970/01/01 00:00:00 bob @0000000000000000000000000000000000000000 (5000)> ** Unknown exception encountered with possibly-broken third-party extension mock
+ $ tail -2 .hg/blackbox.log
+ RuntimeError: raise
+