hgext3rd/topic/__init__.py
changeset 2669 b933a8068c17
parent 2668 1d2c66dc4ee3
child 2677 8cdee1b9ee92
--- a/hgext3rd/topic/__init__.py	Wed Jun 28 01:58:09 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Wed Jun 28 02:45:57 2017 +0200
@@ -122,19 +122,29 @@
 context.basectx.topic = _contexttopic
 
 topicrev = re.compile(r'^t\d+$')
+branchrev = re.compile(r'^b\d+$')
 
 def _namemap(repo, name):
+    revs = None
     if topicrev.match(name):
         idx = int(name[1:])
-        topic = repo.currenttopic
-        if not topic:
+        ttype = 'topic'
+        tname = topic = repo.currenttopic
+        if not tname:
             raise error.Abort(_('cannot resolve "%s": no active topic') % name)
         revs = list(stack.getstack(repo, topic=topic))
+    elif branchrev.match(name):
+        ttype = 'branch'
+        idx = int(name[1:])
+        tname = branch = repo[None].branch()
+        revs = list(stack.getstack(repo, branch=branch))
+
+    if revs is not None:
         try:
             r = revs[idx - 1]
         except IndexError:
-            msg = _('cannot resolve "%s": topic "%s" has only %d changesets')
-            raise error.Abort(msg % (name, topic, len(revs)))
+            msg = _('cannot resolve "%s": %s "%s" has only %d changesets')
+            raise error.Abort(msg % (name, ttype, tname, len(revs)))
         return [repo[r].node()]
     if name not in repo.topics:
         return []
@@ -282,7 +292,7 @@
             topic = repo.currenttopic
         if not topic:
             raise error.Abort(_('no active topic to list'))
-        return stack.showstack(ui, repo, topic, opts)
+        return stack.showstack(ui, repo, topic=topic, opts=opts)
 
     if rev:
         if not obsolete.isenabled(repo, obsolete.createmarkersopt):
@@ -309,10 +319,13 @@
 
     List the current topic by default."""
     if not topic:
+        topic = None
+    branch = None
+    if topic is None and repo.currenttopic:
         topic = repo.currenttopic
-    if not topic:
-        raise error.Abort(_('no active topic to list'))
-    return stack.showstack(ui, repo, topic=topic, opts=opts)
+    if topic is None:
+        branch = repo[None].branch()
+    return stack.showstack(ui, repo, branch=branch, topic=topic, opts=opts)
 
 def _changecurrenttopic(repo, newtopic):
     """changes the current topic."""