Mercurial > hg
comparison mercurial/templatekw.py @ 45676:f95b23283760
templatekw: make {successorssets} always return a list (issue6342)
Previously, {successorssets} returns an empty string instead of an empty list
for a non-obsolete changeset. The changing type of the JSON output makes it
hard to consume from statically-typed languages.
Differential Revision: https://phab.mercurial-scm.org/D9158
author | Aay Jay Chan <aayjaychan@itopia.com.hk> |
---|---|
date | Wed, 07 Oct 2020 00:45:41 +0800 |
parents | 85b03b1e4715 |
children | f67741e8264b |
comparison
equal
deleted
inserted
replaced
45675:59ab71498bee | 45676:f95b23283760 |
---|---|
710 """Returns a string of sets of successors for a changectx. Format used | 710 """Returns a string of sets of successors for a changectx. Format used |
711 is: [ctx1, ctx2], [ctx3] if ctx has been split into ctx1 and ctx2 | 711 is: [ctx1, ctx2], [ctx3] if ctx has been split into ctx1 and ctx2 |
712 while also diverged into ctx3. (EXPERIMENTAL)""" | 712 while also diverged into ctx3. (EXPERIMENTAL)""" |
713 repo = context.resource(mapping, b'repo') | 713 repo = context.resource(mapping, b'repo') |
714 ctx = context.resource(mapping, b'ctx') | 714 ctx = context.resource(mapping, b'ctx') |
715 if not ctx.obsolete(): | |
716 return b'' | |
717 | |
718 ssets = obsutil.successorssets(repo, ctx.node(), closest=True) | |
719 ssets = [[hex(n) for n in ss] for ss in ssets] | |
720 | |
721 data = [] | 715 data = [] |
722 for ss in ssets: | 716 |
723 h = _hybrid( | 717 if ctx.obsolete(): |
724 None, | 718 ssets = obsutil.successorssets(repo, ctx.node(), closest=True) |
725 ss, | 719 ssets = [[hex(n) for n in ss] for ss in ssets] |
726 lambda x: {b'ctx': repo[x]}, | 720 |
727 lambda x: scmutil.formatchangeid(repo[x]), | 721 for ss in ssets: |
728 ) | 722 h = _hybrid( |
729 data.append(h) | 723 None, |
724 ss, | |
725 lambda x: {b'ctx': repo[x]}, | |
726 lambda x: scmutil.formatchangeid(repo[x]), | |
727 ) | |
728 data.append(h) | |
730 | 729 |
731 # Format the successorssets | 730 # Format the successorssets |
732 def render(d): | 731 def render(d): |
733 return templateutil.stringify(context, mapping, d) | 732 return templateutil.stringify(context, mapping, d) |
734 | 733 |