hgweb: wrap {lines} of {diff} with mappedgenerator
authorYuya Nishihara <yuya@tcha.org>
Tue, 03 Apr 2018 23:42:15 +0900
changeset 37985 6a4de2dc78dd
parent 37984 3f70466ec7aa
child 37986 7a9e9fbaa559
hgweb: wrap {lines} of {diff} with mappedgenerator This can't be a mappinggenerator as it switches the templates conditionally.
mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py	Tue Apr 03 23:38:19 2018 +0900
+++ b/mercurial/hgweb/webutil.py	Tue Apr 03 23:42:15 2018 +0900
@@ -519,7 +519,7 @@
     return templateutil.mappedgenerator(_listfilediffsgen,
                                         args=(files, node, max))
 
-def _prettyprintdifflines(tmpl, lines, blockno, lineidprefix):
+def _prettyprintdifflines(context, tmpl, lines, blockno, lineidprefix):
     for lineno, l in enumerate(lines, 1):
         difflineno = "%d.%d" % (blockno, lineno)
         if l.startswith('+'):
@@ -562,11 +562,13 @@
                     continue
             lines.extend(hunklines)
         if lines:
+            l = templateutil.mappedgenerator(_prettyprintdifflines,
+                                             args=(web.tmpl, lines, blockno,
+                                                   lineidprefix))
             yield web.tmpl.generate('diffblock', {
                 'parity': next(parity),
                 'blockno': blockno,
-                'lines': _prettyprintdifflines(web.tmpl, lines, blockno,
-                                               lineidprefix),
+                'lines': l,
             })
 
 def compare(tmpl, context, leftlines, rightlines):