annotate hgext3rd/topic/evolvebits.py @ 5913:e682bbe66e37

compat: add check_at_most_one_arg() and check_incompatible_arguments()
author Anton Shestakov <av6@dwimlabs.net>
date Sat, 15 May 2021 02:58:04 +0800
parents 5abae69db977
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1982
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
1 import collections
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
2
3697
6aff4bb3970d compat: drop compatibility layer for successorssets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3017
diff changeset
3 from mercurial import (
6aff4bb3970d compat: drop compatibility layer for successorssets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3017
diff changeset
4 obsutil,
6aff4bb3970d compat: drop compatibility layer for successorssets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3017
diff changeset
5 )
2694
8a222745a71c topic: adapt to function migrate to obsutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 1982
diff changeset
6
1982
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
7 # Copied from evolve 081605c2e9b6
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
8
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
9 def builddependencies(repo, revs):
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
10 """returns dependency graphs giving an order to solve instability of revs
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
11 (see _orderrevs for more information on usage)"""
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
12
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
13 # For each troubled revision we keep track of what instability if any should
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
14 # be resolved in order to resolve it. Example:
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
15 # dependencies = {3: [6], 6:[]}
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
16 # Means that: 6 has no dependency, 3 depends on 6 to be solved
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
17 dependencies = {}
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
18 # rdependencies is the inverted dict of dependencies
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
19 rdependencies = collections.defaultdict(set)
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
20
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
21 for r in revs:
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
22 dependencies[r] = set()
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
23 for p in repo[r].parents():
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
24 try:
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
25 succ = _singlesuccessor(repo, p)
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
26 except MultipleSuccessorsError as exc:
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
27 dependencies[r] = exc.successorssets
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
28 continue
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
29 if succ in revs:
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
30 dependencies[r].add(succ)
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
31 rdependencies[succ].add(r)
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
32 return dependencies, rdependencies
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
33
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
34 def _singlesuccessor(repo, p):
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
35 """returns p (as rev) if not obsolete or its unique latest successors
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
36
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
37 fail if there are no such successor"""
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
38
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
39 if not p.obsolete():
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
40 return p.rev()
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
41 obs = repo[p]
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
42 ui = repo.ui
5266
9035901412e6 topic: provide cache to successorssets() in _singlesuccessor()
Anton Shestakov <av6@dwimlabs.net>
parents: 5019
diff changeset
43 cache = {}
9035901412e6 topic: provide cache to successorssets() in _singlesuccessor()
Anton Shestakov <av6@dwimlabs.net>
parents: 5019
diff changeset
44 newer = obsutil.successorssets(repo, obs.node(), cache=cache)
1982
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
45 # search of a parent which is not killed
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
46 while not newer:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 3697
diff changeset
47 ui.debug(b"stabilize target %s is plain dead,"
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 3697
diff changeset
48 b" trying to stabilize on its parent\n" %
1982
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
49 obs)
5019
967e9a87e82d cleanup: replace .parents()[0] by .p1()
Martin von Zweigbergk <martinvonz@google.com>
parents: 4814
diff changeset
50 obs = obs.p1()
5266
9035901412e6 topic: provide cache to successorssets() in _singlesuccessor()
Anton Shestakov <av6@dwimlabs.net>
parents: 5019
diff changeset
51 newer = obsutil.successorssets(repo, obs.node(), cache=cache)
3017
0884856a4143 stack: handle basic case of splitting with crash
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2922
diff changeset
52 if 1 < len(newer):
0884856a4143 stack: handle basic case of splitting with crash
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2922
diff changeset
53 # divergence case
0884856a4143 stack: handle basic case of splitting with crash
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2922
diff changeset
54 # we should pick as arbitrary one
1982
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
55 raise MultipleSuccessorsError(newer)
3017
0884856a4143 stack: handle basic case of splitting with crash
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2922
diff changeset
56 elif 1 < len(newer[0]):
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 3697
diff changeset
57 splitheads = list(repo.revs(b'heads(%ln::%ln)', newer[0], newer[0]))
3017
0884856a4143 stack: handle basic case of splitting with crash
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2922
diff changeset
58 if 1 < len(splitheads):
0884856a4143 stack: handle basic case of splitting with crash
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2922
diff changeset
59 # split case, See if we can make sense of it.
0884856a4143 stack: handle basic case of splitting with crash
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2922
diff changeset
60 raise MultipleSuccessorsError(newer)
0884856a4143 stack: handle basic case of splitting with crash
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2922
diff changeset
61 return splitheads[0]
1982
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
62
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
63 return repo[newer[0][0]].rev()
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
64
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
65 class MultipleSuccessorsError(RuntimeError):
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
66 """Exception raised by _singlesuccessor when multiple successor sets exists
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
67
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
68 The object contains the list of successorssets in its 'successorssets'
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
69 attribute to call to easily recover.
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
70 """
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
71
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
72 def __init__(self, successorssets):
d87fc4f749e6 evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
73 self.successorssets = successorssets