D4850: store: pass matcher to store.datafiles() and filter files according to it

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Wed Oct 3 15:02:29 UTC 2018


pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  To get narrow stream clones working, we need a way to filter the storage files
  using a matcher. This patch adds matcher as an argument to store.walk() and
  store.datafiles() so that we can filter the files returned according to the
  matcher.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4850

AFFECTED FILES
  mercurial/store.py

CHANGE DETAILS

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -374,17 +374,21 @@
         l.sort()
         return l
 
-    def datafiles(self):
+    def datafiles(self, matcher=None):
         return self._walk('data', True) + self._walk('meta', True)
 
     def topfiles(self):
         # yield manifest before changelog
         return reversed(self._walk('', False))
 
-    def walk(self):
-        '''yields (unencoded, encoded, size)'''
+    def walk(self, matcher=None):
+        '''yields (unencoded, encoded, size)
+
+        if a matcher is passed, storage files of only those tracked paths
+        are passed with matches the matcher
+        '''
         # yield data files first
-        for x in self.datafiles():
+        for x in self.datafiles(matcher):
             yield x
         for x in self.topfiles():
             yield x
@@ -422,12 +426,14 @@
         self.vfs = vfsmod.filtervfs(vfs, encodefilename)
         self.opener = self.vfs
 
-    def datafiles(self):
+    def datafiles(self, matcher=None):
         for a, b, size in super(encodedstore, self).datafiles():
             try:
                 a = decodefilename(a)
             except KeyError:
                 a = None
+            if matcher and not matcher(_gettrackedpath(a)):
+                continue
             yield a, b, size
 
     def join(self, f):
@@ -551,8 +557,10 @@
     def getsize(self, path):
         return self.rawvfs.stat(path).st_size
 
-    def datafiles(self):
+    def datafiles(self, matcher=None):
         for f in sorted(self.fncache):
+            if matcher and not matcher(_gettrackedpath(f)):
+                continue
             ef = self.encode(f)
             try:
                 yield f, ef, self.getsize(ef)



To: pulkit, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list