hgweb: move archive related attributes to requestcontext
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 22 Aug 2015 15:12:52 -0700
changeset 26136 6defc74f3066
parent 26135 edfb4d3b9672
child 26137 99e8a9ff1f5f
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.
mercurial/hgweb/hgweb_mod.py
mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/hgweb_mod.py	Sat Aug 22 15:02:41 2015 -0700
+++ b/mercurial/hgweb/hgweb_mod.py	Sat Aug 22 15:12:52 2015 -0700
@@ -72,6 +72,8 @@
         object.__setattr__(self, 'app', app)
         object.__setattr__(self, 'repo', app.repo)
 
+        object.__setattr__(self, 'archives', ('zip', 'gz', 'bz2'))
+
         object.__setattr__(self, 'maxchanges',
                            self.configint('web', 'maxchanges', 10))
         object.__setattr__(self, 'stripecount',
@@ -109,6 +111,18 @@
         return self.repo.ui.configlist(section, name, default,
                                        untrusted=untrusted)
 
+    archivespecs = {
+        'bz2': ('application/x-bzip2', 'tbz2', '.tar.bz2', None),
+        'gz': ('application/x-gzip', 'tgz', '.tar.gz', None),
+        'zip': ('application/zip', 'zip', '.zip', None),
+    }
+
+    def archivelist(self, nodeid):
+        allowed = self.configlist('web', 'allow_archive')
+        for typ, spec in self.archivespecs.iteritems():
+            if typ in allowed or self.configbool('web', 'allow%s' % typ):
+                yield {'type': typ, 'extension': spec[2], 'node': nodeid}
+
 class hgweb(object):
     """HTTP server for individual repositories.
 
@@ -145,7 +159,6 @@
         self.repostate = ((-1, -1), (-1, -1))
         self.mtime = -1
         self.reponame = name
-        self.archives = 'zip', 'gz', 'bz2'
         # a repo owner may set web.templates in .hg/hgrc to get any file
         # readable by the user running the CGI script
         self.templatepath = self.config('web', 'templates')
@@ -161,10 +174,6 @@
         return self.repo.ui.configbool(section, name, default,
                                        untrusted=untrusted)
 
-    def configlist(self, section, name, default=None, untrusted=True):
-        return self.repo.ui.configlist(section, name, default,
-                                       untrusted=untrusted)
-
     def _getview(self, repo):
         """The 'web.view' config controls changeset filter to hgweb. Possible
         values are ``served``, ``visible`` and ``all``. Default is ``served``.
@@ -311,7 +320,7 @@
 
             if cmd == 'archive':
                 fn = req.form['node'][0]
-                for type_, spec in self.archive_specs.iteritems():
+                for type_, spec in rctx.archivespecs.iteritems():
                     ext = spec[2]
                     if fn.endswith(ext):
                         req.form['node'] = [fn[:-len(ext)]]
@@ -472,18 +481,6 @@
                                             })
         return tmpl
 
-    def archivelist(self, nodeid):
-        allowed = self.configlist("web", "allow_archive")
-        for i, spec in self.archive_specs.iteritems():
-            if i in allowed or self.configbool("web", "allow" + i):
-                yield {"type" : i, "extension" : spec[2], "node" : nodeid}
-
-    archive_specs = {
-        'bz2': ('application/x-bzip2', 'tbz2', '.tar.bz2', None),
-        'gz': ('application/x-gzip', 'tgz', '.tar.gz', None),
-        'zip': ('application/zip', 'zip', '.zip', None),
-        }
-
     def check_perm(self, rctx, req, op):
         for permhook in permhooks:
             permhook(rctx, req, op)
--- a/mercurial/hgweb/webcommands.py	Sat Aug 22 15:02:41 2015 -0700
+++ b/mercurial/hgweb/webcommands.py	Sat Aug 22 15:12:52 2015 -0700
@@ -1078,7 +1078,7 @@
                 raise ErrorResponse(HTTP_NOT_FOUND,
                     'file(s) not found: %s' % file[0])
 
-    mimetype, artype, extension, encoding = web.archive_specs[type_]
+    mimetype, artype, extension, encoding = web.archivespecs[type_]
     headers = [
         ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension))
         ]