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