Mercurial > hg
changeset 48982:9dfbea54b680
partial-merge: add support for `.args` config (`$local` etc.)
It will be useful to be able to define custom command-line arguments
per partial merge tool just like we have for regular merge tools. In
particular, I expect the same binary to handle multiple languages, so
it will be useful to be able to pass some argument indicating the
language, or perhaps simply an argument defining a regex that's used
for finding lines to merge as a sorted set.
Differential Revision: https://phab.mercurial-scm.org/D12383
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 17 Mar 2022 11:19:06 -0700 |
parents | f3aafd785e65 |
children | 533820f5b997 |
files | mercurial/configitems.py mercurial/filemerge.py tests/test-merge-partial-tool.t |
diffstat | 3 files changed, 57 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/configitems.py Tue Jan 18 13:05:21 2022 -0800 +++ b/mercurial/configitems.py Thu Mar 17 11:19:06 2022 -0700 @@ -1601,6 +1601,14 @@ experimental=True, ) coreconfigitem( + b'partial-merge-tools', + br'.*\.args', + default=b"$local $base $other", + generic=True, + priority=-1, + experimental=True, +) +coreconfigitem( b'merge-tools', b'.*', default=None,
--- a/mercurial/filemerge.py Tue Jan 18 13:05:21 2022 -0800 +++ b/mercurial/filemerge.py Thu Mar 17 11:19:06 2022 -0700 @@ -1119,7 +1119,7 @@ def _run_partial_resolution_tools(repo, local, other, base): """Runs partial-resolution tools on the three inputs and updates them.""" ui = repo.ui - # Tuples of (order, name, executable path) + # Tuples of (order, name, executable path, args) tools = [] seen = set() section = b"partial-merge-tools" @@ -1135,7 +1135,8 @@ if is_match: order = ui.configint(section, b'%s.order' % name, 0) executable = ui.config(section, b'%s.executable' % name, name) - tools.append((order, name, executable)) + args = ui.config(section, b'%s.args' % name) + tools.append((order, name, executable, args)) if not tools: return @@ -1151,11 +1152,21 @@ with _maketempfiles(files) as temppaths: localpath, basepath, otherpath = temppaths - for order, name, executable in tools: + for order, name, executable, args in tools: cmd = procutil.shellquote(executable) - # TODO: Allow the user to configure the command line using - # $local, $base, $other. - cmd = b'%s %s %s %s' % (cmd, localpath, basepath, otherpath) + replace = { + b'local': localpath, + b'base': basepath, + b'other': otherpath, + } + args = util.interpolate( + br'\$', + replace, + args, + lambda s: procutil.shellquote(util.localpath(s)), + ) + + cmd = b'%s %s' % (cmd, args) r = ui.system(cmd, cwd=repo.root, blockedtag=b'partial-mergetool') if r: raise error.StateError(
--- a/tests/test-merge-partial-tool.t Tue Jan 18 13:05:21 2022 -0800 +++ b/tests/test-merge-partial-tool.t Thu Mar 17 11:19:06 2022 -0700 @@ -207,3 +207,35 @@ c d e3 + +Test that arguments get passed as expected. + + $ cat >> "$TESTTMP/log-args.sh" <<'EOF' + > #!/bin/sh + > echo "$@" > args.log + > EOF + $ chmod +x "$TESTTMP/log-args.sh" + $ cat >> "$HGRCPATH" <<EOF + > [partial-merge-tools] + > log-args.executable=$TESTTMP/log-args.sh + > EOF + $ hg up -C 2 + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg merge 1 + merging file + warning: conflicts while merging file! (edit, then use 'hg resolve --mark') + 0 files updated, 0 files merged, 0 files removed, 1 files unresolved + use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon + [1] + $ cat args.log + */hgmerge-*/file~local */hgmerge-*/file~base */hgmerge-*/file~other (glob) + $ hg up -C 2 + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg merge 1 --config partial-merge-tools.log-args.args='--other $other $base --foo --local $local --also-other $other' + merging file + warning: conflicts while merging file! (edit, then use 'hg resolve --mark') + 0 files updated, 0 files merged, 0 files removed, 1 files unresolved + use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon + [1] + $ cat args.log + --other */hgmerge-*/file~other */hgmerge-*/file~base --foo --local */hgmerge-*/file~local --also-other */hgmerge-*/file~other (glob)