hgweb: don't redundantly pass templater with requestcontext (API)
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 10 Mar 2018 19:46:54 -0800
changeset 36885 c68e79dcf21c
parent 36884 ece242db5000
child 36886 563fd95a6efb
hgweb: don't redundantly pass templater with requestcontext (API) The requestcontenxt has a ``tmpl`` attribute to access the templater. We don't need to pass the templater explicitly when passing a requestcontext instance. .. api:: Various helper functions in hgweb.webutil no longer accept a templater instance. Access the templater through the ``web`` argument instead. Differential Revision: https://phab.mercurial-scm.org/D2801
mercurial/hgweb/webcommands.py
mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webcommands.py	Sat Mar 10 20:38:28 2018 -0800
+++ b/mercurial/hgweb/webcommands.py	Sat Mar 10 19:46:54 2018 -0800
@@ -399,7 +399,7 @@
             if curcount > revcount + 1:
                 break
 
-            entry = webutil.changelistentry(web, web.repo[rev], web.tmpl)
+            entry = webutil.changelistentry(web, web.repo[rev])
             entry['parity'] = next(parity)
             yield entry
 
@@ -485,7 +485,7 @@
 
     return web.sendtemplate(
         'changeset',
-        **webutil.changesetentry(web, req, web.tmpl, ctx))
+        **webutil.changesetentry(web, req, ctx))
 
 rev = webcommand('rev')(changeset)
 
@@ -808,7 +808,7 @@
     if 'style' in web.req.qsparams:
         style = web.req.qsparams['style']
 
-    diffs = webutil.diffs(web, web.tmpl, ctx, basectx, [path], style)
+    diffs = webutil.diffs(web, ctx, basectx, [path], style)
     if fctx is not None:
         rename = webutil.renamelink(fctx)
         ctx = fctx
@@ -1066,7 +1066,7 @@
         ctx = fctx.changectx()
         basectx = ctx.p1()
         path = fctx.path()
-        return webutil.diffs(web, web.tmpl, ctx, basectx, [path], diffstyle,
+        return webutil.diffs(web, ctx, basectx, [path], diffstyle,
                              linerange=linerange,
                              lineidprefix='%s-' % ctx.hex()[:12])
 
--- a/mercurial/hgweb/webutil.py	Sat Mar 10 20:38:28 2018 -0800
+++ b/mercurial/hgweb/webutil.py	Sat Mar 10 19:46:54 2018 -0800
@@ -389,7 +389,7 @@
         'child': lambda **x: children(ctx),
     }
 
-def changelistentry(web, ctx, tmpl):
+def changelistentry(web, ctx):
     '''Obtain a dictionary to be used for entries in a changelist.
 
     This function is called when producing items for the "entries" list passed
@@ -398,8 +398,8 @@
     repo = web.repo
     rev = ctx.rev()
     n = ctx.node()
-    showtags = showtag(repo, tmpl, 'changelogtag', n)
-    files = listfilediffs(tmpl, ctx.files(), n, web.maxfiles)
+    showtags = showtag(repo, web.tmpl, 'changelogtag', n)
+    files = listfilediffs(web.tmpl, ctx.files(), n, web.maxfiles)
 
     entry = commonentry(repo, ctx)
     entry.update(
@@ -417,11 +417,11 @@
     else:
         return short(ctx.node())
 
-def changesetentry(web, req, tmpl, ctx):
+def changesetentry(web, req, ctx):
     '''Obtain a dictionary to be used to render the "changeset" template.'''
 
-    showtags = showtag(web.repo, tmpl, 'changesettag', ctx.node())
-    showbookmarks = showbookmark(web.repo, tmpl, 'changesetbookmark',
+    showtags = showtag(web.repo, web.tmpl, 'changesettag', ctx.node())
+    showbookmarks = showbookmark(web.repo, web.tmpl, 'changesetbookmark',
                                  ctx.node())
     showbranch = nodebranchnodefault(ctx)
 
@@ -429,9 +429,9 @@
     parity = paritygen(web.stripecount)
     for blockno, f in enumerate(ctx.files()):
         template = 'filenodelink' if f in ctx else 'filenolink'
-        files.append(tmpl(template,
-                          node=ctx.hex(), file=f, blockno=blockno + 1,
-                          parity=next(parity)))
+        files.append(web.tmpl(template,
+                              node=ctx.hex(), file=f, blockno=blockno + 1,
+                              parity=next(parity)))
 
     basectx = basechangectx(web.repo, req)
     if basectx is None:
@@ -441,11 +441,11 @@
     if 'style' in req.req.qsparams:
         style = req.req.qsparams['style']
 
-    diff = diffs(web, tmpl, ctx, basectx, None, style)
+    diff = diffs(web, ctx, basectx, None, style)
 
     parity = paritygen(web.stripecount)
     diffstatsgen = diffstatgen(ctx, basectx)
-    diffstats = diffstat(tmpl, ctx, diffstatsgen, parity)
+    diffstats = diffstat(web.tmpl, ctx, diffstatsgen, parity)
 
     return dict(
         diff=diff,
@@ -466,7 +466,7 @@
     if len(files) > max:
         yield tmpl('fileellipses')
 
-def diffs(web, tmpl, ctx, basectx, files, style, linerange=None,
+def diffs(web, ctx, basectx, files, style, linerange=None,
           lineidprefix=''):
 
     def prettyprintlines(lines, blockno):
@@ -480,11 +480,12 @@
                 ltype = "difflineat"
             else:
                 ltype = "diffline"
-            yield tmpl(ltype,
-                       line=l,
-                       lineno=lineno,
-                       lineid=lineidprefix + "l%s" % difflineno,
-                       linenumber="% 8s" % difflineno)
+            yield web.tmpl(
+                ltype,
+                line=l,
+                lineno=lineno,
+                lineid=lineidprefix + "l%s" % difflineno,
+                linenumber="% 8s" % difflineno)
 
     repo = web.repo
     if files:
@@ -509,8 +510,8 @@
                     continue
             lines.extend(hunklines)
         if lines:
-            yield tmpl('diffblock', parity=next(parity), blockno=blockno,
-                       lines=prettyprintlines(lines, blockno))
+            yield web.tmpl('diffblock', parity=next(parity), blockno=blockno,
+                           lines=prettyprintlines(lines, blockno))
 
 def compare(tmpl, context, leftlines, rightlines):
     '''Generator function that provides side-by-side comparison data.'''