hgext3rd/topic/stack.py
changeset 1985 03d6b685c16a
parent 1982 d87fc4f749e6
child 1988 9a5d797d25be
--- a/hgext3rd/topic/stack.py	Mon Aug 15 00:19:44 2016 +0200
+++ b/hgext3rd/topic/stack.py	Sun Aug 14 19:57:58 2016 +0200
@@ -4,6 +4,7 @@
 # GNU General Public License version 2 or any later version.
 from mercurial.i18n import _
 from mercurial import (
+    destutil,
     error,
     node,
 )
@@ -69,6 +70,7 @@
     :changesetcount: number of non-obsolete changesets in the stack
     :troubledcount: number on troubled changesets
     :headcount: number of heads on the topic
+    :behindcount: number of changeset on rebase destination
     """
     data = {}
     revs = repo.revs("topic(%s) - obsolete()", topic)
@@ -76,6 +78,19 @@
     data['troubledcount'] = len([r for r in revs if repo[r].troubled()])
     deps, rdeps = builddependencies(repo, revs)
     data['headcount'] = len([r for r in revs if not rdeps[r]])
+    data['behindcount'] = 0
+    if revs:
+        minroot = [min(r for r in revs if not deps[r])]
+        try:
+            dest = destutil.destmerge(repo, action='rebase',
+                                      sourceset=minroot,
+                                      onheadcheck=False)
+            data['behindcount'] = len(repo.revs("only(%d, %ld)", dest,
+                                                minroot))
+        except error.NoMergeDestAbort:
+            data['behindcount'] = 0
+        except error.ManyMergeDestAbort:
+            data['behindcount'] = -1
 
     return data