##// 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 from mercurial import (
77 from mercurial import (
78 cmdutil,
78 cmdutil,
79 commands,
79 commands,
80 dirstate,
81 error,
80 error,
82 extensions,
81 extensions,
83 logcmdutil,
82 logcmdutil,
@@ -104,7 +103,6 b' def extsetup(ui):'
104 _setupclone(ui)
103 _setupclone(ui)
105 _setuplog(ui)
104 _setuplog(ui)
106 _setupadd(ui)
105 _setupadd(ui)
107 _setupdirstate(ui)
108
106
109
107
110 def replacefilecache(cls, propname, replacement):
108 def replacefilecache(cls, propname, replacement):
@@ -207,40 +205,6 b' def _setupadd(ui):'
207 extensions.wrapcommand(commands.table, b'add', _add)
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 @command(
208 @command(
245 b'debugsparse',
209 b'debugsparse',
246 [
210 [
@@ -427,6 +427,7 b' class dirstate:'
427 return
427 return
428 self._dirty = True
428 self._dirty = True
429 if source is not None:
429 if source is not None:
430 self._check_sparse(source)
430 self._map.copymap[dest] = source
431 self._map.copymap[dest] = source
431 else:
432 else:
432 self._map.copymap.pop(dest, None)
433 self._map.copymap.pop(dest, None)
@@ -588,6 +589,19 b' class dirstate:'
588 msg = _(b'file %r in dirstate clashes with %r')
589 msg = _(b'file %r in dirstate clashes with %r')
589 msg %= (pycompat.bytestr(d), pycompat.bytestr(filename))
590 msg %= (pycompat.bytestr(d), pycompat.bytestr(filename))
590 raise error.Abort(msg)
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 def _discoverpath(self, path, normed, ignoremissing, exists, storemap):
606 def _discoverpath(self, path, normed, ignoremissing, exists, storemap):
593 if exists is None:
607 if exists is None:
General Comments 0
You need to be logged in to leave comments. Login now