stack: reusing the index number in base when applicable
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Fri, 26 Aug 2016 12:52:06 +0200
changeset 1991 ba79d23594d6
parent 1990 71410fa2c253
child 1992 28fbc627b704
stack: reusing the index number in base when applicable This clarify the branching when it is easy to track back the branching point. This does not takes the evolution graph into account yet.
hgext3rd/topic/__init__.py
hgext3rd/topic/stack.py
tests/test-topic-stack.t
--- a/hgext3rd/topic/__init__.py	Fri Aug 26 12:37:52 2016 +0200
+++ b/hgext3rd/topic/__init__.py	Fri Aug 26 12:52:06 2016 +0200
@@ -50,6 +50,7 @@
               'topic.list.behindcount': 'cyan',
               'topic.list.behinderror': 'red',
               'topic.stack.index': 'yellow',
+              'topic.stack.index.base': 'none dim',
               'topic.stack.state.base': 'dim',
               'topic.stack.state.clean': 'green',
               'topic.stack.index.current': 'cyan',       # random pick
--- a/hgext3rd/topic/stack.py	Fri Aug 26 12:37:52 2016 +0200
+++ b/hgext3rd/topic/stack.py	Fri Aug 26 12:52:06 2016 +0200
@@ -18,19 +18,21 @@
     fm = ui.formatter('topicstack', opts)
     prev = None
     entries = []
+    idxmap = {}
     for idx, r in enumerate(getstack(repo, topic), 1):
         ctx = repo[r]
         p1 = ctx.p1()
         if p1.obsolete():
             p1 = repo[_singlesuccessor(repo, p1)]
         if p1.rev() != prev and p1.node() != node.nullid:
-            entries.append((None, p1))
-        entries.append((idx, ctx))
+            entries.append((idxmap.get(p1.rev()), False, p1))
+        entries.append((idx, True, ctx))
+        idxmap[ctx.rev()] = idx
         prev = r
 
     # super crude initial version
-    for idx, ctx in entries[::-1]:
-        if idx is None:
+    for idx, isentry, ctx in entries[::-1]:
+        if not isentry:
             symbol = '^'
             state = 'base'
         elif repo.revs('%d and parents()', ctx.rev()):
@@ -43,6 +45,7 @@
             symbol = ':'
             state = 'clean'
         fm.startitem()
+        fm.data(isentry=isentry)
         if idx is None:
             fm.plain('  ')
         else:
--- a/tests/test-topic-stack.t	Fri Aug 26 12:37:52 2016 +0200
+++ b/tests/test-topic-stack.t	Fri Aug 26 12:52:06 2016 +0200
@@ -194,7 +194,7 @@
   $ hg top -l
   t6: c_f
   t5: c_e
-    ^ c_d
+  t2^ c_d (base)
   t4@ c_h (current)
   t3: c_g
   t2: c_d
@@ -236,7 +236,7 @@
   $ hg topic --list
   t6$ c_f (unstable)
   t5$ c_e (unstable)
-    ^ c_D
+  t2^ c_D (base)
   t4: c_h
   t3: c_g
   t2@ c_D (current)