hgweb: fix unbundle.
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Mon, 03 Jul 2006 00:33:19 -0300
changeset 2558 1120302009d7
parent 2557 1727ff712a4e
child 2559 bf67d0f6531c
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.
mercurial/hgweb/hgweb_mod.py
mercurial/hgweb/wsgicgi.py
--- a/mercurial/hgweb/hgweb_mod.py	Mon Jul 03 00:23:58 2006 -0300
+++ b/mercurial/hgweb/hgweb_mod.py	Mon Jul 03 00:33:19 2006 -0300
@@ -932,10 +932,11 @@
 
                 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:
--- a/mercurial/hgweb/wsgicgi.py	Mon Jul 03 00:23:58 2006 -0300
+++ b/mercurial/hgweb/wsgicgi.py	Mon Jul 03 00:33:19 2006 -0300
@@ -27,6 +27,7 @@
 
     headers_set = []
     headers_sent = []
+    out = sys.stdout
 
     def write(data):
         if not headers_set:
@@ -35,13 +36,13 @@
         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: