diff hgext3rd/topic/__init__.py @ 1904:f52c02bf47b7

stack: allow to refer to changeset using "t2" form hg up "t0" is seen as "update to the first changeset of my current topic". Eventually we'll drop the "t2" form in favor of the planned generic indexing operator '.{t2}'.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Mon, 14 Mar 2016 18:39:19 +0000
parents 58cdf061d49a
children 95874e8fc5f2
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Tue Mar 15 17:26:57 2016 +0000
+++ b/hgext3rd/topic/__init__.py	Mon Mar 14 18:39:19 2016 +0000
@@ -12,6 +12,7 @@
 """
 import functools
 import contextlib
+import re
 
 from mercurial.i18n import _
 from mercurial import branchmap
@@ -51,7 +52,22 @@
     return self.extra().get(constants.extrakey, '')
 context.basectx.topic = _contexttopic
 
+topicrev = re.compile(r'^t\d+$')
+
+
 def _namemap(repo, name):
+    if topicrev.match(name):
+        idx = int(name[1:])
+        topic = repo.currenttopic
+        if not topic:
+            raise error.Abort(_('cannot resolve "%s": no active topic') % name)
+        revs = list(stack.getstack(repo, topic))
+        try:
+            r = revs[idx]
+        except IndexError:
+            msg = _('cannot resolve "%s": topic "%s" has only %d changesets')
+            raise error.Abort(msg % (name, topic, len(revs)))
+        return [repo[r].node()]
     return [ctx.node() for ctx in
             repo.set('not public() and extra(topic, %s)', name)]