590 |
590 |
591 Only one of the actions may be performed. |
591 Only one of the actions may be performed. |
592 |
592 |
593 The new config is written out and a working directory refresh is performed. |
593 The new config is written out and a working directory refresh is performed. |
594 """ |
594 """ |
595 wlock = repo.wlock() |
595 with repo.wlock(): |
596 try: |
596 oldmatcher = matcher(repo) |
597 oldsparsematch = matcher(repo) |
|
598 |
597 |
599 raw = repo.vfs.tryread('sparse') |
598 raw = repo.vfs.tryread('sparse') |
600 if raw: |
599 oldinclude, oldexclude, oldprofiles = parseconfig(repo.ui, raw) |
601 oldinclude, oldexclude, oldprofiles = map( |
600 oldprofiles = set(oldprofiles) |
602 set, parseconfig(repo.ui, raw)) |
|
603 else: |
|
604 oldinclude = set() |
|
605 oldexclude = set() |
|
606 oldprofiles = set() |
|
607 |
601 |
608 try: |
602 try: |
609 if reset: |
603 if reset: |
610 newinclude = set() |
604 newinclude = set() |
611 newexclude = set() |
605 newexclude = set() |
635 |
629 |
636 writeconfig(repo, newinclude, newexclude, newprofiles) |
630 writeconfig(repo, newinclude, newexclude, newprofiles) |
637 |
631 |
638 fcounts = map( |
632 fcounts = map( |
639 len, |
633 len, |
640 refreshwdir(repo, oldstatus, oldsparsematch, force=force)) |
634 refreshwdir(repo, oldstatus, oldmatcher, force=force)) |
641 |
635 |
642 profilecount = (len(newprofiles - oldprofiles) - |
636 profilecount = (len(newprofiles - oldprofiles) - |
643 len(oldprofiles - newprofiles)) |
637 len(oldprofiles - newprofiles)) |
644 includecount = (len(newinclude - oldinclude) - |
638 includecount = (len(newinclude - oldinclude) - |
645 len(oldinclude - newinclude)) |
639 len(oldinclude - newinclude)) |
648 printchanges(repo.ui, opts, profilecount, includecount, |
642 printchanges(repo.ui, opts, profilecount, includecount, |
649 excludecount, *fcounts) |
643 excludecount, *fcounts) |
650 except Exception: |
644 except Exception: |
651 writeconfig(repo, oldinclude, oldexclude, oldprofiles) |
645 writeconfig(repo, oldinclude, oldexclude, oldprofiles) |
652 raise |
646 raise |
653 finally: |
|
654 wlock.release() |
|
655 |
647 |
656 def printchanges(ui, opts, profilecount=0, includecount=0, excludecount=0, |
648 def printchanges(ui, opts, profilecount=0, includecount=0, excludecount=0, |
657 added=0, dropped=0, conflicting=0): |
649 added=0, dropped=0, conflicting=0): |
658 """Print output summarizing sparse config changes.""" |
650 """Print output summarizing sparse config changes.""" |
659 with ui.formatter('sparse', opts) as fm: |
651 with ui.formatter('sparse', opts) as fm: |