Patchwork [6,of,9] hgweb: make templater mostly compatible with log templates

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 27, 2018, 2:57 p.m.
Message ID <937e0cab3a4d11da84d2.1519743479@mimosa>
Download mbox | patch
Permalink /patch/28466/
State New
Headers show

Comments

Yuya Nishihara - Feb. 27, 2018, 2:57 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1513947578 -32400
#      Fri Dec 22 21:59:38 2017 +0900
# Node ID 937e0cab3a4d11da84d2f62213901e7405e117ea
# Parent  c5d3987504112f372d4d25dfa7e6dec1eb58d1af
hgweb: make templater mostly compatible with log templates

Prepares for gradually switching templatekw.showsuccsandmarkers() to new API.

This was a PoC showing how to reuse templatekw functions in hgweb. We could
remove rev, node, author, etc. from the commonentry() table, but we'll have
to carefully remove all corresponding symbols from webcommands.*(). Otherwise,
we would face the issue5612.

Still templatekw.keywords aren't exported. Otherwise some tests would fail
because the atom template expects {files} to be empty in filelog, but
templatekw.showfiles() provides the {files} implementation.

Patch

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -27,6 +27,7 @@  from .request import wsgirequest
 from .. import (
     encoding,
     error,
+    formatter,
     hg,
     hook,
     profiling,
@@ -197,7 +198,7 @@  class requestcontext(object):
             return templatefilters.websub(text, self.websubtable)
 
         # create the templater
-
+        # TODO: export all keywords: defaults = templatekw.keywords.copy()
         defaults = {
             'url': req.url,
             'logourl': logourl,
@@ -212,9 +213,11 @@  class requestcontext(object):
             'style': style,
             'nonce': self.nonce,
         }
+        tres = formatter.templateresources(self.repo.ui, self.repo)
         tmpl = templater.templater.frommapfile(mapfile,
                                                filters={'websub': websubfilter},
-                                               defaults=defaults)
+                                               defaults=defaults,
+                                               resources=tres)
         return tmpl
 
 
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -352,8 +352,8 @@  def linerange(req):
 def formatlinerange(fromline, toline):
     return '%d:%d' % (fromline + 1, toline)
 
-def succsandmarkers(repo, ctx):
-    for item in templatekw.showsuccsandmarkers(repo, ctx):
+def succsandmarkers(repo, ctx, **args):
+    for item in templatekw.showsuccsandmarkers(repo, ctx, **args):
         item['successors'] = _siblings(repo[successor]
                                        for successor in item['successors'])
         yield item
@@ -361,6 +361,11 @@  def succsandmarkers(repo, ctx):
 def commonentry(repo, ctx):
     node = ctx.node()
     return {
+        # TODO: perhaps ctx.changectx() should be assigned if ctx is a
+        # filectx, but I'm not pretty sure if that would always work because
+        # fctx.parents() != fctx.changectx.parents() for example.
+        'ctx': ctx,
+        'revcache': {},
         'rev': ctx.rev(),
         'node': hex(node),
         'author': ctx.user(),
@@ -369,7 +374,7 @@  def commonentry(repo, ctx):
         'extra': ctx.extra(),
         'phase': ctx.phasestr(),
         'obsolete': ctx.obsolete(),
-        'succsandmarkers': lambda **x: succsandmarkers(repo, ctx),
+        'succsandmarkers': succsandmarkers,
         'instabilities': [{"instability": i} for i in ctx.instabilities()],
         'branch': nodebranchnodefault(ctx),
         'inbranch': nodeinbranch(repo, ctx),