comparison mercurial/utils/repoviewutil.py @ 51487:1a9bdd0e1c44

branchcache: write branchmap in subset inheritance order This way, we can guarantee a valid subset has been written before touching the branchmap of another filter. This is especially useful as we are bout to start deleting outdated branchmap file.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 08 Mar 2024 15:50:15 +0100
parents 6000f5b25c9b
children
comparison
equal deleted inserted replaced
51486:0ddc34330d41 51487:1a9bdd0e1c44
4 # Logilab SA <contact@logilab.fr> 4 # Logilab SA <contact@logilab.fr>
5 # 5 #
6 # This software may be used and distributed according to the terms of the 6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version. 7 # GNU General Public License version 2 or any later version.
8 8
9 from .. import error
9 10
10 ### Nearest subset relation 11 ### Nearest subset relation
11 # Nearest subset of filter X is a filter Y so that: 12 # Nearest subset of filter X is a filter Y so that:
12 # * Y is included in X, 13 # * Y is included in X,
13 # * X - Y is as small as possible. 14 # * X - Y is as small as possible.
19 b'visible': b'served', 20 b'visible': b'served',
20 b'served.hidden': b'served', 21 b'served.hidden': b'served',
21 b'served': b'immutable', 22 b'served': b'immutable',
22 b'immutable': b'base', 23 b'immutable': b'base',
23 } 24 }
25
26
27 def get_ordered_subset():
28 """return a list of subset name from dependencies to dependents"""
29 _unfinalized = set(subsettable.values())
30 ordered = []
31
32 # the subset table is expected to be small so we do the stupid N² version
33 # of the algorithm
34 while _unfinalized:
35 this_level = []
36 for candidate in _unfinalized:
37 dependency = subsettable.get(candidate)
38 if dependency not in _unfinalized:
39 this_level.append(candidate)
40
41 if not this_level:
42 msg = "cyclic dependencies in repoview subset %r"
43 msg %= subsettable
44 raise error.ProgrammingError(msg)
45
46 this_level.sort(key=lambda x: x if x is not None else '')
47
48 ordered.extend(this_level)
49 _unfinalized.difference_update(this_level)
50
51 return ordered