# HG changeset patch # User Matt Harbison # Date 2017-12-08 04:44:06 # Node ID 79968f91ad0cd5bdb584bb24883dde303f8760c4 # Parent b2f628dd99c376dc357e697a8bc1a568d52b49da lfs: override walk() in lfsvfs In order to fix the missing lfs store after an upgrade, I attempted to walk the store vfs to hardlink to the upgraded repo's store. But the custom join() clashes with the default walk() implementation. First, 'path=None' blew up in the regex matcher, because it wanted a string. But even if that is fixed, the join to walk the root of the vfs wouldn't match the required xx/xx...xx pattern. The first cut of this was a copy/paste/tweak of the base implementation, but this version of walk() hides the internal directories, and treats the vfs as a flat store. I think this makes sense because most vfs methods call join() on input paths, which wants the simple oid format. It also relieves the caller from having to deal with bogus files/directories in the store. diff --git a/hgext/lfs/blobstore.py b/hgext/lfs/blobstore.py --- a/hgext/lfs/blobstore.py +++ b/hgext/lfs/blobstore.py @@ -15,6 +15,7 @@ from mercurial.i18n import _ from mercurial import ( error, + pathutil, url as urlmod, util, vfs as vfsmod, @@ -32,6 +33,28 @@ class lfsvfs(vfsmod.vfs): raise error.ProgrammingError('unexpected lfs path: %s' % path) return super(lfsvfs, self).join(path[0:2], path[2:]) + def walk(self, path=None, onerror=None): + """Yield (dirpath, '', oids) tuple for blobs under path + + Oids only exist in the root of this vfs, so dirpath is always ''. + """ + root = os.path.normpath(self.base) + # when dirpath == root, dirpath[prefixlen:] becomes empty + # because len(dirpath) < prefixlen. + prefixlen = len(pathutil.normasprefix(root)) + oids = [] + + for dirpath, dirs, files in os.walk(self.reljoin(self.base, path or ''), + onerror=onerror): + dirpath = dirpath[prefixlen:] + + # Silently skip unexpected files and directories + if len(dirpath) == 2: + oids.extend([dirpath + f for f in files + if _lfsre.match(dirpath + f)]) + + yield ('', '', oids) + class filewithprogress(object): """a file-like object that supports __len__ and read.