[PATCH 1 of 5] revset: make __len__ part of the offical API

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Oct 15 14:57:58 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1413372383 25200
#      Wed Oct 15 04:26:23 2014 -0700
# Node ID e642e0ab2f8f535f7afc828e0af8fb50deeee6b6
# Parent  48c0b101a9de1fdbd638daa858da845cd05a6be7
revset: make __len__ part of the offical API

This is common for code to ask for the length of a revset. And in fact, all but
generatorset already implement it.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2253,10 +2253,16 @@ class abstractsmartset(object):
         """return the last element in the set (user iteration perspective)
 
         Return None if the set is empty"""
         raise NotImplementedError()
 
+    def __len__(self):
+        """return the length of the smartsets
+
+        This can be expensive on smartset that could be lazy otherwise."""
+        raise NotImplementedError()
+
     def reverse(self):
         """reverse the expected iteration order"""
         raise NotImplementedError()
 
     def sort(self, reverse=True):


More information about the Mercurial-devel mailing list