sparse: don't crash in non-sparse repositories

Summary:
Update the workingfilectxdata() to check that this is actually a sparse
repository before trying to call repo.sparsematch()

Test Plan: Update the test to confirm that "hg diff" works instead of crashes now.

Reviewers: #fbhgext, mbthomas

Reviewed By: #fbhgext, mbthomas

Differential Revision: https://phab.mercurial-scm.org/D1023
This commit is contained in:
Adam Simpkins 2017-10-12 14:08:50 -07:00
parent 04525b995f
commit db0d906e58
2 changed files with 9 additions and 3 deletions

View File

@ -348,6 +348,8 @@ def _setupdiff(ui):
# wrap workingfilectx's data function to return the data for files
# outside the sparse checkout by fetching from the working copy parent.
def workingfilectxdata(orig, self):
if not util.safehasattr(self.repo(), 'sparsematch'):
return orig(self)
sparsematch = self.repo().sparsematch()
if sparsematch(self._path):
return orig(self)

View File

@ -32,6 +32,10 @@ Now create a shared working copy that is not sparse.
Make sure "hg diff" works in the non-sparse working directory.
$ echo z >> file1
$ hg diff |& grep -E 'Unknown exception|AttributeError'
** Unknown exception encountered with possibly-broken third-party extension sparse
AttributeError: 'localrepository' object has no attribute 'sparsematch'
$ hg diff
diff -r 1f02e070b36e file1
--- a/file1 Thu Jan 01 00:00:00 1970 +0000
+++ b/file1 Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +1,2 @@
a
+z