Patchwork [2,of,4] revset: added basic operations to lazyset

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 11, 2014, 12:49 a.m.
Message ID <969baade3f73a6c26172.1392079790@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3558/
State Accepted
Commit 2e33cda452f6c948826dda88fe5c926a56d976a3
Headers show

Comments

Lucas Moscovicz - Feb. 11, 2014, 12:49 a.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1391725537 28800
#      Thu Feb 06 14:25:37 2014 -0800
# Node ID 969baade3f73a6c26172f0c4337d92abd70fd106
# Parent  dd21fb069db6f9d8fffcb50c98f0d3f29db110ba
revset: added basic operations to lazyset

Added methods __add__, __sub__ and __and__ to duck type more methods in
baseset

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2089,5 +2089,15 @@ 
             if cond(x):
                 yield x
 
+    def __and__(self, x):
+        return lazyset(self, lambda r: r in x)
+
+    def __sub__(self, x):
+        return lazyset(self, lambda r: r not in x)
+
+    def __add__(self, x):
+        l = baseset([r for r in self])
+        return l + baseset(x)
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()