topic: extract the code listing all topics
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Sat, 13 Aug 2016 00:13:05 +0200
changeset 1974 20fb4195bfc4
parent 1973 e97458bf53be
child 1975 acbbf7f0751e
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.
hgext3rd/topic/__init__.py
--- a/hgext3rd/topic/__init__.py	Fri Aug 12 11:09:26 2016 +0200
+++ b/hgext3rd/topic/__init__.py	Sat Aug 13 00:13:05 2016 +0200
@@ -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: