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
hgcommit() {
hg commit -u user -d '0 0' "$@"
}
hg init clhead
cd clhead
touch foo && hg add && hgcommit -m 'foo'
touch bar && hg add && hgcommit -m 'bar'
touch baz && hg add && hgcommit -m 'baz'
echo "flub" > foo
hgcommit -m "flub"
echo "nub" > foo
hgcommit -m "nub"
hg up -C 2
echo "c1" > c1
hg add c1
hgcommit -m "c1"
echo "c2" > c1
hgcommit -m "c2"
hg up -C 2
echo "d1" > d1
hg add d1
hgcommit -m "d1"
echo "d2" > d1
hgcommit -m "d2"
hg tag -l good
echo '% fail with three heads'
hg up -C good
hg merge
echo '% close one of the heads'
hg up -C 6
hgcommit -m 'close this head' --close-branch
echo '% succeed with two open heads'
hg up -C good
hg up -C good
hg merge
hgcommit -m 'merged heads'