Mercurial > public > mercurial-scm > hg-stable
diff hgext/lfs/wrapper.py @ 37851:3790efb388ca stable
lfs: bypass wrapped functions when reposetup() hasn't been called (issue5902)
There are only a handful of methods that access repo attributes that are applied
in reposetup(). The `diff` test covers all of the commands that call
scmutil.prefetchfiles(). Along the way, I saw that adding files and upgrading
the repo format were also problems (also tested here).
I don't think running `hg serve` through the commandserver is sane, but I
conditionalized both the capabilities and the wsgirequest handler because it's
trivially correct. It doesn't look like there has ever been a caller of
candownload(), so there's no test for that path.
The upload case isn't testable, because uploadblobs() bails if there are no
pointers. The requirement should be added any time pointers are introduced, and
that would force the extension to be loaded specifically for the repo. This
covers `debuglfsupload`, the pre-push hook (which isn't set until the repo is
promoted to LFS), and uploadblobsfromrevs(), which can be called by other
extensions.
I think readfromstore() and writetostore() are only reachable as a flag
processor for revlog.REVIDX_EXTSTORED, and a requirement is added as soon as
that is seen, so I don't think those are a problem.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 31 May 2018 09:19:09 -0400 |
parents | 7269b87f817c |
children | 37e56607cbb9 |
line wrap: on
line diff
--- a/hgext/lfs/wrapper.py Thu May 24 21:54:31 2018 +0900 +++ b/hgext/lfs/wrapper.py Thu May 31 09:19:09 2018 -0400 @@ -37,8 +37,9 @@ def _capabilities(orig, repo, proto): '''Wrap server command to announce lfs server capability''' caps = orig(repo, proto) - # XXX: change to 'lfs=serve' when separate git server isn't required? - caps.append('lfs') + if util.safehasattr(repo.svfs, 'lfslocalblobstore'): + # XXX: change to 'lfs=serve' when separate git server isn't required? + caps.append('lfs') return caps def bypasscheckhash(self, text): @@ -118,16 +119,18 @@ def filelogaddrevision(orig, self, text, transaction, link, p1, p2, cachedelta=None, node=None, flags=revlog.REVIDX_DEFAULT_FLAGS, **kwds): - textlen = len(text) - # exclude hg rename meta from file size - meta, offset = revlog.parsemeta(text) - if offset: - textlen -= offset + # The matcher isn't available if reposetup() wasn't called. + lfstrack = self.opener.options.get('lfstrack') - lfstrack = self.opener.options['lfstrack'] + if lfstrack: + textlen = len(text) + # exclude hg rename meta from file size + meta, offset = revlog.parsemeta(text) + if offset: + textlen -= offset - if lfstrack(self.filename, textlen): - flags |= revlog.REVIDX_EXTSTORED + if lfstrack(self.filename, textlen): + flags |= revlog.REVIDX_EXTSTORED return orig(self, text, transaction, link, p1, p2, cachedelta=cachedelta, node=node, flags=flags, **kwds) @@ -247,6 +250,9 @@ def _prefetchfiles(repo, revs, match): """Ensure that required LFS blobs are present, fetching them as a group if needed.""" + if not util.safehasattr(repo.svfs, 'lfslocalblobstore'): + return + pointers = [] oids = set() localstore = repo.svfs.lfslocalblobstore @@ -266,10 +272,18 @@ blobstore.remote(repo).readbatch(pointers, localstore) def _canskipupload(repo): + # Skip if this hasn't been passed to reposetup() + if not util.safehasattr(repo.svfs, 'lfsremoteblobstore'): + return True + # if remotestore is a null store, upload is a no-op and can be skipped return isinstance(repo.svfs.lfsremoteblobstore, blobstore._nullremote) def candownload(repo): + # Skip if this hasn't been passed to reposetup() + if not util.safehasattr(repo.svfs, 'lfsremoteblobstore'): + return False + # if remotestore is a null store, downloads will lead to nothing return not isinstance(repo.svfs.lfsremoteblobstore, blobstore._nullremote) @@ -389,13 +403,16 @@ def upgradefinishdatamigration(orig, ui, srcrepo, dstrepo, requirements): orig(ui, srcrepo, dstrepo, requirements) - srclfsvfs = srcrepo.svfs.lfslocalblobstore.vfs - dstlfsvfs = dstrepo.svfs.lfslocalblobstore.vfs + # Skip if this hasn't been passed to reposetup() + if (util.safehasattr(srcrepo.svfs, 'lfslocalblobstore') and + util.safehasattr(dstrepo.svfs, 'lfslocalblobstore')): + srclfsvfs = srcrepo.svfs.lfslocalblobstore.vfs + dstlfsvfs = dstrepo.svfs.lfslocalblobstore.vfs - for dirpath, dirs, files in srclfsvfs.walk(): - for oid in files: - ui.write(_('copying lfs blob %s\n') % oid) - lfutil.link(srclfsvfs.join(oid), dstlfsvfs.join(oid)) + for dirpath, dirs, files in srclfsvfs.walk(): + for oid in files: + ui.write(_('copying lfs blob %s\n') % oid) + lfutil.link(srclfsvfs.join(oid), dstlfsvfs.join(oid)) def upgraderequirements(orig, repo): reqs = orig(repo)