hgext3rd/topic/stack.py
changeset 4650 7c05b1625921
parent 4649 6b7ad4b50d00
child 4651 55c347b4874f
equal deleted inserted replaced
4649:6b7ad4b50d00 4650:7c05b1625921
   240 
   240 
   241     label = 'topic'
   241     label = 'topic'
   242     if topic == repo.currenttopic:
   242     if topic == repo.currenttopic:
   243         label = 'topic.active'
   243         label = 'topic.active'
   244 
   244 
   245     data = stackdata(repo, branch=branch, topic=topic)
   245     st = stack(repo, branch, topic)
   246     empty = False
   246     empty = False
   247     if data['changesetcount'] == 0:
   247     if st.changesetcount == 0:
   248         empty = True
   248         empty = True
   249     if topic is not None:
   249     if topic is not None:
   250         fm.plain(_('### topic: %s')
   250         fm.plain(_('### topic: %s')
   251                  % ui.label(topic, label),
   251                  % ui.label(topic, label),
   252                  label='topic.stack.summary.topic')
   252                  label='topic.stack.summary.topic')
   253 
   253 
   254         if 1 < data['headcount']:
   254         if 1 < len(st.heads):
   255             fm.plain(' (')
   255             fm.plain(' (')
   256             fm.plain('%d heads' % data['headcount'],
   256             fm.plain('%d heads' % len(st.heads),
   257                      label='topic.stack.summary.headcount.multiple')
   257                      label='topic.stack.summary.headcount.multiple')
   258             fm.plain(')')
   258             fm.plain(')')
   259         fm.plain('\n')
   259         fm.plain('\n')
   260     fm.plain(_('### target: %s (branch)')
   260     fm.plain(_('### target: %s (branch)')
   261              % '+'.join(data['branches']), # XXX handle multi branches
   261              % '+'.join(st.branches), # XXX handle multi branches
   262              label='topic.stack.summary.branches')
   262              label='topic.stack.summary.branches')
   263     if topic is None:
   263     if topic is None:
   264         if 1 < data['headcount']:
   264         if 1 < len(st.heads):
   265             fm.plain(' (')
   265             fm.plain(' (')
   266             fm.plain('%d heads' % data['headcount'],
   266             fm.plain('%d heads' % len(st.heads),
   267                      label='topic.stack.summary.headcount.multiple')
   267                      label='topic.stack.summary.headcount.multiple')
   268             fm.plain(')')
   268             fm.plain(')')
   269     else:
   269     else:
   270         if data['behindcount'] == -1:
   270         if st.behindcount == -1:
   271             fm.plain(', ')
   271             fm.plain(', ')
   272             fm.plain('ambiguous rebase destination - %s' % data['behinderror'],
   272             fm.plain('ambiguous rebase destination - %s' % st.behinderror,
   273                      label='topic.stack.summary.behinderror')
   273                      label='topic.stack.summary.behinderror')
   274         elif data['behindcount']:
   274         elif st.behindcount:
   275             fm.plain(', ')
   275             fm.plain(', ')
   276             fm.plain('%d behind' % data['behindcount'], label='topic.stack.summary.behindcount')
   276             fm.plain('%d behind' % st.behindcount, label='topic.stack.summary.behindcount')
   277     fm.plain('\n')
   277     fm.plain('\n')
   278 
   278 
   279     if empty:
   279     if empty:
   280         fm.plain(_("(stack is empty)\n"))
   280         fm.plain(_("(stack is empty)\n"))
   281 
   281 
   374         fm.condwrite(states != ['clean'] and idx is not None, 'topic.stack.state',
   374         fm.condwrite(states != ['clean'] and idx is not None, 'topic.stack.state',
   375                      ' (%s)', fm.formatlist(states, 'topic.stack.state'),
   375                      ' (%s)', fm.formatlist(states, 'topic.stack.state'),
   376                      label='topic.stack.state ' + labelsgen('topic.stack.state.%s', states))
   376                      label='topic.stack.state ' + labelsgen('topic.stack.state.%s', states))
   377         fm.plain('\n')
   377         fm.plain('\n')
   378     fm.end()
   378     fm.end()
   379 
       
   380 def stackdata(repo, branch=None, topic=None):
       
   381     """get various data about a stack
       
   382 
       
   383     :changesetcount: number of non-obsolete changesets in the stack
       
   384     :unstablecount: number of unstable changesets
       
   385     :headcount: number of heads on the topic
       
   386     :behindcount: number of changeset on rebase destination
       
   387     """
       
   388     data = {}
       
   389     current = stack(repo, branch, topic)
       
   390     data['changesetcount'] = current.changesetcount
       
   391     data['unstablecount'] = current.unstablecount
       
   392     data['headcount'] = len(current.heads)
       
   393     data['behindcount'] = current.behindcount
       
   394     data['behinderror'] = current.behinderror
       
   395     data['branches'] = current.branches
       
   396     return data