discovery: prefer loop to double-for list comprehension in changegroupsubset

The double-for form of list comprehensions gets particularly unreadable
when you throw in an 'if' condition. This expands the only remaining
instance of the double-for syntax in our codebase into a loop.
revlog: move file writing to a separate function

Moves the code that actually writes to a file to a separate function in
revlog.py. This allows extensions to intercept and use the data being written to
disk. For example, an extension might want to replicate these writes elsewhere.

When cloning the Mercurial repo on /dev/shm with --pull, I see about a 0.3% perf change.
It goes from 28.2 to 28.3 seconds.
templatekw: allow tagtypes other than global in getlatesttags

hg-git uses tagtype 'git', for example, so it's better
to check for tagtype != 'local', not strictly for 'global'
run-tests: better check for python version

Compare version by using pythons tuple comparison. So we do not match on python
3.0 or newer.