D5094: merge-tools: when calling external merge tool, describe the resolve inputs
spectral (Kyle Lippincott)
phabricator at mercurial-scm.org
Thu Nov 1 19:02:20 EDT 2018
spectral added a comment.
In https://phab.mercurial-scm.org/D5094#77146, @yuja wrote:
> > > We might want to structure these variables as `base.node|short` instead of
> > > `base_node` for example, but that would require more work.
>
> [...]
>
> > Unfortunately, this doesn't work super well, when using the following flags:
>
> There isn't a building block for a mapping dict holding mapping dicts, and
> the formatter API doesn't support such structure either.
>
> Fortunately, we don't need a formatter here since we just want to apply
> a template to a single item. So if we had a wrapper for a single mapping
> dict, the templater can be rendered as follows:
>
> props = {
> 'base': templateutil.mappingdict({'ctx': fca.changectx(), 'fctx': fca,
> 'label': baselabel})
> ...
> }
> cmdutil.rendertemplate(fcd.changectx(), tmpl, props)
>
>
> And `base.path`, `base.node`, etc. should just work.
Done.
> I'll post the dict wrapper if you like the idea.
>
> class mappingdict(mappable, _mappingsequence):
> """Wrapper for a single template mapping
>
> This isn't a sequence in a way that the underlying dict won't be iterated
> as a dict, but shares most of the _mappingsequence functions.
> """
>
> def __init__(self, mapping, name=None, tmpl=None):
> super(mappingdict, self).__init__(name, tmpl)
> self._mapping = mapping
>
> def tomap(self, context):
> return self._mapping
>
> def tobool(self, context, mapping):
> # no idea when a template mapping should be considered an empty, but
> # a mapping dict should have at least one item in practice, so always
> # mark this as non-empty.
> return True
>
> def tovalue(self, context, mapping):
> return super(mappingdict, self).tovalue(context, mapping)[0]
I copy/pasted this to https://phab.mercurial-scm.org/D5211. :)
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D5094
To: spectral, #hg-reviewers
Cc: yuja, mjpieters, mercurial-devel
More information about the Mercurial-devel
mailing list