Bourne shell 'test' does not support '-e' flag. Using '-r' instead.
Then discovered 'hg' was being called three times per pass, so re-ordered
things so just once.
Finally tidied up the if/then/... structure and separated out the
writing of the output file.
Mercurial revision: 624c2470a9858d041e9abbec800dda7361008725