Patchwork [1,of,9] bookmarks: pass in formatter to printbookmarks() instead of opts (API)

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 21, 2018, 1:24 p.m.
Message ID <9e58d4b235e42fbf982d.1537536243@mimosa>
Download mbox | patch
Permalink /patch/34894/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 21, 2018, 1:24 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1536979807 -32400
#      Sat Sep 15 11:50:07 2018 +0900
# Node ID 9e58d4b235e42fbf982dd733252e5d442f211422
# Parent  b2ec79559a4bbc8388aa66416b5a4f34a7bdfa01
bookmarks: pass in formatter to printbookmarks() instead of opts (API)

This clarifies that user options have to be processed before calling
printbookmarks().

Patch

diff --git a/hgext/remotenames.py b/hgext/remotenames.py
--- a/hgext/remotenames.py
+++ b/hgext/remotenames.py
@@ -230,7 +230,7 @@  class remotenames(object):
                     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 @@  def wrapprintbookmarks(orig, ui, repo, b
 
         bmarks[name] = (node, ' ', '')
 
-    return orig(ui, repo, bmarks, **opts)
+    return orig(ui, repo, fm, bmarks)
 
 def extsetup(ui):
     extensions.wrapfunction(bookmarks, '_printbookmarks', wrapprintbookmarks)
diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -915,14 +915,12 @@  def addbookmarks(repo, tr, names, rev=No
     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 @@  def _printbookmarks(ui, repo, bmarks, **
                      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 @@  def printbookmarks(ui, repo, **opts):
             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:
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1011,7 +1011,9 @@  def bookmark(ui, repo, *names, **opts):
             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,