comparison mercurial/hgweb/hgweb_mod.py @ 26135:edfb4d3b9672

hgweb: move some config options to requestcontext Various config options from the repository were stored on the hgweb instance. While unlikely, there could be race conditions between a new request updating these values and an in-flight request seeing both old and new values, leading to weird results. We move some of options/attributes from hgweb to requestcontext. As part of this, we establish config* helpers on requestcontext. As part of the move, we changed int() casts to configint() calls. The int() usage likely predates the existence of configint(). We also removed config option updating from once every refresh to every request. I don't believe obtaining config options is expensive enough to warrant only doing when the repository has changed. The excessive use of object.__setattr__ is unfortunate. But it will eventually disappear once the proxy is no longer necessary.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 22 Aug 2015 15:02:41 -0700
parents e0a6908f066f
children 6defc74f3066
comparison
equal deleted inserted replaced
26134:e0a6908f066f 26135:edfb4d3b9672
70 """ 70 """
71 def __init__(self, app): 71 def __init__(self, app):
72 object.__setattr__(self, 'app', app) 72 object.__setattr__(self, 'app', app)
73 object.__setattr__(self, 'repo', app.repo) 73 object.__setattr__(self, 'repo', app.repo)
74 74
75 object.__setattr__(self, 'maxchanges',
76 self.configint('web', 'maxchanges', 10))
77 object.__setattr__(self, 'stripecount',
78 self.configint('web', 'stripes', 1))
79 object.__setattr__(self, 'maxshortchanges',
80 self.configint('web', 'maxshortchanges', 60))
81 object.__setattr__(self, 'maxfiles',
82 self.configint('web', 'maxfiles', 10))
83 object.__setattr__(self, 'allowpull',
84 self.configbool('web', 'allowpull', True))
85
75 # Proxy unknown reads and writes to the application instance 86 # Proxy unknown reads and writes to the application instance
76 # until everything is moved to us. 87 # until everything is moved to us.
77 def __getattr__(self, name): 88 def __getattr__(self, name):
78 return getattr(self.app, name) 89 return getattr(self.app, name)
79 90
80 def __setattr__(self, name, value): 91 def __setattr__(self, name, value):
81 return setattr(self.app, name, value) 92 return setattr(self.app, name, value)
93
94 # Servers are often run by a user different from the repo owner.
95 # Trust the settings from the .hg/hgrc files by default.
96 def config(self, section, name, default=None, untrusted=True):
97 return self.repo.ui.config(section, name, default,
98 untrusted=untrusted)
99
100 def configbool(self, section, name, default=False, untrusted=True):
101 return self.repo.ui.configbool(section, name, default,
102 untrusted=untrusted)
103
104 def configint(self, section, name, default=None, untrusted=True):
105 return self.repo.ui.configint(section, name, default,
106 untrusted=untrusted)
107
108 def configlist(self, section, name, default=None, untrusted=True):
109 return self.repo.ui.configlist(section, name, default,
110 untrusted=untrusted)
82 111
83 class hgweb(object): 112 class hgweb(object):
84 """HTTP server for individual repositories. 113 """HTTP server for individual repositories.
85 114
86 Instances of this class serve HTTP responses for a particular 115 Instances of this class serve HTTP responses for a particular
115 hook.redirect(True) 144 hook.redirect(True)
116 self.repostate = ((-1, -1), (-1, -1)) 145 self.repostate = ((-1, -1), (-1, -1))
117 self.mtime = -1 146 self.mtime = -1
118 self.reponame = name 147 self.reponame = name
119 self.archives = 'zip', 'gz', 'bz2' 148 self.archives = 'zip', 'gz', 'bz2'
120 self.stripecount = 1
121 # a repo owner may set web.templates in .hg/hgrc to get any file 149 # a repo owner may set web.templates in .hg/hgrc to get any file
122 # readable by the user running the CGI script 150 # readable by the user running the CGI script
123 self.templatepath = self.config('web', 'templates') 151 self.templatepath = self.config('web', 'templates')
124 self.websubtable = self.loadwebsub() 152 self.websubtable = self.loadwebsub()
125 153
168 # we need to compare file size in addition to mtime to catch 196 # we need to compare file size in addition to mtime to catch
169 # changes made less than a second ago 197 # changes made less than a second ago
170 if repostate != self.repostate: 198 if repostate != self.repostate:
171 r = hg.repository(self.repo.baseui, self.repo.url()) 199 r = hg.repository(self.repo.baseui, self.repo.url())
172 self.repo = self._getview(r) 200 self.repo = self._getview(r)
173 self.maxchanges = int(self.config("web", "maxchanges", 10))
174 self.stripecount = int(self.config("web", "stripes", 1))
175 self.maxshortchanges = int(self.config("web", "maxshortchanges",
176 60))
177 self.maxfiles = int(self.config("web", "maxfiles", 10))
178 self.allowpull = self.configbool("web", "allowpull", True)
179 encoding.encoding = self.config("web", "encoding", 201 encoding.encoding = self.config("web", "encoding",
180 encoding.encoding) 202 encoding.encoding)
181 # update these last to avoid threads seeing empty settings 203 # update these last to avoid threads seeing empty settings
182 self.repostate = repostate 204 self.repostate = repostate
183 # mtime is needed for ETag 205 # mtime is needed for ETag