Mercurial > evolve
annotate hgext3rd/topic/stack.py @ 1925:8f8a48a2e97d
stack: whitespace
author | Sean Farley <sean@farley.io> |
---|---|
date | Mon, 21 Mar 2016 21:30:14 -0700 |
parents | eadcc5f8edf6 |
children | 31583ddda6d9 |
rev | line source |
---|---|
1895
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
1 # stack.py - code related to stack workflow |
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
2 # |
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
3 # This software may be used and distributed according to the terms of the |
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
4 # GNU General Public License version 2 or any later version. |
1897
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
5 import collections |
1895
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
6 from mercurial.i18n import _ |
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
7 from mercurial import error |
1897
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
8 from mercurial import obsolete |
1895
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
9 |
1904
f52c02bf47b7
stack: allow to refer to changeset using "t2" form
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
10 def getstack(repo, topic): |
1895
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
11 # XXX need sorting |
1897
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
12 trevs = repo.revs("topic(%s) - obsolete()", topic) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
13 return _orderrevs(repo, trevs) |
1895
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
14 |
1907
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
15 def showstack(ui, repo, topic, opts): |
1895
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
16 if not topic: |
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
17 topic = repo.currenttopic |
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
18 if not topic: |
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
19 raise error.Abort(_('no active topic to list')) |
1907
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
20 fm = ui.formatter('topicstack', opts) |
1909
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
21 prev = None |
1904
f52c02bf47b7
stack: allow to refer to changeset using "t2" form
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
22 for idx, r in enumerate(getstack(repo, topic)): |
1925 | 23 ctx = repo[r] |
1909
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
24 p1 = ctx.p1() |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
25 if p1.obsolete(): |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
26 p1 = repo[_singlesuccessor(repo, p1)] |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
27 if p1.rev() != prev: |
1914 | 28 # display the parent of the changeset |
1909
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
29 state = 'base' |
1925 | 30 symbol = '_' |
1909
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
31 fm.startitem() |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
32 fm.plain(' ') # XXX 2 is the right padding by chance |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
33 fm.write('topic.stack.state', '%s', symbol, |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
34 label='topic.stack.state topic.stack.state.%s' % state) |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
35 fm.plain(' ') |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
36 fm.write('topic.stack.desc', '%s', |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
37 p1.description().splitlines()[0], |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
38 label='topic.stack.desc topic.stack.desc.%s' % state) |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
39 fm.plain('\n') |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
40 fm.end() |
1895
c8e4c6e03957
stack: add a very first version of stack display with 'hg topic --list'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
41 # super crude initial version |
1906
5e9ce6310720
stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1905
diff
changeset
|
42 symbol = ':' |
5e9ce6310720
stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1905
diff
changeset
|
43 state = 'clean' |
5e9ce6310720
stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1905
diff
changeset
|
44 if repo.revs('%d and parents()', r): |
5e9ce6310720
stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1905
diff
changeset
|
45 symbol = '@' |
5e9ce6310720
stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1905
diff
changeset
|
46 state = 'current' |
5e9ce6310720
stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1905
diff
changeset
|
47 if repo.revs('%d and unstable()', r): |
5e9ce6310720
stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1905
diff
changeset
|
48 symbol = '$' |
5e9ce6310720
stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1905
diff
changeset
|
49 state = 'unstable' |
1907
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
50 fm.startitem() |
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
51 fm.write('topic.stack.index', 't%d', idx, |
1925 | 52 label='topic.stack.index topic.stack.index.%s' % state) |
1907
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
53 fm.write('topic.stack.state.symbol', '%s', symbol, |
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
54 label='topic.stack.state topic.stack.state.%s' % state) |
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
55 fm.plain(' ') |
1909
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
56 fm.write('topic.stack.desc', '%s', ctx.description().splitlines()[0], |
1907
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
57 label='topic.stack.desc topic.stack.desc.%s' % state) |
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
58 fm.condwrite(state != 'clean', 'topic.stack.state', ' (%s)', state, |
1925 | 59 label='topic.stack.state topic.stack.state.%s' % state) |
1907
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
60 fm.plain('\n') |
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
61 fm.end() |
1909
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
62 prev = r |
1897
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
63 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
64 # Copied from evolve 081605c2e9b6 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
65 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
66 def _orderrevs(repo, revs): |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
67 """Compute an ordering to solve instability for the given revs |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
68 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
69 revs is a list of unstable revisions. |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
70 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
71 Returns the same revisions ordered to solve their instability from the |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
72 bottom to the top of the stack that the stabilization process will produce |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
73 eventually. |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
74 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
75 This ensures the minimal number of stabilizations, as we can stabilize each |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
76 revision on its final stabilized destination. |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
77 """ |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
78 # Step 1: Build the dependency graph |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
79 dependencies, rdependencies = builddependencies(repo, revs) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
80 # Step 2: Build the ordering |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
81 # Remove the revisions with no dependency(A) and add them to the ordering. |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
82 # Removing these revisions leads to new revisions with no dependency (the |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
83 # one depending on A) that we can remove from the dependency graph and add |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
84 # to the ordering. We progress in a similar fashion until the ordering is |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
85 # built |
1909
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
86 solvablerevs = [r for r in sorted(dependencies.keys()) |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
87 if not dependencies[r]] |
1897
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
88 ordering = [] |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
89 while solvablerevs: |
1909
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
90 rev = solvablerevs.pop() |
1897
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
91 for dependent in rdependencies[rev]: |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
92 dependencies[dependent].remove(rev) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
93 if not dependencies[dependent]: |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
94 solvablerevs.append(dependent) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
95 del dependencies[rev] |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
96 ordering.append(rev) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
97 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
98 ordering.extend(sorted(dependencies)) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
99 return ordering |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
100 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
101 def builddependencies(repo, revs): |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
102 """returns dependency graphs giving an order to solve instability of revs |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
103 (see _orderrevs for more information on usage)""" |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
104 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
105 # For each troubled revision we keep track of what instability if any should |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
106 # be resolved in order to resolve it. Example: |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
107 # dependencies = {3: [6], 6:[]} |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
108 # Means that: 6 has no dependency, 3 depends on 6 to be solved |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
109 dependencies = {} |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
110 # rdependencies is the inverted dict of dependencies |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
111 rdependencies = collections.defaultdict(set) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
112 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
113 for r in revs: |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
114 dependencies[r] = set() |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
115 for p in repo[r].parents(): |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
116 try: |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
117 succ = _singlesuccessor(repo, p) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
118 except MultipleSuccessorsError as exc: |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
119 dependencies[r] = exc.successorssets |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
120 continue |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
121 if succ in revs: |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
122 dependencies[r].add(succ) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
123 rdependencies[succ].add(r) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
124 return dependencies, rdependencies |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
125 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
126 def _singlesuccessor(repo, p): |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
127 """returns p (as rev) if not obsolete or its unique latest successors |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
128 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
129 fail if there are no such successor""" |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
130 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
131 if not p.obsolete(): |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
132 return p.rev() |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
133 obs = repo[p] |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
134 ui = repo.ui |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
135 newer = obsolete.successorssets(repo, obs.node()) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
136 # search of a parent which is not killed |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
137 while not newer: |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
138 ui.debug("stabilize target %s is plain dead," |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
139 " trying to stabilize on its parent\n" % |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
140 obs) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
141 obs = obs.parents()[0] |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
142 newer = obsolete.successorssets(repo, obs.node()) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
143 if len(newer) > 1 or len(newer[0]) > 1: |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
144 raise MultipleSuccessorsError(newer) |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
145 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
146 return repo[newer[0][0]].rev() |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
147 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
148 class MultipleSuccessorsError(RuntimeError): |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
149 """Exception raised by _singlesuccessor when multiple successor sets exists |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
150 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
151 The object contains the list of successorssets in its 'successorssets' |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
152 attribute to call to easily recover. |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
153 """ |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
154 |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
155 def __init__(self, successorssets): |
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
156 self.successorssets = successorssets |