[PATCH 1 of 6] hgweb: extract generator of {files} from changesetentry()

Yuya Nishihara yuya at tcha.org
Thu May 10 14:16:06 UTC 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1522765532 -32400
#      Tue Apr 03 23:25:32 2018 +0900
# Node ID e732dac3aa0afd04b2192cbf723147e88f6a0d6f
# Parent  1943cc2fad78346bac406fa390fe2634e426338c
hgweb: extract generator of {files} from changesetentry()

This will be wrapped with mappedgenerator.

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -463,6 +463,17 @@ def symrevorshortnode(req, ctx):
     else:
         return short(ctx.node())
 
+def _listfilesgen(tmpl, ctx, stripecount):
+    parity = paritygen(stripecount)
+    for blockno, f in enumerate(ctx.files()):
+        template = 'filenodelink' if f in ctx else 'filenolink'
+        yield tmpl.generate(template, {
+            'node': ctx.hex(),
+            'file': f,
+            'blockno': blockno + 1,
+            'parity': next(parity),
+        })
+
 def changesetentry(web, ctx):
     '''Obtain a dictionary to be used to render the "changeset" template.'''
 
@@ -470,17 +481,6 @@ def changesetentry(web, ctx):
     showbookmarks = showbookmark(web.repo, 'changesetbookmark', ctx.node())
     showbranch = nodebranchnodefault(ctx)
 
-    files = []
-    parity = paritygen(web.stripecount)
-    for blockno, f in enumerate(ctx.files()):
-        template = 'filenodelink' if f in ctx else 'filenolink'
-        files.append(web.tmpl.generate(template, {
-            'node': ctx.hex(),
-            'file': f,
-            'blockno': blockno + 1,
-            'parity': next(parity),
-        }))
-
     basectx = basechangectx(web.repo, web.req)
     if basectx is None:
         basectx = ctx.p1()
@@ -502,7 +502,7 @@ def changesetentry(web, ctx):
         changesettag=showtags,
         changesetbookmark=showbookmarks,
         changesetbranch=showbranch,
-        files=files,
+        files=list(_listfilesgen(web.tmpl, ctx, web.stripecount)),
         diffsummary=lambda **x: diffsummary(diffstatsgen),
         diffstat=diffstats,
         archives=web.archivelist(ctx.hex()),


More information about the Mercurial-devel mailing list