[PATCH 5 of 5] revset-only: use __nonzero__ to check if a revset is empty

Augie Fackler raf at durin42.com
Fri Oct 17 08:57:59 CDT 2014


On Wed, Oct 15, 2014 at 12:58:02PM -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at fb.com>
> # Date 1412761521 25200
> #      Wed Oct 08 02:45:21 2014 -0700
> # Node ID 4cc19fe11086cefb513f72509dd41d36fa0f6885
> # Parent  7673821316853069c725ee50ce037434bb5d30db
> revset-only: use __nonzero__ to check if a revset is empty
>

Series LG, queued.

>
> For some smartset, computing length is more expensive than checking if the set
> is empty.
>
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -396,11 +396,11 @@ def only(repo, subset, x):
>      cl = repo.changelog
>      # i18n: "only" is a keyword
>      args = getargs(x, 1, 2, _('only takes one or two arguments'))
>      include = getset(repo, spanset(repo), args[0])
>      if len(args) == 1:
> -        if len(include) == 0:
> +        if not include:
>              return baseset()
>
>          descendants = set(_revdescendants(repo, include, False))
>          exclude = [rev for rev in cl.headrevs()
>              if not rev in descendants and not rev in include]
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list