changeset 30749:e38e7ea21987

hgweb: use archivespecs for links on repo index page too Moving archivespecs to the module level allows using it from other modules (such as hgwebdir_mod), and keeping a reference to it in requestcontext allows current code to just work.
author Anton Shestakov <av6@dwimlabs.net>
date Tue, 10 Jan 2017 23:41:58 +0800
parents 319914d57b9e
children 378686afca52
files mercurial/hgweb/hgweb_mod.py mercurial/hgweb/hgwebdir_mod.py
diffstat 2 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py	Tue Jan 10 23:34:39 2017 +0800
+++ b/mercurial/hgweb/hgweb_mod.py	Tue Jan 10 23:41:58 2017 +0800
@@ -53,6 +53,12 @@
     'pushkey': 'push',
 }
 
+archivespecs = util.sortdict((
+    ('zip', ('application/zip', 'zip', '.zip', None)),
+    ('gz', ('application/x-gzip', 'tgz', '.tar.gz', None)),
+    ('bz2', ('application/x-bzip2', 'tbz2', '.tar.bz2', None)),
+))
+
 def makebreadcrumb(url, prefix=''):
     '''Return a 'URL breadcrumb' list
 
@@ -89,6 +95,8 @@
         self.repo = repo
         self.reponame = app.reponame
 
+        self.archivespecs = archivespecs
+
         self.maxchanges = self.configint('web', 'maxchanges', 10)
         self.stripecount = self.configint('web', 'stripes', 1)
         self.maxshortchanges = self.configint('web', 'maxshortchanges', 60)
@@ -124,12 +132,6 @@
         return self.repo.ui.configlist(section, name, default,
                                        untrusted=untrusted)
 
-    archivespecs = util.sortdict((
-        ('zip', ('application/zip', 'zip', '.zip', None)),
-        ('gz', ('application/x-gzip', 'tgz', '.tar.gz', None)),
-        ('bz2', ('application/x-bzip2', 'tbz2', '.tar.bz2', None)),
-    ))
-
     def archivelist(self, nodeid):
         allowed = self.configlist('web', 'allow_archive')
         for typ, spec in self.archivespecs.iteritems():
--- a/mercurial/hgweb/hgwebdir_mod.py	Tue Jan 10 23:34:39 2017 +0800
+++ b/mercurial/hgweb/hgwebdir_mod.py	Tue Jan 10 23:41:58 2017 +0800
@@ -297,10 +297,10 @@
         def archivelist(ui, nodeid, url):
             allowed = ui.configlist("web", "allow_archive", untrusted=True)
             archives = []
-            for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]:
-                if i[0] in allowed or ui.configbool("web", "allow" + i[0],
+            for typ, spec in hgweb_mod.archivespecs.iteritems():
+                if typ in allowed or ui.configbool("web", "allow" + typ,
                                                     untrusted=True):
-                    archives.append({"type" : i[0], "extension": i[1],
+                    archives.append({"type" : typ, "extension": spec[2],
                                      "node": nodeid, "url": url})
             return archives