changeset 1907:95874e8fc5f2

stack: add basic formatter and label support This still is not great, especially I would like '-T' to be able to control how we display the changeset, but this is useful progress.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Mon, 14 Mar 2016 19:03:32 +0000
parents 5e9ce6310720
children dbd6d51e63f1
files hgext3rd/topic/__init__.py hgext3rd/topic/stack.py
diffstat 2 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Mon Mar 14 18:43:23 2016 +0000
+++ b/hgext3rd/topic/__init__.py	Mon Mar 14 19:03:32 2016 +0000
@@ -54,7 +54,6 @@
 
 topicrev = re.compile(r'^t\d+$')
 
-
 def _namemap(repo, name):
     if topicrev.match(name):
         idx = int(name[1:])
@@ -189,13 +188,13 @@
     ('', 'clear', False, 'clear active topic if any'),
     ('', 'change', '', 'revset of existing revisions to change topic'),
     ('l', 'list', False, 'show the stack of changeset in the topic'),
-])
-def topics(ui, repo, topic='', clear=False, change=None, list=False):
+    ] + commands.formatteropts)
+def topics(ui, repo, topic='', clear=False, change=None, list=False, **opts):
     """View current topic, set current topic, or see all topics."""
     if list:
         if clear or change:
             raise error.Abort(_("cannot use --clear or --change with --list"))
-        return stack.showstack(ui, repo, topic)
+        return stack.showstack(ui, repo, topic, opts)
 
     if change:
         if not obsolete.isenabled(repo, obsolete.createmarkersopt):
--- a/hgext3rd/topic/stack.py	Mon Mar 14 18:43:23 2016 +0000
+++ b/hgext3rd/topic/stack.py	Mon Mar 14 19:03:32 2016 +0000
@@ -13,11 +13,12 @@
     trevs = repo.revs("topic(%s) - obsolete()", topic)
     return _orderrevs(repo, trevs)
 
-def showstack(ui, repo, topic):
+def showstack(ui, repo, topic, opts):
     if not topic:
         topic = repo.currenttopic
     if not topic:
         raise error.Abort(_('no active topic to list'))
+    fm = ui.formatter('topicstack', opts)
     for idx, r in enumerate(getstack(repo, topic)):
         # super crude initial version
         symbol = ':'
@@ -28,14 +29,18 @@
         if repo.revs('%d and unstable()', r):
             symbol = '$'
             state = 'unstable'
-        if state == 'clean':
-            l = "t%d%s %s\n" % (idx, symbol,
-                                repo[r].description().splitlines()[0])
-        else:
-            l = "t%d%s %s (%s)\n" % (idx, symbol,
-                                     repo[r].description().splitlines()[0],
-                                     state)
-        ui.write(l)
+        fm.startitem()
+        fm.write('topic.stack.index', 't%d', idx,
+                  label='topic.stack.index topic.stack.index.%s' % state)
+        fm.write('topic.stack.state.symbol', '%s', symbol,
+                 label='topic.stack.state topic.stack.state.%s' % state)
+        fm.plain(' ')
+        fm.write('topic.stack.desc', '%s', repo[r].description().splitlines()[0],
+                 label='topic.stack.desc topic.stack.desc.%s' % state)
+        fm.condwrite(state != 'clean', 'topic.stack.state', ' (%s)', state,
+                    label='topic.stack.state topic.stack.state.%s' % state)
+        fm.plain('\n')
+        fm.end()
 
 # Copied from evolve 081605c2e9b6