comparison mercurial/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 ccb3e5399921
children c6415195fa78
comparison
equal deleted inserted replaced
33369:d36bcba91845 33370:482320104672
122 if includes: 122 if includes:
123 includes.add('.hg*') 123 includes.add('.hg*')
124 124
125 return includes, excludes, profiles 125 return includes, excludes, profiles
126 126
127 def activeprofiles(repo): 127 def activeconfig(repo):
128 """Determine the active sparse config rules.
129
130 Rules are constructed by reading the current sparse config and bringing in
131 referenced profiles from parents of the working directory.
132 """
128 revs = [repo.changelog.rev(node) for node in 133 revs = [repo.changelog.rev(node) for node in
129 repo.dirstate.parents() if node != nullid] 134 repo.dirstate.parents() if node != nullid]
130 135
131 profiles = set() 136 allincludes = set()
137 allexcludes = set()
138 allprofiles = set()
139
132 for rev in revs: 140 for rev in revs:
133 profiles.update(patternsforrev(repo, rev)[2]) 141 includes, excludes, profiles = patternsforrev(repo, rev)
134 142 allincludes |= includes
135 return profiles 143 allexcludes |= excludes
144 allprofiles |= set(profiles)
145
146 return allincludes, allexcludes, allprofiles
136 147
137 def configsignature(repo, includetemp=True): 148 def configsignature(repo, includetemp=True):
138 """Obtain the signature string for the current sparse configuration. 149 """Obtain the signature string for the current sparse configuration.
139 150
140 This is used to construct a cache key for matchers. 151 This is used to construct a cache key for matchers.
359 370
360 dirstate = repo.dirstate 371 dirstate = repo.dirstate
361 for file, flags, msg in actions: 372 for file, flags, msg in actions:
362 dirstate.normal(file) 373 dirstate.normal(file)
363 374
364 profiles = activeprofiles(repo) 375 profiles = activeconfig(repo)[2]
365 changedprofiles = profiles & files 376 changedprofiles = profiles & files
366 # If an active profile changed during the update, refresh the checkout. 377 # If an active profile changed during the update, refresh the checkout.
367 # Don't do this during a branch merge, since all incoming changes should 378 # Don't do this during a branch merge, since all incoming changes should
368 # have been handled by the temporary includes above. 379 # have been handled by the temporary includes above.
369 if changedprofiles and not branchmerge: 380 if changedprofiles and not branchmerge: