grep: filter target files by matcher
authorYuya Nishihara <yuya@tcha.org>
Thu, 10 Sep 2020 17:14:03 +0900
changeset 45651 bba730d7a6f4
parent 45650 3a024d7cd08e
child 45652 0356b41fe01d
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.
mercurial/commands.py
--- a/mercurial/commands.py	Thu Sep 10 16:14:48 2020 +0900
+++ b/mercurial/commands.py	Thu Sep 10 17:14:03 2020 +0900
@@ -45,6 +45,7 @@
     help,
     hg,
     logcmdutil,
+    match as matchmod,
     merge as mergemod,
     mergestate as mergestatemod,
     narrowspec,
@@ -3621,8 +3622,13 @@
         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.