changeset 39746:25cc5616adc9

bookmarks: pass in formatter to printbookmarks() instead of opts (API) This clarifies that user options have to be processed before calling printbookmarks().
author Yuya Nishihara <yuya@tcha.org>
date Sat, 15 Sep 2018 11:50:07 +0900
parents b2ec79559a4b
children 81d1c963e94a
files hgext/remotenames.py mercurial/bookmarks.py mercurial/commands.py
diffstat 3 files changed, 9 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/remotenames.py	Wed Sep 19 17:09:01 2018 +0200
+++ b/hgext/remotenames.py	Sat Sep 15 11:50:07 2018 +0900
@@ -230,7 +230,7 @@
                     self._nodetohoists.setdefault(node[0], []).append(name)
         return self._nodetohoists
 
-def wrapprintbookmarks(orig, ui, repo, bmarks, **opts):
+def wrapprintbookmarks(orig, ui, repo, fm, bmarks):
     if 'remotebookmarks' not in repo.names:
         return
     ns = repo.names['remotebookmarks']
@@ -243,7 +243,7 @@
 
         bmarks[name] = (node, ' ', '')
 
-    return orig(ui, repo, bmarks, **opts)
+    return orig(ui, repo, fm, bmarks)
 
 def extsetup(ui):
     extensions.wrapfunction(bookmarks, '_printbookmarks', wrapprintbookmarks)
--- a/mercurial/bookmarks.py	Wed Sep 19 17:09:01 2018 +0200
+++ b/mercurial/bookmarks.py	Sat Sep 15 11:50:07 2018 +0900
@@ -915,14 +915,12 @@
     elif cur != tgt and newact == repo._activebookmark:
         deactivate(repo)
 
-def _printbookmarks(ui, repo, bmarks, **opts):
+def _printbookmarks(ui, repo, fm, bmarks):
     """private method to print bookmarks
 
     Provides a way for extensions to control how bookmarks are printed (e.g.
     prepend or postpend names)
     """
-    opts = pycompat.byteskwargs(opts)
-    fm = ui.formatter('bookmarks', opts)
     hexfn = fm.hexfunc
     if len(bmarks) == 0 and fm.isplain():
         ui.status(_("no bookmarks set\n"))
@@ -937,10 +935,9 @@
                      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
+def printbookmarks(ui, repo, fm):
+    """print bookmarks by the given formatter
 
     Provides a way for extensions to control how bookmarks are printed.
     """
@@ -954,7 +951,7 @@
             prefix, label = ' ', ''
 
         bmarks[bmark] = (n, prefix, label)
-    _printbookmarks(ui, repo, bmarks, **opts)
+    _printbookmarks(ui, repo, fm, bmarks)
 
 def preparehookargs(name, old, new):
     if new is None:
--- a/mercurial/commands.py	Wed Sep 19 17:09:01 2018 +0200
+++ b/mercurial/commands.py	Sat Sep 15 11:50:07 2018 +0900
@@ -1011,7 +1011,9 @@
             return 1
         ui.write("%s\n" % book, label=bookmarks.activebookmarklabel)
     else: # show bookmarks
-        bookmarks.printbookmarks(ui, repo, **opts)
+        opts = pycompat.byteskwargs(opts)
+        with ui.formatter('bookmarks', opts) as fm:
+            bookmarks.printbookmarks(ui, repo, fm)
 
 @command('branch',
     [('f', 'force', None,