##// END OF EJS Templates
util: add an interpolate() function to for replacing multiple values...
Steve Losh -
r11988:8380ed69 default
parent child Browse files
Show More
@@ -222,8 +222,8 b' def filemerge(repo, mynode, orig, fcd, f'
222 if "$output" in args:
222 if "$output" in args:
223 out, a = a, back # read input from backup, write to original
223 out, a = a, back # read input from backup, write to original
224 replace = dict(local=a, base=b, other=c, output=out)
224 replace = dict(local=a, base=b, other=c, output=out)
225 args = re.sub("\$(local|base|other|output)",
225 args = util.interpolate(r'\$', replace, args,
226 lambda x: '"%s"' % util.localpath(replace[x.group()[1:]]), args)
226 lambda s: '"%s"' % util.localpath(s))
227 r = util.system(toolpath + ' ' + args, cwd=repo.root, environ=env)
227 r = util.system(toolpath + ' ' + args, cwd=repo.root, environ=env)
228
228
229 if not r and (_toolbool(ui, tool, "checkconflicts") or
229 if not r and (_toolbool(ui, tool, "checkconflicts") or
@@ -1408,3 +1408,18 b' def termwidth():'
1408 except ValueError:
1408 except ValueError:
1409 pass
1409 pass
1410 return termwidth_()
1410 return termwidth_()
1411
1412 def interpolate(prefix, mapping, s, fn=None):
1413 """Return the result of interpolating items in the mapping into string s.
1414
1415 prefix is a single character string, or a two character string with
1416 a backslash as the first character if the prefix needs to be escaped in
1417 a regular expression.
1418
1419 fn is an optional function that will be applied to the replacement text
1420 just before replacement.
1421 """
1422 fn = fn or (lambda s: s)
1423 r = re.compile(r'%s(%s)' % (prefix, '|'.join(mapping.keys())))
1424 return r.sub(lambda x: fn(mapping[x.group()[1:]]), s)
1425
General Comments 0
You need to be logged in to leave comments. Login now