[PATCH 4 of 4] hgweb: export all log template keywords (PoC)

Yuya Nishihara yuya at tcha.org
Fri Dec 22 09:08:30 EST 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1513947578 -32400
#      Fri Dec 22 21:59:38 2017 +0900
# Node ID 440f1555555c6a6d3ef2c1c88520519b1dd9586b
# Parent  d8f9134603553151fd0669d7235729f09188fc53
hgweb: export all log template keywords (PoC)

This is 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.

Some tests fail because the atom template expects {files} to be empty in
filelog, but now templatekw.showfiles() is available by default.

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,12 +27,14 @@ from .request import wsgirequest
 from .. import (
     encoding,
     error,
+    formatter,
     hg,
     hook,
     profiling,
     pycompat,
     repoview,
     templatefilters,
+    templatekw,
     templater,
     ui as uimod,
     util,
@@ -199,8 +201,8 @@ class requestcontext(object):
             return templatefilters.websub(text, self.websubtable)
 
         # create the templater
-
-        defaults = {
+        defaults = templatekw.keywords.copy()
+        defaults.update({
             'url': req.url,
             'logourl': logourl,
             'logoimg': logoimg,
@@ -213,10 +215,12 @@ class requestcontext(object):
             'pathdef': makebreadcrumb(req.url),
             '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
@@ -354,6 +354,11 @@ def formatlinerange(fromline, toline):
 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(),


More information about the Mercurial-devel mailing list