Show More
@@ -72,6 +72,8 class requestcontext(object): | |||
|
72 | 72 | object.__setattr__(self, 'app', app) |
|
73 | 73 | object.__setattr__(self, 'repo', app.repo) |
|
74 | 74 | |
|
75 | object.__setattr__(self, 'archives', ('zip', 'gz', 'bz2')) | |
|
76 | ||
|
75 | 77 | object.__setattr__(self, 'maxchanges', |
|
76 | 78 | self.configint('web', 'maxchanges', 10)) |
|
77 | 79 | object.__setattr__(self, 'stripecount', |
@@ -109,6 +111,18 class requestcontext(object): | |||
|
109 | 111 | return self.repo.ui.configlist(section, name, default, |
|
110 | 112 | untrusted=untrusted) |
|
111 | 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} | |
|
125 | ||
|
112 | 126 | class hgweb(object): |
|
113 | 127 | """HTTP server for individual repositories. |
|
114 | 128 | |
@@ -145,7 +159,6 class hgweb(object): | |||
|
145 | 159 | self.repostate = ((-1, -1), (-1, -1)) |
|
146 | 160 | self.mtime = -1 |
|
147 | 161 | self.reponame = name |
|
148 | self.archives = 'zip', 'gz', 'bz2' | |
|
149 | 162 | # a repo owner may set web.templates in .hg/hgrc to get any file |
|
150 | 163 | # readable by the user running the CGI script |
|
151 | 164 | self.templatepath = self.config('web', 'templates') |
@@ -161,10 +174,6 class hgweb(object): | |||
|
161 | 174 | return self.repo.ui.configbool(section, name, default, |
|
162 | 175 | untrusted=untrusted) |
|
163 | 176 | |
|
164 | def configlist(self, section, name, default=None, untrusted=True): | |
|
165 | return self.repo.ui.configlist(section, name, default, | |
|
166 | untrusted=untrusted) | |
|
167 | ||
|
168 | 177 | def _getview(self, repo): |
|
169 | 178 | """The 'web.view' config controls changeset filter to hgweb. Possible |
|
170 | 179 | values are ``served``, ``visible`` and ``all``. Default is ``served``. |
@@ -311,7 +320,7 class hgweb(object): | |||
|
311 | 320 | |
|
312 | 321 | if cmd == 'archive': |
|
313 | 322 | fn = req.form['node'][0] |
|
314 |
for type_, spec in |
|
|
323 | for type_, spec in rctx.archivespecs.iteritems(): | |
|
315 | 324 | ext = spec[2] |
|
316 | 325 | if fn.endswith(ext): |
|
317 | 326 | req.form['node'] = [fn[:-len(ext)]] |
@@ -472,18 +481,6 class hgweb(object): | |||
|
472 | 481 | }) |
|
473 | 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 | 484 | def check_perm(self, rctx, req, op): |
|
488 | 485 | for permhook in permhooks: |
|
489 | 486 | permhook(rctx, req, op) |
@@ -1078,7 +1078,7 def archive(web, req, tmpl): | |||
|
1078 | 1078 | raise ErrorResponse(HTTP_NOT_FOUND, |
|
1079 | 1079 | 'file(s) not found: %s' % file[0]) |
|
1080 | 1080 | |
|
1081 |
mimetype, artype, extension, encoding = web.archive |
|
|
1081 | mimetype, artype, extension, encoding = web.archivespecs[type_] | |
|
1082 | 1082 | headers = [ |
|
1083 | 1083 | ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) |
|
1084 | 1084 | ] |
General Comments 0
You need to be logged in to leave comments.
Login now