##// END OF EJS Templates
sparse: directly inline the `set_tracked` and `copy` wrapping...
marmoute -
r50255:bd3519dc default
parent child Browse files
Show More
@@ -77,7 +77,6 b' from mercurial.pycompat import setattr'
77 77 from mercurial import (
78 78 cmdutil,
79 79 commands,
80 dirstate,
81 80 error,
82 81 extensions,
83 82 logcmdutil,
@@ -104,7 +103,6 b' def extsetup(ui):'
104 103 _setupclone(ui)
105 104 _setuplog(ui)
106 105 _setupadd(ui)
107 _setupdirstate(ui)
108 106
109 107
110 108 def replacefilecache(cls, propname, replacement):
@@ -207,40 +205,6 b' def _setupadd(ui):'
207 205 extensions.wrapcommand(commands.table, b'add', _add)
208 206
209 207
210 def _setupdirstate(ui):
211 """Modify the dirstate to prevent stat'ing excluded files,
212 and to prevent modifications to files outside the checkout.
213 """
214
215 # Prevent adding files that are outside the sparse checkout
216 editfuncs = [
217 b'set_tracked',
218 b'copy',
219 ]
220 hint = _(
221 b'include file with `hg debugsparse --include <pattern>` or use '
222 + b'`hg add -s <file>` to include file directory while adding'
223 )
224 for func in editfuncs:
225
226 def _wrapper(orig, self, *args, **kwargs):
227 sparsematch = self._sparsematcher
228 if sparsematch is not None and not sparsematch.always():
229 for f in args:
230 if f is not None and not sparsematch(f) and f not in self:
231 raise error.Abort(
232 _(
233 b"cannot add '%s' - it is outside "
234 b"the sparse checkout"
235 )
236 % f,
237 hint=hint,
238 )
239 return orig(self, *args, **kwargs)
240
241 extensions.wrapfunction(dirstate.dirstate, func, _wrapper)
242
243
244 208 @command(
245 209 b'debugsparse',
246 210 [
@@ -427,6 +427,7 b' class dirstate:'
427 427 return
428 428 self._dirty = True
429 429 if source is not None:
430 self._check_sparse(source)
430 431 self._map.copymap[dest] = source
431 432 else:
432 433 self._map.copymap.pop(dest, None)
@@ -588,6 +589,19 b' class dirstate:'
588 589 msg = _(b'file %r in dirstate clashes with %r')
589 590 msg %= (pycompat.bytestr(d), pycompat.bytestr(filename))
590 591 raise error.Abort(msg)
592 self._check_sparse(filename)
593
594 def _check_sparse(self, filename):
595 """Check that a filename is inside the sparse profile"""
596 sparsematch = self._sparsematcher
597 if sparsematch is not None and not sparsematch.always():
598 if not sparsematch(filename):
599 msg = _(b"cannot add '%s' - it is outside the sparse checkout")
600 hint = _(
601 b'include file with `hg debugsparse --include <pattern>` or use '
602 b'`hg add -s <file>` to include file directory while adding'
603 )
604 raise error.Abort(msg % filename, hint=hint)
591 605
592 606 def _discoverpath(self, path, normed, ignoremissing, exists, storemap):
593 607 if exists is None:
General Comments 0
You need to be logged in to leave comments. Login now