# HG changeset patch # User Pierre-Yves David # Date 1654673461 -7200 # Node ID 216f273b6b30a66a64a972fa451e80bf4d43f33f # Parent fa8d974284f8ab2fb33b64e78d125ce0a388c547 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. diff -r fa8d974284f8 -r 216f273b6b30 hgext/sparse.py --- a/hgext/sparse.py Fri Jun 10 19:54:08 2022 +0200 +++ b/hgext/sparse.py Wed Jun 08 09:31:01 2022 +0200 @@ -397,6 +397,9 @@ if count > 1: raise error.Abort(_(b"too many flags specified")) + # enable sparse on repo even if the requirements is missing. + repo._has_sparse = True + if count == 0: if repo.vfs.exists(b'sparse'): ui.status(repo.vfs.read(b"sparse") + b"\n") @@ -452,3 +455,5 @@ ) finally: wlock.release() + + del repo._has_sparse diff -r fa8d974284f8 -r 216f273b6b30 mercurial/sparse.py --- 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()]