comparison 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
comparison
equal deleted inserted replaced
49353:fa8d974284f8 49354:216f273b6b30
26 26
27 # Whether sparse features are enabled. This variable is intended to be 27 # Whether sparse features are enabled. This variable is intended to be
28 # temporary to facilitate porting sparse to core. It should eventually be 28 # temporary to facilitate porting sparse to core. It should eventually be
29 # a per-repo option, possibly a repo requirement. 29 # a per-repo option, possibly a repo requirement.
30 enabled = False 30 enabled = False
31
32
33 def use_sparse(repo):
34 if getattr(repo, "_has_sparse", False):
35 # When enabling sparse the first time we need it to be enabled before
36 # actually enabling it. This hack could be avoided if the code was
37 # improved further, however this is an improvement over the previously
38 # existing global variable.
39 return True
40 return requirements.SPARSE_REQUIREMENT in repo.requirements
31 41
32 42
33 def parseconfig(ui, raw, action): 43 def parseconfig(ui, raw, action):
34 """Parse sparse config file content. 44 """Parse sparse config file content.
35 45
112 122
113 Returns a tuple of iterables representing includes, excludes, and 123 Returns a tuple of iterables representing includes, excludes, and
114 patterns. 124 patterns.
115 """ 125 """
116 # Feature isn't enabled. No-op. 126 # Feature isn't enabled. No-op.
117 if not enabled: 127 if not use_sparse(repo):
118 return set(), set(), set() 128 return set(), set(), set()
119 129
120 raw = repo.vfs.tryread(b'sparse') 130 raw = repo.vfs.tryread(b'sparse')
121 if not raw: 131 if not raw:
122 return set(), set(), set() 132 return set(), set(), set()
258 includes.add(i) 268 includes.add(i)
259 writetemporaryincludes(repo, includes) 269 writetemporaryincludes(repo, includes)
260 270
261 271
262 def prunetemporaryincludes(repo): 272 def prunetemporaryincludes(repo):
263 if not enabled or not repo.vfs.exists(b'tempsparse'): 273 if not use_sparse(repo) or not repo.vfs.exists(b'tempsparse'):
264 return 274 return
265 275
266 s = repo.status() 276 s = repo.status()
267 if s.modified or s.added or s.removed or s.deleted: 277 if s.modified or s.added or s.removed or s.deleted:
268 # Still have pending changes. Don't bother trying to prune. 278 # Still have pending changes. Don't bother trying to prune.
311 revs. 321 revs.
312 322
313 ``includetemp`` indicates whether to use the temporary sparse profile. 323 ``includetemp`` indicates whether to use the temporary sparse profile.
314 """ 324 """
315 # If sparse isn't enabled, sparse matcher matches everything. 325 # If sparse isn't enabled, sparse matcher matches everything.
316 if not enabled: 326 if not use_sparse(repo):
317 return matchmod.always() 327 return matchmod.always()
318 328
319 if not revs or revs == [None]: 329 if not revs or revs == [None]:
320 revs = [ 330 revs = [
321 repo.changelog.rev(node) 331 repo.changelog.rev(node)
365 return result 375 return result
366 376
367 377
368 def filterupdatesactions(repo, wctx, mctx, branchmerge, mresult): 378 def filterupdatesactions(repo, wctx, mctx, branchmerge, mresult):
369 """Filter updates to only lay out files that match the sparse rules.""" 379 """Filter updates to only lay out files that match the sparse rules."""
370 if not enabled: 380 if not use_sparse(repo):
371 return 381 return
372 382
373 oldrevs = [pctx.rev() for pctx in wctx.parents()] 383 oldrevs = [pctx.rev() for pctx in wctx.parents()]
374 oldsparsematch = matcher(repo, oldrevs) 384 oldsparsematch = matcher(repo, oldrevs)
375 385