[PATCH 2 of 5 V2] revset: add _getlengthhint function
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Wed Oct 1 15:22:55 CDT 2014
On 09/30/2014 01:02 PM, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham at fb.com>
> # Date 1412097821 25200
> # Tue Sep 30 10:23:41 2014 -0700
> # Node ID f224c6c8c7a1f0fa5a3151b1cb045367f99da28e
> # Parent c6129c781a9f11be26191e64dcebf8d539c8c76a
> revset: add _getlengthhint function
>
> Adds a function that tries to get a length hint from the set when possible. If
> not possible, it returns None. This will be used later to optimize revsets such
> as 'X & Y' to iterate over the smaller of the two sets.
>
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -16,6 +16,7 @@ import encoding
> import obsolete as obsmod
> import pathutil
> import repoview
> +import util
>
> def _revancestors(repo, revs, followfirst):
> """Like revlog.ancestors(), but supports followfirst."""
> @@ -2194,6 +2195,17 @@ def funcsused(tree):
> funcs.add(tree[1][1])
> return funcs
>
> +def _getlengthhint(revs):
> + """Returns the length hint for the given set. If no length hint is avaiable,
> + it returns None.
> + """
> + if util.safehasattr(revs, '__length_hint__'):
> + return revs.__length_hint__()
> + elif util.safehasattr(revs, '__len__'):
> + return len(revs)
I'm not sure it is a good idea to use __len__ here, multiple smartset
have a super expensive __len_ implementation right now.
> + else:
> + return None
> +
> class baseset(list):
> """Basic data structure that represents a revset and contains the basic
> operation that it should be able to perform.
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>
--
Pierre-Yves David
More information about the Mercurial-devel
mailing list