changeset 3384:2b06f144b6e0

topics: add a new templatekeyword `topic` This patch adds a new templatekeyword topic which can be used to list the topic of the changeset when using commands which supports templating.
author Pulkit Goyal <7895pulkit@gmail.com>
date Tue, 09 Jan 2018 23:42:57 +0530
parents 733e01473ec2
children 823031b51d81
files CHANGELOG hgext3rd/topic/__init__.py tests/test-topic-change.t tests/test-topic-rebase.t tests/test-topic-stack-data.t tests/test-topic-tutorial.t
diffstat 6 files changed, 35 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG	Wed Jan 10 10:54:02 2018 +0000
+++ b/CHANGELOG	Tue Jan 09 23:42:57 2018 +0530
@@ -26,6 +26,7 @@
 topic (0.6.1)
 
   * fix compatibility with Mercurial-4.3
+  * new template keyword `topic` to get changesets topic
 
 7.1.0 -- 2017-12-12
 -------------------
--- a/hgext3rd/topic/__init__.py	Wed Jan 10 10:54:02 2018 +0000
+++ b/hgext3rd/topic/__init__.py	Tue Jan 09 23:42:57 2018 +0530
@@ -127,6 +127,7 @@
     registrar,
     scmutil,
     templatefilters,
+    templatekw,
     util,
 )
 
@@ -325,6 +326,7 @@
 
     cmdutil.summaryhooks.add('topic', summaryhook)
 
+    templatekw.keywords['topic'] = topickw
     # Wrap workingctx extra to return the topic name
     extensions.wrapfunction(context.workingctx, '__init__', wrapinit)
     # Wrap changelog.add to drop empty topic
@@ -491,6 +493,10 @@
             'topics', 'topic', namemap=_namemap, nodemap=_nodemap,
             listnames=lambda repo: repo.topics))
 
+def topickw(**args):
+    """:topic: String. The topic of the changeset"""
+    return args['ctx'].topic()
+
 def wrapinit(orig, self, repo, *args, **kwargs):
     orig(self, repo, *args, **kwargs)
     if getattr(repo, 'currenttopic', ''):
--- a/tests/test-topic-change.t	Wed Jan 10 10:54:02 2018 +0000
+++ b/tests/test-topic-change.t	Tue Jan 09 23:42:57 2018 +0530
@@ -10,7 +10,7 @@
   > [phases]
   > publish=false
   > [alias]
-  > glog = log -G -T "{rev}:{node|short} \{{topics}}\n{desc}  ({bookmarks})\n\n"
+  > glog = log -G -T "{rev}:{node|short} \{{topic}}\n{desc}  ({bookmarks})\n\n"
   > EOF
 
 About the glog output: {} contains the topic name and () will contain the bookmark
--- a/tests/test-topic-rebase.t	Wed Jan 10 10:54:02 2018 +0000
+++ b/tests/test-topic-rebase.t	Tue Jan 09 23:42:57 2018 +0530
@@ -28,7 +28,7 @@
   >    hg ci -m "add $1" $2 $3
   > }
   $ logtopic() {
-  >    hg log -G -T "{rev}:{node}\ntopics: {topics}" 
+  >    hg log -G -T "{rev}:{node}\ntopics: {topic}" 
   > }
 
 Check that rebase keep the topic in the simple case (1 changeset, no merge conflict)
--- a/tests/test-topic-stack-data.t	Wed Jan 10 10:54:02 2018 +0000
+++ b/tests/test-topic-stack-data.t	Tue Jan 09 23:42:57 2018 +0530
@@ -114,33 +114,33 @@
   orphan: 3 changesets
   topic:  foo
   $ hg log --graph -T '{desc} ({branch}) [{topic}]'
-  @  add foo_b (lake) []
+  @  add foo_b (lake) [foo]
   |
-  o  add foo_a (lake) []
+  o  add foo_a (lake) [foo]
   |
-  | o  bar1_d (default) []
+  | o  bar1_d (default) [bar]
   | |
-  | | *  add bar_e (default) []
+  | | *  add bar_e (default) [bar]
   | | |
-  | | x  add bar_d (default) []
+  | | x  add bar_d (default) [bar]
   | |/
-  | | o  add bar_c (default) []
+  | | o  add bar_c (default) [bar]
   | |/
-  | o  add bar_b (default) []
+  | o  add bar_b (default) [bar]
   | |
-  | o  add bar_a (default) []
+  | o  add bar_a (default) [bar]
   | |
-  | | o  fuz1_a (default) []
+  | | o  fuz1_a (default) [fuz]
   | | |
-  | | | *  add fuz_c (default) []
+  | | | *  add fuz_c (default) [fuz]
   | | | |
-  | | | *  add fuz_b (default) []
+  | | | *  add fuz_b (default) [fuz]
   | | | |
-  | | | x  add fuz_a (default) []
+  | | | x  add fuz_a (default) [fuz]
   | | |/
-  | | | o  add baz_b (default) []
+  | | | o  add baz_b (default) [baz]
   | | | |
-  | | | o  add baz_a (default) []
+  | | | o  add baz_a (default) [baz]
   | | | |
   +-------o  add lake_c (lake) []
   | | | |
--- a/tests/test-topic-tutorial.t	Wed Jan 10 10:54:02 2018 +0000
+++ b/tests/test-topic-tutorial.t	Tue Jan 09 23:42:57 2018 +0530
@@ -575,6 +575,18 @@
       }
 #endif
 
+There exists a template keyword named "topic" which can be used
+
+  $ hg log -GT "{rev}:{node|short} {topic}\n {desc}"
+  @  5:2d50db8b5b4c food
+  |   adding fruits
+  o  4:4011b46eeb33 food
+  |   adding condiments
+  o  3:6104862e8b84
+  |   Adding clothes
+  o  0:38da43f0a2ea
+      Shopping list
+
 The topic information will disappear when we publish the changesets:
 
   $ hg topics