Patchwork [2,of,3] hgweb: use util.sortdict for archivespecs

login
register
mail settings
Submitter Anton Shestakov
Date Jan. 11, 2017, 2:53 a.m.
Message ID <371a1ab6cf5054605d63.1484103198@neuro>
Download mbox | patch
Permalink /patch/18178/
State Accepted
Headers show

Comments

Anton Shestakov - Jan. 11, 2017, 2:53 a.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1484062479 -28800
#      Tue Jan 10 23:34:39 2017 +0800
# Node ID 371a1ab6cf5054605d63ba497153115f2117ef10
# Parent  942eaf4846b85c7baa1c0622e2db0c299296a2b9
hgweb: use util.sortdict for archivespecs

Thus we allow dict-like indexing and "in" checks, and also preserve the order
of archive types and can generate links in a certain order (so
requestcontext.archives is no longer needed).

Patch

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -89,8 +89,6 @@  class requestcontext(object):
         self.repo = repo
         self.reponame = app.reponame
 
-        self.archives = ('zip', 'gz', 'bz2')
-
         self.maxchanges = self.configint('web', 'maxchanges', 10)
         self.stripecount = self.configint('web', 'stripes', 1)
         self.maxshortchanges = self.configint('web', 'maxshortchanges', 60)
@@ -126,16 +124,15 @@  class requestcontext(object):
         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),
-    }
+    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 in self.archives:
-            spec = self.archivespecs[typ]
+        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}