Mercurial > evolve
annotate hgext3rd/topic/stack.py @ 1997:ce86f7bb4b7b
stack: add some behind information
This is the next useful thing after branch
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Fri, 26 Aug 2016 14:55:58 +0200 |
parents | 5c40dd2cf131 |
children | 302be26a3fd8 |
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. |
1995
54d6dff699f0
stack: add some header with the topic name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1991
diff
changeset
|
5 from mercurial.i18n import _ |
1936
31583ddda6d9
stack: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1925
diff
changeset
|
6 from mercurial import ( |
1985
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
7 destutil, |
1936
31583ddda6d9
stack: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1925
diff
changeset
|
8 error, |
1961
d9c7fced94fc
stack: prevent crash when topic is rooted on nullid
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1957
diff
changeset
|
9 node, |
1936
31583ddda6d9
stack: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1925
diff
changeset
|
10 ) |
1982
d87fc4f749e6
evolve: extract the code copied from evolve in a submodule
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1979
diff
changeset
|
11 from .evolvebits import builddependencies, _orderrevs, _singlesuccessor |
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
|
12 |
1904
f52c02bf47b7
stack: allow to refer to changeset using "t2" form
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1901
diff
changeset
|
13 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
|
14 # 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
|
15 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
|
16 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
|
17 |
1907
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
18 def showstack(ui, repo, topic, opts): |
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
19 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
|
20 prev = None |
1955
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
21 entries = [] |
1991
ba79d23594d6
stack: reusing the index number in base when applicable
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1990
diff
changeset
|
22 idxmap = {} |
1995
54d6dff699f0
stack: add some header with the topic name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1991
diff
changeset
|
23 |
54d6dff699f0
stack: add some header with the topic name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1991
diff
changeset
|
24 label = 'topic' |
54d6dff699f0
stack: add some header with the topic name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1991
diff
changeset
|
25 if topic == repo.currenttopic: |
54d6dff699f0
stack: add some header with the topic name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1991
diff
changeset
|
26 label = 'topic.active' |
54d6dff699f0
stack: add some header with the topic name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1991
diff
changeset
|
27 |
1996
5c40dd2cf131
stack: add some basic branch information
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1995
diff
changeset
|
28 data = stackdata(repo, topic) |
1995
54d6dff699f0
stack: add some header with the topic name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1991
diff
changeset
|
29 fm.plain(_('### topic: %s\n') % ui.label(topic, label), |
54d6dff699f0
stack: add some header with the topic name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1991
diff
changeset
|
30 label='topic.stack.summary.topic') |
1997
ce86f7bb4b7b
stack: add some behind information
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1996
diff
changeset
|
31 fm.plain(_('### branch: %s') |
1996
5c40dd2cf131
stack: add some basic branch information
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1995
diff
changeset
|
32 % '+'.join(data['branches']), # XXX handle multi branches |
5c40dd2cf131
stack: add some basic branch information
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1995
diff
changeset
|
33 label='topic.stack.summary.branches') |
1997
ce86f7bb4b7b
stack: add some behind information
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1996
diff
changeset
|
34 if data['behindcount'] == -1: |
ce86f7bb4b7b
stack: add some behind information
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1996
diff
changeset
|
35 fm.plain(', ') |
ce86f7bb4b7b
stack: add some behind information
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1996
diff
changeset
|
36 fm.plain('ambigious rebase destination', label='topic.stack.summary.behinderror') |
ce86f7bb4b7b
stack: add some behind information
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1996
diff
changeset
|
37 elif data['behindcount']: |
ce86f7bb4b7b
stack: add some behind information
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1996
diff
changeset
|
38 fm.plain(', ') |
ce86f7bb4b7b
stack: add some behind information
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1996
diff
changeset
|
39 fm.plain('%d behind' % data['behindcount'], label='topic.stack.summary.behindcount') |
ce86f7bb4b7b
stack: add some behind information
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1996
diff
changeset
|
40 fm.plain('\n') |
1995
54d6dff699f0
stack: add some header with the topic name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1991
diff
changeset
|
41 |
1954
61f36480740f
stack: start indexing at 't1' instead of 't0'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1936
diff
changeset
|
42 for idx, r in enumerate(getstack(repo, topic), 1): |
1925 | 43 ctx = repo[r] |
1909
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
44 p1 = ctx.p1() |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
45 if p1.obsolete(): |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
46 p1 = repo[_singlesuccessor(repo, p1)] |
1961
d9c7fced94fc
stack: prevent crash when topic is rooted on nullid
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1957
diff
changeset
|
47 if p1.rev() != prev and p1.node() != node.nullid: |
1991
ba79d23594d6
stack: reusing the index number in base when applicable
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1990
diff
changeset
|
48 entries.append((idxmap.get(p1.rev()), False, p1)) |
ba79d23594d6
stack: reusing the index number in base when applicable
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1990
diff
changeset
|
49 entries.append((idx, True, ctx)) |
ba79d23594d6
stack: reusing the index number in base when applicable
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1990
diff
changeset
|
50 idxmap[ctx.rev()] = idx |
1955
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
51 prev = r |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
52 |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
53 # super crude initial version |
1991
ba79d23594d6
stack: reusing the index number in base when applicable
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1990
diff
changeset
|
54 for idx, isentry, ctx in entries[::-1]: |
ba79d23594d6
stack: reusing the index number in base when applicable
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1990
diff
changeset
|
55 if not isentry: |
1957
ea5553e47027
stack: change the ascii symbold for base
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1956
diff
changeset
|
56 symbol = '^' |
1955
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
57 state = 'base' |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
58 elif repo.revs('%d and parents()', ctx.rev()): |
1906
5e9ce6310720
stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1905
diff
changeset
|
59 symbol = '@' |
5e9ce6310720
stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1905
diff
changeset
|
60 state = 'current' |
1955
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
61 elif repo.revs('%d and unstable()', ctx.rev()): |
1906
5e9ce6310720
stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1905
diff
changeset
|
62 symbol = '$' |
5e9ce6310720
stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1905
diff
changeset
|
63 state = 'unstable' |
1955
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
64 else: |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
65 symbol = ':' |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
66 state = 'clean' |
1907
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
67 fm.startitem() |
1991
ba79d23594d6
stack: reusing the index number in base when applicable
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1990
diff
changeset
|
68 fm.data(isentry=isentry) |
1955
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
69 if idx is None: |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
70 fm.plain(' ') |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
71 else: |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
72 fm.write('topic.stack.index', 't%d', idx, |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
73 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
|
74 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
|
75 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
|
76 fm.plain(' ') |
1909
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
77 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
|
78 label='topic.stack.desc topic.stack.desc.%s' % state) |
1955
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
79 fm.condwrite(state != 'clean' and idx is not None, 'topic.stack.state', |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
80 ' (%s)', state, |
1925 | 81 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
|
82 fm.plain('\n') |
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
83 fm.end() |
1897
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
84 |
1977
137f8b04901e
topic: list the number of changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1961
diff
changeset
|
85 def stackdata(repo, topic): |
137f8b04901e
topic: list the number of changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1961
diff
changeset
|
86 """get various data about a stack |
137f8b04901e
topic: list the number of changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1961
diff
changeset
|
87 |
137f8b04901e
topic: list the number of changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1961
diff
changeset
|
88 :changesetcount: number of non-obsolete changesets in the stack |
1978
e42dd4523c0d
topic: list the number of troubled changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1977
diff
changeset
|
89 :troubledcount: number on troubled changesets |
1979
bee7a1ef8ba8
topic: list the number of head when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1978
diff
changeset
|
90 :headcount: number of heads on the topic |
1985
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
91 :behindcount: number of changeset on rebase destination |
1977
137f8b04901e
topic: list the number of changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1961
diff
changeset
|
92 """ |
137f8b04901e
topic: list the number of changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1961
diff
changeset
|
93 data = {} |
137f8b04901e
topic: list the number of changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1961
diff
changeset
|
94 revs = repo.revs("topic(%s) - obsolete()", topic) |
137f8b04901e
topic: list the number of changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1961
diff
changeset
|
95 data['changesetcount'] = len(revs) |
1978
e42dd4523c0d
topic: list the number of troubled changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1977
diff
changeset
|
96 data['troubledcount'] = len([r for r in revs if repo[r].troubled()]) |
1979
bee7a1ef8ba8
topic: list the number of head when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1978
diff
changeset
|
97 deps, rdeps = builddependencies(repo, revs) |
bee7a1ef8ba8
topic: list the number of head when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1978
diff
changeset
|
98 data['headcount'] = len([r for r in revs if not rdeps[r]]) |
1985
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
99 data['behindcount'] = 0 |
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
100 if revs: |
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
101 minroot = [min(r for r in revs if not deps[r])] |
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
102 try: |
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
103 dest = destutil.destmerge(repo, action='rebase', |
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
104 sourceset=minroot, |
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
105 onheadcheck=False) |
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
106 data['behindcount'] = len(repo.revs("only(%d, %ld)", dest, |
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
107 minroot)) |
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
108 except error.NoMergeDestAbort: |
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
109 data['behindcount'] = 0 |
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
110 except error.ManyMergeDestAbort: |
03d6b685c16a
topic: list the number of 'behind' changeset when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1982
diff
changeset
|
111 data['behindcount'] = -1 |
1988
9a5d797d25be
topic: list the branches this topic belong to when verbose
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1985
diff
changeset
|
112 data['branches'] = sorted(set(repo[r].branch() for r in revs)) |
1979
bee7a1ef8ba8
topic: list the number of head when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1978
diff
changeset
|
113 |
1977
137f8b04901e
topic: list the number of changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1961
diff
changeset
|
114 return data |
137f8b04901e
topic: list the number of changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1961
diff
changeset
|
115 |