[PATCH 4 of 4 topic-experiment] topics: show more information in `hg topics`

Pulkit Goyal 7895pulkit at gmail.com
Mon Jun 26 04:28:53 EDT 2017


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1497889184 -19800
#      Mon Jun 19 21:49:44 2017 +0530
# Node ID 8523d4018183cf29600c4b1633479e941f89c6c2
# Parent  4c0852883a31643a3f4fe50688f85ac90a8d63b9
topics: show more information in `hg topics`

`hg topics` is the only way to show the list of topics currently. The default
version shows only the topics name which is very less. This patch makes `hg
topics` show number of changeset and branch related information also.

diff --git a/hgext3rd/topic/__init__.py b/hgext3rd/topic/__init__.py
--- a/hgext3rd/topic/__init__.py
+++ b/hgext3rd/topic/__init__.py
@@ -395,7 +395,7 @@
     fm = ui.formatter('bookmarks', opts)
     activetopic = repo.currenttopic
     namemask = '%s'
-    if repo.topics and ui.verbose:
+    if repo.topics:
         maxwidth = max(len(t) for t in repo.topics)
         namemask = '%%-%is' % maxwidth
     for topic in sorted(repo.topics):
@@ -411,8 +411,7 @@
             fm.plain(' %s ' % marker, label=label)
         fm.write('topic', namemask, topic, label=label)
         fm.data(active=active)
-        if ui.verbose:
-            # XXX we should include the data even when not verbose
+        if not ui.quiet:
             data = stack.stackdata(repo, topic)
             fm.plain(' (')
             fm.write('branches+', 'on branch: %s',
@@ -421,26 +420,27 @@
             fm.plain(', ')
             fm.write('changesetcount', '%d changesets', data['changesetcount'],
                      label='topic.list.changesetcount')
-            if data['troubledcount']:
-                fm.plain(', ')
-                fm.write('troubledcount', '%d troubled',
-                         data['troubledcount'],
-                         label='topic.list.troubledcount')
-            if 1 < data['headcount']:
-                fm.plain(', ')
-                fm.write('headcount', '%d heads',
-                         data['headcount'],
-                         label='topic.list.headcount.multiple')
-            if 0 < data['behindcount']:
-                fm.plain(', ')
-                fm.write('behindcount', '%d behind',
-                         data['behindcount'],
-                         label='topic.list.behindcount')
-            elif -1 == data['behindcount']:
-                fm.plain(', ')
-                fm.write('behinderror', '%s',
-                         _('ambiguous destination'),
-                         label='topic.list.behinderror')
+            if ui.verbose:
+                if data['troubledcount']:
+                    fm.plain(', ')
+                    fm.write('troubledcount', '%d troubled',
+                             data['troubledcount'],
+                             label='topic.list.troubledcount')
+                if 1 < data['headcount']:
+                    fm.plain(', ')
+                    fm.write('headcount', '%d heads',
+                             data['headcount'],
+                             label='topic.list.headcount.multiple')
+                if 0 < data['behindcount']:
+                    fm.plain(', ')
+                    fm.write('behindcount', '%d behind',
+                             data['behindcount'],
+                             label='topic.list.behindcount')
+                elif -1 == data['behindcount']:
+                    fm.plain(', ')
+                    fm.write('behinderror', '%s',
+                             _('ambiguous destination'),
+                             label='topic.list.behinderror')
             fm.plain(')')
         fm.plain('\n')
     fm.end()
diff --git a/tests/test-topic-dest.t b/tests/test-topic-dest.t
--- a/tests/test-topic-dest.t
+++ b/tests/test-topic-dest.t
@@ -229,12 +229,12 @@
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ hg topic
-     elephant
-   * monkey
+     elephant (on branch: default, 1 changesets)
+   * monkey   (on branch: default, 2 changesets)
   $ hg ci -m 'merge with default'
   $ hg topic
-     elephant
-   * monkey
+     elephant (on branch: default, 1 changesets)
+   * monkey   (on branch: default, 3 changesets)
   $ hg log -G
   @    13 (monkey) merge with default
   |\
diff --git a/tests/test-topic-stack-data.t b/tests/test-topic-stack-data.t
--- a/tests/test-topic-stack-data.t
+++ b/tests/test-topic-stack-data.t
@@ -157,10 +157,10 @@
 basic output
 
   $ hg topic
-     bar
-     baz
-   * foo
-     fuz
+     bar (on branch: default, 5 changesets)
+     baz (on branch: default, 2 changesets)
+   * foo (on branch: lake, 2 changesets)
+     fuz (on branch: default, 3 changesets)
 
 quiet version
 
@@ -184,18 +184,26 @@
   [
    {
     "active": false,
+    "branches+": "default",
+    "changesetcount": 5,
     "topic": "bar"
    },
    {
     "active": false,
+    "branches+": "default",
+    "changesetcount": 2,
     "topic": "baz"
    },
    {
     "active": true,
+    "branches+": "lake",
+    "changesetcount": 2,
     "topic": "foo"
    },
    {
     "active": false,
+    "branches+": "default",
+    "changesetcount": 3,
     "topic": "fuz"
    }
   ]
diff --git a/tests/test-topic-stack.t b/tests/test-topic-stack.t
--- a/tests/test-topic-stack.t
+++ b/tests/test-topic-stack.t
@@ -68,7 +68,7 @@
 'hg stack' list all changeset in the topic
 
   $ hg topic
-   * foo
+   * foo (on branch: default, 4 changesets)
   $ hg stack
   ### topic: foo
   ### branch: default
diff --git a/tests/test-topic-tutorial.t b/tests/test-topic-tutorial.t
--- a/tests/test-topic-tutorial.t
+++ b/tests/test-topic-tutorial.t
@@ -60,7 +60,7 @@
 As for named branch, our topic is active but it does not contains any changesets yet::
 
   $ hg topic
-   * food
+   * food (on branch: , 0 changesets)
   $ hg summary
   parent: 0:38da43f0a2ea tip
    Shopping list
@@ -131,7 +131,7 @@
   $ hg up default
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg topic
-     food
+     food (on branch: default, 2 changesets)
 
 Note that ``default`` (name of the branch) now refers to the tipmost changeset of default without a topic::
 
@@ -161,7 +161,7 @@
   switching to topic food
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg topic
-   * food
+   * food (on branch: default, 2 changesets)
 
 The name used for updating does not affect the activation of the topic, updating to a revision part of a topic will activate it in all cases::
 
@@ -171,7 +171,7 @@
   switching to topic food
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg topic
-   * food
+   * food (on branch: default, 2 changesets)
 
 .. server side activity::
 
@@ -274,7 +274,7 @@
 The topic information will fade out when we publish the changesets::
 
   $ hg topic
-     food
+     food (on branch: default, 2 changesets)
   $ hg push
   pushing to $TESTTMP/server (glob)
   searching for changes
@@ -343,8 +343,8 @@
 We now have two topics::
 
   $ hg topic
-   * drinks
-     tools
+   * drinks (on branch: default, 2 changesets)
+     tools  (on branch: default, 3 changesets)
 
 The information ``hg stack`` command adapt to the active topic::
 
diff --git a/tests/test-topic.t b/tests/test-topic.t
--- a/tests/test-topic.t
+++ b/tests/test-topic.t
@@ -68,28 +68,28 @@
   [255]
   $ hg revert alpha
   $ hg topic
-   * topicflag
+   * topicflag (on branch: , 0 changesets)
 
 Make a topic
   $ hg topic narf
   $ hg topics
-   * narf
+   * narf (on branch: , 0 changesets)
   $ echo topic work >> alpha
   $ hg ci -m 'start on narf'
   $ hg co .^
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg topic fran
   $ hg topics
-   * fran
-     narf
+   * fran (on branch: , 0 changesets)
+     narf (on branch: default, 1 changesets)
   $ echo >> fran work >> beta
   $ hg ci -m 'start on fran'
   $ hg co narf
   switching to topic narf
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg topic
-     fran
-   * narf
+     fran (on branch: default, 1 changesets)
+   * narf (on branch: default, 1 changesets)
   $ hg log -r . -T '{topics}\n'
   narf
   $ echo 'narf!!!' >> alpha
@@ -288,7 +288,7 @@
   |    summary:     start on narf
   |
   $ hg topics
-   * query
+   * query (on branch: default, 1 changesets)
   $ cd ../pinky
   $ hg co query
   switching to topic query
@@ -307,9 +307,9 @@
   $ hg topic narf
   $ hg ci -m 'Finish narf'
   $ hg topics
-     fran
-   * narf
-     query
+     fran  (on branch: default, 1 changesets)
+   * narf  (on branch: default, 2 changesets)
+     query (on branch: default, 2 changesets)
   $ hg debugnamecomplete # branch:topic here is a buggy side effect
   default
   default:fran
@@ -325,8 +325,8 @@
 narf commits public:
 
   $ hg topics
-     fran
-   * narf
+     fran (on branch: default, 1 changesets)
+   * narf (on branch: , 0 changesets)
   $ hg log -Gl 6
   @    changeset:   9:ae074045b7a7
   |\   tag:         tip
@@ -367,7 +367,7 @@
   |
   $ cd ../brain
   $ hg topics
-   * query
+   * query (on branch: default, 1 changesets)
   $ hg pull ../pinky -r narf
   pulling from ../pinky
   abort: unknown revision 'narf'!
@@ -381,7 +381,7 @@
   added 3 changesets with 3 changes to 1 files
   (run 'hg update' to get a working copy)
   $ hg topics
-   * query
+   * query (on branch: , 0 changesets)
 
 We can pull in the draft-phase change and we get the new topic
 
@@ -394,8 +394,8 @@
   added 1 changesets with 1 changes to 1 files (+1 heads)
   (run 'hg heads' to see heads)
   $ hg topics
-     fran
-   * query
+     fran  (on branch: default, 1 changesets)
+   * query (on branch: , 0 changesets)
   $ hg log -Gr 'draft()'
   o  changeset:   9:0469d521db49
   |  tag:         tip
@@ -411,7 +411,7 @@
 
   $ hg topics --clear
   $ hg topics
-     fran
+     fran (on branch: default, 1 changesets)
 
 --clear when we don't have an active topic isn't an error:
 
@@ -502,7 +502,7 @@
 
 Match current topic:
   $ hg topic
-     fran
+     fran (on branch: default, 1 changesets)
   $ hg log -r 'topic(.)'
 (no output is expected)
   $ hg co fran
@@ -520,7 +520,7 @@
 
 Deactivate the topic.
   $ hg topics
-   * fran
+   * fran (on branch: default, 1 changesets)
   $ hg topics --clear
   $ echo fran? >> beta
   $ hg ci -m 'fran?'
@@ -540,7 +540,7 @@
   |  summary:     start on fran
   |
   $ hg topics
-     fran
+     fran (on branch: default, 1 changesets)
 Changing topic fails if we don't give a topic
   $ hg topic --rev 9
   abort: changing topic requires a topic name or --clear


More information about the Mercurial-devel mailing list