Mercurial > evolve
annotate hgext3rd/topic/stack.py @ 2915:b3abdb3d819e
stack: replace 'getstack' with direct call to 'stack'
The dedicated function do not add any value. We can update all the callers.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 04 Sep 2017 12:23:03 +0200 |
parents | 9897babc1fb5 |
children | 17749d9d3968 |
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, |
2838
1c9150e30b28
context: unstable was deprecated
Boris Feld <boris.feld@octobus.net>
parents:
2750
diff
changeset
|
8 context, |
1936
31583ddda6d9
stack: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1925
diff
changeset
|
9 error, |
1961
d9c7fced94fc
stack: prevent crash when topic is rooted on nullid
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1957
diff
changeset
|
10 node, |
2838
1c9150e30b28
context: unstable was deprecated
Boris Feld <boris.feld@octobus.net>
parents:
2750
diff
changeset
|
11 util, |
1936
31583ddda6d9
stack: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1925
diff
changeset
|
12 ) |
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
|
13 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
|
14 |
2750
bd3824d1b795
stack: show short node of changesets in `hg stack -v`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2712
diff
changeset
|
15 short = node.short |
bd3824d1b795
stack: show short node of changesets in `hg stack -v`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2712
diff
changeset
|
16 |
2838
1c9150e30b28
context: unstable was deprecated
Boris Feld <boris.feld@octobus.net>
parents:
2750
diff
changeset
|
17 # TODO: compat |
1c9150e30b28
context: unstable was deprecated
Boris Feld <boris.feld@octobus.net>
parents:
2750
diff
changeset
|
18 |
1c9150e30b28
context: unstable was deprecated
Boris Feld <boris.feld@octobus.net>
parents:
2750
diff
changeset
|
19 if not util.safehasattr(context.basectx, 'orphan'): |
1c9150e30b28
context: unstable was deprecated
Boris Feld <boris.feld@octobus.net>
parents:
2750
diff
changeset
|
20 context.basectx.orphan = context.basectx.unstable |
1c9150e30b28
context: unstable was deprecated
Boris Feld <boris.feld@octobus.net>
parents:
2750
diff
changeset
|
21 |
2839
f9c8c754a528
context: troubled was deprecated
Boris Feld <boris.feld@octobus.net>
parents:
2838
diff
changeset
|
22 if not util.safehasattr(context.basectx, 'isunstable'): |
f9c8c754a528
context: troubled was deprecated
Boris Feld <boris.feld@octobus.net>
parents:
2838
diff
changeset
|
23 context.basectx.isunstable = context.basectx.troubled |
f9c8c754a528
context: troubled was deprecated
Boris Feld <boris.feld@octobus.net>
parents:
2838
diff
changeset
|
24 |
2914
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
25 class stack(object): |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
26 """object represent a stack and common logic associated to it.""" |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
27 |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
28 def __init__(self, repo, branch=None, topic=None): |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
29 self._repo = repo |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
30 self.branch = branch |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
31 self.topic = topic |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
32 if topic is not None and branch is not None: |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
33 raise error.ProgrammingError('both branch and topic specified (not defined yet)') |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
34 elif topic is not None: |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
35 trevs = repo.revs("topic(%s) - obsolete()", topic) |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
36 elif branch is not None: |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
37 trevs = repo.revs("branch(%s) - public() - obsolete() - topic()", branch) |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
38 else: |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
39 raise error.ProgrammingError('neither branch and topic specified (not defined yet)') |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
40 self._revs = trevs |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
41 |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
42 def __iter__(self): |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
43 return iter(self.revs) |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
44 |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
45 def __getitem__(self, index): |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
46 return self.revs[index] |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
47 |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
48 def index(self, item): |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
49 return self.revs.index(item) |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
50 |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
51 @util.propertycache |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
52 def revs(self): |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
53 revs = _orderrevs(self._repo, self._revs) |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
54 if revs: |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
55 pt1 = self._repo[revs[0]].p1() |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
56 if pt1.obsolete(): |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
57 pt1 = self._repo[_singlesuccessor(self._repo, pt1)] |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
58 revs.insert(0, pt1.rev()) |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
59 return revs |
9897babc1fb5
stack: introduce a rich stack object
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2839
diff
changeset
|
60 |
2348
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
61 def labelsgen(prefix, labelssuffix): |
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
62 """ Takes a label prefix and a list of suffixes. Returns a string of the prefix |
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
63 formatted with each suffix separated with a space. |
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
64 """ |
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
65 return ' '.join(prefix % suffix for suffix in labelssuffix) |
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
66 |
2669
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
67 def showstack(ui, repo, branch=None, topic=None, opts=None): |
2668
1d2c66dc4ee3
topic: explicitly pass topic as a keyword argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2632
diff
changeset
|
68 if opts is None: |
1d2c66dc4ee3
topic: explicitly pass topic as a keyword argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2632
diff
changeset
|
69 opts = {} |
2627
42abd3bd30ee
topics: abort if user wants to show the stack of a non-existent topic
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2626
diff
changeset
|
70 |
2669
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
71 if topic is not None and branch is not None: |
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
72 msg = 'both branch and topic specified [%s]{%s}(not defined yet)' |
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
73 msg %= (branch, topic) |
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
74 raise error.ProgrammingError(msg) |
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
75 elif topic is not None: |
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
76 prefix = 't' |
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
77 if topic not in repo.topics: |
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
78 raise error.Abort(_('cannot resolve "%s": no such topic found') % topic) |
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
79 elif branch is not None: |
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
80 prefix = 'b' |
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
81 else: |
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
82 raise error.ProgrammingError('neither branch and topic specified (not defined yet)') |
2627
42abd3bd30ee
topics: abort if user wants to show the stack of a non-existent topic
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2626
diff
changeset
|
83 |
1907
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
84 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
|
85 prev = None |
1955
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
86 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
|
87 idxmap = {} |
1995
54d6dff699f0
stack: add some header with the topic name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1991
diff
changeset
|
88 |
54d6dff699f0
stack: add some header with the topic name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1991
diff
changeset
|
89 label = 'topic' |
54d6dff699f0
stack: add some header with the topic name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1991
diff
changeset
|
90 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
|
91 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
|
92 |
2669
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
93 data = stackdata(repo, branch=branch, topic=topic) |
2670
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
94 if topic is not None: |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
95 fm.plain(_('### topic: %s') |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
96 % ui.label(topic, label), |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
97 label='topic.stack.summary.topic') |
1998
302be26a3fd8
stack: add warning about multiple heads
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1997
diff
changeset
|
98 |
2670
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
99 if 1 < data['headcount']: |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
100 fm.plain(' (') |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
101 fm.plain('%d heads' % data['headcount'], |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
102 label='topic.stack.summary.headcount.multiple') |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
103 fm.plain(')') |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
104 fm.plain('\n') |
1997
ce86f7bb4b7b
stack: add some behind information
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1996
diff
changeset
|
105 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
|
106 % '+'.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
|
107 label='topic.stack.summary.branches') |
2670
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
108 if topic is None: |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
109 if 1 < data['headcount']: |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
110 fm.plain(' (') |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
111 fm.plain('%d heads' % data['headcount'], |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
112 label='topic.stack.summary.headcount.multiple') |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
113 fm.plain(')') |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
114 else: |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
115 if data['behindcount'] == -1: |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
116 fm.plain(', ') |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
117 fm.plain('ambigious rebase destination', label='topic.stack.summary.behinderror') |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
118 elif data['behindcount']: |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
119 fm.plain(', ') |
f5d52fa1cd55
topic: move the heads data to the branch line when appropriates
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2669
diff
changeset
|
120 fm.plain('%d behind' % data['behindcount'], label='topic.stack.summary.behindcount') |
1997
ce86f7bb4b7b
stack: add some behind information
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1996
diff
changeset
|
121 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
|
122 |
2915
b3abdb3d819e
stack: replace 'getstack' with direct call to 'stack'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2914
diff
changeset
|
123 for idx, r in enumerate(stack(repo, branch=branch, topic=topic), 0): |
1925 | 124 ctx = repo[r] |
2712
f19b314d8475
topics: add t0 and b0 to the stack
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2684
diff
changeset
|
125 # special case for t0, b0 as it's hard to plugin into rest of the logic |
f19b314d8475
topics: add t0 and b0 to the stack
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2684
diff
changeset
|
126 if idx == 0: |
f19b314d8475
topics: add t0 and b0 to the stack
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2684
diff
changeset
|
127 # t0, b0 can be None |
f19b314d8475
topics: add t0 and b0 to the stack
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2684
diff
changeset
|
128 if r == -1: |
f19b314d8475
topics: add t0 and b0 to the stack
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2684
diff
changeset
|
129 continue |
f19b314d8475
topics: add t0 and b0 to the stack
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2684
diff
changeset
|
130 entries.append((idx, False, ctx)) |
f19b314d8475
topics: add t0 and b0 to the stack
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2684
diff
changeset
|
131 prev = ctx.rev() |
f19b314d8475
topics: add t0 and b0 to the stack
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2684
diff
changeset
|
132 continue |
1909
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
133 p1 = ctx.p1() |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
134 if p1.obsolete(): |
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
135 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
|
136 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
|
137 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
|
138 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
|
139 idxmap[ctx.rev()] = idx |
1955
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
140 prev = r |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
141 |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
142 # 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
|
143 for idx, isentry, ctx in entries[::-1]: |
2348
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
144 |
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
145 states = [] |
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
146 iscurrentrevision = repo.revs('%d and parents()', ctx.rev()) |
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
147 |
1991
ba79d23594d6
stack: reusing the index number in base when applicable
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1990
diff
changeset
|
148 if not isentry: |
1957
ea5553e47027
stack: change the ascii symbold for base
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1956
diff
changeset
|
149 symbol = '^' |
2348
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
150 # "base" is kind of a "ghost" entry |
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
151 # skip other label for them (no current, no unstable) |
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
152 states = ['base'] |
2838
1c9150e30b28
context: unstable was deprecated
Boris Feld <boris.feld@octobus.net>
parents:
2750
diff
changeset
|
153 elif ctx.orphan(): |
2626
bc36a608e9e4
stack: show unstable state for the current revision if it is one (issue5553)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2348
diff
changeset
|
154 # current revision can be unstable also, so in that case show both |
bc36a608e9e4
stack: show unstable state for the current revision if it is one (issue5553)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2348
diff
changeset
|
155 # the states and the symbol '@' (issue5553) |
bc36a608e9e4
stack: show unstable state for the current revision if it is one (issue5553)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2348
diff
changeset
|
156 if iscurrentrevision: |
bc36a608e9e4
stack: show unstable state for the current revision if it is one (issue5553)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2348
diff
changeset
|
157 states.append('current') |
bc36a608e9e4
stack: show unstable state for the current revision if it is one (issue5553)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2348
diff
changeset
|
158 symbol = '@' |
1906
5e9ce6310720
stack: show the currently active changeset and unstable ones
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1905
diff
changeset
|
159 symbol = '$' |
2348
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
160 states.append('unstable') |
2626
bc36a608e9e4
stack: show unstable state for the current revision if it is one (issue5553)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2348
diff
changeset
|
161 elif iscurrentrevision: |
bc36a608e9e4
stack: show unstable state for the current revision if it is one (issue5553)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2348
diff
changeset
|
162 states.append('current') |
bc36a608e9e4
stack: show unstable state for the current revision if it is one (issue5553)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2348
diff
changeset
|
163 symbol = '@' |
1955
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
164 else: |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
165 symbol = ':' |
2348
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
166 states.append('clean') |
1907
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
167 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
|
168 fm.data(isentry=isentry) |
2348
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
169 |
1955
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
170 if idx is None: |
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
171 fm.plain(' ') |
2750
bd3824d1b795
stack: show short node of changesets in `hg stack -v`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2712
diff
changeset
|
172 if ui.verbose: |
bd3824d1b795
stack: show short node of changesets in `hg stack -v`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2712
diff
changeset
|
173 fm.plain(' ') |
1955
5452a575b4e5
topic: extract display from entry computation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1954
diff
changeset
|
174 else: |
2669
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
175 fm.write('topic.stack.index', '%s%%d' % prefix, idx, |
2348
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
176 label='topic.stack.index ' + labelsgen('topic.stack.index.%s', states)) |
2750
bd3824d1b795
stack: show short node of changesets in `hg stack -v`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2712
diff
changeset
|
177 if ui.verbose: |
bd3824d1b795
stack: show short node of changesets in `hg stack -v`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2712
diff
changeset
|
178 fm.write('topic.stack.shortnode', '(%s)', short(ctx.node()), |
bd3824d1b795
stack: show short node of changesets in `hg stack -v`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
2712
diff
changeset
|
179 label='topic.stack.shortnode ' + labelsgen('topic.stack.shortnode.%s', states)) |
1907
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
180 fm.write('topic.stack.state.symbol', '%s', symbol, |
2348
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
181 label='topic.stack.state ' + labelsgen('topic.stack.state.%s', states)) |
1907
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
182 fm.plain(' ') |
1909
36112e361ee4
stack: display the base of the stack
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1907
diff
changeset
|
183 fm.write('topic.stack.desc', '%s', ctx.description().splitlines()[0], |
2348
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
184 label='topic.stack.desc ' + labelsgen('topic.stack.desc.%s', states)) |
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
185 fm.condwrite(states != ['clean'] and idx is not None, 'topic.stack.state', |
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
186 ' (%s)', fm.formatlist(states, 'topic.stack.state'), |
5737e0680f10
ui: hg topic now display if current revision is in bad state (issue5533)
Boris Feld <boris.feld@octobus.net>
parents:
2341
diff
changeset
|
187 label='topic.stack.state ' + labelsgen('topic.stack.state.%s', states)) |
1907
95874e8fc5f2
stack: add basic formatter and label support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1906
diff
changeset
|
188 fm.plain('\n') |
2341
a5117a5becf8
ui: Fix hg stack json output
Boris Feld <boris.feld@octobus.net>
parents:
2003
diff
changeset
|
189 fm.end() |
1897
38570c53b1cf
stack: fix printing order in case of unstability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
1896
diff
changeset
|
190 |
2669
b933a8068c17
topic: add some initial support for using stack on named branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2668
diff
changeset
|
191 def stackdata(repo, branch=None, topic=None): |
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
|
192 """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
|
193 |
137f8b04901e
topic: list the number of changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1961
diff
changeset
|
194 :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
|
195 :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
|
196 :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
|
197 :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
|
198 """ |
137f8b04901e
topic: list the number of changesets when --verbose is used
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
1961
diff
changeset
|
199 data = {} |
2915
b3abdb3d819e
stack: replace 'getstack' with direct call to 'stack'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2914
diff
changeset
|
200 revs = stack(repo, branch, topic)[1:] |
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
|
201 data['changesetcount'] = len(revs) |
2839
f9c8c754a528
context: troubled was deprecated
Boris Feld <boris.feld@octobus.net>
parents:
2838
diff
changeset
|
202 data['troubledcount'] = len([r for r in revs if repo[r].isunstable()]) |
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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 |
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
|
220 return data |