Mercurial > hg
view tests/test-relink @ 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 | 750b7a4f01f6 |
children |
line wrap: on
line source
#!/bin/sh echo "[extensions]" >> $HGRCPATH echo "relink=" >> $HGRCPATH fix_path() { tr '\\' / } cat > arelinked.py <<EOF import sys, os from mercurial import util path1, path2 = sys.argv[1:3] if util.samefile(path1, path2): print '%s == %s' % (path1, path2) else: print '%s != %s' % (path1, path2) EOF echo '% create source repository' hg init repo cd repo echo '[ui]' > .hg/hgrc echo 'username= A. Foo <a.foo@bar.com>' >> .hg/hgrc echo a > a echo b > b hg ci -Am addfile echo a >> a echo a >> b hg ci -Am changefiles # Test files are read in binary mode python -c "file('.hg/store/data/dummy.i', 'wb').write('a\r\nb\n')" cd .. echo '% clone and pull to break links' hg clone --pull -r0 repo clone cd clone echo '[ui]' >> .hg/hgrc echo 'username= A. Baz <a.baz@bar.com>' >> .hg/hgrc hg pull -q echo b >> b hg ci -m changeb python -c "file('.hg/store/data/dummy.i', 'wb').write('a\nb\r\n')" echo '% relink' hg relink --debug | sed 's:relinking.*store:relinking .hg/store:g' \ | fix_path cd .. echo '% check hardlinks' python arelinked.py repo/.hg/store/data/a.i clone/.hg/store/data/a.i python arelinked.py repo/.hg/store/data/b.i clone/.hg/store/data/b.i