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

Lucas Moscovicz lmoscovicz at fb.com
Sat Feb 22 13:19:33 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 01e0d36c542521cea4569185506909c47df3d129
# Parent  857bff65281118fee59b3d636835409925cabafc
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
@@ -2125,6 +2125,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