Mercurial > hg
comparison mercurial/formatter.py @ 34425:12bfecd0ffe6
formatter: fix default list/dict generator to be evaluated more than once
Before, _hybrid.gen must be a generator which could be consumed only once.
It was okay in templatekw.py since template keywords are functions which
create temporary hybrid objects, but the formatter doesn't work in that way.
To work around the issue, this patch makes _hybrid.gen optionally be a
function returning a generator.
Thanks to Pulkit for finding this issue.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 01 Oct 2017 08:37:04 +0100 |
parents | ebf2c1b0c70c |
children | f17a0e18c47e |
comparison
equal
deleted
inserted
replaced
34424:e416819d9ebb | 34425:12bfecd0ffe6 |
---|---|
346 def formatdict(data, key, value, fmt, sep): | 346 def formatdict(data, key, value, fmt, sep): |
347 '''build object that can be evaluated as either plain string or dict''' | 347 '''build object that can be evaluated as either plain string or dict''' |
348 data = util.sortdict(_iteritems(data)) | 348 data = util.sortdict(_iteritems(data)) |
349 def f(): | 349 def f(): |
350 yield _plainconverter.formatdict(data, key, value, fmt, sep) | 350 yield _plainconverter.formatdict(data, key, value, fmt, sep) |
351 return templatekw.hybriddict(data, key=key, value=value, fmt=fmt, | 351 return templatekw.hybriddict(data, key=key, value=value, fmt=fmt, gen=f) |
352 gen=f()) | |
353 @staticmethod | 352 @staticmethod |
354 def formatlist(data, name, fmt, sep): | 353 def formatlist(data, name, fmt, sep): |
355 '''build object that can be evaluated as either plain string or list''' | 354 '''build object that can be evaluated as either plain string or list''' |
356 data = list(data) | 355 data = list(data) |
357 def f(): | 356 def f(): |
358 yield _plainconverter.formatlist(data, name, fmt, sep) | 357 yield _plainconverter.formatlist(data, name, fmt, sep) |
359 return templatekw.hybridlist(data, name=name, fmt=fmt, gen=f()) | 358 return templatekw.hybridlist(data, name=name, fmt=fmt, gen=f) |
360 | 359 |
361 class templateformatter(baseformatter): | 360 class templateformatter(baseformatter): |
362 def __init__(self, ui, out, topic, opts): | 361 def __init__(self, ui, out, topic, opts): |
363 baseformatter.__init__(self, ui, topic, opts, _templateconverter) | 362 baseformatter.__init__(self, ui, topic, opts, _templateconverter) |
364 self._out = out | 363 self._out = out |