Commit 0c064f2e authored by Yuya Nishihara's avatar Yuya Nishihara

grep: filter target files by matcher

Prepares for the migration to logcmdutil's logic, where cmdutil.walkchangerevs()
won't always build an exact set of paths to be scanned.
parent 3a024d7cd08e
......@@ -45,6 +45,7 @@ from . import (
help,
hg,
logcmdutil,
match as matchmod,
merge as mergemod,
mergestate as mergestatemod,
narrowspec,
......@@ -3621,8 +3622,13 @@ def grep(ui, repo, pattern, *pats, **opts):
else:
contextmanager = util.nullcontextmanager
with contextmanager():
assert fmatch.isexact()
for fn in fmatch.files():
# TODO: maybe better to warn missing files?
if all_files:
fmatch = matchmod.badmatch(fmatch, lambda f, msg: None)
filenames = ctx.matches(fmatch)
else:
filenames = (f for f in ctx.files() if fmatch(f))
for fn in filenames:
# fn might not exist in the revision (could be a file removed by
# the revision). We could check `fn not in ctx` even when rev is
# None, but it's less racy to protect againt that in readfile.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment