102 sparse.enabled = True |
101 sparse.enabled = True |
103 |
102 |
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): |
111 """Replace a filecache property with a new class. This allows changing the |
109 """Replace a filecache property with a new class. This allows changing the |
112 cache invalidation condition.""" |
110 cache invalidation condition.""" |
203 dirs.add(dirname) |
201 dirs.add(dirname) |
204 sparse.updateconfig(repo, opts, include=list(dirs)) |
202 sparse.updateconfig(repo, opts, include=list(dirs)) |
205 return orig(ui, repo, *pats, **opts) |
203 return orig(ui, repo, *pats, **opts) |
206 |
204 |
207 extensions.wrapcommand(commands.table, b'add', _add) |
205 extensions.wrapcommand(commands.table, b'add', _add) |
208 |
|
209 |
|
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 |
206 |
243 |
207 |
244 @command( |
208 @command( |
245 b'debugsparse', |
209 b'debugsparse', |
246 [ |
210 [ |