[PATCH 1 of 4] revset: added lazyset class to return values as soon as they are computed

Matt Mackall mpm at selenic.com
Thu Feb 6 12:30:17 CST 2014


On Thu, 2014-02-06 at 10:02 -0800, Lucas Moscovicz wrote:
> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz at fb.com>
> # Date 1390951154 28800
> #      Tue Jan 28 15:19:14 2014 -0800
> # Node ID ebd119f34a845b1a92462291e025879f80f4b2e7
> # Parent  19b9ecbf916636b9bbb74cb9e14b5f20aad39eb0
> revset: added lazyset class to return values as soon as they are computed
> 
> This class allows us to return values from large revsets as soon as they are
> computed instead of having to wait for the entire revset to be calculated.

Two problems here. First, we'd really like to get a patch with just the
class first, for readability. Second, we have a failure to ducktype:

> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -1489,6 +1489,8 @@
>          # returns the revision matching A then the revision matching B. Sort
>          # again to fix that.
>          revs = matcher(repo, revs)
> +        if isinstance(revs, revset.lazyset):
> +            revs = revset.baseset(revs)

Nothing outside of revset.py should ever know there are different types.
Very little inside of revset.py should know there are different types
either. A lazyset should appear to "work" exactly like a baseset to
outside observers so anywhere you need to do this you should probably
consider a bug. You can do this in a combination of two ways: (1) adding
emulation of baseset behavior to lazyset (2) removing usage of baseset
behavior from other code.

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

We should probably instead ensure that all methods are returning
baseset-compatible objects.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list