Show More
@@ -504,6 +504,10 class templateresources(templater.resour | |||||
504 | 'ui': ui, |
|
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 | def knownkeys(self): |
|
511 | def knownkeys(self): | |
508 | return self._knownkeys |
|
512 | return self._knownkeys | |
509 |
|
513 |
@@ -563,6 +563,10 class resourcemapper(object): | |||||
563 | __metaclass__ = abc.ABCMeta |
|
563 | __metaclass__ = abc.ABCMeta | |
564 |
|
564 | |||
565 | @abc.abstractmethod |
|
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 | def knownkeys(self): |
|
570 | def knownkeys(self): | |
567 | """Return a set of supported resource keys""" |
|
571 | """Return a set of supported resource keys""" | |
568 |
|
572 | |||
@@ -571,6 +575,9 class resourcemapper(object): | |||||
571 | """Return a resource for the key if available; otherwise None""" |
|
575 | """Return a resource for the key if available; otherwise None""" | |
572 |
|
576 | |||
573 | class nullresourcemapper(resourcemapper): |
|
577 | class nullresourcemapper(resourcemapper): | |
|
578 | def availablekeys(self, context, mapping): | |||
|
579 | return set() | |||
|
580 | ||||
574 | def knownkeys(self): |
|
581 | def knownkeys(self): | |
575 | return set() |
|
582 | return set() | |
576 |
|
583 | |||
@@ -616,10 +623,23 class engine(object): | |||||
616 | def overlaymap(self, origmapping, newmapping): |
|
623 | def overlaymap(self, origmapping, newmapping): | |
617 | """Create combined mapping from the original mapping and partial |
|
624 | """Create combined mapping from the original mapping and partial | |
618 | mapping to override the original""" |
|
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 | mapping.update(newmapping) |
|
633 | mapping.update(newmapping) | |
621 | return mapping |
|
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 | def symbol(self, mapping, key): |
|
643 | def symbol(self, mapping, key): | |
624 | """Resolve symbol to value or function; None if nothing found""" |
|
644 | """Resolve symbol to value or function; None if nothing found""" | |
625 | v = None |
|
645 | v = None |
@@ -63,6 +63,16 test template keywords and functions whi | |||||
63 | $ hg id -T '{parents % "{rev} {node|shortest} {desc}\n"}' |
|
63 | $ hg id -T '{parents % "{rev} {node|shortest} {desc}\n"}' | |
64 | 0 cb9a a |
|
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 | with modifications |
|
76 | with modifications | |
67 |
|
77 | |||
68 | $ echo b > a |
|
78 | $ echo b > a |
General Comments 0
You need to be logged in to leave comments.
Login now