comparison mercurial/hgweb/hgweb_mod.py @ 30748:319914d57b9e

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).
author Anton Shestakov <av6@dwimlabs.net>
date Tue, 10 Jan 2017 23:34:39 +0800
parents 9823e2f50a93
children e38e7ea21987
comparison
equal deleted inserted replaced
30747:4259df518223 30748:319914d57b9e
87 """ 87 """
88 def __init__(self, app, repo): 88 def __init__(self, app, repo):
89 self.repo = repo 89 self.repo = repo
90 self.reponame = app.reponame 90 self.reponame = app.reponame
91 91
92 self.archives = ('zip', 'gz', 'bz2')
93
94 self.maxchanges = self.configint('web', 'maxchanges', 10) 92 self.maxchanges = self.configint('web', 'maxchanges', 10)
95 self.stripecount = self.configint('web', 'stripes', 1) 93 self.stripecount = self.configint('web', 'stripes', 1)
96 self.maxshortchanges = self.configint('web', 'maxshortchanges', 60) 94 self.maxshortchanges = self.configint('web', 'maxshortchanges', 60)
97 self.maxfiles = self.configint('web', 'maxfiles', 10) 95 self.maxfiles = self.configint('web', 'maxfiles', 10)
98 self.allowpull = self.configbool('web', 'allowpull', True) 96 self.allowpull = self.configbool('web', 'allowpull', True)
124 122
125 def configlist(self, section, name, default=None, untrusted=True): 123 def configlist(self, section, name, default=None, untrusted=True):
126 return self.repo.ui.configlist(section, name, default, 124 return self.repo.ui.configlist(section, name, default,
127 untrusted=untrusted) 125 untrusted=untrusted)
128 126
129 archivespecs = { 127 archivespecs = util.sortdict((
130 'bz2': ('application/x-bzip2', 'tbz2', '.tar.bz2', None), 128 ('zip', ('application/zip', 'zip', '.zip', None)),
131 'gz': ('application/x-gzip', 'tgz', '.tar.gz', None), 129 ('gz', ('application/x-gzip', 'tgz', '.tar.gz', None)),
132 'zip': ('application/zip', 'zip', '.zip', None), 130 ('bz2', ('application/x-bzip2', 'tbz2', '.tar.bz2', None)),
133 } 131 ))
134 132
135 def archivelist(self, nodeid): 133 def archivelist(self, nodeid):
136 allowed = self.configlist('web', 'allow_archive') 134 allowed = self.configlist('web', 'allow_archive')
137 for typ in self.archives: 135 for typ, spec in self.archivespecs.iteritems():
138 spec = self.archivespecs[typ]
139 if typ in allowed or self.configbool('web', 'allow%s' % typ): 136 if typ in allowed or self.configbool('web', 'allow%s' % typ):
140 yield {'type': typ, 'extension': spec[2], 'node': nodeid} 137 yield {'type': typ, 'extension': spec[2], 'node': nodeid}
141 138
142 def templater(self, req): 139 def templater(self, req):
143 # determine scheme, port and server name 140 # determine scheme, port and server name