changeset 37597:d110167610db

formatter: carry opts to file-based formatters by basefm This makes it slightly easier to port "hg export" to formatter.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 12 Apr 2018 23:25:58 +0900
parents 8c121a9837ca
children 7a9c905e51f9
files mercurial/cmdutil.py mercurial/commands.py mercurial/formatter.py
diffstat 3 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Thu Apr 12 23:24:33 2018 +0900
+++ b/mercurial/cmdutil.py	Thu Apr 12 23:25:58 2018 +0900
@@ -2231,7 +2231,7 @@
                 os.makedirs(os.path.dirname(filename))
             except OSError:
                 pass
-        with formatter.maybereopen(basefm, filename, opts) as fm:
+        with formatter.maybereopen(basefm, filename) as fm:
             _updatecatformatter(fm, ctx, matcher, path, opts.get('decode'))
 
     # Automation often uses hg cat on single files, so special case it
--- a/mercurial/commands.py	Thu Apr 12 23:24:33 2018 +0900
+++ b/mercurial/commands.py	Thu Apr 12 23:25:58 2018 +0900
@@ -1318,7 +1318,7 @@
         fntemplate = ''
 
     if fntemplate:
-        fm = formatter.nullformatter(ui, 'cat')
+        fm = formatter.nullformatter(ui, 'cat', opts)
     else:
         ui.pager('cat')
         fm = ui.formatter('cat', opts)
--- a/mercurial/formatter.py	Thu Apr 12 23:24:33 2018 +0900
+++ b/mercurial/formatter.py	Thu Apr 12 23:25:58 2018 +0900
@@ -160,6 +160,7 @@
     def __init__(self, ui, topic, opts, converter):
         self._ui = ui
         self._topic = topic
+        self._opts = opts
         self._converter = converter
         self._item = None
         # function to convert node to string suitable for this output
@@ -222,9 +223,9 @@
         if self._item is not None:
             self._showitem()
 
-def nullformatter(ui, topic):
+def nullformatter(ui, topic, opts):
     '''formatter that prints nothing'''
-    return baseformatter(ui, topic, opts={}, converter=_nullconverter)
+    return baseformatter(ui, topic, opts, converter=_nullconverter)
 
 class _nestedformatter(baseformatter):
     '''build sub items and store them in the parent formatter'''
@@ -595,7 +596,7 @@
 def _neverending(fm):
     yield fm
 
-def maybereopen(fm, filename, opts):
+def maybereopen(fm, filename):
     """Create a formatter backed by file if filename specified, else return
     the given formatter
 
@@ -603,6 +604,6 @@
     of the given formatter.
     """
     if filename:
-        return openformatter(fm._ui, filename, fm._topic, opts)
+        return openformatter(fm._ui, filename, fm._topic, fm._opts)
     else:
         return _neverending(fm)