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

login
register
mail settings
Submitter Yuya Nishihara
Date May 12, 2018, 3:35 a.m.
Message ID <11a0e939b544d0c091c2.1526096109@mimosa>
Download mbox | patch
Permalink /patch/31533/
State Accepted
Headers show

Comments

Yuya Nishihara - May 12, 2018, 3:35 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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.

Patch

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):