diff mercurial/scmutil.py @ 45073:a56ba57c837d

scmutil: allowing different files to be prefetched per revision The old API takes a list of revision separate from the file matcher, and thus provides no way to fetch different sets of files from each revision. In preparation for adding one such usage, I'm changing the API to take a list of (revision, file matcher) tuples instead. Differential Revision: https://phab.mercurial-scm.org/D8721
author Rodrigo Damazio Bovendorp <rdamazio@google.com>
date Thu, 09 Jul 2020 18:48:55 -0700
parents d044b66d8429
children a03c177a4679
line wrap: on
line diff
--- a/mercurial/scmutil.py	Sat Jul 11 00:31:21 2020 +0530
+++ b/mercurial/scmutil.py	Thu Jul 09 18:48:55 2020 -0700
@@ -1880,18 +1880,29 @@
 ]
 
 
-def prefetchfiles(repo, revs, match):
+def prefetchfiles(repo, revmatches):
     """Invokes the registered file prefetch functions, allowing extensions to
     ensure the corresponding files are available locally, before the command
-    uses them."""
-    if match:
-        # The command itself will complain about files that don't exist, so
-        # don't duplicate the message.
-        match = matchmod.badmatch(match, lambda fn, msg: None)
-    else:
-        match = matchall(repo)
+    uses them.
+
+    Args:
+      revmatches: a list of (revision, match) tuples to indicate the files to
+      fetch at each revision. If any of the match elements is None, it matches
+      all files.
+    """
 
-    fileprefetchhooks(repo, revs, match)
+    def _matcher(m):
+        if m:
+            assert isinstance(m, matchmod.basematcher)
+            # The command itself will complain about files that don't exist, so
+            # don't duplicate the message.
+            return matchmod.badmatch(m, lambda fn, msg: None)
+        else:
+            return matchall(repo)
+
+    revbadmatches = [(rev, _matcher(match)) for (rev, match) in revmatches]
+
+    fileprefetchhooks(repo, revbadmatches)
 
 
 # a list of (repo, revs, match) prefetch functions