[PATCH 02 of 10] hgweb: wrap {lines} of {diff} with mappedgenerator

Yuya Nishihara yuya at tcha.org
Fri May 11 23:35:09 EDT 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1522766535 -32400
#      Tue Apr 03 23:42:15 2018 +0900
# Node ID 11a0e939b544d0c091c20b1d82bdc775a3b0b9ff
# Parent  093cd239abcc1a6a79e80f03f3536df427753ebe
hgweb: wrap {lines} of {diff} with mappedgenerator

This can't be a mappinggenerator as it switches the templates conditionally.

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -519,7 +519,7 @@ def listfilediffs(files, node, max):
     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 @@ def diffs(web, ctx, basectx, files, styl
                     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):


More information about the Mercurial-devel mailing list