##// END OF EJS Templates
sparse: rework debugsparse's interface...
Valentin Gatien-Baron -
r49588:a6efb918 default
parent child Browse files
Show More
@@ -76,6 +76,7 b' from __future__ import absolute_import'
76 76 from mercurial.i18n import _
77 77 from mercurial.pycompat import setattr
78 78 from mercurial import (
79 cmdutil,
79 80 commands,
80 81 dirstate,
81 82 error,
@@ -153,22 +154,11 b' def _setuplog(ui):'
153 154
154 155
155 156 def _clonesparsecmd(orig, ui, repo, *args, **opts):
156 include_pat = opts.get('include')
157 exclude_pat = opts.get('exclude')
158 enableprofile_pat = opts.get('enable_profile')
157 include = opts.get('include')
158 exclude = opts.get('exclude')
159 enableprofile = opts.get('enable_profile')
159 160 narrow_pat = opts.get('narrow')
160 include = exclude = enableprofile = False
161 if include_pat:
162 pat = include_pat
163 include = True
164 if exclude_pat:
165 pat = exclude_pat
166 exclude = True
167 if enableprofile_pat:
168 pat = enableprofile_pat
169 enableprofile = True
170 if sum([include, exclude, enableprofile]) > 1:
171 raise error.Abort(_(b"too many flags specified."))
161
172 162 # if --narrow is passed, it means they are includes and excludes for narrow
173 163 # clone
174 164 if not narrow_pat and (include or exclude or enableprofile):
@@ -176,7 +166,6 b' def _clonesparsecmd(orig, ui, repo, *arg'
176 166 def clonesparse(orig, ctx, *args, **kwargs):
177 167 sparse.updateconfig(
178 168 ctx.repo().unfiltered(),
179 pat,
180 169 {},
181 170 include=include,
182 171 exclude=exclude,
@@ -214,7 +203,7 b' def _setupadd(ui):'
214 203 for pat in pats:
215 204 dirname, basename = util.split(pat)
216 205 dirs.add(dirname)
217 sparse.updateconfig(repo, list(dirs), opts, include=True)
206 sparse.updateconfig(repo, opts, include=list(dirs))
218 207 return orig(ui, repo, *pats, **opts)
219 208
220 209 extensions.wrapcommand(commands.table, b'add', _add)
@@ -286,18 +275,54 b' def _setupdirstate(ui):'
286 275 @command(
287 276 b'debugsparse',
288 277 [
289 (b'I', b'include', False, _(b'include files in the sparse checkout')),
290 (b'X', b'exclude', False, _(b'exclude files in the sparse checkout')),
291 (b'd', b'delete', False, _(b'delete an include/exclude rule')),
278 (
279 b'I',
280 b'include',
281 [],
282 _(b'include files in the sparse checkout'),
283 _(b'PATTERN'),
284 ),
285 (
286 b'X',
287 b'exclude',
288 [],
289 _(b'exclude files in the sparse checkout'),
290 _(b'PATTERN'),
291 ),
292 (
293 b'd',
294 b'delete',
295 [],
296 _(b'delete an include/exclude rule'),
297 _(b'PATTERN'),
298 ),
292 299 (
293 300 b'f',
294 301 b'force',
295 302 False,
296 303 _(b'allow changing rules even with pending changes'),
297 304 ),
298 (b'', b'enable-profile', False, _(b'enables the specified profile')),
299 (b'', b'disable-profile', False, _(b'disables the specified profile')),
300 (b'', b'import-rules', False, _(b'imports rules from a file')),
305 (
306 b'',
307 b'enable-profile',
308 [],
309 _(b'enables the specified profile'),
310 _(b'PATTERN'),
311 ),
312 (
313 b'',
314 b'disable-profile',
315 [],
316 _(b'disables the specified profile'),
317 _(b'PATTERN'),
318 ),
319 (
320 b'',
321 b'import-rules',
322 [],
323 _(b'imports rules from a file'),
324 _(b'PATTERN'),
325 ),
301 326 (b'', b'clear-rules', False, _(b'clears local include/exclude rules')),
302 327 (
303 328 b'',
@@ -308,10 +333,10 b' def _setupdirstate(ui):'
308 333 (b'', b'reset', False, _(b'makes the repo full again')),
309 334 ]
310 335 + commands.templateopts,
311 _(b'[--OPTION] PATTERN...'),
336 _(b'[--OPTION]'),
312 337 helpbasic=True,
313 338 )
314 def debugsparse(ui, repo, *pats, **opts):
339 def debugsparse(ui, repo, **opts):
315 340 """make the current checkout sparse, or edit the existing checkout
316 341
317 342 The sparse command is used to make the current checkout sparse.
@@ -363,19 +388,13 b' def debugsparse(ui, repo, *pats, **opts)'
363 388 delete = opts.get(b'delete')
364 389 refresh = opts.get(b'refresh')
365 390 reset = opts.get(b'reset')
366 count = sum(
367 [
368 include,
369 exclude,
370 enableprofile,
371 disableprofile,
372 delete,
373 importrules,
374 refresh,
375 clearrules,
376 reset,
377 ]
391 action = cmdutil.check_at_most_one_arg(
392 opts, b'import_rules', b'clear_rules', b'refresh'
378 393 )
394 updateconfig = bool(
395 include or exclude or delete or reset or enableprofile or disableprofile
396 )
397 count = sum([updateconfig, bool(action)])
379 398 if count > 1:
380 399 raise error.Abort(_(b"too many flags specified"))
381 400
@@ -397,10 +416,9 b' def debugsparse(ui, repo, *pats, **opts)'
397 416 )
398 417 )
399 418
400 if include or exclude or delete or reset or enableprofile or disableprofile:
419 if updateconfig:
401 420 sparse.updateconfig(
402 421 repo,
403 pats,
404 422 opts,
405 423 include=include,
406 424 exclude=exclude,
@@ -412,7 +430,7 b' def debugsparse(ui, repo, *pats, **opts)'
412 430 )
413 431
414 432 if importrules:
415 sparse.importfromfiles(repo, opts, pats, force=force)
433 sparse.importfromfiles(repo, opts, importrules, force=force)
416 434
417 435 if clearrules:
418 436 sparse.clearrules(repo, force=force)
@@ -704,21 +704,18 b' def importfromfiles(repo, opts, paths, f'
704 704
705 705 def updateconfig(
706 706 repo,
707 pats,
708 707 opts,
709 include=False,
710 exclude=False,
708 include=(),
709 exclude=(),
711 710 reset=False,
712 delete=False,
713 enableprofile=False,
714 disableprofile=False,
711 delete=(),
712 enableprofile=(),
713 disableprofile=(),
715 714 force=False,
716 715 usereporootpaths=False,
717 716 ):
718 717 """Perform a sparse config update.
719 718
720 Only one of the actions may be performed.
721
722 719 The new config is written out and a working directory refresh is performed.
723 720 """
724 721 with repo.wlock(), repo.lock(), repo.dirstate.parentchange():
@@ -736,10 +733,13 b' def updateconfig('
736 733 newexclude = set(oldexclude)
737 734 newprofiles = set(oldprofiles)
738 735
739 if any(os.path.isabs(pat) for pat in pats):
740 raise error.Abort(_(b'paths cannot be absolute'))
736 def normalize_pats(pats):
737 if any(os.path.isabs(pat) for pat in pats):
738 raise error.Abort(_(b'paths cannot be absolute'))
741 739
742 if not usereporootpaths:
740 if usereporootpaths:
741 return pats
742
743 743 # let's treat paths as relative to cwd
744 744 root, cwd = repo.root, repo.getcwd()
745 745 abspats = []
@@ -752,19 +752,20 b' def updateconfig('
752 752 abspats.append(ap)
753 753 else:
754 754 abspats.append(kindpat)
755 pats = abspats
755 return abspats
756 756
757 if include:
758 newinclude.update(pats)
759 elif exclude:
760 newexclude.update(pats)
761 elif enableprofile:
762 newprofiles.update(pats)
763 elif disableprofile:
764 newprofiles.difference_update(pats)
765 elif delete:
766 newinclude.difference_update(pats)
767 newexclude.difference_update(pats)
757 include = normalize_pats(include)
758 exclude = normalize_pats(exclude)
759 delete = normalize_pats(delete)
760 disableprofile = normalize_pats(disableprofile)
761 enableprofile = normalize_pats(enableprofile)
762
763 newinclude.difference_update(delete)
764 newexclude.difference_update(delete)
765 newprofiles.difference_update(disableprofile)
766 newinclude.update(include)
767 newprofiles.update(enableprofile)
768 newexclude.update(exclude)
768 769
769 770 profilecount = len(newprofiles - oldprofiles) - len(
770 771 oldprofiles - newprofiles
@@ -42,7 +42,7 b' Clear rules when there are includes'
42 42
43 43 Clear rules when there are excludes
44 44
45 $ hg debugsparse --exclude *.sparse
45 $ hg debugsparse -X base.sparse -X webpage.sparse
46 46 $ ls -A
47 47 .hg
48 48 data.py
@@ -147,7 +147,7 b' Verify deleting sparseness while a file '
147 147
148 148 Verify deleting sparseness with --force brings back files
149 149
150 $ hg debugsparse --delete -f 'show*'
150 $ hg debugsparse -f --delete 'show*'
151 151 pending changes to 'hide'
152 152 $ ls -A
153 153 .hg
@@ -170,7 +170,7 b' Verify editing sparseness fails if pendi'
170 170
171 171 Verify adding sparseness hides files
172 172
173 $ hg debugsparse --exclude -f 'hide*'
173 $ hg debugsparse -f --exclude 'hide*'
174 174 pending changes to 'hide'
175 175 $ ls -A
176 176 .hg
@@ -254,6 +254,15 b' Verify merge fails if merging excluded f'
254 254 hide*
255 255
256 256
257 Multiple -I and -X can be passed at once
258
259 $ hg debugsparse --reset -I '*2' -X 'hide2'
260 $ ls -A
261 .hg
262 hide.orig
263 show2
264 $ hg debugsparse --reset -X 'hide*'
265
257 266 Verify strip -k resets dirstate correctly
258 267
259 268 $ hg status
General Comments 0
You need to be logged in to leave comments. Login now