##// END OF EJS Templates
templater: drop symbols which should be overridden by new 'ctx' (issue5612)...
Yuya Nishihara -
r37093:46859b43 default
parent child Browse files
Show More
@@ -504,6 +504,10 b' class templateresources(templater.resour'
504 504 'ui': ui,
505 505 }
506 506
507 def availablekeys(self, context, mapping):
508 return {k for k, g in self._gettermap.iteritems()
509 if g(self, context, mapping, k) is not None}
510
507 511 def knownkeys(self):
508 512 return self._knownkeys
509 513
@@ -563,6 +563,10 b' class resourcemapper(object):'
563 563 __metaclass__ = abc.ABCMeta
564 564
565 565 @abc.abstractmethod
566 def availablekeys(self, context, mapping):
567 """Return a set of available resource keys based on the given mapping"""
568
569 @abc.abstractmethod
566 570 def knownkeys(self):
567 571 """Return a set of supported resource keys"""
568 572
@@ -571,6 +575,9 b' class resourcemapper(object):'
571 575 """Return a resource for the key if available; otherwise None"""
572 576
573 577 class nullresourcemapper(resourcemapper):
578 def availablekeys(self, context, mapping):
579 return set()
580
574 581 def knownkeys(self):
575 582 return set()
576 583
@@ -616,10 +623,23 b' class engine(object):'
616 623 def overlaymap(self, origmapping, newmapping):
617 624 """Create combined mapping from the original mapping and partial
618 625 mapping to override the original"""
619 mapping = origmapping.copy()
626 # do not copy symbols which overrides the defaults depending on
627 # new resources, so the defaults will be re-evaluated (issue5612)
628 knownres = self._resources.knownkeys()
629 newres = self._resources.availablekeys(self, newmapping)
630 mapping = {k: v for k, v in origmapping.iteritems()
631 if (k in knownres # not a symbol per self.symbol()
632 or newres.isdisjoint(self._defaultrequires(k)))}
620 633 mapping.update(newmapping)
621 634 return mapping
622 635
636 def _defaultrequires(self, key):
637 """Resource keys required by the specified default symbol function"""
638 v = self._defaults.get(key)
639 if v is None or not callable(v):
640 return ()
641 return getattr(v, '_requires', ())
642
623 643 def symbol(self, mapping, key):
624 644 """Resolve symbol to value or function; None if nothing found"""
625 645 v = None
@@ -63,6 +63,16 b' test template keywords and functions whi'
63 63 $ hg id -T '{parents % "{rev} {node|shortest} {desc}\n"}'
64 64 0 cb9a a
65 65
66 test nested template: '{tags}'/'{node}' constants shouldn't override the
67 default keywords, but '{id}' persists because there's no default keyword
68 for '{id}' (issue5612)
69
70 $ hg id -T '{tags}\n'
71 tip
72 $ hg id -T '{revset("null:.") % "{rev}:{node|short} {tags} {id}\n"}'
73 -1:000000000000 cb9a9f314b8b
74 0:cb9a9f314b8b tip cb9a9f314b8b
75
66 76 with modifications
67 77
68 78 $ echo b > a
General Comments 0
You need to be logged in to leave comments. Login now