From a051eb159cfa6495c806001fa758dfb3ab58f4de Mon Sep 17 00:00:00 2001 From: Matt Harbison Date: Fri, 22 Jun 2018 16:06:35 -0400 Subject: [PATCH 1/3] #989 load global configuration in hgweb on Mercurial 4.1 and later --- .../src/main/resources/sonia/scm/python/hgweb.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/hgweb.py b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/hgweb.py index e2e7d8e931..7f99a85585 100644 --- a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/hgweb.py +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/hgweb.py @@ -36,7 +36,11 @@ from mercurial.hgweb import hgweb, wsgicgi demandimport.enable() -u = uimod.ui() +try: + u = uimod.ui.load() +except AttributeError: + # For installations earlier than Mercurial 4.1 + u = uimod.ui() # pass SCM_HTTP_POST_ARGS to enable experimental httppostargs protocol of mercurial # SCM_HTTP_POST_ARGS is set by HgCGIServlet From 2d103b7f958939cc912f9bcc55dae47cda7c1492 Mon Sep 17 00:00:00 2001 From: Matt Harbison Date: Fri, 22 Jun 2018 16:33:52 -0400 Subject: [PATCH 2/3] optionally print tracebacks when the Mercurial hook swallows an exception If `ui.traceback=True` is set on the server, this prints the stacktrace for the exception on the client side. Otherwise, nothing happens. I tried allowing the exception to propagate back to Mercurial, but then the client sees this message with 4.4.2 and 4.6.1: abort: remote error: Mercurial/Python process ends with return code 1 Something odd changed when upgrading from CentOS 7.4 to 7.5 around forwarding requests from the loopback address that I don't fully understand. First, we were getting a ValueError from inside `opener.open()` saying that 'localhost' didn't match the host listed in the SSL certificate. That wasn't visible until adding this. Then what happened is a connection refused out of the same function, so the traceback is added to the other handler too. Running the equivalent command on the command line from the 'vcs' host stopped working in 7.5: $ curl https://vcs.domain.com/hook/hg/?ping=true curl: (7) Failed connect to vcs.domain.com:443; Connection refused But it works when run on another machine targeting that same 'vcs' host. Adding another firewall rule allows everything to work from the 'vcs' host again: $ iptables -t nat -I OUTPUT -p tcp -o lo --dport 443 -j REDIRECT --to-ports 8443 --- .../src/main/resources/sonia/scm/python/scmhooks.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py index e9a58d589f..73b5bfe083 100644 --- a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py @@ -78,8 +78,10 @@ def callHookUrl(ui, repo, hooktype, node): printMessages(ui, msg.splitlines(True)) else: ui.warn( "ERROR: scm-hook failed with an unknown error\n" ) + ui.traceback() except ValueError: ui.warn( "scm-hook failed with an exception\n" ) + ui.traceback() return abort def callback(ui, repo, hooktype, node=None, source=None, pending=None, **kwargs): From 405dd672754ddd80ca9a7972eb9460aaf1fb67cf Mon Sep 17 00:00:00 2001 From: Matt Harbison Date: Fri, 22 Jun 2018 16:42:05 -0400 Subject: [PATCH 3/3] ensure each message line printed in the Mercurial hook gets a trailing newline I noticed that the exception printed in the previous commit started on the same line as the print for the `str(e)` case right before it. Since this also prints the content of urllib2.URLError.read(), it seems better to remove any existing newline and re-add it, than to just assume the `str(e)` case was the only problem. --- .../src/main/resources/sonia/scm/python/scmhooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py index 73b5bfe083..d4999cf2fd 100644 --- a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py @@ -46,7 +46,7 @@ def printMessages(ui, msgs): for line in msgs: if line.startswith("_e") or line.startswith("_n"): line = line[2:]; - ui.warn(line); + ui.warn('%s\n' % line.rstrip()) def callHookUrl(ui, repo, hooktype, node): abort = True