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

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 22, 2014, 7:19 p.m.
Message ID <01e0d36c542521cea456.1393096773@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3740/
State Accepted
Commit 0e99a66eb7bcdb857c0079001df2039d79755782
Headers show

Comments

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

Patch

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