Mercurial > hg
diff 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 |
line wrap: on
line diff
--- a/mercurial/sparse.py Wed Feb 09 13:04:37 2022 -0500 +++ b/mercurial/sparse.py Mon Feb 07 00:33:22 2022 -0500 @@ -704,21 +704,18 @@ def updateconfig( repo, - pats, opts, - include=False, - exclude=False, + include=(), + exclude=(), reset=False, - delete=False, - enableprofile=False, - disableprofile=False, + delete=(), + enableprofile=(), + disableprofile=(), force=False, usereporootpaths=False, ): """Perform a sparse config update. - Only one of the actions may be performed. - The new config is written out and a working directory refresh is performed. """ with repo.wlock(), repo.lock(), repo.dirstate.parentchange(): @@ -736,10 +733,13 @@ newexclude = set(oldexclude) newprofiles = set(oldprofiles) - if any(os.path.isabs(pat) for pat in pats): - raise error.Abort(_(b'paths cannot be absolute')) + def normalize_pats(pats): + if any(os.path.isabs(pat) for pat in pats): + raise error.Abort(_(b'paths cannot be absolute')) - if not usereporootpaths: + if usereporootpaths: + return pats + # let's treat paths as relative to cwd root, cwd = repo.root, repo.getcwd() abspats = [] @@ -752,19 +752,20 @@ abspats.append(ap) else: abspats.append(kindpat) - pats = abspats + return abspats - if include: - newinclude.update(pats) - elif exclude: - newexclude.update(pats) - elif enableprofile: - newprofiles.update(pats) - elif disableprofile: - newprofiles.difference_update(pats) - elif delete: - newinclude.difference_update(pats) - newexclude.difference_update(pats) + include = normalize_pats(include) + exclude = normalize_pats(exclude) + delete = normalize_pats(delete) + disableprofile = normalize_pats(disableprofile) + enableprofile = normalize_pats(enableprofile) + + newinclude.difference_update(delete) + newexclude.difference_update(delete) + newprofiles.difference_update(disableprofile) + newinclude.update(include) + newprofiles.update(enableprofile) + newexclude.update(exclude) profilecount = len(newprofiles - oldprofiles) - len( oldprofiles - newprofiles