changeset 2744:ddfe336de779

topic: add a 'topicidx()' to context This will be useful for the `t0` logic in `hg prev`
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 14 Jul 2017 02:42:33 +0200
parents 2fe562f94ead
children b38112b43a27
files hgext3rd/topic/__init__.py
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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+$')