comparison hgext/narrow/narrowrepo.py @ 36466:a8b4d7673d8e

narrow: move checking for narrow requirement into _narrowmatch() We want to move narrowmatch() and others into core, so we need to get rid of the dependence on the "narrow_opts" from the closure in narrowrepo.wraprepo(). We can simply check if the narrow requirement is set. I think that seems like an improvement regardless of moving narrowmatch(). Differential Revision: https://phab.mercurial-scm.org/D2489
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 28 Feb 2018 10:22:54 -0800
parents 3f0af89e008d
children d851951b421c
comparison
equal deleted inserted replaced
36465:94709406f10d 36466:a8b4d7673d8e
36 spec = f.read() 36 spec = f.read()
37 with repo.vfs(narrowspec.FILENAME, 'w') as f: 37 with repo.vfs(narrowspec.FILENAME, 'w') as f:
38 f.write(spec) 38 f.write(spec)
39 return orig(ui, repo, repopath) 39 return orig(ui, repo, repopath)
40 40
41 def wraprepo(repo, opts_narrow): 41 def wraprepo(repo):
42 """Enables narrow clone functionality on a single local repository.""" 42 """Enables narrow clone functionality on a single local repository."""
43 43
44 cacheprop = localrepo.storecache 44 cacheprop = localrepo.storecache
45 if isinstance(repo, bundlerepo.bundlerepository): 45 if isinstance(repo, bundlerepo.bundlerepository):
46 # We have to use a different caching property decorator for 46 # We have to use a different caching property decorator for
75 """ 75 """
76 return narrowspec.load(self) 76 return narrowspec.load(self)
77 77
78 @localrepo.repofilecache(narrowspec.FILENAME) 78 @localrepo.repofilecache(narrowspec.FILENAME)
79 def _narrowmatch(self): 79 def _narrowmatch(self):
80 if changegroup.NARROW_REQUIREMENT not in self.requirements:
81 return matchmod.always(self.root, '')
80 include, exclude = self.narrowpats 82 include, exclude = self.narrowpats
81 if not opts_narrow and not include and not exclude:
82 return matchmod.always(self.root, '')
83 return narrowspec.match(self.root, include=include, exclude=exclude) 83 return narrowspec.match(self.root, include=include, exclude=exclude)
84 84
85 # TODO(martinvonz): make this property-like instead? 85 # TODO(martinvonz): make this property-like instead?
86 def narrowmatch(self): 86 def narrowmatch(self):
87 return self._narrowmatch 87 return self._narrowmatch