hgweb: move additional state setting outside of refresh
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 22 Aug 2015 15:30:39 -0700
changeset 26160 952e0564b46e
parent 26159 f3b467aca485
child 26161 16d54bbdbf89
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.
mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py	Wed Sep 02 23:50:45 2015 -0400
+++ b/mercurial/hgweb/hgweb_mod.py	Sat Aug 22 15:30:39 2015 -0700
@@ -195,7 +195,7 @@
         else:
             return repo.filtered('served')
 
-    def refresh(self, request):
+    def refresh(self):
         repostate = []
         # file of interrests mtime and size
         for meth, fname in foi:
@@ -208,15 +208,11 @@
         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.
 
@@ -243,9 +239,13 @@
         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