# HG changeset patch # User Matt Harbison # Date 2022-10-03 21:24:52 # Node ID e02dcc6251713fda8747a80b001694bd32e750a3 # Parent 946c023212b85bc5f9f56c68b91f663e6e8d6090 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) diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -2342,9 +2342,14 @@ def roots(repo, subset, x): 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'') diff --git a/tests/test-revset2.t b/tests/test-revset2.t --- a/tests/test-revset2.t +++ b/tests/test-revset2.t @@ -1481,6 +1481,13 @@ prepare repository that has "default" br $ 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 @@ prepare repository that has "default" br $ 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)'