[PATCH 3 of 4] revset: added __nonzero__ method to lazyset

Lucas Moscovicz lmoscovicz at fb.com
Fri Feb 21 18:35:48 CST 2014


# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at fb.com>
# Date 1392920138 28800
#      Thu Feb 20 10:15:38 2014 -0800
# Node ID 6ee73bff903fa66d3946815cd665e6d236ea5acb
# Parent  c21e05d37daa1689935d83f10213f9faba4493ad
revset: added __nonzero__ method to lazyset

Now it doesn't have to go through all the set and can return lazily as soon as
it finds one element.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2131,6 +2131,11 @@
         l = baseset([r for r in self])
         return l + baseset(x)
 
+    def __nonzero__(self):
+        for r in self:
+            return True
+        return False
+
     def __len__(self):
         # Basic implementation to be changed in future patches.
         l = baseset([r for r in self])


More information about the Mercurial-devel mailing list