comparison hgext3rd/topic/stack.py @ 2668:1d2c66dc4ee3

topic: explicitly pass topic as a keyword argument This clarify all callers before adding more logic related to bare branch in stack.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 28 Jun 2017 01:58:09 +0200
parents 62eb5a2d2112
children b933a8068c17
comparison
equal deleted inserted replaced
2667:e7079bba383d 2668:1d2c66dc4ee3
8 error, 8 error,
9 node, 9 node,
10 ) 10 )
11 from .evolvebits import builddependencies, _orderrevs, _singlesuccessor 11 from .evolvebits import builddependencies, _orderrevs, _singlesuccessor
12 12
13 def getstack(repo, topic): 13 def getstack(repo, topic=None):
14 # XXX need sorting 14 # XXX need sorting
15 trevs = repo.revs("topic(%s) - obsolete()", topic) 15 trevs = repo.revs("topic(%s) - obsolete()", topic)
16 return _orderrevs(repo, trevs) 16 return _orderrevs(repo, trevs)
17 17
18 def labelsgen(prefix, labelssuffix): 18 def labelsgen(prefix, labelssuffix):
19 """ Takes a label prefix and a list of suffixes. Returns a string of the prefix 19 """ Takes a label prefix and a list of suffixes. Returns a string of the prefix
20 formatted with each suffix separated with a space. 20 formatted with each suffix separated with a space.
21 """ 21 """
22 return ' '.join(prefix % suffix for suffix in labelssuffix) 22 return ' '.join(prefix % suffix for suffix in labelssuffix)
23 23
24 def showstack(ui, repo, topic, opts): 24 def showstack(ui, repo, topic=None, opts=None):
25 if opts is None:
26 opts = {}
25 27
26 if topic not in repo.topics: 28 if topic not in repo.topics:
27 raise error.Abort(_('cannot resolve "%s": no such topic found') % topic) 29 raise error.Abort(_('cannot resolve "%s": no such topic found') % topic)
28 30
29 fm = ui.formatter('topicstack', opts) 31 fm = ui.formatter('topicstack', opts)
33 35
34 label = 'topic' 36 label = 'topic'
35 if topic == repo.currenttopic: 37 if topic == repo.currenttopic:
36 label = 'topic.active' 38 label = 'topic.active'
37 39
38 data = stackdata(repo, topic) 40 data = stackdata(repo, topic=topic)
39 fm.plain(_('### topic: %s') % ui.label(topic, label), 41 fm.plain(_('### topic: %s') % ui.label(topic, label),
40 label='topic.stack.summary.topic') 42 label='topic.stack.summary.topic')
41 43
42 if 1 < data['headcount']: 44 if 1 < data['headcount']:
43 fm.plain(' (') 45 fm.plain(' (')
54 elif data['behindcount']: 56 elif data['behindcount']:
55 fm.plain(', ') 57 fm.plain(', ')
56 fm.plain('%d behind' % data['behindcount'], label='topic.stack.summary.behindcount') 58 fm.plain('%d behind' % data['behindcount'], label='topic.stack.summary.behindcount')
57 fm.plain('\n') 59 fm.plain('\n')
58 60
59 for idx, r in enumerate(getstack(repo, topic), 1): 61 for idx, r in enumerate(getstack(repo, topic=topic), 1):
60 ctx = repo[r] 62 ctx = repo[r]
61 p1 = ctx.p1() 63 p1 = ctx.p1()
62 if p1.obsolete(): 64 if p1.obsolete():
63 p1 = repo[_singlesuccessor(repo, p1)] 65 p1 = repo[_singlesuccessor(repo, p1)]
64 if p1.rev() != prev and p1.node() != node.nullid: 66 if p1.rev() != prev and p1.node() != node.nullid:
109 ' (%s)', fm.formatlist(states, 'topic.stack.state'), 111 ' (%s)', fm.formatlist(states, 'topic.stack.state'),
110 label='topic.stack.state ' + labelsgen('topic.stack.state.%s', states)) 112 label='topic.stack.state ' + labelsgen('topic.stack.state.%s', states))
111 fm.plain('\n') 113 fm.plain('\n')
112 fm.end() 114 fm.end()
113 115
114 def stackdata(repo, topic): 116 def stackdata(repo, topic=None):
115 """get various data about a stack 117 """get various data about a stack
116 118
117 :changesetcount: number of non-obsolete changesets in the stack 119 :changesetcount: number of non-obsolete changesets in the stack
118 :troubledcount: number on troubled changesets 120 :troubledcount: number on troubled changesets
119 :headcount: number of heads on the topic 121 :headcount: number of heads on the topic