Mercurial > hg
comparison mercurial/sparse.py @ 33374:4dc04cdf2520
sparse: move config updating function into core
As part of the move, the ui argument was dropped.
Additional fixups will be made in a follow-up commit.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 10 Jul 2017 21:39:49 -0700 |
parents | c6415195fa78 |
children | df6dd6d536bb |
comparison
equal
deleted
inserted
replaced
33373:fb320398a21c | 33374:4dc04cdf2520 |
---|---|
581 raise | 581 raise |
582 | 582 |
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.""" |
589 with ui.formatter('sparse', opts) as fm: | 659 with ui.formatter('sparse', opts) as fm: |
590 fm.startitem() | 660 fm.startitem() |