# HG changeset patch # User Alexis S. L. Carvalho # Date 1151897599 10800 # Node ID 1120302009d79ea3b0bb0c73a5671783eac6b5cf # Parent 1727ff712a4e57416c3f6af326395ed12734af86 hgweb: fix unbundle. After the WSGI changes, even if a push over HTTP succeeds, apache complains about "Premature end of script headers: hgwebdir.cgi" and returns a "HTTP Error 500: Internal Server Error", making the local hg abort. The change to either of the files touched by this patch is enough to fix this, but I think changing both is a more robust solution. diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -932,10 +932,11 @@ class hgweb(object): try: ret = self.repo.addchangegroup(fp, 'serve') - req.write('%d\n' % ret) - req.write(sys.stdout.getvalue()) finally: + val = sys.stdout.getvalue() sys.stdout = old_stdout + req.write('%d\n' % ret) + req.write(val) finally: lock.release() finally: diff --git a/mercurial/hgweb/wsgicgi.py b/mercurial/hgweb/wsgicgi.py --- a/mercurial/hgweb/wsgicgi.py +++ b/mercurial/hgweb/wsgicgi.py @@ -27,6 +27,7 @@ def launch(application): headers_set = [] headers_sent = [] + out = sys.stdout def write(data): if not headers_set: @@ -35,13 +36,13 @@ def launch(application): elif not headers_sent: # Before the first output, send the stored headers status, response_headers = headers_sent[:] = headers_set - sys.stdout.write('Status: %s\r\n' % status) + out.write('Status: %s\r\n' % status) for header in response_headers: - sys.stdout.write('%s: %s\r\n' % header) - sys.stdout.write('\r\n') + out.write('%s: %s\r\n' % header) + out.write('\r\n') - sys.stdout.write(data) - sys.stdout.flush() + out.write(data) + out.flush() def start_response(status,response_headers,exc_info=None): if exc_info: