tests/test-convert-hg-svn
author David Greenaway <hg-dev@davidgreenaway.com>
Sat, 03 Apr 2010 11:58:16 +1100
changeset 11060 e6df01776e08
parent 10775 c52057614c72
permissions -rwxr-xr-x
findrenames: Optimise "addremove -s100" by matching files by their SHA1 hashes. We speed up 'findrenames' for the usecase when a user specifies they want a similarity of 100% by matching files by their exact SHA1 hash value. This reduces the number of comparisons required to find exact matches from O(n^2) to O(n). While it would be nice if we could just use mercurial's pre-calculated SHA1 hash for existing files, this hash includes the file's ancestor information making it unsuitable for our purposes. Instead, we calculate the hash of old content from scratch. The following benchmarks were taken on the current head of crew: addremove 100% similarity: rm -rf *; hg up -C; mv tests tests.new hg --time addremove -s100 --dry-run before: real 176.350 secs (user 128.890+0.000 sys 47.430+0.000) after: real 2.130 secs (user 1.890+0.000 sys 0.240+0.000) addremove 75% similarity: rm -rf *; hg up -C; mv tests tests.new; \ for i in tests.new/*; do echo x >> $i; done hg --time addremove -s75 --dry-run before: real 264.560 secs (user 215.130+0.000 sys 49.410+0.000) after: real 218.710 secs (user 172.790+0.000 sys 45.870+0.000)

#!/bin/sh

"$TESTDIR/hghave" svn svn-bindings || exit 80

fix_path()
{
    tr '\\' /
}

echo "[extensions]" >> $HGRCPATH
echo "convert = " >> $HGRCPATH
echo "mq = " >> $HGRCPATH

svnpath=`pwd | fix_path`/svn-repo
svnadmin create "$svnpath"

cat > "$svnpath"/hooks/pre-revprop-change <<'EOF'
#!/bin/sh

REPOS="$1"
REV="$2"
USER="$3"
PROPNAME="$4"
ACTION="$5"

if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi
if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-branch" ]; then exit 0; fi
if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-rev" ]; then exit 0; fi

echo "Changing prohibited revision property" >&2
exit 1
EOF
chmod +x "$svnpath"/hooks/pre-revprop-change

# SVN wants all paths to start with a slash. Unfortunately,
# Windows ones don't. Handle that.
svnurl="$svnpath"
expr "$svnurl" : "\/" > /dev/null
if [ $? -ne 0 ]; then
    svnurl="/$svnurl"
fi
svnurl="file://$svnurl"
svn co "$svnurl" "$svnpath"-wc

cd "$svnpath"-wc
echo a > a
svn add a
svn ci -m'added a' a

cd ..

echo % initial roundtrip
hg convert -s svn -d hg "$svnpath"-wc "$svnpath"-hg | grep -v initializing
hg convert -s hg -d svn "$svnpath"-hg "$svnpath"-wc

echo % second roundtrip should do nothing
hg convert -s svn -d hg "$svnpath"-wc "$svnpath"-hg
hg convert -s hg -d svn "$svnpath"-hg "$svnpath"-wc

echo % new hg rev

hg clone "$svnpath"-hg "$svnpath"-work
cd "$svnpath"-work
echo b > b
hg add b
hg ci -mb
echo '% adding an empty revision'
hg qnew -m emtpy empty
hg qfinish -a
cd ..

echo % echo hg to svn
hg --cwd "$svnpath"-hg pull -q "$svnpath"-work
hg convert -s hg -d svn "$svnpath"-hg "$svnpath"-wc

echo % svn back to hg should do nothing
hg convert -s svn -d hg "$svnpath"-wc "$svnpath"-hg
echo % hg back to svn should do nothing
hg convert -s hg -d svn "$svnpath"-hg "$svnpath"-wc