Mercurial > hg
changeset 10600:033d2fdc3b9d
hgweb: separate generation of entries and sorting (cleanup)
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Sat, 06 Mar 2010 12:45:14 +0100 |
parents | df92846d590b |
children | b98b6a7363ae |
files | mercurial/hgweb/hgwebdir_mod.py |
diffstat | 1 files changed, 14 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py Fri Mar 05 18:08:23 2010 -0800 +++ b/mercurial/hgweb/hgwebdir_mod.py Sat Mar 06 12:45:14 2010 +0100 @@ -195,11 +195,8 @@ yield {"type" : i[0], "extension": i[1], "node": nodeid, "url": url} - sortdefault = None, False - def entries(sortcolumn="", descending=False, subdir="", **map): + def rawentries(subdir="", **map): - rows = [] - parity = paritygen(self.stripecount) descend = self.ui.configbool('web', 'descend', True) for name, path in self.repos: @@ -253,19 +250,19 @@ lastchange=d, lastchange_sort=d[1]-d[0], archives=archivelist(u, "tip", url)) - if (not sortcolumn or (sortcolumn, descending) == sortdefault): - # fast path for unsorted output - row['parity'] = parity.next() - yield row - else: - rows.append((row["%s_sort" % sortcolumn], row)) - if rows: - rows.sort() - if descending: - rows.reverse() - for key, row in rows: - row['parity'] = parity.next() - yield row + yield row + + sortdefault = None, False + def entries(sortcolumn="", descending=False, subdir="", **map): + rows = rawentries(subdir=subdir, **map) + + if sortcolumn and sortdefault != (sortcolumn, descending): + sortkey = '%s_sort' % sortcolumn + rows = sorted(rows, key=lambda x: x[sortkey], + reverse=descending) + for row, parity in zip(rows, paritygen(self.stripecount)): + row['parity'] = parity + yield row self.refresh() sortable = ["name", "description", "contact", "lastchange"]