Mercurial > hg-stable
changeset 37700:495fbeae63cc
hgweb: convert _siblings to a factory function of mappinggenerator
IIUC, only reason it was a class is to make the generator restartable,
which is now served by the mappinggenerator.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 01 Apr 2018 23:50:34 +0900 |
parents | 0e02eb838b96 |
children | 492531ff81bc |
files | mercurial/hgweb/webutil.py |
diffstat | 1 files changed, 8 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/webutil.py Sun Apr 01 23:47:43 2018 +0900 +++ b/mercurial/hgweb/webutil.py Sun Apr 01 23:50:34 2018 +0900 @@ -183,7 +183,7 @@ # TODO: maybe this can be a wrapper class for changectx/filectx list, which # yields {'ctx': ctx} -def _ctxsgen(ctxs): +def _ctxsgen(context, ctxs): for s in ctxs: d = { 'node': s.hex(), @@ -197,19 +197,13 @@ d['file'] = s.path() yield d -class _siblings(object): - def __init__(self, siblings=None, hiderev=None): - if siblings is None: - siblings = [] - self.siblings = [s for s in siblings if s.node() != nullid] - if len(self.siblings) == 1 and self.siblings[0].rev() == hiderev: - self.siblings = [] - - def __iter__(self): - return _ctxsgen(self.siblings) - - def __len__(self): - return len(self.siblings) +def _siblings(siblings=None, hiderev=None): + if siblings is None: + siblings = [] + siblings = [s for s in siblings if s.node() != nullid] + if len(siblings) == 1 and siblings[0].rev() == hiderev: + siblings = [] + return templateutil.mappinggenerator(_ctxsgen, args=(siblings,)) def difffeatureopts(req, ui, section): diffopts = patch.difffeatureopts(ui, untrusted=True,