diff --git a/hgext3rd/sparse.py b/hgext3rd/sparse.py --- a/hgext3rd/sparse.py +++ b/hgext3rd/sparse.py @@ -31,6 +31,7 @@ _setuplog(ui) _setupadd(ui) _setupdirstate(ui) + _setupdiff(ui) # if fsmonitor is enabled, tell it to use our hash function try: fsmonitor = extensions.find('fsmonitor') @@ -340,6 +341,18 @@ return orig(self, *args) extensions.wrapfunction(dirstate.dirstate, func, _wrapper) +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): + sparsematch = self.repo().sparsematch() + if sparsematch(self._path): + return orig(self) + else: + basectx = self._changectx._parents[0] + return basectx[self._path].data() + extensions.wrapfunction(context.workingfilectx, 'data', workingfilectxdata) + def _wraprepo(ui, repo): class SparseRepo(repo.__class__): def readsparseconfig(self, raw): diff --git a/tests/test-sparse-diff.t b/tests/test-sparse-diff.t new file mode 100644 --- /dev/null +++ b/tests/test-sparse-diff.t @@ -0,0 +1,31 @@ + $ hg init repo + $ cd repo + $ cat > .hg/hgrc < [extensions] + > sparse=$TESTDIR/../hgext3rd/sparse.py + > EOF + $ mkdir a b + $ echo a1 > a/a + $ echo b1 > b/b + $ hg add a/a b/b + $ hg commit -m "add files" + $ echo a2 > a/a + $ echo b2 > b/b + $ hg commit -m "modify files" + $ hg sparse --exclude b + +Run diff. This should still show the file contents of excluded files (and should not crash). + + $ hg diff -r ".^" + diff -r 45479a47b024 a/a + --- a/a/a Thu Jan 01 00:00:00 1970 +0000 + +++ b/a/a Thu Jan 01 00:00:00 1970 +0000 + @@ -1,1 +1,1 @@ + -a1 + +a2 + diff -r 45479a47b024 b/b + --- a/b/b Thu Jan 01 00:00:00 1970 +0000 + +++ b/b/b Thu Jan 01 00:00:00 1970 +0000 + @@ -1,1 +1,1 @@ + -b1 + +b2