changeset 41276:5affe1583e1d

revset: use changelog's `headrevs` method to compute heads Instead of implementing our own algorithm, we reuse a more generic one. This previous algorithm did not leave much room for laziness so we do not really regress in that regards. A small impact is visible for first/last value in some of the simpler cases. The time needed to compute all values improves overall. Small optimization in the dagop.headrevs function will help to buy this back in the next changesets. There is room to introduce actual laziness in this algorithm, but this is out of scope for this series. This has no visible effect on expensive cases: revset: heads(matching(tip, "author")) plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast 0) 7.574666 7.545950 7.570743 7.578697 7.525725 7.509929 7.443854 7.488442 7.452880 7.445411 7.689107 1) 7.549390 7.389162 7.529790 7.536297 7.450467 7.555347 7.404586 7.514948 7.542794 7.524787 7.536918 revset: heads(matching(tip, "author")) and -10000:-1 plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast 0) 7.512533 7.605877 7.382894 7.462109 7.420086 7.575034 7.448452 7.549374 7.457880 7.450308 7.515019 1) 7.548677 7.551832 7.629598 7.494857 7.550554 7.521838 7.451794 error 7.321781 7.546885 7.557523 revset: (-10000:-1) and heads(matching(tip, "author")) plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast 0) 7.465419 7.570089 7.439594 7.521221 7.498716 7.492922 7.479108 7.552397 7.407888 error 7.468264 1) 7.539866 7.548045 7.491761 7.517170 7.469824 7.501990 7.579102 7.502568 7.578102 7.555754 7.567622 In simpler cases, we see a 10-15% impact when retrieving a single value, the full computation time is equivalent or improved: revset: (-5000:-1000) and heads(-10000:-1) plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast 0) 0.004244 0.003368 0.003313 0.003367 0.003327 0.004325 0.003401 0.003379 0.004310 0.003359 0.003396 1) 0.003969 93% 0.003862 114% 0.003834 115% 0.003810 113% 0.003822 114% 0.003940 91% 0.003908 114% 0.003814 112% 0.003986 92% 0.003954 117% 0.003816 112% revset: heads(all()) plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast 0) 0.036503 0.032564 0.030024 0.032378 0.030887 0.036367 0.031713 0.032205 0.036467 0.032286 0.030300 1) 0.036668 0.035347 108% 0.035611 118% 0.035358 109% 0.035726 115% 0.036411 0.035261 111% 0.036096 112% 0.036052 0.035095 108% 0.035792 118% revset: heads(-10000:-1) plain min max first last reverse rev..rst rev..ast sort sor..rst sor..ast 0) 0.003936 0.003218 0.003227 0.003302 0.003328 0.003848 0.003305 0.003252 0.003839 0.003306 0.003279 1) 0.003870 0.003785 117% 0.003821 118% 0.003780 114% 0.003769 113% 0.003776 0.003792 114% 0.003805 117% 0.003810 0.003798 114% 0.003840 117%
author Boris Feld <boris.feld@octobus.net>
date Mon, 14 Jan 2019 17:10:51 +0100
parents 1421d0487a61
children 61f9ef23a12f
files mercurial/revset.py tests/test-revset.t
diffstat 2 files changed, 13 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Mon Jan 14 17:06:00 2019 +0100
+++ b/mercurial/revset.py	Mon Jan 14 17:10:51 2019 +0100
@@ -1169,17 +1169,18 @@
     if order == defineorder:
         order = followorder
     inputset = getset(repo, fullreposet(repo), x, order=order)
-    ps = set()
-    cl = repo.changelog
-    up = ps.update
-    parentrevs = cl.parentrevs
-    for r in inputset:
-        try:
-            up(parentrevs(r))
-        except error.WdirUnsupported:
-            up(p.rev() for p in repo[r].parents())
-    ps.discard(node.nullrev)
-    return subset & (inputset - ps)
+    wdirparents = None
+    if node.wdirrev in inputset:
+        # a bit slower, but not common so good enough for now
+        wdirparents = [p.rev() for p in repo[None].parents()]
+        inputset = set(inputset)
+        inputset.discard(node.wdirrev)
+    heads = repo.changelog.headrevs(inputset)
+    if wdirparents is not None:
+        heads.difference_update(wdirparents)
+        heads.add(node.wdirrev)
+    heads = baseset(heads)
+    return subset & heads
 
 @predicate('hidden()', safe=True)
 def hidden(repo, subset, x):
--- a/tests/test-revset.t	Mon Jan 14 17:06:00 2019 +0100
+++ b/tests/test-revset.t	Mon Jan 14 17:10:51 2019 +0100
@@ -1428,9 +1428,7 @@
   * set:
   <filteredset
     <baseset [9]>,
-    <filteredset
-      <spanset+ 0:10>,
-      <not set([0, 1, 2, 3, 4, 5, 6, 8])>>>
+    <baseset+ [7, 9]>>
   9
 
  but should follow the order of the subset