hgweb: extract a generator function of _siblings class
_siblings will be converted to a plain function.
--- 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)