D655: blackbox: set lastui even if ui.log is not called (issue5518)
quark (Jun Wu)
phabricator at mercurial-scm.org
Thu Sep 7 05:33:08 UTC 2017
quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
Running the added test case using the old code, it won't log anything in
blackbox.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D655
AFFECTED FILES
hgext/blackbox.py
tests/test-blackbox.t
CHANGE DETAILS
diff --git a/tests/test-blackbox.t b/tests/test-blackbox.t
--- a/tests/test-blackbox.t
+++ b/tests/test-blackbox.t
@@ -15,13 +15,15 @@
$ 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
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
@@ -285,3 +288,40 @@
#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
+
diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -197,6 +197,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',
To: quark, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list