Re: D5094: merge-tools: when calling external merge tool, describe the resolve inputs

2018-11-02 Thread Yuya Nishihara
>   >   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. :)

I sent my version with `{p1}/{p2}` example.

You don't need to update this series. I'll queue it once my patches are
accepted.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: D5094: merge-tools: when calling external merge tool, describe the resolve inputs

2018-10-19 Thread Yuya Nishihara
>   > 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.

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]
```
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: D5094: merge-tools: when calling external merge tool, describe the resolve inputs

2018-10-16 Thread Yuya Nishihara
> +def _describemerge(ui, repo, env, toolpath, args):
> +template = ui.config('ui', 'pre-merge-tool-output-template')
> +if not template:
> +return
> +
> +# Remove HG_ prefix from entries in `env` and lowercase them
> +def sanitizeenv(k):
> +if k.startswith('HG_'):
> +return k[3:].lower()
> +return k

Nit: `HG_FILE` should be called as `path` per
https://www.mercurial-scm.org/wiki/GenericTemplatingPlan#Dictionary

We might want to structure these variables as `base.node|short` instead of
`base_node` for example, but that would require more work.

> +data = {sanitizeenv(k): v for k, v in env.items()}
> +data['toolpath'] = toolpath
> +data['toolargs'] = args
> +
> +# TODO: make all of this something that can be specified on a per-tool 
> basis
> +template = templater.unquotestring(template)
> +
> +fm = ui.formatter("extmerge", pycompat.byteskwargs({'template': 
> template}))
 
Unnecessary. It's bytes dict.

> +fm.data(repo=repo, **data)
  ^^
Here pycompat.strkwargs() would be needed.

And use `fm.context(repo=repo)` or `fm.context(fctx=fcd)` since `repo` is
unprintable.

> +coreconfigitem('ui', 'pre-merge-tool-output-template',
> +default=None,
> +)

Can you update the help/config.txt as well?
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel