Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/hgweb_mod.py @ 26136:6defc74f3066
hgweb: move archive related attributes to requestcontext
As part of this, "archive_specs" was renamed to "archivespecs" to align
with naming conventions.
"archive_specs" didn't technically need to be moved from hgweb. But it
seemed to make sense to have all the archive code in the same class.
As part of this, hgweb.configlist is no longer used, so it was deleted.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 22 Aug 2015 15:12:52 -0700 |
parents | edfb4d3b9672 |
children | f77a3f27cea5 |
comparison
equal
deleted
inserted
replaced
26135:edfb4d3b9672 | 26136:6defc74f3066 |
---|---|
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, 'archives', ('zip', 'gz', 'bz2')) | |
76 | |
75 object.__setattr__(self, 'maxchanges', | 77 object.__setattr__(self, 'maxchanges', |
76 self.configint('web', 'maxchanges', 10)) | 78 self.configint('web', 'maxchanges', 10)) |
77 object.__setattr__(self, 'stripecount', | 79 object.__setattr__(self, 'stripecount', |
78 self.configint('web', 'stripes', 1)) | 80 self.configint('web', 'stripes', 1)) |
79 object.__setattr__(self, 'maxshortchanges', | 81 object.__setattr__(self, 'maxshortchanges', |
106 untrusted=untrusted) | 108 untrusted=untrusted) |
107 | 109 |
108 def configlist(self, section, name, default=None, untrusted=True): | 110 def configlist(self, section, name, default=None, untrusted=True): |
109 return self.repo.ui.configlist(section, name, default, | 111 return self.repo.ui.configlist(section, name, default, |
110 untrusted=untrusted) | 112 untrusted=untrusted) |
113 | |
114 archivespecs = { | |
115 'bz2': ('application/x-bzip2', 'tbz2', '.tar.bz2', None), | |
116 'gz': ('application/x-gzip', 'tgz', '.tar.gz', None), | |
117 'zip': ('application/zip', 'zip', '.zip', None), | |
118 } | |
119 | |
120 def archivelist(self, nodeid): | |
121 allowed = self.configlist('web', 'allow_archive') | |
122 for typ, spec in self.archivespecs.iteritems(): | |
123 if typ in allowed or self.configbool('web', 'allow%s' % typ): | |
124 yield {'type': typ, 'extension': spec[2], 'node': nodeid} | |
111 | 125 |
112 class hgweb(object): | 126 class hgweb(object): |
113 """HTTP server for individual repositories. | 127 """HTTP server for individual repositories. |
114 | 128 |
115 Instances of this class serve HTTP responses for a particular | 129 Instances of this class serve HTTP responses for a particular |
143 self.repo = r | 157 self.repo = r |
144 hook.redirect(True) | 158 hook.redirect(True) |
145 self.repostate = ((-1, -1), (-1, -1)) | 159 self.repostate = ((-1, -1), (-1, -1)) |
146 self.mtime = -1 | 160 self.mtime = -1 |
147 self.reponame = name | 161 self.reponame = name |
148 self.archives = 'zip', 'gz', 'bz2' | |
149 # a repo owner may set web.templates in .hg/hgrc to get any file | 162 # a repo owner may set web.templates in .hg/hgrc to get any file |
150 # readable by the user running the CGI script | 163 # readable by the user running the CGI script |
151 self.templatepath = self.config('web', 'templates') | 164 self.templatepath = self.config('web', 'templates') |
152 self.websubtable = self.loadwebsub() | 165 self.websubtable = self.loadwebsub() |
153 | 166 |
157 return self.repo.ui.config(section, name, default, | 170 return self.repo.ui.config(section, name, default, |
158 untrusted=untrusted) | 171 untrusted=untrusted) |
159 | 172 |
160 def configbool(self, section, name, default=False, untrusted=True): | 173 def configbool(self, section, name, default=False, untrusted=True): |
161 return self.repo.ui.configbool(section, name, default, | 174 return self.repo.ui.configbool(section, name, default, |
162 untrusted=untrusted) | |
163 | |
164 def configlist(self, section, name, default=None, untrusted=True): | |
165 return self.repo.ui.configlist(section, name, default, | |
166 untrusted=untrusted) | 175 untrusted=untrusted) |
167 | 176 |
168 def _getview(self, repo): | 177 def _getview(self, repo): |
169 """The 'web.view' config controls changeset filter to hgweb. Possible | 178 """The 'web.view' config controls changeset filter to hgweb. Possible |
170 values are ``served``, ``visible`` and ``all``. Default is ``served``. | 179 values are ``served``, ``visible`` and ``all``. Default is ``served``. |
309 if cmd == 'rev' and 'mercurial' in ua: | 318 if cmd == 'rev' and 'mercurial' in ua: |
310 req.form['style'] = ['raw'] | 319 req.form['style'] = ['raw'] |
311 | 320 |
312 if cmd == 'archive': | 321 if cmd == 'archive': |
313 fn = req.form['node'][0] | 322 fn = req.form['node'][0] |
314 for type_, spec in self.archive_specs.iteritems(): | 323 for type_, spec in rctx.archivespecs.iteritems(): |
315 ext = spec[2] | 324 ext = spec[2] |
316 if fn.endswith(ext): | 325 if fn.endswith(ext): |
317 req.form['node'] = [fn[:-len(ext)]] | 326 req.form['node'] = [fn[:-len(ext)]] |
318 req.form['type'] = [type_] | 327 req.form['type'] = [type_] |
319 | 328 |
470 "pathdef": makebreadcrumb(req.url), | 479 "pathdef": makebreadcrumb(req.url), |
471 "style": style, | 480 "style": style, |
472 }) | 481 }) |
473 return tmpl | 482 return tmpl |
474 | 483 |
475 def archivelist(self, nodeid): | |
476 allowed = self.configlist("web", "allow_archive") | |
477 for i, spec in self.archive_specs.iteritems(): | |
478 if i in allowed or self.configbool("web", "allow" + i): | |
479 yield {"type" : i, "extension" : spec[2], "node" : nodeid} | |
480 | |
481 archive_specs = { | |
482 'bz2': ('application/x-bzip2', 'tbz2', '.tar.bz2', None), | |
483 'gz': ('application/x-gzip', 'tgz', '.tar.gz', None), | |
484 'zip': ('application/zip', 'zip', '.zip', None), | |
485 } | |
486 | |
487 def check_perm(self, rctx, req, op): | 484 def check_perm(self, rctx, req, op): |
488 for permhook in permhooks: | 485 for permhook in permhooks: |
489 permhook(rctx, req, op) | 486 permhook(rctx, req, op) |