Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/hgwebdir_mod.py @ 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 | 4612cded5176 |
children | 13341047d517 |
comparison
equal
deleted
inserted
replaced
10599:df92846d590b | 10600:033d2fdc3b9d |
---|---|
193 if i[0] in allowed or ui.configbool("web", "allow" + i[0], | 193 if i[0] in allowed or ui.configbool("web", "allow" + i[0], |
194 untrusted=True): | 194 untrusted=True): |
195 yield {"type" : i[0], "extension": i[1], | 195 yield {"type" : i[0], "extension": i[1], |
196 "node": nodeid, "url": url} | 196 "node": nodeid, "url": url} |
197 | 197 |
198 sortdefault = None, False | 198 def rawentries(subdir="", **map): |
199 def entries(sortcolumn="", descending=False, subdir="", **map): | 199 |
200 | |
201 rows = [] | |
202 parity = paritygen(self.stripecount) | |
203 descend = self.ui.configbool('web', 'descend', True) | 200 descend = self.ui.configbool('web', 'descend', True) |
204 for name, path in self.repos: | 201 for name, path in self.repos: |
205 | 202 |
206 if not name.startswith(subdir): | 203 if not name.startswith(subdir): |
207 continue | 204 continue |
251 description=description or "unknown", | 248 description=description or "unknown", |
252 description_sort=description.upper() or "unknown", | 249 description_sort=description.upper() or "unknown", |
253 lastchange=d, | 250 lastchange=d, |
254 lastchange_sort=d[1]-d[0], | 251 lastchange_sort=d[1]-d[0], |
255 archives=archivelist(u, "tip", url)) | 252 archives=archivelist(u, "tip", url)) |
256 if (not sortcolumn or (sortcolumn, descending) == sortdefault): | 253 yield row |
257 # fast path for unsorted output | 254 |
258 row['parity'] = parity.next() | 255 sortdefault = None, False |
259 yield row | 256 def entries(sortcolumn="", descending=False, subdir="", **map): |
260 else: | 257 rows = rawentries(subdir=subdir, **map) |
261 rows.append((row["%s_sort" % sortcolumn], row)) | 258 |
262 if rows: | 259 if sortcolumn and sortdefault != (sortcolumn, descending): |
263 rows.sort() | 260 sortkey = '%s_sort' % sortcolumn |
264 if descending: | 261 rows = sorted(rows, key=lambda x: x[sortkey], |
265 rows.reverse() | 262 reverse=descending) |
266 for key, row in rows: | 263 for row, parity in zip(rows, paritygen(self.stripecount)): |
267 row['parity'] = parity.next() | 264 row['parity'] = parity |
268 yield row | 265 yield row |
269 | 266 |
270 self.refresh() | 267 self.refresh() |
271 sortable = ["name", "description", "contact", "lastchange"] | 268 sortable = ["name", "description", "contact", "lastchange"] |
272 sortcolumn, descending = sortdefault | 269 sortcolumn, descending = sortdefault |
273 if 'sort' in req.form: | 270 if 'sort' in req.form: |