Patchwork [1,of,3] formatter: reorder code that builds template mapping

login
register
mail settings
Submitter Yuya Nishihara
Date April 2, 2017, 2:32 p.m.
Message ID <926cfc20a8563bd47263.1491143531@mimosa>
Download mbox | patch
Permalink /patch/19908/
State Accepted
Headers show

Comments

Yuya Nishihara - April 2, 2017, 2:32 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1491140598 -32400
#      Sun Apr 02 22:43:18 2017 +0900
# Node ID 926cfc20a8563bd4726380045dbf3207359b0922
# Parent  3a4cc3a42efc903f0fd900e9ec72444c1100c57b
formatter: reorder code that builds template mapping

This makes the future patch slightly simpler.

Patch

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -364,16 +364,16 @@  class templateformatter(baseformatter):
         # TODO: add support for filectx. probably each template keyword or
         # function will have to declare dependent resources. e.g.
         # @templatekeyword(..., requires=('ctx',))
+        props = {}
         if 'ctx' in self._item:
-            props = templatekw.keywords.copy()
-            # explicitly-defined fields precede templatekw
-            props.update(self._item)
+            props.update(templatekw.keywords)
+        # explicitly-defined fields precede templatekw
+        props.update(self._item)
+        if 'ctx' in self._item:
             # but template resources must be always available
             props['templ'] = self._t
             props['repo'] = props['ctx'].repo()
             props['revcache'] = {}
-        else:
-            props = self._item
         g = self._t(self._topic, ui=self._ui, cache=self._cache, **props)
         self._out.write(templater.stringify(g))