hgext3rd/topic/stack.py
changeset 2712 f19b314d8475
parent 2684 90e11985d0cc
child 2750 bd3824d1b795
--- a/hgext3rd/topic/stack.py	Tue Jul 04 00:15:36 2017 +0530
+++ b/hgext3rd/topic/stack.py	Tue Jul 04 01:30:14 2017 +0530
@@ -20,7 +20,13 @@
         trevs = repo.revs("branch(%s) - public() - obsolete() - topic()", branch)
     else:
         raise error.ProgrammingError('neither branch and topic specified (not defined yet)')
-    return _orderrevs(repo, trevs)
+    revs = _orderrevs(repo, trevs)
+    if revs:
+        pt1 = repo[revs[0]].p1()
+        if pt1.obsolete():
+            pt1 = repo[_singlesuccessor(repo, pt1)]
+        revs.insert(0, pt1.rev())
+    return revs
 
 def labelsgen(prefix, labelssuffix):
     """ Takes a label prefix and a list of suffixes. Returns a string of the prefix
@@ -84,8 +90,16 @@
             fm.plain('%d behind' % data['behindcount'], label='topic.stack.summary.behindcount')
     fm.plain('\n')
 
-    for idx, r in enumerate(getstack(repo, branch=branch, topic=topic), 1):
+    for idx, r in enumerate(getstack(repo, branch=branch, topic=topic), 0):
         ctx = repo[r]
+        # special case for t0, b0 as it's hard to plugin into rest of the logic
+        if idx == 0:
+            # t0, b0 can be None
+            if r == -1:
+                continue
+            entries.append((idx, False, ctx))
+            prev = ctx.rev()
+            continue
         p1 = ctx.p1()
         if p1.obsolete():
             p1 = repo[_singlesuccessor(repo, p1)]
@@ -148,7 +162,7 @@
     :behindcount: number of changeset on rebase destination
     """
     data = {}
-    revs = getstack(repo, branch, topic)
+    revs = getstack(repo, branch, topic)[1:]
     data['changesetcount'] = len(revs)
     data['troubledcount'] = len([r for r in revs if repo[r].troubled()])
     deps, rdeps = builddependencies(repo, revs)