Mercurial > hg
diff mercurial/sparse.py @ 49354:216f273b6b30
sparse: start moving away from the global variable for detection of usage
Code is now checking if the repository using the sparse feature and that's it.
Some code in `debugsparse` still rely on "global" state, as it apply sparse
logic before updating the requirement. Cleaning that up is more work that we
signed up for, but we could narrow the hack to that specific command.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 08 Jun 2022 09:31:01 +0200 |
parents | f254fc73d956 |
children | c166b212bdee |
line wrap: on
line diff
--- a/mercurial/sparse.py Fri Jun 10 19:54:08 2022 +0200 +++ b/mercurial/sparse.py Wed Jun 08 09:31:01 2022 +0200 @@ -30,6 +30,16 @@ enabled = False +def use_sparse(repo): + if getattr(repo, "_has_sparse", False): + # When enabling sparse the first time we need it to be enabled before + # actually enabling it. This hack could be avoided if the code was + # improved further, however this is an improvement over the previously + # existing global variable. + return True + return requirements.SPARSE_REQUIREMENT in repo.requirements + + def parseconfig(ui, raw, action): """Parse sparse config file content. @@ -114,7 +124,7 @@ patterns. """ # Feature isn't enabled. No-op. - if not enabled: + if not use_sparse(repo): return set(), set(), set() raw = repo.vfs.tryread(b'sparse') @@ -260,7 +270,7 @@ def prunetemporaryincludes(repo): - if not enabled or not repo.vfs.exists(b'tempsparse'): + if not use_sparse(repo) or not repo.vfs.exists(b'tempsparse'): return s = repo.status() @@ -313,7 +323,7 @@ ``includetemp`` indicates whether to use the temporary sparse profile. """ # If sparse isn't enabled, sparse matcher matches everything. - if not enabled: + if not use_sparse(repo): return matchmod.always() if not revs or revs == [None]: @@ -367,7 +377,7 @@ def filterupdatesactions(repo, wctx, mctx, branchmerge, mresult): """Filter updates to only lay out files that match the sparse rules.""" - if not enabled: + if not use_sparse(repo): return oldrevs = [pctx.rev() for pctx in wctx.parents()]