changeset 49510:e02dcc625171

revset: handle wdir() in `roots()` This is already handled in `heads()`, and both are needed to determine if a set is contiguous. I'm guessing the `0 <= p` check was to try to filter out the null revision, but it looks like that comes through in the corner case of a new repo with no commits. But that was already the case, as shown by the tests. Before (on a clone of hg): $ python3.8 hg perf::revset --config extensions.perf=contrib/perf.py 'roots(all())' ! wall 0.059301 comb 0.040000 user 0.040000 sys 0.000000 (best of 100) After: $ python3.8 hg perf::revset --config extensions.perf=contrib/perf.py 'roots(all())' ! wall 0.059387 comb 0.060000 user 0.060000 sys 0.000000 (best of 100)
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 03 Oct 2022 17:24:52 -0400
parents 946c023212b8
children 117dcc4a0e67
files mercurial/revset.py tests/test-revset2.t
diffstat 2 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Tue Sep 20 14:04:54 2022 +0200
+++ b/mercurial/revset.py	Mon Oct 03 17:24:52 2022 -0400
@@ -2342,9 +2342,14 @@
     parents = repo.changelog.parentrevs
 
     def filter(r):
-        for p in parents(r):
-            if 0 <= p and p in s:
-                return False
+        try:
+            for p in parents(r):
+                if 0 <= p and p in s:
+                    return False
+        except error.WdirUnsupported:
+            for p in repo[None].parents():
+                if p.rev() in s:
+                    return False
         return True
 
     return subset & s.filter(filter, condrepr=b'<roots>')
--- a/tests/test-revset2.t	Tue Sep 20 14:04:54 2022 +0200
+++ b/tests/test-revset2.t	Mon Oct 03 17:24:52 2022 -0400
@@ -1481,6 +1481,13 @@
   $ hg init namedbranch
   $ cd namedbranch
 
+  $ log 'roots(.)'
+  -1
+  $ log 'roots(. or wdir())'
+  -1
+  $ log 'roots(wdir())'
+  2147483647
+
   $ echo default0 >> a
   $ hg ci -Aqm0
   $ echo default1 >> a
@@ -1498,6 +1505,11 @@
   $ echo default5 >> a
   $ hg ci -m5
 
+  $ log 'roots(. or wdir())'
+  5
+  $ log 'roots(wdir())'
+  2147483647
+
 "null" revision belongs to "default" branch (issue4683)
 
   $ log 'branch(null)'