Patchwork [3,of,4] formatter: port handling of 'originalnode' to populatemap() hook

login
register
mail settings
Submitter Yuya Nishihara
Date March 22, 2018, 3:02 p.m.
Message ID <f55f39a2f6d079703583.1521730963@mimosa>
Download mbox | patch
Permalink /patch/29790/
State Accepted
Headers show

Comments

Yuya Nishihara - March 22, 2018, 3:02 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1521276067 -32400
#      Sat Mar 17 17:41:07 2018 +0900
# Node ID f55f39a2f6d079703583d27b7e8eb0965e3c8cbb
# Parent  9cb74d4a9abe21e1c9902dc17a145be6ab289173
formatter: port handling of 'originalnode' to populatemap() hook

This isn't a pure templating business, so let's move out of the templater
module.

Note that this works only in web templates where mapping['node'] is a static
value.

Patch

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -514,6 +514,8 @@  class templateresources(templater.resour
         mapping = {}
         if self._hasctx(newmapping):
             mapping['revcache'] = {}  # per-ctx cache
+        if 'node' in origmapping and 'node' in newmapping:
+            mapping['originalnode'] = origmapping['node']
         return mapping
 
     def _getsome(self, context, mapping, key):
diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -406,7 +406,6 @@  def runmap(context, mapping, data):
         if isinstance(v, dict):
             lm = context.overlaymap(mapping, v)
             lm['index'] = i
-            lm['originalnode'] = mapping.get('node')
             yield evalrawexp(context, lm, targ)
         else:
             # v is not an iterable of dicts, this happen when 'key'