Patchwork [1,of,7] hgweb: wrap {diffstat} with mappedgenerator

login
register
mail settings
Submitter Yuya Nishihara
Date May 13, 2018, 3:19 a.m.
Message ID <19ec816173c015626e20.1526181598@mimosa>
Download mbox | patch
Permalink /patch/31569/
State Accepted
Headers show

Comments

Yuya Nishihara - May 13, 2018, 3:19 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1522768777 -32400
#      Wed Apr 04 00:19:37 2018 +0900
# Node ID 19ec816173c015626e2001e14ed3fe2be7a13d8b
# Parent  74982ab8ca762a3cfe3648740dae27555232476b
hgweb: wrap {diffstat} with mappedgenerator

This can't be a mappinggenerator since the associated templates are switched
per item.

We already have webutil.diffstatgen(). That's why the generator function is
named as _diffstattmplgen().

Patch

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -654,9 +654,7 @@  def diffsummary(statgen):
     return _(' %d files changed, %d insertions(+), %d deletions(-)\n') % (
              len(stats), addtotal, removetotal)
 
-def diffstat(tmpl, ctx, statgen, parity):
-    '''Return a diffstat template for each file in the diff.'''
-
+def _diffstattmplgen(context, tmpl, ctx, statgen, parity):
     stats, maxname, maxtotal, addtotal, removetotal, binary = next(statgen)
     files = ctx.files()
 
@@ -680,6 +678,11 @@  def diffstat(tmpl, ctx, statgen, parity)
             'parity': next(parity),
         })
 
+def diffstat(tmpl, ctx, statgen, parity):
+    '''Return a diffstat template for each file in the diff.'''
+    args = (tmpl, ctx, statgen, parity)
+    return templateutil.mappedgenerator(_diffstattmplgen, args=args)
+
 class sessionvars(templateutil.wrapped):
     def __init__(self, vars, start='?'):
         self._start = start