[PATCH 1 of 5 hgweb-thread-isolation] hgweb: move additional state setting outside of refresh

Gregory Szorc gregory.szorc at gmail.com
Wed Sep 2 19:24:45 CDT 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1440282639 25200
#      Sat Aug 22 15:30:39 2015 -0700
# Node ID 63335f089212b601410235611b31303c7463d513
# Parent  fd9b1262f0e4fbcec1f66f01839bf3d4ee4cff59
hgweb: move additional state setting outside of refresh

We want refresh() to only be about refreshing repository
instances. This state doesn't belong in requestcontext
because it is shared across multiple threads.

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
@@ -194,9 +194,9 @@ class hgweb(object):
             return repo.filtered(viewconfig)
         else:
             return repo.filtered('served')
 
-    def refresh(self, request):
+    def refresh(self):
         repostate = []
         # file of interrests mtime and size
         for meth, fname in foi:
             prefix = getattr(self.repo, meth)
@@ -207,17 +207,13 @@ class hgweb(object):
         # changes made less than a second ago
         if repostate != self.repostate:
             r = hg.repository(self.repo.baseui, self.repo.url())
             self.repo = self._getview(r)
-            encoding.encoding = self.config("web", "encoding",
-                                            encoding.encoding)
             # update these last to avoid threads seeing empty settings
             self.repostate = repostate
             # mtime is needed for ETag
             self.mtime = st.st_mtime
 
-        self.repo.ui.environ = request.env
-
     def run(self):
         """Start a server from CGI environment.
 
         Modern servers should be using WSGI and should avoid this
@@ -242,11 +238,15 @@ class hgweb(object):
 
         This is typically only called by Mercurial. External consumers
         should be using instances of this class as the WSGI application.
         """
-        self.refresh(req)
+        self.refresh()
         rctx = requestcontext(self)
 
+        # This state is global across all threads.
+        encoding.encoding = rctx.config('web', 'encoding', encoding.encoding)
+        rctx.repo.ui.environ = req.env
+
         # work with CGI variables to create coherent structure
         # use SCRIPT_NAME, PATH_INFO and QUERY_STRING as well as our REPO_NAME
 
         req.url = req.env['SCRIPT_NAME']


More information about the Mercurial-devel mailing list