comparison hgext/sparse.py @ 33370:482320104672

sparse: refactor activeprofiles into a generic function (API) activeprofiles() is a special case of a more generic function. Furthermore, that generic function is essentially already implemented inline in the sparse extension. So, refactor activeprofiles() to a generic activeconfig(). Change the only consumer of activeprofiles() to use it. And have the inline implementation in the sparse extension use it.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 08 Jul 2017 14:01:32 -0700
parents 9087f9997f42
children c6415195fa78
comparison
equal deleted inserted replaced
33369:d36bcba91845 33370:482320104672
73 """ 73 """
74 74
75 from __future__ import absolute_import 75 from __future__ import absolute_import
76 76
77 from mercurial.i18n import _ 77 from mercurial.i18n import _
78 from mercurial.node import nullid
79 from mercurial import ( 78 from mercurial import (
80 cmdutil, 79 cmdutil,
81 commands, 80 commands,
82 dirstate, 81 dirstate,
83 error, 82 error,
446 finally: 445 finally:
447 wlock.release() 446 wlock.release()
448 447
449 def _import(ui, repo, files, opts, force=False): 448 def _import(ui, repo, files, opts, force=False):
450 with repo.wlock(): 449 with repo.wlock():
451 # load union of current active profile
452 revs = [repo.changelog.rev(node) for node in
453 repo.dirstate.parents() if node != nullid]
454
455 # read current configuration 450 # read current configuration
456 raw = repo.vfs.tryread('sparse') 451 raw = repo.vfs.tryread('sparse')
457 oincludes, oexcludes, oprofiles = sparse.parseconfig(ui, raw) 452 oincludes, oexcludes, oprofiles = sparse.parseconfig(ui, raw)
458 includes, excludes, profiles = map( 453 includes, excludes, profiles = map(
459 set, (oincludes, oexcludes, oprofiles)) 454 set, (oincludes, oexcludes, oprofiles))
460 455
461 # all active rules 456 aincludes, aexcludes, aprofiles = sparse.activeconfig(repo)
462 aincludes, aexcludes, aprofiles = set(), set(), set()
463 for rev in revs:
464 rincludes, rexcludes, rprofiles = sparse.patternsforrev(repo, rev)
465 aincludes.update(rincludes)
466 aexcludes.update(rexcludes)
467 aprofiles.update(rprofiles)
468 457
469 # import rules on top; only take in rules that are not yet 458 # import rules on top; only take in rules that are not yet
470 # part of the active rules. 459 # part of the active rules.
471 changed = False 460 changed = False
472 for file in files: 461 for file in files: