Mercurial > hg
changeset 37699:0e02eb838b96
hgweb: extract a generator function of _siblings class
_siblings will be converted to a plain function.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 01 Apr 2018 23:47:43 +0900 |
parents | 7738ae638b62 |
children | 495fbeae63cc |
files | mercurial/hgweb/webutil.py |
diffstat | 1 files changed, 17 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/webutil.py Sun Apr 01 23:40:08 2018 +0900 +++ b/mercurial/hgweb/webutil.py Sun Apr 01 23:47:43 2018 +0900 @@ -181,6 +181,22 @@ def hex(self, rev): return hex(self._changelog.node(self._revlog.linkrev(rev))) +# TODO: maybe this can be a wrapper class for changectx/filectx list, which +# yields {'ctx': ctx} +def _ctxsgen(ctxs): + for s in ctxs: + d = { + 'node': s.hex(), + 'rev': s.rev(), + 'user': s.user(), + 'date': s.date(), + 'description': s.description(), + 'branch': s.branch(), + } + if util.safehasattr(s, 'path'): + d['file'] = s.path() + yield d + class _siblings(object): def __init__(self, siblings=None, hiderev=None): if siblings is None: @@ -190,18 +206,7 @@ self.siblings = [] def __iter__(self): - for s in self.siblings: - d = { - 'node': s.hex(), - 'rev': s.rev(), - 'user': s.user(), - 'date': s.date(), - 'description': s.description(), - 'branch': s.branch(), - } - if util.safehasattr(s, 'path'): - d['file'] = s.path() - yield d + return _ctxsgen(self.siblings) def __len__(self): return len(self.siblings)