Patchwork [3,of,3] hgweb: use archivespecs for links on repo index page too

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

Comments

Anton Shestakov - Jan. 11, 2017, 2:53 a.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1484062918 -28800
#      Tue Jan 10 23:41:58 2017 +0800
# Node ID e0ed84e1828ad1763c2a0e9ba4e66cf35847cf6f
# Parent  371a1ab6cf5054605d63ba497153115f2117ef10
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.
Pierre-Yves David - Jan. 11, 2017, 7:45 a.m.
On 01/11/2017 03:53 AM, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6@dwimlabs.net>
> # Date 1484062918 -28800
> #      Tue Jan 10 23:41:58 2017 +0800
> # Node ID e0ed84e1828ad1763c2a0e9ba4e66cf35847cf6f
> # Parent  371a1ab6cf5054605d63ba497153115f2117ef10
> 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.

These are pushed, thanks.

Cheers,

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
@@ -53,6 +53,12 @@  perms = {
     '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 @@  class requestcontext(object):
         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 @@  class requestcontext(object):
         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():
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
@@ -297,10 +297,10 @@  class hgwebdir(object):
         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