hgext3rd/topic/stack.py
changeset 2669 b933a8068c17
parent 2668 1d2c66dc4ee3
child 2670 f5d52fa1cd55
--- a/hgext3rd/topic/stack.py	Wed Jun 28 01:58:09 2017 +0200
+++ b/hgext3rd/topic/stack.py	Wed Jun 28 02:45:57 2017 +0200
@@ -10,9 +10,16 @@
 )
 from .evolvebits import builddependencies, _orderrevs, _singlesuccessor
 
-def getstack(repo, topic=None):
+def getstack(repo, branch=None, topic=None):
     # XXX need sorting
-    trevs = repo.revs("topic(%s) - obsolete()", topic)
+    if topic is not None and branch is not None:
+        raise error.ProgrammingError('both branch and topic specified (not defined yet)')
+    elif topic is not None:
+        trevs = repo.revs("topic(%s) - obsolete()", topic)
+    elif branch is not None:
+        trevs = repo.revs("branch(%s) - obsolete()", branch)
+    else:
+        raise error.ProgrammingError('neither branch and topic specified (not defined yet)')
     return _orderrevs(repo, trevs)
 
 def labelsgen(prefix, labelssuffix):
@@ -21,12 +28,22 @@
     """
     return ' '.join(prefix % suffix for suffix in labelssuffix)
 
-def showstack(ui, repo, topic=None, opts=None):
+def showstack(ui, repo, branch=None, topic=None, opts=None):
     if opts is None:
         opts = {}
 
-    if topic not in repo.topics:
-        raise error.Abort(_('cannot resolve "%s": no such topic found') % topic)
+    if topic is not None and branch is not None:
+        msg = 'both branch and topic specified [%s]{%s}(not defined yet)'
+        msg %= (branch, topic)
+        raise error.ProgrammingError(msg)
+    elif topic is not None:
+        prefix = 't'
+        if topic not in repo.topics:
+            raise error.Abort(_('cannot resolve "%s": no such topic found') % topic)
+    elif branch is not None:
+        prefix = 'b'
+    else:
+        raise error.ProgrammingError('neither branch and topic specified (not defined yet)')
 
     fm = ui.formatter('topicstack', opts)
     prev = None
@@ -37,7 +54,7 @@
     if topic == repo.currenttopic:
         label = 'topic.active'
 
-    data = stackdata(repo, topic=topic)
+    data = stackdata(repo, branch=branch, topic=topic)
     fm.plain(_('### topic: %s') % ui.label(topic, label),
              label='topic.stack.summary.topic')
 
@@ -58,7 +75,7 @@
         fm.plain('%d behind' % data['behindcount'], label='topic.stack.summary.behindcount')
     fm.plain('\n')
 
-    for idx, r in enumerate(getstack(repo, topic=topic), 1):
+    for idx, r in enumerate(getstack(repo, branch=branch, topic=topic), 1):
         ctx = repo[r]
         p1 = ctx.p1()
         if p1.obsolete():
@@ -100,7 +117,7 @@
         if idx is None:
             fm.plain('  ')
         else:
-            fm.write('topic.stack.index', 't%d', idx,
+            fm.write('topic.stack.index', '%s%%d' % prefix, idx,
                      label='topic.stack.index ' + labelsgen('topic.stack.index.%s', states))
         fm.write('topic.stack.state.symbol', '%s', symbol,
                  label='topic.stack.state ' + labelsgen('topic.stack.state.%s', states))
@@ -113,7 +130,7 @@
         fm.plain('\n')
     fm.end()
 
-def stackdata(repo, topic=None):
+def stackdata(repo, branch=None, topic=None):
     """get various data about a stack
 
     :changesetcount: number of non-obsolete changesets in the stack
@@ -122,7 +139,7 @@
     :behindcount: number of changeset on rebase destination
     """
     data = {}
-    revs = repo.revs("topic(%s) - obsolete()", topic)
+    revs = getstack(repo, branch, topic)
     data['changesetcount'] = len(revs)
     data['troubledcount'] = len([r for r in revs if repo[r].troubled()])
     deps, rdeps = builddependencies(repo, revs)