Patchwork [4,of,4] revset: changed getset so that it can return a lazyset

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 11, 2014, 12:49 a.m.
Message ID <55a68ea5907fe7b3f45e.1392079792@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3560/
State Superseded
Commit b68984d288d4638667b5a1a0587de58236551a38
Headers show

Comments

Matt Mackall - Feb. 10, 2014, 11:22 p.m.
On Mon, 2014-02-10 at 16:49 -0800, Lucas Moscovicz wrote:
> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz@fb.com>
> # Date 1390951154 28800
> #      Tue Jan 28 15:19:14 2014 -0800
> # Node ID 55a68ea5907fe7b3f45ea44e87818b03fa9553d7
> # Parent  ecb4171110b4f2a9df166ec4a3087ded6577f857
> revset: changed getset so that it can return a lazyset
> 
> Tested manually on getset if the return type is a lazyset to let it pass
> instead of converting it to a baseset. This is temporal until everything is
> implemented to work with lazysets and there is no need to convert it back to a
> baseset.

> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -195,7 +195,10 @@
>  def getset(repo, subset, x):
>      if not x:
>          raise error.ParseError(_("missing argument"))
> -    return baseset(methods[x[0]](repo, subset, *x[1:]))
> +    s = methods[x[0]](repo, subset, *x[1:])
> +    if isinstance(s, lazyset):
> +        return s
> +    return baseset(s)

As I tried to explain earlier, this is the wrong approach. It is a
duck-typing failure because we have to look at the types rather than
treat everything as though it were the same.

How do we fix this? Easy: every function in methods must be changed to
always return a baseset-compatible type. Then this code can be changed
to:

+    return methods[x[0]](repo, subset, *x[1:])


I've queued the first three patches in this series, thanks.
Lucas Moscovicz - Feb. 11, 2014, 12:49 a.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1390951154 28800
#      Tue Jan 28 15:19:14 2014 -0800
# Node ID 55a68ea5907fe7b3f45ea44e87818b03fa9553d7
# Parent  ecb4171110b4f2a9df166ec4a3087ded6577f857
revset: changed getset so that it can return a lazyset

Tested manually on getset if the return type is a lazyset to let it pass
instead of converting it to a baseset. This is temporal until everything is
implemented to work with lazysets and there is no need to convert it back to a
baseset.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -195,7 +195,10 @@ 
 def getset(repo, subset, x):
     if not x:
         raise error.ParseError(_("missing argument"))
-    return baseset(methods[x[0]](repo, subset, *x[1:]))
+    s = methods[x[0]](repo, subset, *x[1:])
+    if isinstance(s, lazyset):
+        return s
+    return baseset(s)
 
 def _getrevsource(repo, r):
     extra = repo[r].extra()