Patchwork [2,of,4] revset: implemented discard method on lazy classes

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 22, 2014, 12:35 a.m.
Message ID <c21e05d37daa1689935d.1393029347@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3734/
State Deferred
Headers show

Comments

Lucas Moscovicz - Feb. 22, 2014, 12:35 a.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1392395021 28800
#      Fri Feb 14 08:23:41 2014 -0800
# Node ID c21e05d37daa1689935d83f10213f9faba4493ad
# Parent  857bff65281118fee59b3d636835409925cabafc
revset: implemented discard method on lazy classes

Implemented this method to duck type set when used in cmdutil.
Matt Mackall - Feb. 22, 2014, 12:58 a.m.
On Fri, 2014-02-21 at 16:35 -0800, Lucas Moscovicz wrote:
> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz@fb.com>
> # Date 1392395021 28800
> #      Fri Feb 14 08:23:41 2014 -0800
> # Node ID c21e05d37daa1689935d83f10213f9faba4493ad
> # Parent  857bff65281118fee59b3d636835409925cabafc
> revset: implemented discard method on lazy classes
> 
> Implemented this method to duck type set when used in cmdutil.

Same question: what uses discard and have you considered changing it to
not use discard? Since old-style revset list objects didn't even have a
discard method, something is a little weird here.

If the answer is "walkchangerevs", remember that one of the goals here
is to kill that function and most of its friends, at which point this
code will be orphaned. So it's better to do a hack inside walkchangerevs
so that we can kill everything altogether.

> +    def discard(self, x):
> +        self._hiddenrevs.add(x)

This is almost certainly wrong. This is a reference, not a copy, so
changing it will have an impact on everything that checks hidden revs.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2093,6 +2093,12 @@ 
         l = [r for r in x if r not in s]
         return baseset(list(self) + l)
 
+    def discard(self, x):
+        if x in self:
+            self.remove(x)
+        if self._set:
+            self._set.discard(x)
+
 class lazyset(object):
     """Duck type for baseset class which iterates lazily over the revisions in
     the subset and contains a function which tests for membership in the
@@ -2143,6 +2149,10 @@ 
     def reverse(self):
         self._subset.reverse()
 
+    def discard(self, x):
+        self._subset.discard(x)
+        self._cache[x] = False
+
     def set(self):
         return set([r for r in self])
 
@@ -2279,5 +2289,8 @@ 
     def set(self):
         return self
 
+    def discard(self, x):
+        self._hiddenrevs.add(x)
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()