# HG changeset patch # User Pierre-Yves David # Date 1499992953 -7200 # Node ID ddfe336de779e2af0118477e4416d585f29d71c2 # Parent 2fe562f94ead00f49a5c02e2c1b3a83024d6c013 topic: add a 'topicidx()' to context This will be useful for the `t0` logic in `hg prev` diff -r 2fe562f94ead -r ddfe336de779 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+$')