Show More
@@ -155,8 +155,8 b' def _clonesparsecmd(orig, ui, repo, *arg' | |||||
155 | raise error.Abort(_("too many flags specified.")) |
|
155 | raise error.Abort(_("too many flags specified.")) | |
156 | if include or exclude or enableprofile: |
|
156 | if include or exclude or enableprofile: | |
157 | def clonesparse(orig, self, node, overwrite, *args, **kwargs): |
|
157 | def clonesparse(orig, self, node, overwrite, *args, **kwargs): | |
158 |
|
|
158 | sparse.updateconfig(self.unfiltered(), pat, {}, include=include, | |
159 | exclude=exclude, enableprofile=enableprofile) |
|
159 | exclude=exclude, enableprofile=enableprofile) | |
160 | return orig(self, node, overwrite, *args, **kwargs) |
|
160 | return orig(self, node, overwrite, *args, **kwargs) | |
161 | extensions.wrapfunction(hg, 'updaterepo', clonesparse) |
|
161 | extensions.wrapfunction(hg, 'updaterepo', clonesparse) | |
162 | return orig(ui, repo, *args, **opts) |
|
162 | return orig(ui, repo, *args, **opts) | |
@@ -182,7 +182,7 b' def _setupadd(ui):' | |||||
182 | for pat in pats: |
|
182 | for pat in pats: | |
183 | dirname, basename = util.split(pat) |
|
183 | dirname, basename = util.split(pat) | |
184 | dirs.add(dirname) |
|
184 | dirs.add(dirname) | |
185 |
|
|
185 | sparse.updateconfig(repo, list(dirs), opts, include=True) | |
186 | return orig(ui, repo, *pats, **opts) |
|
186 | return orig(ui, repo, *pats, **opts) | |
187 |
|
187 | |||
188 | extensions.wrapcommand(commands.table, 'add', _add) |
|
188 | extensions.wrapcommand(commands.table, 'add', _add) | |
@@ -338,9 +338,10 b' def debugsparse(ui, repo, *pats, **opts)' | |||||
338 | return |
|
338 | return | |
339 |
|
339 | |||
340 | if include or exclude or delete or reset or enableprofile or disableprofile: |
|
340 | if include or exclude or delete or reset or enableprofile or disableprofile: | |
341 |
|
|
341 | sparse.updateconfig(repo, pats, opts, include=include, exclude=exclude, | |
342 |
reset=reset, delete=delete, |
|
342 | reset=reset, delete=delete, | |
343 |
|
|
343 | enableprofile=enableprofile, | |
|
344 | disableprofile=disableprofile, force=force) | |||
344 |
|
345 | |||
345 | if importrules: |
|
346 | if importrules: | |
346 | sparse.importfromfiles(repo, opts, pats, force=force) |
|
347 | sparse.importfromfiles(repo, opts, pats, force=force) | |
@@ -359,70 +360,3 b' def debugsparse(ui, repo, *pats, **opts)' | |||||
359 | conflicting=fcounts[2]) |
|
360 | conflicting=fcounts[2]) | |
360 | finally: |
|
361 | finally: | |
361 | wlock.release() |
|
362 | wlock.release() | |
362 |
|
||||
363 | def _config(ui, repo, pats, opts, include=False, exclude=False, reset=False, |
|
|||
364 | delete=False, enableprofile=False, disableprofile=False, |
|
|||
365 | force=False): |
|
|||
366 | """ |
|
|||
367 | Perform a sparse config update. Only one of the kwargs may be specified. |
|
|||
368 | """ |
|
|||
369 | wlock = repo.wlock() |
|
|||
370 | try: |
|
|||
371 | oldsparsematch = sparse.matcher(repo) |
|
|||
372 |
|
||||
373 | raw = repo.vfs.tryread('sparse') |
|
|||
374 | if raw: |
|
|||
375 | oldinclude, oldexclude, oldprofiles = map( |
|
|||
376 | set, sparse.parseconfig(ui, raw)) |
|
|||
377 | else: |
|
|||
378 | oldinclude = set() |
|
|||
379 | oldexclude = set() |
|
|||
380 | oldprofiles = set() |
|
|||
381 |
|
||||
382 | try: |
|
|||
383 | if reset: |
|
|||
384 | newinclude = set() |
|
|||
385 | newexclude = set() |
|
|||
386 | newprofiles = set() |
|
|||
387 | else: |
|
|||
388 | newinclude = set(oldinclude) |
|
|||
389 | newexclude = set(oldexclude) |
|
|||
390 | newprofiles = set(oldprofiles) |
|
|||
391 |
|
||||
392 | oldstatus = repo.status() |
|
|||
393 |
|
||||
394 | if any(pat.startswith('/') for pat in pats): |
|
|||
395 | ui.warn(_('warning: paths cannot start with /, ignoring: %s\n') |
|
|||
396 | % ([pat for pat in pats if pat.startswith('/')])) |
|
|||
397 | elif include: |
|
|||
398 | newinclude.update(pats) |
|
|||
399 | elif exclude: |
|
|||
400 | newexclude.update(pats) |
|
|||
401 | elif enableprofile: |
|
|||
402 | newprofiles.update(pats) |
|
|||
403 | elif disableprofile: |
|
|||
404 | newprofiles.difference_update(pats) |
|
|||
405 | elif delete: |
|
|||
406 | newinclude.difference_update(pats) |
|
|||
407 | newexclude.difference_update(pats) |
|
|||
408 |
|
||||
409 | sparse.writeconfig(repo, newinclude, newexclude, newprofiles) |
|
|||
410 |
|
||||
411 | fcounts = map( |
|
|||
412 | len, |
|
|||
413 | sparse.refreshwdir(repo, oldstatus, oldsparsematch, |
|
|||
414 | force=force)) |
|
|||
415 |
|
||||
416 | profilecount = (len(newprofiles - oldprofiles) - |
|
|||
417 | len(oldprofiles - newprofiles)) |
|
|||
418 | includecount = (len(newinclude - oldinclude) - |
|
|||
419 | len(oldinclude - newinclude)) |
|
|||
420 | excludecount = (len(newexclude - oldexclude) - |
|
|||
421 | len(oldexclude - newexclude)) |
|
|||
422 | sparse.printchanges(ui, opts, profilecount, includecount, |
|
|||
423 | excludecount, *fcounts) |
|
|||
424 | except Exception: |
|
|||
425 | sparse.writeconfig(repo, oldinclude, oldexclude, oldprofiles) |
|
|||
426 | raise |
|
|||
427 | finally: |
|
|||
428 | wlock.release() |
|
@@ -583,6 +583,76 b' def importfromfiles(repo, opts, paths, f' | |||||
583 | printchanges(repo.ui, opts, profilecount, includecount, excludecount, |
|
583 | printchanges(repo.ui, opts, profilecount, includecount, excludecount, | |
584 | *fcounts) |
|
584 | *fcounts) | |
585 |
|
585 | |||
|
586 | def updateconfig(repo, pats, opts, include=False, exclude=False, reset=False, | |||
|
587 | delete=False, enableprofile=False, disableprofile=False, | |||
|
588 | force=False): | |||
|
589 | """Perform a sparse config update. | |||
|
590 | ||||
|
591 | Only one of the actions may be performed. | |||
|
592 | ||||
|
593 | The new config is written out and a working directory refresh is performed. | |||
|
594 | """ | |||
|
595 | wlock = repo.wlock() | |||
|
596 | try: | |||
|
597 | oldsparsematch = matcher(repo) | |||
|
598 | ||||
|
599 | raw = repo.vfs.tryread('sparse') | |||
|
600 | if raw: | |||
|
601 | oldinclude, oldexclude, oldprofiles = map( | |||
|
602 | set, parseconfig(repo.ui, raw)) | |||
|
603 | else: | |||
|
604 | oldinclude = set() | |||
|
605 | oldexclude = set() | |||
|
606 | oldprofiles = set() | |||
|
607 | ||||
|
608 | try: | |||
|
609 | if reset: | |||
|
610 | newinclude = set() | |||
|
611 | newexclude = set() | |||
|
612 | newprofiles = set() | |||
|
613 | else: | |||
|
614 | newinclude = set(oldinclude) | |||
|
615 | newexclude = set(oldexclude) | |||
|
616 | newprofiles = set(oldprofiles) | |||
|
617 | ||||
|
618 | oldstatus = repo.status() | |||
|
619 | ||||
|
620 | if any(pat.startswith('/') for pat in pats): | |||
|
621 | repo.ui.warn(_('warning: paths cannot start with /, ' | |||
|
622 | 'ignoring: %s\n') % | |||
|
623 | ([pat for pat in pats if pat.startswith('/')])) | |||
|
624 | elif include: | |||
|
625 | newinclude.update(pats) | |||
|
626 | elif exclude: | |||
|
627 | newexclude.update(pats) | |||
|
628 | elif enableprofile: | |||
|
629 | newprofiles.update(pats) | |||
|
630 | elif disableprofile: | |||
|
631 | newprofiles.difference_update(pats) | |||
|
632 | elif delete: | |||
|
633 | newinclude.difference_update(pats) | |||
|
634 | newexclude.difference_update(pats) | |||
|
635 | ||||
|
636 | writeconfig(repo, newinclude, newexclude, newprofiles) | |||
|
637 | ||||
|
638 | fcounts = map( | |||
|
639 | len, | |||
|
640 | refreshwdir(repo, oldstatus, oldsparsematch, force=force)) | |||
|
641 | ||||
|
642 | profilecount = (len(newprofiles - oldprofiles) - | |||
|
643 | len(oldprofiles - newprofiles)) | |||
|
644 | includecount = (len(newinclude - oldinclude) - | |||
|
645 | len(oldinclude - newinclude)) | |||
|
646 | excludecount = (len(newexclude - oldexclude) - | |||
|
647 | len(oldexclude - newexclude)) | |||
|
648 | printchanges(repo.ui, opts, profilecount, includecount, | |||
|
649 | excludecount, *fcounts) | |||
|
650 | except Exception: | |||
|
651 | writeconfig(repo, oldinclude, oldexclude, oldprofiles) | |||
|
652 | raise | |||
|
653 | finally: | |||
|
654 | wlock.release() | |||
|
655 | ||||
586 | def printchanges(ui, opts, profilecount=0, includecount=0, excludecount=0, |
|
656 | def printchanges(ui, opts, profilecount=0, includecount=0, excludecount=0, | |
587 | added=0, dropped=0, conflicting=0): |
|
657 | added=0, dropped=0, conflicting=0): | |
588 | """Print output summarizing sparse config changes.""" |
|
658 | """Print output summarizing sparse config changes.""" |
General Comments 0
You need to be logged in to leave comments.
Login now