comparison mercurial/filemerge.py @ 49061: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 db93041e5b1c
comparison
equal deleted inserted replaced
49060:f3aafd785e65 49061:9dfbea54b680
1117 1117
1118 1118
1119 def _run_partial_resolution_tools(repo, local, other, base): 1119 def _run_partial_resolution_tools(repo, local, other, base):
1120 """Runs partial-resolution tools on the three inputs and updates them.""" 1120 """Runs partial-resolution tools on the three inputs and updates them."""
1121 ui = repo.ui 1121 ui = repo.ui
1122 # Tuples of (order, name, executable path) 1122 # Tuples of (order, name, executable path, args)
1123 tools = [] 1123 tools = []
1124 seen = set() 1124 seen = set()
1125 section = b"partial-merge-tools" 1125 section = b"partial-merge-tools"
1126 for k, v in ui.configitems(section): 1126 for k, v in ui.configitems(section):
1127 name = k.split(b'.')[0] 1127 name = k.split(b'.')[0]
1133 m = match.match(repo.root, b'', patterns) 1133 m = match.match(repo.root, b'', patterns)
1134 is_match = m(local.fctx.path()) 1134 is_match = m(local.fctx.path())
1135 if is_match: 1135 if is_match:
1136 order = ui.configint(section, b'%s.order' % name, 0) 1136 order = ui.configint(section, b'%s.order' % name, 0)
1137 executable = ui.config(section, b'%s.executable' % name, name) 1137 executable = ui.config(section, b'%s.executable' % name, name)
1138 tools.append((order, name, executable)) 1138 args = ui.config(section, b'%s.args' % name)
1139 tools.append((order, name, executable, args))
1139 1140
1140 if not tools: 1141 if not tools:
1141 return 1142 return
1142 # Sort in configured order (first in tuple) 1143 # Sort in configured order (first in tuple)
1143 tools.sort() 1144 tools.sort()
1149 ] 1150 ]
1150 1151
1151 with _maketempfiles(files) as temppaths: 1152 with _maketempfiles(files) as temppaths:
1152 localpath, basepath, otherpath = temppaths 1153 localpath, basepath, otherpath = temppaths
1153 1154
1154 for order, name, executable in tools: 1155 for order, name, executable, args in tools:
1155 cmd = procutil.shellquote(executable) 1156 cmd = procutil.shellquote(executable)
1156 # TODO: Allow the user to configure the command line using 1157 replace = {
1157 # $local, $base, $other. 1158 b'local': localpath,
1158 cmd = b'%s %s %s %s' % (cmd, localpath, basepath, otherpath) 1159 b'base': basepath,
1160 b'other': otherpath,
1161 }
1162 args = util.interpolate(
1163 br'\$',
1164 replace,
1165 args,
1166 lambda s: procutil.shellquote(util.localpath(s)),
1167 )
1168
1169 cmd = b'%s %s' % (cmd, args)
1159 r = ui.system(cmd, cwd=repo.root, blockedtag=b'partial-mergetool') 1170 r = ui.system(cmd, cwd=repo.root, blockedtag=b'partial-mergetool')
1160 if r: 1171 if r:
1161 raise error.StateError( 1172 raise error.StateError(
1162 b'partial merge tool %s exited with code %d' % (name, r) 1173 b'partial merge tool %s exited with code %d' % (name, r)
1163 ) 1174 )