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

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Oct 15 14:58:02 CDT 2014


# 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

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]


More information about the Mercurial-devel mailing list