changeset 38027:3f70466ec7aa

hgweb: move prettyprintlines() closure out of diffs() This will be wrapped with mappedgenerator.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 03 Apr 2018 23:38:19 +0900
parents b9e6b71dc272
children 6a4de2dc78dd
files mercurial/hgweb/webutil.py
diffstat 1 files changed, 20 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/webutil.py	Sun Apr 29 22:27:05 2018 +0530
+++ b/mercurial/hgweb/webutil.py	Tue Apr 03 23:38:19 2018 +0900
@@ -519,27 +519,26 @@
     return templateutil.mappedgenerator(_listfilediffsgen,
                                         args=(files, node, max))
 
+def _prettyprintdifflines(tmpl, lines, blockno, lineidprefix):
+    for lineno, l in enumerate(lines, 1):
+        difflineno = "%d.%d" % (blockno, lineno)
+        if l.startswith('+'):
+            ltype = "difflineplus"
+        elif l.startswith('-'):
+            ltype = "difflineminus"
+        elif l.startswith('@'):
+            ltype = "difflineat"
+        else:
+            ltype = "diffline"
+        yield tmpl.generate(ltype, {
+            'line': l,
+            'lineno': lineno,
+            'lineid': lineidprefix + "l%s" % difflineno,
+            'linenumber': "% 8s" % difflineno,
+        })
+
 def diffs(web, ctx, basectx, files, style, linerange=None,
           lineidprefix=''):
-
-    def prettyprintlines(lines, blockno):
-        for lineno, l in enumerate(lines, 1):
-            difflineno = "%d.%d" % (blockno, lineno)
-            if l.startswith('+'):
-                ltype = "difflineplus"
-            elif l.startswith('-'):
-                ltype = "difflineminus"
-            elif l.startswith('@'):
-                ltype = "difflineat"
-            else:
-                ltype = "diffline"
-            yield web.tmpl.generate(ltype, {
-                'line': l,
-                'lineno': lineno,
-                'lineid': lineidprefix + "l%s" % difflineno,
-                'linenumber': "% 8s" % difflineno,
-            })
-
     repo = web.repo
     if files:
         m = match.exact(repo.root, repo.getcwd(), files)
@@ -566,7 +565,8 @@
             yield web.tmpl.generate('diffblock', {
                 'parity': next(parity),
                 'blockno': blockno,
-                'lines': prettyprintlines(lines, blockno),
+                'lines': _prettyprintdifflines(web.tmpl, lines, blockno,
+                                               lineidprefix),
             })
 
 def compare(tmpl, context, leftlines, rightlines):