D12383: partial-merge: add support for `.args` config (`$local` etc.)
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Thu Mar 17 20:02:16 UTC 2022
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
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.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D12383
AFFECTED FILES
mercurial/configitems.py
mercurial/filemerge.py
tests/test-merge-partial-tool.t
CHANGE DETAILS
diff --git a/tests/test-merge-partial-tool.t b/tests/test-merge-partial-tool.t
--- a/tests/test-merge-partial-tool.t
+++ b/tests/test-merge-partial-tool.t
@@ -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)
diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -1120,7 +1120,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"
@@ -1136,7 +1136,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
@@ -1152,11 +1153,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(
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -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,
To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list