templater: implement __len__ for _hybrid
authorAnton Shestakov <engored@ya.ru>
Mon, 08 Sep 2014 20:12:58 +0900
changeset 22393 293930a1fa0a
parent 22392 2dd1cbee569d
child 22394 813c6855b97f
templater: implement __len__ for _hybrid Objects of class _hybrid are returned by such template keywords as children, bookmarks, tags and others, and also by revset() template function. They are representing "list of strings" (as hg help template says) for use in templates. So it would be logical to implement a handy way to count the number of strings in such list, and that's what __len__ method does.
mercurial/templatekw.py
--- a/mercurial/templatekw.py	Fri Sep 05 19:54:26 2014 +0200
+++ b/mercurial/templatekw.py	Mon Sep 08 20:12:58 2014 +0900
@@ -26,6 +26,8 @@
     def __call__(self):
         for x in self.values:
             yield x
+    def __len__(self):
+        return len(self.values)
 
 def showlist(name, values, plural=None, element=None, **args):
     if not element: