changeset 2070:20fb4195bfc4

topic: extract the code listing all topics The code will become more complexe with formatter support and additional data in the verbose output. We extract the code in its own function first.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Sat, 13 Aug 2016 00:13:05 +0200
parents e97458bf53be
children acbbf7f0751e
files hgext3rd/topic/__init__.py
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py
+++ b/hgext3rd/topic/__init__.py
@@ -263,10 +263,7 @@
             with repo.vfs.open('topic', 'w') as f:
                 f.write(topic)
         return
-    current = repo.currenttopic
-    for t in sorted(repo.topics):
-        marker = '*' if t == current else ' '
-        ui.write(' %s %s\n' % (marker, t))
+    _listtopics(ui, repo)
 
 @command('stack [TOPIC]', [] + commands.formatteropts)
 def cmdstack(ui, repo, topic='', **opts):
@@ -275,6 +272,12 @@
     List the current topic by default."""
     return stack.showstack(ui, repo, topic, opts)
 
+def _listtopics(ui, repo):
+    current = repo.currenttopic
+    for t in sorted(repo.topics):
+        marker = '*' if t == current else ' '
+        ui.write(' %s %s\n' % (marker, t))
+
 def summaryhook(ui, repo):
     t = repo.currenttopic
     if not t: