changeset 33010:f5f4c72de71a

bookmarks: factor out bookmark printing from commands
author Sean Farley <sean@farley.io>
date Tue, 20 Jun 2017 16:36:25 -0700
parents 4b81776baa7a
children 8299eb9b08c7
files mercurial/bookmarks.py mercurial/commands.py
diffstat 2 files changed, 29 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bookmarks.py	Tue Jun 20 15:56:29 2017 -0700
+++ b/mercurial/bookmarks.py	Tue Jun 20 16:36:25 2017 -0700
@@ -764,3 +764,31 @@
     elif cur != tgt and newact == repo._activebookmark:
         deactivate(repo)
     marks.recordchange(tr)
+
+def printbookmarks(ui, repo, **opts):
+    """print bookmarks to a formatter
+
+    Provides a way for extensions to control how bookmarks are printed.
+    """
+    fm = ui.formatter('bookmarks', opts)
+    hexfn = fm.hexfunc
+    marks = repo._bookmarks
+    if len(marks) == 0 and fm.isplain():
+        ui.status(_("no bookmarks set\n"))
+    for bmark, n in sorted(marks.iteritems()):
+        active = repo._activebookmark
+        if bmark == active:
+            prefix, label = '*', activebookmarklabel
+        else:
+            prefix, label = ' ', ''
+
+        fm.startitem()
+        if not ui.quiet:
+            fm.plain(' %s ' % prefix, label=label)
+        fm.write('bookmark', '%s', bmark, label=label)
+        pad = " " * (25 - encoding.colwidth(bmark))
+        fm.condwrite(not ui.quiet, 'rev node', pad + ' %d:%s',
+                     repo.changelog.rev(n), hexfn(n), label=label)
+        fm.data(active=(bmark == active))
+        fm.plain('\n')
+    fm.end()
--- a/mercurial/commands.py	Tue Jun 20 15:56:29 2017 -0700
+++ b/mercurial/commands.py	Tue Jun 20 16:36:25 2017 -0700
@@ -980,28 +980,7 @@
                 else:
                     bookmarks.deactivate(repo)
     else: # show bookmarks
-        fm = ui.formatter('bookmarks', opts)
-        hexfn = fm.hexfunc
-        marks = repo._bookmarks
-        if len(marks) == 0 and fm.isplain():
-            ui.status(_("no bookmarks set\n"))
-        for bmark, n in sorted(marks.iteritems()):
-            active = repo._activebookmark
-            if bmark == active:
-                prefix, label = '*', bookmarks.activebookmarklabel
-            else:
-                prefix, label = ' ', ''
-
-            fm.startitem()
-            if not ui.quiet:
-                fm.plain(' %s ' % prefix, label=label)
-            fm.write('bookmark', '%s', bmark, label=label)
-            pad = " " * (25 - encoding.colwidth(bmark))
-            fm.condwrite(not ui.quiet, 'rev node', pad + ' %d:%s',
-                         repo.changelog.rev(n), hexfn(n), label=label)
-            fm.data(active=(bmark == active))
-            fm.plain('\n')
-        fm.end()
+        bookmarks.printbookmarks(ui, repo, **opts)
 
 @command('branch',
     [('f', 'force', None,