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

Gregory Szorc gregory.szorc at gmail.com
Tue Sep 1 15:58:54 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 135600f7a3b1125c9d405a17aab9fa33e5b4c924
# Parent  39b2f4ae88f898d00a3b28d700c7c358f35c1940
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
@@ -193,9 +193,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)
@@ -206,17 +206,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
@@ -241,11 +237,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