D5094: merge-tools: when calling external merge tool, describe the resolve inputs
spectral (Kyle Lippincott)
phabricator at mercurial-scm.org
Wed Oct 17 11:16:36 EDT 2018
spectral planned changes to this revision.
spectral added a comment.
In https://phab.mercurial-scm.org/D5094#76457, @yuja wrote:
> > +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
Done.
> We might want to structure these variables as `base.node|short` instead of
> `base_node` for example, but that would require more work.
I tried to do this, producing this json output:
{
"base": {"islink": false, "label": "base", "name": "base", "node": "TZ>fP͏~\u0019������%`������z3������)"},
"local": {"islink": false, "label": "working copy", "name": "local", "node": "ot���G-������xq���\u0001������o1c������"},
"other": {"islink": false, "label": "merge rev", "name": "other", "node": " ���`���\u0013s_\u0011������0������\u0002���������K������"},
"path": "mercurial/dispatch.py",
"toolargs": "/usr/local/google/home/spectral/src/hg/hg_work/mercurial/dispatch.py '/usr/local/google/tmp/tmp/dispatch~base.erx9yG.py' '/usr/local/google/tmp/tmp/dispatch~other.gbxRqg.py'",
"toolpath": "/bin/false"
}
Unfortunately, this doesn't work super well, when using the following flags:
--config ui.pre-merge-tool-output-template='{myfunc(local)}' --config 'templatealias.myfunc(d)="{d.label}"'
I get this error:
hg: parse error: {'node': 'ot\xc4G-\xd0\xc3\x92\xdcxq\x97\x01\x90\xdbo1c\xb1\x95', 'name': 'local', 'islink': False, 'label': 'working copy'} is not a dictionary
(keyword 'local' does not support member operation)
I can fix this with a pretty simple patch to templateutil's makewrapped, making it return hybriddict or hybridlist if it receives a dict or a list. I couldn't find any other similar ways of causing this error, though, so it's possible I'm doing something wrong?
Things I tried:
≻ hg log -r . -T'{myfunc(dict(k1="hi", k2="bye"))}' --config 'templatealias.myfunc(d)="{d.k1}"'
hi
≻ hg log -r . -T'{myfunc(namespaces)}' --config 'templatealias.myfunc(d)="{d.tags}"'
tip
I looked through all functions that accept 'formatteropts' and couldn't find any hg command that produces a dict that's *not* in a list. I also couldn't identify any way of interacting with these dicts-inside-of-lists as a single unit (i.e. `hg version -T'{extensions%"{extension|json}"}'` doesn't work: 'extension' isn't a way of referring to the dictionary that's in the 'extensions' list. I have to do something like `hg version -T'{extensions%dict(name, ver, bundled)|json)}'` to re-create the dictionary.)
>> + 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.
Done.
>
>
>> + fm.data(repo=repo, **data)
>
> ^^^^^^
>
> Here pycompat.strkwargs() would be needed.
Done.
> And use `fm.context(repo=repo)` or `fm.context(fctx=fcd)` since `repo` is
> unprintable.
Done. Did both (fm.context(repo=repo, fctx=fcl))
>
>
>> +coreconfigitem('ui', 'pre-merge-tool-output-template',
>> + default=None,
>> +)
>
> Can you update the help/config.txt as well?
Will do before sending final version (marking as 'changes planned' for now - I'm going to be unavailable for several days).
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