From db0d906e58013d862239425d6eda03bca8fc2bc6 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Thu, 12 Oct 2017 14:08:50 -0700 Subject: [PATCH] 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 --- hgext3rd/sparse.py | 2 ++ tests/test-sparse-notsparse.t | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hgext3rd/sparse.py b/hgext3rd/sparse.py index 62a7121798..d67210302e 100644 --- a/hgext3rd/sparse.py +++ b/hgext3rd/sparse.py @@ -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) diff --git a/tests/test-sparse-notsparse.t b/tests/test-sparse-notsparse.t index e7b0e453a2..847f79ea4e 100644 --- a/tests/test-sparse-notsparse.t +++ b/tests/test-sparse-notsparse.t @@ -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