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

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 22, 2014, 12:35 a.m.
Message ID <6ee73bff903fa66d3946.1393029348@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3736/
State Superseded
Commit 0e99a66eb7bcdb857c0079001df2039d79755782
Headers show

Comments

Lucas Moscovicz - Feb. 22, 2014, 12:35 a.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@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.

Patch

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])