Patchwork [4,of,6] formatter: factor out function that detects node change and document it

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 2, 2018, 7:43 a.m.
Message ID <a216d798fdd777f6f063.1535874181@mimosa>
Download mbox | patch
Permalink /patch/34249/
State New
Headers show

Comments

Yuya Nishihara - Sept. 2, 2018, 7:43 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1528374973 -32400
#      Thu Jun 07 21:36:13 2018 +0900
# Node ID a216d798fdd777f6f06306dcdf4e6ee487fdddf6
# Parent  a7705bfb43080a977945aa42bec757b5ee88216c
formatter: factor out function that detects node change and document it

This prepares for demand loading of ctx/fctx objects. With this change,
'revcache' is also recreated if 'node' value changes, which will be needed
to support loading of ctx from (repo, node) pair.

Patch

diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -567,10 +567,9 @@  class templateresources(templater.resour
 
     def populatemap(self, context, origmapping, newmapping):
         mapping = {}
-        if self._hasctx(newmapping):
+        if self._hasnodespec(newmapping):
             mapping['revcache'] = {}  # per-ctx cache
-        if (('node' in origmapping or self._hasctx(origmapping))
-            and ('node' in newmapping or self._hasctx(newmapping))):
+        if self._hasnodespec(origmapping) and self._hasnodespec(newmapping):
             orignode = templateutil.runsymbol(context, origmapping, 'node')
             mapping['originalnode'] = orignode
         return mapping
@@ -581,8 +580,9 @@  class templateresources(templater.resour
             return v
         return self._resmap.get(key)
 
-    def _hasctx(self, mapping):
-        return 'ctx' in mapping
+    def _hasnodespec(self, mapping):
+        """Test if context revision is set or unset in the given mapping"""
+        return 'node' in mapping or 'ctx' in mapping
 
 def formatter(ui, out, topic, opts):
     template = opts.get("template", "")