[PATCH] Issue937: error messages from hooks not sent over HTTP

Jesse Glick Jesse.Glick at Sun.COM
Mon Feb 25 08:56:18 CST 2008


# HG changeset patch
# User Jesse Glick <jesse.glick at sun.com>
# Date 1203951357 18000
# Node ID a11224f526a5be548c2af818d887f6ea2a5a6305
# Parent  963000ed8cacd72310a54fb5956f3ab3d3e21997
Issue937: error messages from hooks not sent over HTTP.

Turns out that stderr - where ui.warn would send messages - was not
being proxied over the HTTP connection. stdout was, and it seems you
need both. (The streams are interleaved for readability.)

Tested on Ubuntu 7.10 with lighttpd on hgweb.cgi with HTTP Basic auth,
no SSL, using a changeset failing win32text.forbidcrlf.

diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py
--- a/mercurial/hgweb/protocol.py
+++ b/mercurial/hgweb/protocol.py
@@ -176,8 +176,8 @@ def unbundle(web, req):
 
                 # send addchangegroup output to client
 
-                old_stdout = sys.stdout
-                sys.stdout = cStringIO.StringIO()
+                oldio = sys.stdout, sys.stderr
+                sys.stderr = sys.stdout = cStringIO.StringIO()
 
                 try:
                     url = 'remote:%s:%s' % (proto,
@@ -189,7 +189,7 @@ def unbundle(web, req):
                         ret = 0
                 finally:
                     val = sys.stdout.getvalue()
-                    sys.stdout = old_stdout
+                    sys.stdout, sys.stderr = oldio
                 req.write('%d\n' % ret)
                 req.write(val)
             finally:


More information about the Mercurial-devel mailing list