Patchwork [2,of,5] generatorset: implement __len__

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 15, 2014, 7:57 p.m.
Message ID <98ec45f8b54e2935711b.1413403079@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6281/
State Accepted
Headers show

Comments

Pierre-Yves David - Oct. 15, 2014, 7:57 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1413372535 25200
#      Wed Oct 15 04:28:55 2014 -0700
# Node ID 98ec45f8b54e2935711b64132f179924586ccc33
# Parent  e642e0ab2f8f535f7afc828e0af8fb50deeee6b6
generatorset: implement __len__

It was the only smartset class without a `__len__` implementation.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2774,10 +2774,15 @@  class generatorset(abstractsmartset):
             asc.sort()
             self._asclist = asc
             self.fastasc = asc.__iter__
             self.fastdesc = asc.__reversed__
 
+    def __len__(self):
+        for x in self._consumegen():
+            pass
+        return len(self._genlist)
+
     def sort(self, reverse=False):
         self._ascending = not reverse
 
     def reverse(self):
         self._ascending = not self._ascending