Show More
@@ -72,6 +72,8 b' class requestcontext(object):' | |||||
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', | |
@@ -109,6 +111,18 b' class requestcontext(object):' | |||||
109 | return self.repo.ui.configlist(section, name, default, |
|
111 | return self.repo.ui.configlist(section, name, default, | |
110 | untrusted=untrusted) |
|
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 | class hgweb(object): |
|
126 | class hgweb(object): | |
113 | """HTTP server for individual repositories. |
|
127 | """HTTP server for individual repositories. | |
114 |
|
128 | |||
@@ -145,7 +159,6 b' class hgweb(object):' | |||||
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') | |
@@ -161,10 +174,6 b' class hgweb(object):' | |||||
161 | return self.repo.ui.configbool(section, name, default, |
|
174 | return self.repo.ui.configbool(section, name, default, | |
162 | untrusted=untrusted) |
|
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 | 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``. | |
@@ -311,7 +320,7 b' class hgweb(object):' | |||||
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 |
|
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)]] | |
@@ -472,18 +481,6 b' class hgweb(object):' | |||||
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) |
@@ -1078,7 +1078,7 b' def archive(web, req, tmpl):' | |||||
1078 | raise ErrorResponse(HTTP_NOT_FOUND, |
|
1078 | raise ErrorResponse(HTTP_NOT_FOUND, | |
1079 | 'file(s) not found: %s' % file[0]) |
|
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 | headers = [ |
|
1082 | headers = [ | |
1083 | ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) |
|
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