hgweb: extract a generator function of _siblings class
authorYuya Nishihara <yuya@tcha.org>
Sun, 01 Apr 2018 23:47:43 +0900
changeset 37699 0e02eb838b96
parent 37698 7738ae638b62
child 37700 495fbeae63cc
hgweb: extract a generator function of _siblings class _siblings will be converted to a plain function.
mercurial/hgweb/webutil.py
--- 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)