Patchwork [2,of,6] cmdutil: make walkchangerevs() call prepare with matcher instead of filenames

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 3, 2020, 4:10 a.m.
Message ID <c0d5362379c3b13d6d64.1601698206@mimosa>
Download mbox | patch
Permalink /patch/47368/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 3, 2020, 4:10 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1599722088 -32400
#      Thu Sep 10 16:14:48 2020 +0900
# Node ID c0d5362379c3b13d6d644260d395bad169888924
# Parent  14815a48ad0acf0e4e4da658c4cca0bee459351d
cmdutil: make walkchangerevs() call prepare with matcher instead of filenames

Prepares for migrating walkchangerevs() to logcmdutil's logic, which provides
matcher-based interface.

Patch

diff --git a/hgext/churn.py b/hgext/churn.py
--- a/hgext/churn.py
+++ b/hgext/churn.py
@@ -36,9 +36,8 @@  command = registrar.command(cmdtable)
 testedwith = b'ships-with-hg-core'
 
 
-def changedlines(ui, repo, ctx1, ctx2, fns):
+def changedlines(ui, repo, ctx1, ctx2, fmatch):
     added, removed = 0, 0
-    fmatch = scmutil.matchfiles(repo, fns)
     diff = b''.join(patch.diff(repo, ctx1.node(), ctx2.node(), fmatch))
     for l in diff.split(b'\n'):
         if l.startswith(b"+") and not l.startswith(b"+++ "):
@@ -79,7 +78,7 @@  def countrate(ui, repo, amap, *pats, **o
 
     m = scmutil.match(repo[None], pats, opts)
 
-    def prep(ctx, fns):
+    def prep(ctx, fmatch):
         rev = ctx.rev()
         if df and not df(ctx.date()[0]):  # doesn't match date format
             return
@@ -95,7 +94,7 @@  def countrate(ui, repo, amap, *pats, **o
                 return
 
             ctx1 = parents[0]
-            lines = changedlines(ui, repo, ctx1, ctx, fns)
+            lines = changedlines(ui, repo, ctx1, ctx, fmatch)
             rate[key] = [r + l for r, l in zip(rate.get(key, (0, 0)), lines)]
 
         progress.increment()
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2574,7 +2574,7 @@  def walkchangerevs(repo, match, opts, pr
                                     yield f
 
                     fns = fns_generator()
-                prepare(ctx, fns)
+                prepare(ctx, scmutil.matchfiles(repo, fns))
             for rev in nrevs:
                 yield change(rev)
 
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3606,7 +3606,7 @@  def grep(ui, repo, pattern, *pats, **opt
                     % {b'filename': fn, b'revnum': pycompat.bytestr(rev),}
                 )
 
-    def prep(ctx, fns):
+    def prep(ctx, fmatch):
         rev = ctx.rev()
         pctx = ctx.p1()
         matches.setdefault(rev, {})
@@ -3621,7 +3621,8 @@  def grep(ui, repo, pattern, *pats, **opt
         else:
             contextmanager = util.nullcontextmanager
         with contextmanager():
-            for fn in fns:
+            assert fmatch.isexact()
+            for fn in fmatch.files():
                 # 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.