remotefilelog: don't define a sparsematch() method

Summary:
The remotefilelog extension previously unconditionally added a sparsematch()
method to repository objects, which just called super.sparsematch() if this is
a sparse repository, and returned None if this isn't a sparse repository.

However, defining a sparsematch() method that returns None confuses the sparse
extension.  The sparse extension expects that all repositories that define
sparesmatch() are actually sparse repositories, and never expects this method
to return null.

This updates the remotefilelog code to call its method maybesparsematch()
instead.

Test Plan:
Confirmed existing remotefilelog unit tests pass, and that the sparse extension
no longer crashes when it is used with non-sparse repositories.  (This happens
when using the share extension, if the current working directory is non-sparse
but the sharedpath repository configuration loads the sparse extension.)

Reviewers: tja, durham

Reviewed By: durham

Subscribers: net-systems-diffs@, yogeshwer, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4466108

Signature: t1:4466108:1485451483:287a519151e35bdb99f5be0d9287b4698386183e
This commit is contained in:
Adam Simpkins 2017-01-26 11:01:31 -08:00
parent d9d96358f5
commit 9d76f8392d
2 changed files with 14 additions and 10 deletions

View File

@ -229,7 +229,7 @@ def onetimeclientsetup(ui):
*args, **kwargs):
if shallowrepo.requirement in repo.requirements:
files = []
sparsematch = repo.sparsematch(mctx.rev())
sparsematch = repo.maybesparsematch(mctx.rev())
for f, (m, actionargs, msg) in actions.iteritems():
if sparsematch and not sparsematch(f):
continue
@ -277,7 +277,7 @@ def onetimeclientsetup(ui):
m2 = c2.manifest()
files = []
sparsematch1 = repo.sparsematch(c1.rev())
sparsematch1 = repo.maybesparsematch(c1.rev())
if sparsematch1:
sparseu1 = []
for f in u1:
@ -286,7 +286,7 @@ def onetimeclientsetup(ui):
sparseu1.append(f)
u1 = sparseu1
sparsematch2 = repo.sparsematch(c2.rev())
sparsematch2 = repo.maybesparsematch(c2.rev())
if sparsematch2:
sparseu2 = []
for f in u2:
@ -308,7 +308,7 @@ def onetimeclientsetup(ui):
mb = b.manifest()
files = []
sparsematch = repo.sparsematch(b.rev())
sparsematch = repo.maybesparsematch(b.rev())
if sparsematch:
sparsemissing = []
for f in missing:
@ -733,7 +733,7 @@ def _revertprefetch(orig, repo, ctx, *files):
if shallowrepo.requirement in repo.requirements:
allfiles = []
mf = ctx.manifest()
sparsematch = repo.sparsematch(ctx.rev())
sparsematch = repo.maybesparsematch(ctx.rev())
for f in files:
for path in f:
if (not sparsematch or sparsematch(path)) and path in mf:

View File

@ -35,10 +35,14 @@ def wraprepo(repo):
repo.ui.config("remotefilelog", "fallbackrepo",
repo.ui.config("paths", "default")))
def sparsematch(self, *revs, **kwargs):
baseinstance = super(shallowrepository, self)
if util.safehasattr(baseinstance, 'sparsematch'):
return baseinstance.sparsematch(*revs, **kwargs)
def maybesparsematch(self, *revs, **kwargs):
'''
A wrapper that allows the remotefilelog to invoke sparsematch() if
this is a sparse repository, or returns None if this is not a
sparse repository.
'''
if util.safehasattr(self, 'sparsematch'):
return self.sparsematch(*revs, **kwargs)
return None
@ -117,7 +121,7 @@ def wraprepo(repo):
ctx = repo[rev]
if pats:
m = scmutil.match(ctx, pats, opts)
sparsematch = repo.sparsematch(rev)
sparsematch = repo.maybesparsematch(rev)
mfnode = ctx.manifestnode()
mfrev = mfrevlog.rev(mfnode)