[PATCH 6 of 7] hgweb: extract a generator function of _siblings class
Yuya Nishihara
yuya at tcha.org
Sat Apr 14 08:49:16 EDT 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1522594063 -32400
# Sun Apr 01 23:47:43 2018 +0900
# Node ID 8e479b1d96bf94e81f76c78605c16b2864b219a5
# Parent affefa7df3fe2dd06be7cab086c16626010bc8b4
hgweb: extract a generator function of _siblings class
_siblings will be converted to a plain function.
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -181,6 +181,22 @@ class filerevnav(revnav):
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 @@ class _siblings(object):
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)
More information about the Mercurial-devel
mailing list