Patchwork [2,of,3] hgweb: mark all lambda template keywords as new-style function

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 6, 2018, 1:53 p.m.
Message ID <7633562bfbe0ca069194.1533563629@mimosa>
Download mbox | patch
Permalink /patch/33333/
State New
Headers show

Comments

Yuya Nishihara - Aug. 6, 2018, 1:53 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1532780364 -32400
#      Sat Jul 28 21:19:24 2018 +0900
# Node ID 7633562bfbe0ca069194cd0f86043cf31a6d78e0
# Parent  85ca5ee20667c00b087d4a817f240545704f547d
hgweb: mark all lambda template keywords as new-style function

This is just a temporary workaround, and will be removed in Mercurial 4.9.

Patch

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -408,6 +408,12 @@  def whyunstable(context, mapping):
 
 whyunstable._requires = {'repo', 'ctx'}
 
+# helper to mark a function as a new-style template keyword; can be removed
+# once old-style function gets unsupported and new-style becomes the default
+def _kwfunc(f):
+    f._requires = ()
+    return f
+
 def commonentry(repo, ctx):
     node = ctx.node()
     return {
@@ -432,8 +438,8 @@  def commonentry(repo, ctx):
         'branches': nodebranchdict(repo, ctx),
         'tags': nodetagsdict(repo, node),
         'bookmarks': nodebookmarksdict(repo, node),
-        'parent': lambda **x: parents(ctx),
-        'child': lambda **x: children(ctx),
+        'parent': _kwfunc(lambda context, mapping: parents(ctx)),
+        'child': _kwfunc(lambda context, mapping: children(ctx)),
     }
 
 def changelistentry(web, ctx):
@@ -450,9 +456,9 @@  def changelistentry(web, ctx):
 
     entry = commonentry(repo, ctx)
     entry.update(
-        allparents=lambda **x: parents(ctx),
-        parent=lambda **x: parents(ctx, rev - 1),
-        child=lambda **x: children(ctx, rev + 1),
+        allparents=_kwfunc(lambda context, mapping: parents(ctx)),
+        parent=_kwfunc(lambda context, mapping: parents(ctx, rev - 1)),
+        child=_kwfunc(lambda context, mapping: children(ctx, rev + 1)),
         changelogtag=showtags,
         files=files,
     )
@@ -521,7 +527,7 @@  def changesetentry(web, ctx):
         changesetbranch=showbranch,
         files=templateutil.mappedgenerator(_listfilesgen,
                                            args=(ctx, web.stripecount)),
-        diffsummary=lambda **x: diffsummary(diffstatsgen),
+        diffsummary=_kwfunc(lambda context, mapping: diffsummary(diffstatsgen)),
         diffstat=diffstats,
         archives=web.archivelist(ctx.hex()),
         **pycompat.strkwargs(commonentry(web.repo, ctx)))