Patchwork revset: changed revsets to use spanset

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 18, 2014, 5:33 p.m.
Message ID <1062b23968e304d61dc4.1392744835@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3687/
State Superseded
Commit 9ad6dae67845b3d106f233b16bdc207389ee9d19
Headers show

Comments

Lucas Moscovicz - Feb. 18, 2014, 5:33 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1391451315 28800
#      Mon Feb 03 10:15:15 2014 -0800
# Node ID 1062b23968e304d61dc4ff958e7c34633f187544
# Parent  84f626df10a5df208b211d3ad907562034d33c1e
revset: changed revsets to use spanset

Performance Benchmarking:

$ hg perfrevset "first(all())"
! wall 0.304936 comb 0.300000 user 0.280000 sys 0.020000 (best of 33)

$ ./hg perfrevset "first(all())"
! wall 0.175640 comb 0.180000 user 0.160000 sys 0.020000 (best of 56)
Matt Mackall - Feb. 18, 2014, 7:33 p.m.
On Tue, 2014-02-18 at 09:33 -0800, Lucas Moscovicz wrote:
> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz@fb.com>
> # Date 1391451315 28800
> #      Mon Feb 03 10:15:15 2014 -0800
> # Node ID 1062b23968e304d61dc4ff958e7c34633f187544
> # Parent  84f626df10a5df208b211d3ad907562034d33c1e
> revset: changed revsets to use spanset
> 
> Performance Benchmarking:
> 
> $ hg perfrevset "first(all())"
> ! wall 0.304936 comb 0.300000 user 0.280000 sys 0.020000 (best of 33)
> 
> $ ./hg perfrevset "first(all())"
> ! wall 0.175640 comb 0.180000 user 0.160000 sys 0.020000 (best of 56)
> 
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -2558,7 +2558,8 @@
>          if newtree != tree:
>              ui.note(revset.prettyformat(newtree), "\n")
>      func = revset.match(ui, expr)
> -    for c in func(repo, revset.baseset(range(len(repo)))):
> +    for c in func(repo, revset.spanset(0, len(repo),
> +        repo.changelog.filteredrevs)):

Ok, I'm noticing something I didn't see in your earlier patch. It'd be
better if spansets took a repo object:

 spanset(repo, start, end)

..and looked up the hidden revs internally. This way less code has to be
explicitly aware of hidden revs. Then we can get lazy and add some
default args like:

 spanset(repo, start=0, end=None)

so that we can just do:

 spanset(repo) # 0:len(repo) implied

..because we do that a bunch. And this ends up only slightly more
verbose than our old list(repo) version.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2558,7 +2558,8 @@ 
         if newtree != tree:
             ui.note(revset.prettyformat(newtree), "\n")
     func = revset.match(ui, expr)
-    for c in func(repo, revset.baseset(range(len(repo)))):
+    for c in func(repo, revset.spanset(0, len(repo),
+        repo.changelog.filteredrevs)):
         ui.write("%s\n" % c)
 
 @command('debugsetparents', [], _('REV1 [REV2]'))
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -232,14 +232,13 @@ 
     m, n = m[0], n[-1]
 
     if m < n:
-        r = range(m, n + 1)
+        r = spanset(m, n + 1, repo.changelog.filteredrevs)
     else:
-        r = range(m, n - 1, -1)
-    s = subset.set()
-    return baseset([x for x in r if x in s])
+        r = spanset(m, n - 1, repo.changelog.filteredrevs)
+    return r & subset
 
 def dagrange(repo, subset, x, y):
-    r = baseset(repo)
+    r = spanset(0, len(repo), repo.changelog.filteredrevs)
     xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
     s = subset.set()
     return baseset([r for r in xs if r in s])
@@ -287,7 +286,7 @@ 
     """
     # i18n: "ancestor" is a keyword
     l = getlist(x)
-    rl = baseset(repo)
+    rl = spanset(0, len(repo), repo.changelog.filteredrevs)
     anc = None
 
     # (getset(repo, rl, i) for i in l) generates a list of lists
@@ -306,7 +305,8 @@ 
     return baseset([])
 
 def _ancestors(repo, subset, x, followfirst=False):
-    args = getset(repo, baseset(repo), x)
+    args = getset(repo, spanset(0, len(repo),
+        repo.changelog.filteredrevs), x)
     if not args:
         return baseset([])
     s = set(_revancestors(repo, args, followfirst)) | set(args)
@@ -433,7 +433,8 @@ 
         else:
             return lazyset(subset, lambda r: matcher(repo[r].branch()))
 
-    s = getset(repo, baseset(repo), x)
+    s = getset(repo, spanset(0, len(repo), repo.changelog.filteredrevs),
+                x)
     b = set()
     for r in s:
         b.add(repo[r].branch())
@@ -596,11 +597,12 @@ 
     return lazyset(subset, matches)
 
 def _descendants(repo, subset, x, followfirst=False):
-    args = getset(repo, baseset(repo), x)
+    args = getset(repo, spanset(0, len(repo),
+        repo.changelog.filteredrevs), x)
     if not args:
         return baseset([])
     s = set(_revdescendants(repo, args, followfirst)) | set(args)
-    return baseset([r for r in subset if r in s])
+    return subset & s
 
 def descendants(repo, subset, x):
     """``descendants(set)``
@@ -620,9 +622,11 @@ 
     is the same as passing all().
     """
     if x is not None:
-        args = getset(repo, baseset(repo), x).set()
+        args = getset(repo, spanset(0, len(repo),
+            repo.changelog.filteredrevs), x).set()
     else:
-        args = getall(repo, baseset(repo), x).set()
+        args = getall(repo, spanset(0, len(repo),
+            repo.changelog.filteredrevs), x).set()
 
     dests = set()
 
@@ -943,7 +947,8 @@ 
         # i18n: "limit" is a keyword
         raise error.ParseError(_("limit expects a number"))
     ss = subset.set()
-    os = getset(repo, baseset(repo), l[0])
+    os = getset(repo, spanset(0, len(repo), repo.changelog.filteredrevs),
+                l[0])
     bs = baseset([])
     it = iter(os)
     for x in xrange(lim):
@@ -970,14 +975,16 @@ 
         # i18n: "last" is a keyword
         raise error.ParseError(_("last expects a number"))
     ss = subset.set()
-    os = getset(repo, baseset(repo), l[0])[-lim:]
+    os = getset(repo, spanset(0, len(repo), repo.changelog.filteredrevs),
+                l[0])[-lim:]
     return baseset([r for r in os if r in ss])
 
 def maxrev(repo, subset, x):
     """``max(set)``
     Changeset with highest revision number in set.
     """
-    os = getset(repo, baseset(repo), x)
+    os = getset(repo, spanset(0, len(repo), repo.changelog.filteredrevs),
+                x)
     if os:
         m = max(os)
         if m in subset:
@@ -1014,7 +1021,8 @@ 
     """``min(set)``
     Changeset with lowest revision number in set.
     """
-    os = getset(repo, baseset(repo), x)
+    os = getset(repo, spanset(0, len(repo), repo.changelog.filteredrevs),
+                x)
     if os:
         m = min(os)
         if m in subset:
@@ -1068,9 +1076,11 @@ 
     for the first operation is selected.
     """
     if x is not None:
-        args = getset(repo, baseset(repo), x).set()
+        args = getset(repo, spanset(0, len(repo),
+            repo.changelog.filteredrevs), x).set()
     else:
-        args = getall(repo, baseset(repo), x).set()
+        args = getall(repo, spanset(0, len(repo),
+            repo.changelog.filteredrevs), x).set()
 
     def _firstsrc(rev):
         src = _getrevsource(repo, rev)
@@ -1120,7 +1130,8 @@ 
 
     ps = set()
     cl = repo.changelog
-    for r in getset(repo, baseset(repo), x):
+    for r in getset(repo, spanset(0, len(repo),
+        repo.changelog.filteredrevs), x):
         ps.add(cl.parentrevs(r)[0])
     return subset & ps
 
@@ -1138,7 +1149,8 @@ 
 
     ps = set()
     cl = repo.changelog
-    for r in getset(repo, baseset(repo), x):
+    for r in getset(repo, spanset(0, len(repo),
+        repo.changelog.filteredrevs), x):
         ps.add(cl.parentrevs(r)[1])
     return subset & ps
 
@@ -1152,7 +1164,8 @@ 
 
     ps = set()
     cl = repo.changelog
-    for r in getset(repo, baseset(repo), x):
+    for r in getset(repo, spanset(0, len(repo),
+        repo.changelog.filteredrevs), x):
         ps.update(cl.parentrevs(r))
     return subset & ps
 
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -524,7 +524,8 @@ 
 
         # fall through to new-style queries if old-style fails
         m = revset.match(repo.ui, spec)
-        dl = [r for r in m(repo, revset.baseset(repo)) if r not in seen]
+        dl = [r for r in m(repo, revset.spanset(0, len(repo),
+            repo.changelog.filteredrevs)) if r not in seen]
         l.extend(dl)
         seen.update(dl)