topic: add a 'topicidx()' to context
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 14 Jul 2017 02:42:33 +0200
changeset 2744 ddfe336de779
parent 2743 2fe562f94ead
child 2745 b38112b43a27
topic: add a 'topicidx()' to context This will be useful for the `t0` logic in `hg prev`
hgext3rd/topic/__init__.py
--- a/hgext3rd/topic/__init__.py	Fri Jul 14 02:41:53 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Fri Jul 14 02:42:33 2017 +0200
@@ -126,6 +126,19 @@
         return ''
     return self.extra().get(constants.extrakey, '')
 context.basectx.topic = _contexttopic
+def _contexttopicidx(self):
+    topic = self.topic()
+    if not topic:
+        # XXX we might want to include t0 here,
+        # however t0 is related to  'currenttopic' which has no place here.
+        return None
+    revlist = stack.getstack(self._repo, topic=topic)
+    try:
+        return revlist.index(self.rev())
+    except IndexError:
+        # Lets move to the last ctx of the current topic
+        return None
+context.basectx.topicidx = _contexttopicidx
 
 topicrev = re.compile(r'^t\d+$')
 branchrev = re.compile(r'^b\d+$')