From patchwork Tue Apr 10 15:41:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [6,of,8] hgweb: move archivelist() of hgwebdir to webutil From: Yuya Nishihara X-Patchwork-Id: 30637 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Wed, 11 Apr 2018 00:41:39 +0900 # HG changeset patch # User Yuya Nishihara # Date 1522589823 -32400 # Sun Apr 01 22:37:03 2018 +0900 # Node ID f698f65fbaf88305353eb769e0130299fc747f08 # Parent cf2d909fdec997a9bb39573ded50ae362a667221 hgweb: move archivelist() of hgwebdir to webutil diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py +++ b/mercurial/hgweb/hgwebdir_mod.py @@ -105,22 +105,6 @@ def readallowed(ui, req): return False -def archivelist(ui, nodeid, url): - allowed = ui.configlist('web', 'allow_archive', untrusted=True) - archives = [] - - for typ, spec in webutil.archivespecs.iteritems(): - if typ in allowed or ui.configbool('web', 'allow' + typ, - untrusted=True): - archives.append({ - 'type': typ, - 'extension': spec[2], - 'node': nodeid, - 'url': url, - }) - - return archives - def rawindexentries(ui, repos, req, subdir=''): descend = ui.configbool('web', 'descend') collapse = ui.configbool('web', 'collapse') @@ -241,7 +225,7 @@ def rawindexentries(ui, repos, req, subd 'description_sort': description.upper() or "unknown", 'lastchange': d, 'lastchange_sort': d[1] - d[0], - 'archives': archivelist(u, "tip", url), + 'archives': webutil.archivelist(u, "tip", url), 'isdirectory': None, 'labels': templateutil.hybridlist(labels, name='label'), } diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py --- a/mercurial/hgweb/webutil.py +++ b/mercurial/hgweb/webutil.py @@ -49,6 +49,22 @@ archivespecs = util.sortdict(( ('bz2', ('application/x-bzip2', 'tbz2', '.tar.bz2', None)), )) +def archivelist(ui, nodeid, url): + allowed = ui.configlist('web', 'allow_archive', untrusted=True) + archives = [] + + for typ, spec in archivespecs.iteritems(): + if typ in allowed or ui.configbool('web', 'allow' + typ, + untrusted=True): + archives.append({ + 'type': typ, + 'extension': spec[2], + 'node': nodeid, + 'url': url, + }) + + return archives + def up(p): if p[0:1] != "/": p = "/" + p