##// END OF EJS Templates
formatter: carry opts to file-based formatters by basefm...
Yuya Nishihara -
r37615:d1101676 default
parent child Browse files
Show More
@@ -2231,7 +2231,7 b' def cat(ui, repo, ctx, matcher, basefm, '
2231 os.makedirs(os.path.dirname(filename))
2231 os.makedirs(os.path.dirname(filename))
2232 except OSError:
2232 except OSError:
2233 pass
2233 pass
2234 with formatter.maybereopen(basefm, filename, opts) as fm:
2234 with formatter.maybereopen(basefm, filename) as fm:
2235 _updatecatformatter(fm, ctx, matcher, path, opts.get('decode'))
2235 _updatecatformatter(fm, ctx, matcher, path, opts.get('decode'))
2236
2236
2237 # Automation often uses hg cat on single files, so special case it
2237 # Automation often uses hg cat on single files, so special case it
@@ -1318,7 +1318,7 b' def cat(ui, repo, file1, *pats, **opts):'
1318 fntemplate = ''
1318 fntemplate = ''
1319
1319
1320 if fntemplate:
1320 if fntemplate:
1321 fm = formatter.nullformatter(ui, 'cat')
1321 fm = formatter.nullformatter(ui, 'cat', opts)
1322 else:
1322 else:
1323 ui.pager('cat')
1323 ui.pager('cat')
1324 fm = ui.formatter('cat', opts)
1324 fm = ui.formatter('cat', opts)
@@ -160,6 +160,7 b' class baseformatter(object):'
160 def __init__(self, ui, topic, opts, converter):
160 def __init__(self, ui, topic, opts, converter):
161 self._ui = ui
161 self._ui = ui
162 self._topic = topic
162 self._topic = topic
163 self._opts = opts
163 self._converter = converter
164 self._converter = converter
164 self._item = None
165 self._item = None
165 # function to convert node to string suitable for this output
166 # function to convert node to string suitable for this output
@@ -222,9 +223,9 b' class baseformatter(object):'
222 if self._item is not None:
223 if self._item is not None:
223 self._showitem()
224 self._showitem()
224
225
225 def nullformatter(ui, topic):
226 def nullformatter(ui, topic, opts):
226 '''formatter that prints nothing'''
227 '''formatter that prints nothing'''
227 return baseformatter(ui, topic, opts={}, converter=_nullconverter)
228 return baseformatter(ui, topic, opts, converter=_nullconverter)
228
229
229 class _nestedformatter(baseformatter):
230 class _nestedformatter(baseformatter):
230 '''build sub items and store them in the parent formatter'''
231 '''build sub items and store them in the parent formatter'''
@@ -595,7 +596,7 b' def openformatter(ui, filename, topic, o'
595 def _neverending(fm):
596 def _neverending(fm):
596 yield fm
597 yield fm
597
598
598 def maybereopen(fm, filename, opts):
599 def maybereopen(fm, filename):
599 """Create a formatter backed by file if filename specified, else return
600 """Create a formatter backed by file if filename specified, else return
600 the given formatter
601 the given formatter
601
602
@@ -603,6 +604,6 b' def maybereopen(fm, filename, opts):'
603 of the given formatter.
604 of the given formatter.
604 """
605 """
605 if filename:
606 if filename:
606 return openformatter(fm._ui, filename, fm._topic, opts)
607 return openformatter(fm._ui, filename, fm._topic, fm._opts)
607 else:
608 else:
608 return _neverending(fm)
609 return _neverending(fm)
General Comments 0
You need to be logged in to leave comments. Login now