comparison mercurial/sparse.py @ 48737:a6efb9180764

sparse: rework debugsparse's interface hg debugsparse supports arguments like --include, similar to `hg tracked --addinclude` or `hg log --include`. But in `hg debugsparse`, the pattern is not an argument of the flag, instead the patterns are the anonymous command line arguments. Not only is this surprising, it makes it impossible to use --include and --exclude in the same invocation, or --reset --exclude. So I propose making debugsparse making --include, --exclude take an argument, and rejecting anonymous command line arguments, as well as allowing mixing several of these flags in one invocations. Differential Revision: https://phab.mercurial-scm.org/D12155
author Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
date Mon, 07 Feb 2022 00:33:22 -0500
parents 5dfaca4464d1
children c4149a110b5f
comparison
equal deleted inserted replaced
48736:fd2cf9e0c64e 48737:a6efb9180764
702 ) 702 )
703 703
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
720 Only one of the actions may be performed.
721 718
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():
725 raw = repo.vfs.tryread(b'sparse') 722 raw = repo.vfs.tryread(b'sparse')
734 else: 731 else:
735 newinclude = set(oldinclude) 732 newinclude = set(oldinclude)
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):
741 738 raise error.Abort(_(b'paths cannot be absolute'))
742 if not usereporootpaths: 739
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 = []
746 for kindpat in pats: 746 for kindpat in pats:
747 kind, pat = matchmod._patsplit(kindpat, None) 747 kind, pat = matchmod._patsplit(kindpat, None)
750 root, cwd, pat 750 root, cwd, pat
751 ) 751 )
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
771 ) 772 )
772 includecount = len(newinclude - oldinclude) - len( 773 includecount = len(newinclude - oldinclude) - len(