diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -1164,8 +1164,16 @@ def _matchfiles(repo, subset, x): m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, exclude=exc, ctx=repo[rev], default=default) + # This directly read the changelog data as creating changectx for all + # revisions is quite expensive. + getchangeset = repo.changelog.read + wdirrev = node.wdirrev def matches(x): - for f in repo[x].files(): + if x == wdirrev: + files = repo[x].files() + else: + files = getchangeset(x)[3] + for f in files: if m(f): return True return False