##// END OF EJS Templates
dirstate: expose a sparse matcher on dirstate (API)...
Gregory Szorc -
r33373:fb320398 default
parent child Browse files
Show More
@@ -26,6 +26,7 b' from mercurial import ('
26 26 node,
27 27 pycompat,
28 28 scmutil,
29 sparse,
29 30 util,
30 31 vfs as vfsmod,
31 32 )
@@ -147,7 +148,8 b' def openlfdirstate(ui, repo, create=True'
147 148 lfstoredir = longname
148 149 opener = vfsmod.vfs(vfs.join(lfstoredir))
149 150 lfdirstate = largefilesdirstate(opener, ui, repo.root,
150 repo.dirstate._validate)
151 repo.dirstate._validate,
152 lambda: sparse.matcher(repo))
151 153
152 154 # If the largefiles dirstate does not exist, populate and create
153 155 # it. This ensures that we create it on the first meaningful
@@ -82,7 +82,6 b' from mercurial import ('
82 82 error,
83 83 extensions,
84 84 hg,
85 localrepo,
86 85 match as matchmod,
87 86 registrar,
88 87 sparse,
@@ -106,13 +105,6 b' def extsetup(ui):'
106 105 _setupadd(ui)
107 106 _setupdirstate(ui)
108 107
109 def reposetup(ui, repo):
110 if not util.safehasattr(repo, 'dirstate'):
111 return
112
113 if 'dirstate' in repo._filecache:
114 repo.dirstate.repo = repo
115
116 108 def replacefilecache(cls, propname, replacement):
117 109 """Replace a filecache property with a new class. This allows changing the
118 110 cache invalidation condition."""
@@ -200,13 +192,6 b' def _setupdirstate(ui):'
200 192 and to prevent modifications to files outside the checkout.
201 193 """
202 194
203 def _dirstate(orig, repo):
204 dirstate = orig(repo)
205 dirstate.repo = repo
206 return dirstate
207 extensions.wrapfunction(
208 localrepo.localrepository.dirstate, 'func', _dirstate)
209
210 195 # The atrocity below is needed to wrap dirstate._ignore. It is a cached
211 196 # property, which means normal function wrapping doesn't work.
212 197 class ignorewrapper(object):
@@ -217,10 +202,9 b' def _setupdirstate(ui):'
217 202 self.sparsematch = None
218 203
219 204 def __get__(self, obj, type=None):
220 repo = obj.repo
221 205 origignore = self.orig.__get__(obj)
222 206
223 sparsematch = sparse.matcher(repo)
207 sparsematch = obj._sparsematcher
224 208 if sparsematch.always():
225 209 return origignore
226 210
@@ -241,7 +225,7 b' def _setupdirstate(ui):'
241 225
242 226 # dirstate.rebuild should not add non-matching files
243 227 def _rebuild(orig, self, parent, allfiles, changedfiles=None):
244 matcher = sparse.matcher(self.repo)
228 matcher = self._sparsematcher
245 229 if not matcher.always():
246 230 allfiles = allfiles.matches(matcher)
247 231 if changedfiles:
@@ -262,8 +246,7 b' def _setupdirstate(ui):'
262 246 '`hg add -s <file>` to include file directory while adding')
263 247 for func in editfuncs:
264 248 def _wrapper(orig, self, *args):
265 repo = self.repo
266 sparsematch = sparse.matcher(repo)
249 sparsematch = self._sparsematcher
267 250 if not sparsematch.always():
268 251 for f in args:
269 252 if (f is not None and not sparsematch(f) and
@@ -70,7 +70,7 b' def nonnormalentries(dmap):'
70 70
71 71 class dirstate(object):
72 72
73 def __init__(self, opener, ui, root, validate):
73 def __init__(self, opener, ui, root, validate, sparsematchfn):
74 74 '''Create a new dirstate object.
75 75
76 76 opener is an open()-like callable that can be used to open the
@@ -80,6 +80,7 b' class dirstate(object):'
80 80 self._opener = opener
81 81 self._validate = validate
82 82 self._root = root
83 self._sparsematchfn = sparsematchfn
83 84 # ntpath.join(root, '') of Python 2.7.9 does not add sep if root is
84 85 # UNC path pointing to root share (issue4557)
85 86 self._rootdir = pathutil.normasprefix(root)
@@ -197,6 +198,19 b' class dirstate(object):'
197 198 f[normcase(name)] = name
198 199 return f
199 200
201 @property
202 def _sparsematcher(self):
203 """The matcher for the sparse checkout.
204
205 The working directory may not include every file from a manifest. The
206 matcher obtained by this property will match a path if it is to be
207 included in the working directory.
208 """
209 # TODO there is potential to cache this property. For now, the matcher
210 # is resolved on every access. (But the called function does use a
211 # cache to keep the lookup fast.)
212 return self._sparsematchfn()
213
200 214 @repocache('branch')
201 215 def _branch(self):
202 216 try:
@@ -53,6 +53,7 b' from . import ('
53 53 revset,
54 54 revsetlang,
55 55 scmutil,
56 sparse,
56 57 store,
57 58 subrepo,
58 59 tags as tagsmod,
@@ -570,8 +571,10 b' class localrepository(object):'
570 571
571 572 @repofilecache('dirstate')
572 573 def dirstate(self):
574 sparsematchfn = lambda: sparse.matcher(self)
575
573 576 return dirstate.dirstate(self.vfs, self.ui, self.root,
574 self._dirstatevalidate)
577 self._dirstatevalidate, sparsematchfn)
575 578
576 579 def _dirstatevalidate(self, node):
577 580 try:
General Comments 0
You need to be logged in to leave comments. Login now