# HG changeset patch # User Gregory Szorc # Date 1440291028 25200 # Node ID 0d0a0837895d1e2eea28afe92946882c7e4d2fb7 # Parent e86d12404d69e48e3a82d55385cba74716a9c966 hgweb: remove proxy to hgweb instance We were temporarily routing attributes until all request-specific attributes from hgweb were moved to requestcontext. We have finally reached that juncture and we can remove the proxy. At this point, only the repo instance is prone to race conditions between threads. This will be dealt with shortly. diff -r e86d12404d69 -r 0d0a0837895d mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py Thu Sep 10 09:30:10 2015 -0400 +++ b/mercurial/hgweb/hgweb_mod.py Sat Aug 22 17:50:28 2015 -0700 @@ -67,45 +67,29 @@ mutable and race-free state for requests. """ def __init__(self, app): - object.__setattr__(self, 'app', app) - object.__setattr__(self, 'repo', app.repo) - object.__setattr__(self, 'reponame', app.reponame) + self.repo = app.repo + self.reponame = app.reponame - object.__setattr__(self, 'archives', ('zip', 'gz', 'bz2')) + self.archives = ('zip', 'gz', 'bz2') - object.__setattr__(self, 'maxchanges', - self.configint('web', 'maxchanges', 10)) - object.__setattr__(self, 'stripecount', - self.configint('web', 'stripes', 1)) - object.__setattr__(self, 'maxshortchanges', - self.configint('web', 'maxshortchanges', 60)) - object.__setattr__(self, 'maxfiles', - self.configint('web', 'maxfiles', 10)) - object.__setattr__(self, 'allowpull', - self.configbool('web', 'allowpull', True)) + self.maxchanges = self.configint('web', 'maxchanges', 10) + self.stripecount = self.configint('web', 'stripes', 1) + self.maxshortchanges = self.configint('web', 'maxshortchanges', 60) + self.maxfiles = self.configint('web', 'maxfiles', 10) + self.allowpull = self.configbool('web', 'allowpull', True) # we use untrusted=False to prevent a repo owner from using # web.templates in .hg/hgrc to get access to any file readable # by the user running the CGI script - object.__setattr__(self, 'templatepath', - self.config('web', 'templates', untrusted=False)) + self.templatepath = self.config('web', 'templates', untrusted=False) # This object is more expensive to build than simple config values. # It is shared across requests. The app will replace the object # if it is updated. Since this is a reference and nothing should # modify the underlying object, it should be constant for the lifetime # of the request. - object.__setattr__(self, 'websubtable', app.websubtable) + self.websubtable = app.websubtable - # Proxy unknown reads and writes to the application instance - # until everything is moved to us. - def __getattr__(self, name): - return getattr(self.app, name) - - def __setattr__(self, name, value): - return setattr(self.app, name, value) - - # Servers are often run by a user different from the repo owner. # Trust the settings from the .hg/hgrc files by default. def config(self, section, name, default=None, untrusted=True): return self.repo.ui.config(section, name, default, @@ -177,10 +161,9 @@ sessionvars = webutil.sessionvars(vars, start) if not self.reponame: - object.__setattr__(self, 'reponame', - (self.config('web', 'name') - or req.env.get('REPO_NAME') - or req.url.strip('/') or self.repo.root)) + self.reponame = (self.config('web', 'name') + or req.env.get('REPO_NAME') + or req.url.strip('/') or self.repo.root) def websubfilter(text): return websub(text, self.websubtable) @@ -398,8 +381,7 @@ msg = 'no such method: %s' % cmd raise ErrorResponse(HTTP_BAD_REQUEST, msg) elif cmd == 'file' and 'raw' in req.form.get('style', []): - # TODO convert to regular assignment once app proxy is removed. - object.__setattr__(rctx, 'ctype', ctype) + rctx.ctype = ctype content = webcommands.rawfile(rctx, req, tmpl) else: content = getattr(webcommands, cmd)(rctx, req, tmpl)