stack: show short node of changesets in `hg stack -v`
authorPulkit Goyal <7895pulkit@gmail.com>
Fri, 14 Jul 2017 07:19:15 +0530
changeset 2750 bd3824d1b795
parent 2749 e1b7ea48e243
child 2751 4f560f117fff
stack: show short node of changesets in `hg stack -v` After this patch, hg stack -v shows short nodes for changesets which have topic index, i.e. excluding the bases except t0.
hgext3rd/topic/__init__.py
hgext3rd/topic/stack.py
tests/test-stack-branch.t
tests/test-topic-stack-data.t
tests/test-topic-stack.t
--- a/hgext3rd/topic/__init__.py	Fri Jul 21 01:04:32 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Fri Jul 14 07:19:15 2017 +0530
@@ -101,11 +101,13 @@
               'topic.stack.index': 'yellow',
               'topic.stack.index.base': 'none dim',
               'topic.stack.desc.base': 'none dim',
+              'topic.stack.shortnode.base': 'none dim',
               'topic.stack.state.base': 'dim',
               'topic.stack.state.clean': 'green',
               'topic.stack.index.current': 'cyan',       # random pick
               'topic.stack.state.current': 'cyan bold',  # random pick
               'topic.stack.desc.current': 'cyan',        # random pick
+              'topic.stack.shortnode.current': 'cyan',   # random pick
               'topic.stack.state.unstable': 'red',
               'topic.stack.summary.behindcount': 'cyan',
               'topic.stack.summary.behinderror': 'red',
@@ -366,7 +368,10 @@
 def cmdstack(ui, repo, topic='', **opts):
     """list all changesets in a topic and other information
 
-    List the current topic by default."""
+    List the current topic by default.
+
+    The --verbose version shows short nodes for the commits also.
+    """
     if not topic:
         topic = None
     branch = None
--- a/hgext3rd/topic/stack.py	Fri Jul 21 01:04:32 2017 +0200
+++ b/hgext3rd/topic/stack.py	Fri Jul 14 07:19:15 2017 +0530
@@ -10,6 +10,8 @@
 )
 from .evolvebits import builddependencies, _orderrevs, _singlesuccessor
 
+short = node.short
+
 def getstack(repo, branch=None, topic=None):
     # XXX need sorting
     if topic is not None and branch is not None:
@@ -139,9 +141,14 @@
 
         if idx is None:
             fm.plain('  ')
+            if ui.verbose:
+                fm.plain('              ')
         else:
             fm.write('topic.stack.index', '%s%%d' % prefix, idx,
                      label='topic.stack.index ' + labelsgen('topic.stack.index.%s', states))
+            if ui.verbose:
+                fm.write('topic.stack.shortnode', '(%s)', short(ctx.node()),
+                         label='topic.stack.shortnode ' + labelsgen('topic.stack.shortnode.%s', states))
         fm.write('topic.stack.state.symbol', '%s', symbol,
                  label='topic.stack.state ' + labelsgen('topic.stack.state.%s', states))
         fm.plain(' ')
--- a/tests/test-stack-branch.t	Fri Jul 21 01:04:32 2017 +0200
+++ b/tests/test-stack-branch.t	Fri Jul 14 07:19:15 2017 +0530
@@ -76,6 +76,13 @@
   b2: c_d
   b1: c_c
   b0^ c_b (base)
+  $ hg stack -v
+  ### branch: foo
+  b4(913c298d8b0a)@ c_f (current)
+  b3(4f2a69f6d380): c_e
+  b2(f61adbacd17a): c_d
+  b1(3e9313bc4b71): c_c
+  b0(4a04f1104a27)^ c_b (base)
 
 Test "t#" reference
 -------------------
--- a/tests/test-topic-stack-data.t	Fri Jul 21 01:04:32 2017 +0200
+++ b/tests/test-topic-stack-data.t	Fri Jul 14 07:19:15 2017 +0530
@@ -249,6 +249,16 @@
   t2: add bar_b
   t1: add bar_a
   t0^ add base_e (base)
+  $ hg stack bar -v
+  ### topic: bar (2 heads)
+  ### branch: default
+  t5(9cbadf11b44d): add bar_c
+  t2(e555c7e8c767)^ add bar_b (base)
+  t4(a920412b5a05)$ add bar_e (unstable)
+  t3(6915989374b1): bar1_d
+  t2(e555c7e8c767): add bar_b
+  t1(a5c2b4e00bbf): add bar_a
+  t0(92f489a6251f)^ add base_e (base)
   $ hg stack baz
   ### topic: baz
   ### branch: default, 2 behind
--- a/tests/test-topic-stack.t	Fri Jul 21 01:04:32 2017 +0200
+++ b/tests/test-topic-stack.t	Fri Jul 14 07:19:15 2017 +0530
@@ -77,6 +77,14 @@
   t2: c_d
   t1: c_c
   t0^ c_b (base)
+  $ hg stack -v
+  ### topic: foo
+  ### branch: default
+  t4(6559e6d93aea)@ c_f (current)
+  t3(0f9ac936c87d): c_e
+  t2(e629654d7050): c_d
+  t1(8522f9e3fee9): c_c
+  t0(ea705abc4f51)^ c_b (base)
   $ hg stack -Tjson | python -m json.tool
   [
       {
@@ -125,6 +133,59 @@
           "topic.stack.state.symbol": "^"
       }
   ]
+  $ hg stack -v -Tjson | python -m json.tool
+  [
+      {
+          "isentry": true,
+          "topic.stack.desc": "c_f",
+          "topic.stack.index": 4,
+          "topic.stack.shortnode": "6559e6d93aea",
+          "topic.stack.state": [
+              "current"
+          ],
+          "topic.stack.state.symbol": "@"
+      },
+      {
+          "isentry": true,
+          "topic.stack.desc": "c_e",
+          "topic.stack.index": 3,
+          "topic.stack.shortnode": "0f9ac936c87d",
+          "topic.stack.state": [
+              "clean"
+          ],
+          "topic.stack.state.symbol": ":"
+      },
+      {
+          "isentry": true,
+          "topic.stack.desc": "c_d",
+          "topic.stack.index": 2,
+          "topic.stack.shortnode": "e629654d7050",
+          "topic.stack.state": [
+              "clean"
+          ],
+          "topic.stack.state.symbol": ":"
+      },
+      {
+          "isentry": true,
+          "topic.stack.desc": "c_c",
+          "topic.stack.index": 1,
+          "topic.stack.shortnode": "8522f9e3fee9",
+          "topic.stack.state": [
+              "clean"
+          ],
+          "topic.stack.state.symbol": ":"
+      },
+      {
+          "isentry": false,
+          "topic.stack.desc": "c_b",
+          "topic.stack.index": 0,
+          "topic.stack.shortnode": "ea705abc4f51",
+          "topic.stack.state": [
+              "base"
+          ],
+          "topic.stack.state.symbol": "^"
+      }
+  ]
 
 error case, nothing to list