Patchwork [2,of,2] hgweb: generate archive links in order

login
register
mail settings
Submitter Anton Shestakov
Date Jan. 8, 2017, 1:52 a.m.
Message ID <cfd14b0508ddf8edf156.1483840376@neuro>
Download mbox | patch
Permalink /patch/18133/
State Accepted
Headers show

Comments

Anton Shestakov - Jan. 8, 2017, 1:52 a.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1483807974 -28800
#      Sun Jan 08 00:52:54 2017 +0800
# Node ID cfd14b0508ddf8edf156d202e2c5d07b259c2f46
# Parent  3cecf85b42c6cf3e2d81ff5d69e9328bb204d209
hgweb: generate archive links in order

It would be nice for archive links to always be in a certain commonly used
order, such as 'zip', 'bz', 'gzip2'. Repo index page (hgwebdir_mod) already
shows archive links in this order, let's do the same in hgweb_mod.

Sadly, archivespecs is a regular unordered dict, and collections.OrderedDict is
new in 2.7. But requestcontext.archives is a tuple of archive types, so it can
be used as an index to archivespecs.
Sean Farley - Jan. 8, 2017, 3:08 a.m.
Anton Shestakov <av6@dwimlabs.net> writes:

> # HG changeset patch
> # User Anton Shestakov <av6@dwimlabs.net>
> # Date 1483807974 -28800
> #      Sun Jan 08 00:52:54 2017 +0800
> # Node ID cfd14b0508ddf8edf156d202e2c5d07b259c2f46
> # Parent  3cecf85b42c6cf3e2d81ff5d69e9328bb204d209
> hgweb: generate archive links in order
>
> It would be nice for archive links to always be in a certain commonly used
> order, such as 'zip', 'bz', 'gzip2'. Repo index page (hgwebdir_mod) already
> shows archive links in this order, let's do the same in hgweb_mod.
>
> Sadly, archivespecs is a regular unordered dict, and collections.OrderedDict is
> new in 2.7. But requestcontext.archives is a tuple of archive types, so it can
> be used as an index to archivespecs.

Sure, this looks good to me.
Augie Fackler - Jan. 9, 2017, 11:42 p.m.
On Sat, Jan 07, 2017 at 07:08:08PM -0800, Sean Farley wrote:
> Anton Shestakov <av6@dwimlabs.net> writes:
>
> > # HG changeset patch
> > # User Anton Shestakov <av6@dwimlabs.net>
> > # Date 1483807974 -28800
> > #      Sun Jan 08 00:52:54 2017 +0800
> > # Node ID cfd14b0508ddf8edf156d202e2c5d07b259c2f46
> > # Parent  3cecf85b42c6cf3e2d81ff5d69e9328bb204d209
> > hgweb: generate archive links in order
> >
> > It would be nice for archive links to always be in a certain commonly used
> > order, such as 'zip', 'bz', 'gzip2'. Repo index page (hgwebdir_mod) already
> > shows archive links in this order, let's do the same in hgweb_mod.
> >
> > Sadly, archivespecs is a regular unordered dict, and collections.OrderedDict is
> > new in 2.7. But requestcontext.archives is a tuple of archive types, so it can
> > be used as an index to archivespecs.
>
> Sure, this looks good to me.

Queued, thanks.

> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Yuya Nishihara - Jan. 10, 2017, 2:53 p.m.
On Sun, 08 Jan 2017 09:52:56 +0800, Anton Shestakov wrote:
> Sadly, archivespecs is a regular unordered dict, and collections.OrderedDict is
> new in 2.7.

There's util.sortdict() if you like.
Anton Shestakov - Jan. 10, 2017, 2:59 p.m.
On Tue, 10 Jan 2017 23:53:09 +0900
Yuya Nishihara <yuya@tcha.org> wrote:

> On Sun, 08 Jan 2017 09:52:56 +0800, Anton Shestakov wrote:
> > Sadly, archivespecs is a regular unordered dict, and collections.OrderedDict is
> > new in 2.7.  
> 
> There's util.sortdict() if you like.

Oh. Well, I missed that, because I've only searched for "ordered".

Thanks, I'll use it in my next series then.

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
@@ -134,7 +134,8 @@  class requestcontext(object):
 
     def archivelist(self, nodeid):
         allowed = self.configlist('web', 'allow_archive')
-        for typ, spec in self.archivespecs.iteritems():
+        for typ in self.archives:
+            spec = self.archivespecs[typ]
             if typ in allowed or self.configbool('web', 'allow%s' % typ):
                 yield {'type': typ, 'extension': spec[2], 'node': nodeid}