cleanup: use the deque type where appropriate
There have been quite a few places where we pop elements off the
front of a list. This can turn O(n) algorithms into something more
like O(n**2). Python has provided a deque type that can do this
efficiently since at least 2.4.
As an example of the difference a deque can make, it improves
perfancestors performance on a Linux repo from 0.50 seconds to 0.36.
$ hg init
$ echo 0 > a
$ echo 0 > b
$ hg ci -A -m m
adding a
adding b
$ hg rm a
$ hg cat a
0
$ hg cat --decode a # more tests in test-encode
0
$ echo 1 > b
$ hg ci -m m
$ echo 2 > b
$ hg cat -r 0 a
0
$ hg cat -r 0 b
0
$ hg cat -r 1 a
a: no such file in rev 7040230c159c
[1]
$ hg cat -r 1 b
1