mercurial/bookmarks.py
changeset 33027 8299eb9b08c7
parent 33026 f5f4c72de71a
child 33104 d170f59f6f55
--- a/mercurial/bookmarks.py	Tue Jun 20 16:36:25 2017 -0700
+++ b/mercurial/bookmarks.py	Tue Jun 20 17:18:20 2017 -0700
@@ -765,16 +765,35 @@
         deactivate(repo)
     marks.recordchange(tr)
 
+def _printbookmarks(ui, repo, bmarks, **opts):
+    """private method to print bookmarks
+
+    Provides a way for extensions to control how bookmarks are printed (e.g.
+    prepend or postpend names)
+    """
+    fm = ui.formatter('bookmarks', opts)
+    hexfn = fm.hexfunc
+    if len(bmarks) == 0 and fm.isplain():
+        ui.status(_("no bookmarks set\n"))
+    for bmark, (n, prefix, label) in sorted(bmarks.iteritems()):
+        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=(activebookmarklabel in label))
+        fm.plain('\n')
+    fm.end()
+
 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"))
+    bmarks = {}
     for bmark, n in sorted(marks.iteritems()):
         active = repo._activebookmark
         if bmark == active:
@@ -782,13 +801,5 @@
         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()
+        bmarks[bmark] = (n, prefix, label)
+    _printbookmarks(ui, repo, bmarks, **opts)