Mercurial > public > mercurial-scm > hg-stable
diff mercurial/filemerge.py @ 11988:8380ed691df8
util: add an interpolate() function to for replacing multiple values
util.interpolate can be used to replace multiple items in a string all at once
(and optionally apply a function to the replacement), without worrying about
recursing:
>>> import util
>>> s = '$foo, $spam'
>>> util.interpolate(r'\$', { 'foo': 'bar', 'spam': 'eggs' }, s)
'bar, eggs'
>>> util.interpolate(r'\$', { 'foo': 'spam', 'spam': 'foo' }, s)
'spam, foo'
>>> util.interpolate(r'\$', { 'foo': 'spam', 'spam': 'foo' }, s, lambda s: s.upper())
'SPAM, FOO'
The patch also changes filemerge.py to use this new function.
author | Steve Losh <steve@stevelosh.com> |
---|---|
date | Wed, 18 Aug 2010 18:18:26 -0400 |
parents | eb07fbc21e9c |
children | ce818cf215dc |
line wrap: on
line diff
--- a/mercurial/filemerge.py Thu Aug 19 11:14:09 2010 -0500 +++ b/mercurial/filemerge.py Wed Aug 18 18:18:26 2010 -0400 @@ -222,8 +222,8 @@ if "$output" in args: out, a = a, back # read input from backup, write to original replace = dict(local=a, base=b, other=c, output=out) - args = re.sub("\$(local|base|other|output)", - lambda x: '"%s"' % util.localpath(replace[x.group()[1:]]), args) + args = util.interpolate(r'\$', replace, args, + lambda s: '"%s"' % util.localpath(s)) r = util.system(toolpath + ' ' + args, cwd=repo.root, environ=env) if not r and (_toolbool(ui, tool, "checkconflicts") or