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

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

Comments

Yuya Nishihara - May 12, 2018, 3:35 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1522767000 -32400
#      Tue Apr 03 23:50:00 2018 +0900
# Node ID 1e645f7b2fd870569e56a0560a3c65c120319a8e
# Parent  61596d8c9f8c083ccac07334e3a4010df7ad9646
hgweb: convert {diff} to a mappinggenerator with named template

No more bare generator. Fortunately, this one is associated with a single
template, so it can be a mappinggenerator.

Patch

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -537,9 +537,8 @@  def _prettyprintdifflines(context, lines
             'linenumber': "% 8s" % difflineno,
         })
 
-def diffs(web, ctx, basectx, files, style, linerange=None,
-          lineidprefix=''):
-    repo = web.repo
+def _diffsgen(context, repo, ctx, basectx, files, style, stripecount,
+              linerange, lineidprefix):
     if files:
         m = match.exact(repo.root, repo.getcwd(), files)
     else:
@@ -548,7 +547,7 @@  def diffs(web, ctx, basectx, files, styl
     diffopts = patch.diffopts(repo.ui, untrusted=True)
     node1 = basectx.node()
     node2 = ctx.node()
-    parity = paritygen(web.stripecount)
+    parity = paritygen(stripecount)
 
     diffhunks = patch.diffhunks(repo, node1, node2, m, opts=diffopts)
     for blockno, (fctx1, fctx2, header, hunks) in enumerate(diffhunks, 1):
@@ -565,11 +564,16 @@  def diffs(web, ctx, basectx, files, styl
             l = templateutil.mappedgenerator(_prettyprintdifflines,
                                              args=(lines, blockno,
                                                    lineidprefix))
-            yield web.tmpl.generate('diffblock', {
+            yield {
                 'parity': next(parity),
                 'blockno': blockno,
                 'lines': l,
-            })
+            }
+
+def diffs(web, ctx, basectx, files, style, linerange=None, lineidprefix=''):
+    args = (web.repo, ctx, basectx, files, style, web.stripecount,
+            linerange, lineidprefix)
+    return templateutil.mappinggenerator(_diffsgen, args=args, name='diffblock')
 
 def compare(tmpl, context, leftlines, rightlines):
     '''Generator function that provides side-by-side comparison data.'''