Patchwork [09,of,10] hgweb: convert {comparison} to a mappinggenerator with named template

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

Comments

Yuya Nishihara - May 12, 2018, 3:35 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1522844230 -32400
#      Wed Apr 04 21:17:10 2018 +0900
# Node ID c0f7a01a162982f383e69a69ecd2fd89b031d2cb
# Parent  94ed335f53c7c5fb2b2c9b36d452c3ae47d0c8f1
hgweb: convert {comparison} to a mappinggenerator with named template

No bare generator.

Patch

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -622,16 +622,21 @@  def _getcompblock(leftlines, rightlines,
     return templateutil.mappinggenerator(_getcompblockgen, args=args,
                                          name='comparisonline')
 
-def compare(tmpl, contextnum, leftlines, rightlines):
+def _comparegen(context, contextnum, leftlines, rightlines):
     '''Generator function that provides side-by-side comparison data.'''
     s = difflib.SequenceMatcher(None, leftlines, rightlines)
     if contextnum < 0:
         l = _getcompblock(leftlines, rightlines, s.get_opcodes())
-        yield tmpl.generate('comparisonblock', {'lines': l})
+        yield {'lines': l}
     else:
         for oc in s.get_grouped_opcodes(n=contextnum):
             l = _getcompblock(leftlines, rightlines, oc)
-            yield tmpl.generate('comparisonblock', {'lines': l})
+            yield {'lines': l}
+
+def compare(tmpl, contextnum, leftlines, rightlines):
+    args = (contextnum, leftlines, rightlines)
+    return templateutil.mappinggenerator(_comparegen, args=args,
+                                         name='comparisonblock')
 
 def diffstatgen(ctx, basectx):
     '''Generator function that provides the diffstat data.'''