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

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 15, 2014, 7:58 p.m.
Message ID <4cc19fe11086cefb513f.1413403082@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6285/
State Accepted
Headers show

Comments

Pierre-Yves David - Oct. 15, 2014, 7:58 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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

For some smartset, computing length is more expensive than checking if the set
is empty.
Augie Fackler - Oct. 17, 2014, 1:57 p.m.
On Wed, Oct 15, 2014 at 12:58:02PM -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@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@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

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]