Mercurial > hg
annotate mercurial/utils/repoviewutil.py @ 52281:854e2b9bca57 stable
Added signature for changeset b267c5764cc6
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Wed, 20 Nov 2024 15:38:57 +0100 |
parents | f4733654f144 |
children |
rev | line source |
---|---|
42138
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 # repoviewutil.py - constaints data relevant to repoview.py and other module |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 # |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 # Copyright 2012 Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 # Logilab SA <contact@logilab.fr> |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 # |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 # GNU General Public License version 2 or any later version. |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 |
51863
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51487
diff
changeset
|
9 from __future__ import annotations |
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51487
diff
changeset
|
10 |
51487
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
11 from .. import error |
42138
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 ### Nearest subset relation |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 # Nearest subset of filter X is a filter Y so that: |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 # * Y is included in X, |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 # * X - Y is as small as possible. |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 # This create and ordering used for branchmap purpose. |
caebe5e7f4bd
repoview: move subsettable in a dedicated module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 # the ordering may be partial |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42138
diff
changeset
|
19 subsettable = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
20 None: b'visible', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
21 b'visible-hidden': b'visible', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
22 b'visible': b'served', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
23 b'served.hidden': b'served', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
24 b'served': b'immutable', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
25 b'immutable': b'base', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42138
diff
changeset
|
26 } |
51487
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
27 |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
28 |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
29 def get_ordered_subset(): |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
30 """return a list of subset name from dependencies to dependents""" |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
31 _unfinalized = set(subsettable.values()) |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
32 ordered = [] |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
33 |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
34 # the subset table is expected to be small so we do the stupid N² version |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
35 # of the algorithm |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
36 while _unfinalized: |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
37 this_level = [] |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
38 for candidate in _unfinalized: |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
39 dependency = subsettable.get(candidate) |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
40 if dependency not in _unfinalized: |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
41 this_level.append(candidate) |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
42 |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
43 if not this_level: |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
44 msg = "cyclic dependencies in repoview subset %r" |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
45 msg %= subsettable |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
46 raise error.ProgrammingError(msg) |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
47 |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
48 this_level.sort(key=lambda x: x if x is not None else '') |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
49 |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
50 ordered.extend(this_level) |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
51 _unfinalized.difference_update(this_level) |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
52 |
1a9bdd0e1c44
branchcache: write branchmap in subset inheritance order
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
53 return ordered |