Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/hgwebdir_mod.py @ 36899:455918512ed2
hgweb: extract entries() to standalone function
There was some real wonkiness going on here. Essentially, the
inline function was being executed with default arguments because
a function reference was passed as-is into the templater. That
seemed odd. So now we pass an explicit generator of the function
result.
Moving this code out of makeindex() makes makeindex() small enough
to reason about. This makes it easier to see weird things, like the
fact that we're calling self.refresh() twice. Why, I'm not sure.
I'm also not sure why we need to call updatereqenv() to possibly
update the SERVER_NAME, SERVER_PORT, and SCRIPT_NAME variables as
part of rendering an index. I'll dig into these things in subsequent
commits.
Differential Revision: https://phab.mercurial-scm.org/D2815
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 11 Mar 2018 10:37:25 -0700 |
parents | f370f1b4f12c |
children | ee395147bb28 |
comparison
equal
deleted
inserted
replaced
36898:f370f1b4f12c | 36899:455918512ed2 |
---|---|
271 'labels': u.configlist('web', 'labels', untrusted=True), | 271 'labels': u.configlist('web', 'labels', untrusted=True), |
272 } | 272 } |
273 | 273 |
274 yield row | 274 yield row |
275 | 275 |
276 def indexentries(ui, repos, wsgireq, req, stripecount, sortcolumn='', | |
277 descending=False, subdir='', **map): | |
278 | |
279 rows = rawindexentries(ui, repos, wsgireq, req, subdir=subdir, **map) | |
280 | |
281 sortdefault = None, False | |
282 | |
283 if sortcolumn and sortdefault != (sortcolumn, descending): | |
284 sortkey = '%s_sort' % sortcolumn | |
285 rows = sorted(rows, key=lambda x: x[sortkey], | |
286 reverse=descending) | |
287 | |
288 for row, parity in zip(rows, paritygen(stripecount)): | |
289 row['parity'] = parity | |
290 yield row | |
291 | |
276 class hgwebdir(object): | 292 class hgwebdir(object): |
277 """HTTP server for multiple repositories. | 293 """HTTP server for multiple repositories. |
278 | 294 |
279 Given a configuration, different repositories will be served depending | 295 Given a configuration, different repositories will be served depending |
280 on the request path. | 296 on the request path. |
470 tmpl = None | 486 tmpl = None |
471 | 487 |
472 def makeindex(self, wsgireq, tmpl, subdir=""): | 488 def makeindex(self, wsgireq, tmpl, subdir=""): |
473 req = wsgireq.req | 489 req = wsgireq.req |
474 | 490 |
475 sortdefault = None, False | |
476 def entries(sortcolumn="", descending=False, subdir="", **map): | |
477 rows = rawindexentries(self.ui, self.repos, wsgireq, req, | |
478 subdir=subdir, **map) | |
479 | |
480 if sortcolumn and sortdefault != (sortcolumn, descending): | |
481 sortkey = '%s_sort' % sortcolumn | |
482 rows = sorted(rows, key=lambda x: x[sortkey], | |
483 reverse=descending) | |
484 for row, parity in zip(rows, paritygen(self.stripecount)): | |
485 row['parity'] = parity | |
486 yield row | |
487 | |
488 self.refresh() | 491 self.refresh() |
489 sortable = ["name", "description", "contact", "lastchange"] | 492 sortable = ["name", "description", "contact", "lastchange"] |
490 sortcolumn, descending = sortdefault | 493 sortcolumn, descending = None, False |
491 if 'sort' in req.qsparams: | 494 if 'sort' in req.qsparams: |
492 sortcolumn = req.qsparams['sort'] | 495 sortcolumn = req.qsparams['sort'] |
493 descending = sortcolumn.startswith('-') | 496 descending = sortcolumn.startswith('-') |
494 if descending: | 497 if descending: |
495 sortcolumn = sortcolumn[1:] | 498 sortcolumn = sortcolumn[1:] |
501 and "-" or "", column)) | 504 and "-" or "", column)) |
502 for column in sortable] | 505 for column in sortable] |
503 | 506 |
504 self.refresh() | 507 self.refresh() |
505 self.updatereqenv(wsgireq.env) | 508 self.updatereqenv(wsgireq.env) |
509 | |
510 entries = indexentries(self.ui, self.repos, wsgireq, req, | |
511 self.stripecount, sortcolumn=sortcolumn, | |
512 descending=descending, subdir=subdir) | |
506 | 513 |
507 return tmpl("index", entries=entries, subdir=subdir, | 514 return tmpl("index", entries=entries, subdir=subdir, |
508 pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix), | 515 pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix), |
509 sortcolumn=sortcolumn, descending=descending, | 516 sortcolumn=sortcolumn, descending=descending, |
510 **dict(sort)) | 517 **dict(sort)) |